aboutsummaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
authorForest Bond <forest@alittletooquiet.net>2009-04-25 10:30:44 -0400
committerGreg Kroah-Hartman <gregkh@suse.de>2009-06-19 14:00:51 -0400
commit5449c685a4b39534f18869a93896370224463715 (patch)
treedfe5ddb2fef11dc59ccb9720c086583b7d62c6a8 /drivers
parentbe2e10710b1c330d25e66724ef10b8aabdae4a83 (diff)
Staging: Add pristine upstream vt6655 driver sources
Add pristine upstream vt6655 driver sources to drivers/staging/vt6655. These files were literally copied from the driver directory in the upstream source archive, available here: http://www.viaarena.com/Driver/vt6655_linux_src_v1.19.12_x86.zip Signed-off-by: Forest Bond <forest@alittletooquiet.net> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
Diffstat (limited to 'drivers')
-rw-r--r--drivers/staging/vt6655/80211hdr.h357
-rw-r--r--drivers/staging/vt6655/80211mgr.c1050
-rw-r--r--drivers/staging/vt6655/80211mgr.h832
-rw-r--r--drivers/staging/vt6655/IEEE11h.c324
-rw-r--r--drivers/staging/vt6655/IEEE11h.h68
-rw-r--r--drivers/staging/vt6655/Makefile218
-rw-r--r--drivers/staging/vt6655/Makefile.arm181
-rw-r--r--drivers/staging/vt6655/Makefile.x86209
-rw-r--r--drivers/staging/vt6655/aes_ccmp.c410
-rw-r--r--drivers/staging/vt6655/aes_ccmp.h48
-rw-r--r--drivers/staging/vt6655/baseband.c2990
-rw-r--r--drivers/staging/vt6655/baseband.h198
-rw-r--r--drivers/staging/vt6655/bssdb.c1791
-rw-r--r--drivers/staging/vt6655/bssdb.h380
-rw-r--r--drivers/staging/vt6655/card.c3126
-rw-r--r--drivers/staging/vt6655/card.h273
-rw-r--r--drivers/staging/vt6655/country.h192
-rw-r--r--drivers/staging/vt6655/datarate.c455
-rw-r--r--drivers/staging/vt6655/datarate.h95
-rw-r--r--drivers/staging/vt6655/desc.h697
-rw-r--r--drivers/staging/vt6655/device.h1063
-rw-r--r--drivers/staging/vt6655/device_main.c4153
-rw-r--r--drivers/staging/vt6655/dpc.c1688
-rw-r--r--drivers/staging/vt6655/dpc.h75
-rw-r--r--drivers/staging/vt6655/hostap.c907
-rw-r--r--drivers/staging/vt6655/hostap.h94
-rw-r--r--drivers/staging/vt6655/ioctl.c775
-rw-r--r--drivers/staging/vt6655/ioctl.h74
-rw-r--r--drivers/staging/vt6655/iwctl.c2453
-rw-r--r--drivers/staging/vt6655/iwctl.h332
-rw-r--r--drivers/staging/vt6655/kcompat.h302
-rw-r--r--drivers/staging/vt6655/key.c836
-rw-r--r--drivers/staging/vt6655/key.h202
-rw-r--r--drivers/staging/vt6655/mac.c1752
-rw-r--r--drivers/staging/vt6655/mac.h1166
-rw-r--r--drivers/staging/vt6655/mib.c616
-rw-r--r--drivers/staging/vt6655/mib.h399
-rw-r--r--drivers/staging/vt6655/michael.c188
-rw-r--r--drivers/staging/vt6655/michael.h62
-rw-r--r--drivers/staging/vt6655/power.c441
-rw-r--r--drivers/staging/vt6655/power.h85
-rw-r--r--drivers/staging/vt6655/rc4.c86
-rw-r--r--drivers/staging/vt6655/rc4.h51
-rw-r--r--drivers/staging/vt6655/rf.c1283
-rw-r--r--drivers/staging/vt6655/rf.h118
-rw-r--r--drivers/staging/vt6655/rxtx.c3269
-rw-r--r--drivers/staging/vt6655/rxtx.h132
-rw-r--r--drivers/staging/vt6655/srom.c437
-rw-r--r--drivers/staging/vt6655/srom.h179
-rw-r--r--drivers/staging/vt6655/tbit.h78
-rw-r--r--drivers/staging/vt6655/tcrc.c207
-rw-r--r--drivers/staging/vt6655/tcrc.h71
-rw-r--r--drivers/staging/vt6655/test9
-rw-r--r--drivers/staging/vt6655/tether.c123
-rw-r--r--drivers/staging/vt6655/tether.h256
-rw-r--r--drivers/staging/vt6655/tkip.c284
-rw-r--r--drivers/staging/vt6655/tkip.h76
-rw-r--r--drivers/staging/vt6655/tmacro.h152
-rw-r--r--drivers/staging/vt6655/tpci.h117
-rw-r--r--drivers/staging/vt6655/umem.h75
-rw-r--r--drivers/staging/vt6655/upc.h171
-rw-r--r--drivers/staging/vt6655/vntconfiguration.dat1
-rw-r--r--drivers/staging/vt6655/vntwifi.c832
-rw-r--r--drivers/staging/vt6655/vntwifi.h330
-rw-r--r--drivers/staging/vt6655/wcmd.c1178
-rw-r--r--drivers/staging/vt6655/wcmd.h151
-rw-r--r--drivers/staging/vt6655/wctl.c261
-rw-r--r--drivers/staging/vt6655/wctl.h127
-rw-r--r--drivers/staging/vt6655/wmgr.c5100
-rw-r--r--drivers/staging/vt6655/wmgr.h521
-rw-r--r--drivers/staging/vt6655/wpa.c339
-rw-r--r--drivers/staging/vt6655/wpa.h98
-rw-r--r--drivers/staging/vt6655/wpa2.c373
-rw-r--r--drivers/staging/vt6655/wpa2.h100
-rw-r--r--drivers/staging/vt6655/wpactl.c1014
-rw-r--r--drivers/staging/vt6655/wpactl.h89
-rw-r--r--drivers/staging/vt6655/wroute.c211
-rw-r--r--drivers/staging/vt6655/wroute.h65
78 files changed, 49521 insertions, 0 deletions
diff --git a/drivers/staging/vt6655/80211hdr.h b/drivers/staging/vt6655/80211hdr.h
new file mode 100644
index 000000000000..b4bbb8d3c243
--- /dev/null
+++ b/drivers/staging/vt6655/80211hdr.h
@@ -0,0 +1,357 @@
1/*
2 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
3 * All rights reserved.
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * File: 80211hdr.h
20 *
21 * Purpose: Defines the macros, types, and functions for dealing
22 * with 802.11 MAC headers.
23 *
24 * Author: Lyndon Chen
25 *
26 * Date: Apr 8, 2002
27 *
28 */
29
30
31
32#ifndef __80211HDR_H__
33#define __80211HDR_H__
34
35
36#if !defined(__TTYPE_H__)
37#include "ttype.h"
38#endif
39
40/*--------------------- Export Definitions -------------------------*/
41// bit type
42#define BIT0 0x00000001
43#define BIT1 0x00000002
44#define BIT2 0x00000004
45#define BIT3 0x00000008
46#define BIT4 0x00000010
47#define BIT5 0x00000020
48#define BIT6 0x00000040
49#define BIT7 0x00000080
50#define BIT8 0x00000100
51#define BIT9 0x00000200
52#define BIT10 0x00000400
53#define BIT11 0x00000800
54#define BIT12 0x00001000
55#define BIT13 0x00002000
56#define BIT14 0x00004000
57#define BIT15 0x00008000
58#define BIT16 0x00010000
59#define BIT17 0x00020000
60#define BIT18 0x00040000
61#define BIT19 0x00080000
62#define BIT20 0x00100000
63#define BIT21 0x00200000
64#define BIT22 0x00400000
65#define BIT23 0x00800000
66#define BIT24 0x01000000
67#define BIT25 0x02000000
68#define BIT26 0x04000000
69#define BIT27 0x08000000
70#define BIT28 0x10000000
71#define BIT29 0x20000000
72#define BIT30 0x40000000
73#define BIT31 0x80000000
74
75// 802.11 frame related, defined as 802.11 spec
76#define WLAN_ADDR_LEN 6
77#define WLAN_CRC_LEN 4
78#define WLAN_CRC32_LEN 4
79#define WLAN_FCS_LEN 4
80#define WLAN_BSSID_LEN 6
81#define WLAN_BSS_TS_LEN 8
82#define WLAN_HDR_ADDR2_LEN 16
83#define WLAN_HDR_ADDR3_LEN 24
84#define WLAN_HDR_ADDR4_LEN 30
85#define WLAN_IEHDR_LEN 2
86#define WLAN_SSID_MAXLEN 32
87//#define WLAN_RATES_MAXLEN 255
88#define WLAN_RATES_MAXLEN 16
89#define WLAN_RATES_MAXLEN_11B 4
90#define WLAN_RSN_MAXLEN 32
91#define WLAN_DATA_MAXLEN 2312
92#define WLAN_A3FR_MAXLEN (WLAN_HDR_ADDR3_LEN + WLAN_DATA_MAXLEN + WLAN_CRC_LEN)
93
94
95#define WLAN_BEACON_FR_MAXLEN WLAN_A3FR_MAXLEN
96#define WLAN_ATIM_FR_MAXLEN (WLAN_HDR_ADDR3_LEN + 0)
97#define WLAN_NULLDATA_FR_MAXLEN (WLAN_HDR_ADDR3_LEN + 0)
98#define WLAN_DISASSOC_FR_MAXLEN (WLAN_HDR_ADDR3_LEN + 2)
99#define WLAN_ASSOCREQ_FR_MAXLEN WLAN_A3FR_MAXLEN
100#define WLAN_ASSOCRESP_FR_MAXLEN WLAN_A3FR_MAXLEN
101#define WLAN_REASSOCREQ_FR_MAXLEN WLAN_A3FR_MAXLEN
102#define WLAN_REASSOCRESP_FR_MAXLEN WLAN_A3FR_MAXLEN
103#define WLAN_PROBEREQ_FR_MAXLEN WLAN_A3FR_MAXLEN
104#define WLAN_PROBERESP_FR_MAXLEN WLAN_A3FR_MAXLEN
105#define WLAN_AUTHEN_FR_MAXLEN WLAN_A3FR_MAXLEN
106#define WLAN_DEAUTHEN_FR_MAXLEN (WLAN_HDR_ADDR3_LEN + 2)
107
108
109#define WLAN_WEP_NKEYS 4
110#define WLAN_WEP40_KEYLEN 5
111#define WLAN_WEP104_KEYLEN 13
112#define WLAN_WEP232_KEYLEN 29
113//#define WLAN_WEPMAX_KEYLEN 29
114#define WLAN_WEPMAX_KEYLEN 32
115#define WLAN_CHALLENGE_IE_MAXLEN 255
116#define WLAN_CHALLENGE_IE_LEN 130
117#define WLAN_CHALLENGE_LEN 128
118#define WLAN_WEP_IV_LEN 4
119#define WLAN_WEP_ICV_LEN 4
120#define WLAN_FRAGS_MAX 16
121
122// Frame Type
123#define WLAN_TYPE_MGR 0x00
124#define WLAN_TYPE_CTL 0x01
125#define WLAN_TYPE_DATA 0x02
126
127#define WLAN_FTYPE_MGMT 0x00
128#define WLAN_FTYPE_CTL 0x01
129#define WLAN_FTYPE_DATA 0x02
130
131
132// Frame Subtypes
133#define WLAN_FSTYPE_ASSOCREQ 0x00
134#define WLAN_FSTYPE_ASSOCRESP 0x01
135#define WLAN_FSTYPE_REASSOCREQ 0x02
136#define WLAN_FSTYPE_REASSOCRESP 0x03
137#define WLAN_FSTYPE_PROBEREQ 0x04
138#define WLAN_FSTYPE_PROBERESP 0x05
139#define WLAN_FSTYPE_BEACON 0x08
140#define WLAN_FSTYPE_ATIM 0x09
141#define WLAN_FSTYPE_DISASSOC 0x0a
142#define WLAN_FSTYPE_AUTHEN 0x0b
143#define WLAN_FSTYPE_DEAUTHEN 0x0c
144#define WLAN_FSTYPE_ACTION 0x0d
145
146// Control
147#define WLAN_FSTYPE_PSPOLL 0x0a
148#define WLAN_FSTYPE_RTS 0x0b
149#define WLAN_FSTYPE_CTS 0x0c
150#define WLAN_FSTYPE_ACK 0x0d
151#define WLAN_FSTYPE_CFEND 0x0e
152#define WLAN_FSTYPE_CFENDCFACK 0x0f
153
154// Data
155#define WLAN_FSTYPE_DATAONLY 0x00
156#define WLAN_FSTYPE_DATA_CFACK 0x01
157#define WLAN_FSTYPE_DATA_CFPOLL 0x02
158#define WLAN_FSTYPE_DATA_CFACK_CFPOLL 0x03
159#define WLAN_FSTYPE_NULL 0x04
160#define WLAN_FSTYPE_CFACK 0x05
161#define WLAN_FSTYPE_CFPOLL 0x06
162#define WLAN_FSTYPE_CFACK_CFPOLL 0x07
163
164
165#ifdef __BIG_ENDIAN
166
167// GET & SET Frame Control bit
168#define WLAN_GET_FC_PRVER(n) ((((WORD)(n) >> 8) & (BIT0 | BIT1))
169#define WLAN_GET_FC_FTYPE(n) ((((WORD)(n) >> 8) & (BIT2 | BIT3)) >> 2)
170#define WLAN_GET_FC_FSTYPE(n) ((((WORD)(n) >> 8) & (BIT4|BIT5|BIT6|BIT7)) >> 4)
171#define WLAN_GET_FC_TODS(n) ((((WORD)(n) << 8) & (BIT8)) >> 8)
172#define WLAN_GET_FC_FROMDS(n) ((((WORD)(n) << 8) & (BIT9)) >> 9)
173#define WLAN_GET_FC_MOREFRAG(n) ((((WORD)(n) << 8) & (BIT10)) >> 10)
174#define WLAN_GET_FC_RETRY(n) ((((WORD)(n) << 8) & (BIT11)) >> 11)
175#define WLAN_GET_FC_PWRMGT(n) ((((WORD)(n) << 8) & (BIT12)) >> 12)
176#define WLAN_GET_FC_MOREDATA(n) ((((WORD)(n) << 8) & (BIT13)) >> 13)
177#define WLAN_GET_FC_ISWEP(n) ((((WORD)(n) << 8) & (BIT14)) >> 14)
178#define WLAN_GET_FC_ORDER(n) ((((WORD)(n) << 8) & (BIT15)) >> 15)
179
180// Sequence Field bit
181#define WLAN_GET_SEQ_FRGNUM(n) (((WORD)(n) >> 8) & (BIT0|BIT1|BIT2|BIT3))
182#define WLAN_GET_SEQ_SEQNUM(n) ((((WORD)(n) >> 8) & (~(BIT0|BIT1|BIT2|BIT3))) >> 4)
183
184
185// Capability Field bit
186#define WLAN_GET_CAP_INFO_ESS(n) (((n) >> 8) & BIT0)
187#define WLAN_GET_CAP_INFO_IBSS(n) ((((n) >> 8) & BIT1) >> 1)
188#define WLAN_GET_CAP_INFO_CFPOLLABLE(n) ((((n) >> 8) & BIT2) >> 2)
189#define WLAN_GET_CAP_INFO_CFPOLLREQ(n) ((((n) >> 8) & BIT3) >> 3)
190#define WLAN_GET_CAP_INFO_PRIVACY(n) ((((n) >> 8) & BIT4) >> 4)
191#define WLAN_GET_CAP_INFO_SHORTPREAMBLE(n) ((((n) >> 8) & BIT5) >> 5)
192#define WLAN_GET_CAP_INFO_PBCC(n) ((((n) >> 8) & BIT6) >> 6)
193#define WLAN_GET_CAP_INFO_AGILITY(n) ((((n) >> 8) & BIT7) >> 7)
194#define WLAN_GET_CAP_INFO_SPECTRUMMNG(n) ((((n)) & BIT8) >> 10)
195#define WLAN_GET_CAP_INFO_SHORTSLOTTIME(n) ((((n)) & BIT10) >> 10)
196#define WLAN_GET_CAP_INFO_DSSSOFDM(n) ((((n)) & BIT13) >> 13)
197#define WLAN_GET_CAP_INFO_GRPACK(n) ((((n)) & BIT14) >> 14)
198
199
200#else
201
202// GET & SET Frame Control bit
203#define WLAN_GET_FC_PRVER(n) (((WORD)(n)) & (BIT0 | BIT1))
204#define WLAN_GET_FC_FTYPE(n) ((((WORD)(n)) & (BIT2 | BIT3)) >> 2)
205#define WLAN_GET_FC_FSTYPE(n) ((((WORD)(n)) & (BIT4|BIT5|BIT6|BIT7)) >> 4)
206#define WLAN_GET_FC_TODS(n) ((((WORD)(n)) & (BIT8)) >> 8)
207#define WLAN_GET_FC_FROMDS(n) ((((WORD)(n)) & (BIT9)) >> 9)
208#define WLAN_GET_FC_MOREFRAG(n) ((((WORD)(n)) & (BIT10)) >> 10)
209#define WLAN_GET_FC_RETRY(n) ((((WORD)(n)) & (BIT11)) >> 11)
210#define WLAN_GET_FC_PWRMGT(n) ((((WORD)(n)) & (BIT12)) >> 12)
211#define WLAN_GET_FC_MOREDATA(n) ((((WORD)(n)) & (BIT13)) >> 13)
212#define WLAN_GET_FC_ISWEP(n) ((((WORD)(n)) & (BIT14)) >> 14)
213#define WLAN_GET_FC_ORDER(n) ((((WORD)(n)) & (BIT15)) >> 15)
214
215
216// Sequence Field bit
217#define WLAN_GET_SEQ_FRGNUM(n) (((WORD)(n)) & (BIT0|BIT1|BIT2|BIT3))
218#define WLAN_GET_SEQ_SEQNUM(n) ((((WORD)(n)) & (~(BIT0|BIT1|BIT2|BIT3))) >> 4)
219
220
221// Capability Field bit
222#define WLAN_GET_CAP_INFO_ESS(n) ((n) & BIT0)
223#define WLAN_GET_CAP_INFO_IBSS(n) (((n) & BIT1) >> 1)
224#define WLAN_GET_CAP_INFO_CFPOLLABLE(n) (((n) & BIT2) >> 2)
225#define WLAN_GET_CAP_INFO_CFPOLLREQ(n) (((n) & BIT3) >> 3)
226#define WLAN_GET_CAP_INFO_PRIVACY(n) (((n) & BIT4) >> 4)
227#define WLAN_GET_CAP_INFO_SHORTPREAMBLE(n) (((n) & BIT5) >> 5)
228#define WLAN_GET_CAP_INFO_PBCC(n) (((n) & BIT6) >> 6)
229#define WLAN_GET_CAP_INFO_AGILITY(n) (((n) & BIT7) >> 7)
230#define WLAN_GET_CAP_INFO_SPECTRUMMNG(n) (((n) & BIT8) >> 10)
231#define WLAN_GET_CAP_INFO_SHORTSLOTTIME(n) (((n) & BIT10) >> 10)
232#define WLAN_GET_CAP_INFO_DSSSOFDM(n) (((n) & BIT13) >> 13)
233#define WLAN_GET_CAP_INFO_GRPACK(n) (((n) & BIT14) >> 14)
234
235
236#endif //#ifdef __BIG_ENDIAN
237
238
239#define WLAN_SET_CAP_INFO_ESS(n) (n)
240#define WLAN_SET_CAP_INFO_IBSS(n) ((n) << 1)
241#define WLAN_SET_CAP_INFO_CFPOLLABLE(n) ((n) << 2)
242#define WLAN_SET_CAP_INFO_CFPOLLREQ(n) ((n) << 3)
243#define WLAN_SET_CAP_INFO_PRIVACY(n) ((n) << 4)
244#define WLAN_SET_CAP_INFO_SHORTPREAMBLE(n) ((n) << 5)
245#define WLAN_SET_CAP_INFO_SPECTRUMMNG(n) ((n) << 8)
246#define WLAN_SET_CAP_INFO_PBCC(n) ((n) << 6)
247#define WLAN_SET_CAP_INFO_AGILITY(n) ((n) << 7)
248#define WLAN_SET_CAP_INFO_SHORTSLOTTIME(n) ((n) << 10)
249#define WLAN_SET_CAP_INFO_DSSSOFDM(n) ((n) << 13)
250#define WLAN_SET_CAP_INFO_GRPACK(n) ((n) << 14)
251
252
253#define WLAN_SET_FC_PRVER(n) ((WORD)(n))
254#define WLAN_SET_FC_FTYPE(n) (((WORD)(n)) << 2)
255#define WLAN_SET_FC_FSTYPE(n) (((WORD)(n)) << 4)
256#define WLAN_SET_FC_TODS(n) (((WORD)(n)) << 8)
257#define WLAN_SET_FC_FROMDS(n) (((WORD)(n)) << 9)
258#define WLAN_SET_FC_MOREFRAG(n) (((WORD)(n)) << 10)
259#define WLAN_SET_FC_RETRY(n) (((WORD)(n)) << 11)
260#define WLAN_SET_FC_PWRMGT(n) (((WORD)(n)) << 12)
261#define WLAN_SET_FC_MOREDATA(n) (((WORD)(n)) << 13)
262#define WLAN_SET_FC_ISWEP(n) (((WORD)(n)) << 14)
263#define WLAN_SET_FC_ORDER(n) (((WORD)(n)) << 15)
264
265#define WLAN_SET_SEQ_FRGNUM(n) ((WORD)(n))
266#define WLAN_SET_SEQ_SEQNUM(n) (((WORD)(n)) << 4)
267
268// ERP Field bit
269
270#define WLAN_GET_ERP_NONERP_PRESENT(n) ((n) & BIT0)
271#define WLAN_GET_ERP_USE_PROTECTION(n) (((n) & BIT1) >> 1)
272#define WLAN_GET_ERP_BARKER_MODE(n) (((n) & BIT2) >> 2)
273
274#define WLAN_SET_ERP_NONERP_PRESENT(n) (n)
275#define WLAN_SET_ERP_USE_PROTECTION(n) ((n) << 1)
276#define WLAN_SET_ERP_BARKER_MODE(n) ((n) << 2)
277
278
279
280// Support & Basic Rates field
281#define WLAN_MGMT_IS_BASICRATE(b) ((b) & BIT7)
282#define WLAN_MGMT_GET_RATE(b) ((b) & ~BIT7)
283
284// TIM field
285#define WLAN_MGMT_IS_MULTICAST_TIM(b) ((b) & BIT0)
286#define WLAN_MGMT_GET_TIM_OFFSET(b) (((b) & ~BIT0) >> 1)
287
288// 3-Addr & 4-Addr
289#define WLAN_HDR_A3_DATA_PTR(p) (((PBYTE)(p)) + WLAN_HDR_ADDR3_LEN)
290#define WLAN_HDR_A4_DATA_PTR(p) (((PBYTE)(p)) + WLAN_HDR_ADDR4_LEN)
291
292// IEEE ADDR
293#define IEEE_ADDR_UNIVERSAL 0x02
294#define IEEE_ADDR_GROUP 0x01
295
296typedef struct {
297 BYTE abyAddr[6];
298} IEEE_ADDR, *PIEEE_ADDR;
299
300// 802.11 Header Format
301
302typedef struct tagWLAN_80211HDR_A2 {
303
304 WORD wFrameCtl;
305 WORD wDurationID;
306 BYTE abyAddr1[WLAN_ADDR_LEN];
307 BYTE abyAddr2[WLAN_ADDR_LEN];
308
309}__attribute__ ((__packed__))
310WLAN_80211HDR_A2, *PWLAN_80211HDR_A2;
311
312typedef struct tagWLAN_80211HDR_A3 {
313
314 WORD wFrameCtl;
315 WORD wDurationID;
316 BYTE abyAddr1[WLAN_ADDR_LEN];
317 BYTE abyAddr2[WLAN_ADDR_LEN];
318 BYTE abyAddr3[WLAN_ADDR_LEN];
319 WORD wSeqCtl;
320
321}__attribute__ ((__packed__))
322WLAN_80211HDR_A3, *PWLAN_80211HDR_A3;
323
324typedef struct tagWLAN_80211HDR_A4 {
325
326 WORD wFrameCtl;
327 WORD wDurationID;
328 BYTE abyAddr1[WLAN_ADDR_LEN];
329 BYTE abyAddr2[WLAN_ADDR_LEN];
330 BYTE abyAddr3[WLAN_ADDR_LEN];
331 WORD wSeqCtl;
332 BYTE abyAddr4[WLAN_ADDR_LEN];
333
334}__attribute__ ((__packed__))
335WLAN_80211HDR_A4, *PWLAN_80211HDR_A4;
336
337
338typedef union tagUWLAN_80211HDR {
339
340 WLAN_80211HDR_A2 sA2;
341 WLAN_80211HDR_A3 sA3;
342 WLAN_80211HDR_A4 sA4;
343
344} UWLAN_80211HDR, *PUWLAN_80211HDR;
345
346
347/*--------------------- Export Classes ----------------------------*/
348
349/*--------------------- Export Variables --------------------------*/
350
351/*--------------------- Export Functions --------------------------*/
352
353
354
355#endif // __80211HDR_H__
356
357
diff --git a/drivers/staging/vt6655/80211mgr.c b/drivers/staging/vt6655/80211mgr.c
new file mode 100644
index 000000000000..84745fb6b035
--- /dev/null
+++ b/drivers/staging/vt6655/80211mgr.c
@@ -0,0 +1,1050 @@
1/*
2 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
3 * All rights reserved.
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 *
20 * File: 80211mgr.c
21 *
22 * Purpose: Handles the 802.11 managment support functions
23 *
24 * Author: Lyndon Chen
25 *
26 * Date: May 8, 2002
27 *
28 * Functions:
29 * vMgrEncodeBeacon - Encode the Beacon frame
30 * vMgrDecodeBeacon - Decode the Beacon frame
31 * vMgrEncodeIBSSATIM - Encode the IBSS ATIM frame
32 * vMgrDecodeIBSSATIM - Decode the IBSS ATIM frame
33 * vMgrEncodeDisassociation - Encode the Disassociation frame
34 * vMgrDecodeDisassociation - Decode the Disassociation frame
35 * vMgrEncodeAssocRequest - Encode the Association request frame
36 * vMgrDecodeAssocRequest - Decode the Association request frame
37 * vMgrEncodeAssocResponse - Encode the Association response frame
38 * vMgrDecodeAssocResponse - Decode the Association response frame
39 * vMgrEncodeReAssocRequest - Encode the ReAssociation request frame
40 * vMgrDecodeReAssocRequest - Decode the ReAssociation request frame
41 * vMgrEncodeProbeRequest - Encode the Probe request frame
42 * vMgrDecodeProbeRequest - Decode the Probe request frame
43 * vMgrEncodeProbeResponse - Encode the Probe response frame
44 * vMgrDecodeProbeResponse - Decode the Probe response frame
45 * vMgrEncodeAuthen - Encode the Authentication frame
46 * vMgrDecodeAuthen - Decode the Authentication frame
47 * vMgrEncodeDeauthen - Encode the DeAuthentication frame
48 * vMgrDecodeDeauthen - Decode the DeAuthentication frame
49 * vMgrEncodeReassocResponse - Encode the Reassociation response frame
50 * vMgrDecodeReassocResponse - Decode the Reassociation response frame
51 *
52 * Revision History:
53 *
54 */
55
56
57
58#if !defined(__TMACRO_H__)
59#include "tmacro.h"
60#endif
61#if !defined(__TETHER_H__)
62#include "tether.h"
63#endif
64#if !defined(__80211MGR_H__)
65#include "80211mgr.h"
66#endif
67#if !defined(__80211HDR_H__)
68#include "80211hdr.h"
69#endif
70#if !defined(__DEVICE_H__)
71#include "device.h"
72#endif
73#if !defined(__WPA_H__)
74#include "wpa.h"
75#endif
76
77
78
79/*--------------------- Static Definitions -------------------------*/
80
81
82
83/*--------------------- Static Classes ----------------------------*/
84
85/*--------------------- Static Variables --------------------------*/
86
87static int msglevel =MSG_LEVEL_INFO;
88//static int msglevel =MSG_LEVEL_DEBUG;
89/*--------------------- Static Functions --------------------------*/
90
91
92
93/*--------------------- Export Variables --------------------------*/
94
95
96/*--------------------- Export Functions --------------------------*/
97
98
99/*+
100 *
101 * Routine Description:
102 * Encode Beacon frame body offset
103 *
104 * Return Value:
105 * None.
106 *
107-*/
108
109VOID
110vMgrEncodeBeacon(
111 IN PWLAN_FR_BEACON pFrame
112 )
113{
114 pFrame->pHdr = (PUWLAN_80211HDR)pFrame->pBuf;
115
116 // Fixed Fields
117 pFrame->pqwTimestamp = (PQWORD)(WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3))
118 + WLAN_BEACON_OFF_TS);
119 pFrame->pwBeaconInterval = (PWORD)(WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3))
120 + WLAN_BEACON_OFF_BCN_INT);
121 pFrame->pwCapInfo = (PWORD)(WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3))
122 + WLAN_BEACON_OFF_CAPINFO);
123
124 pFrame->len = WLAN_HDR_ADDR3_LEN + WLAN_BEACON_OFF_SSID;
125
126 return;
127}
128
129/*+
130 *
131 * Routine Description:
132 * Decode Beacon frame body offset
133 *
134 *
135 * Return Value:
136 * None.
137 *
138-*/
139
140
141VOID
142vMgrDecodeBeacon(
143 IN PWLAN_FR_BEACON pFrame
144 )
145{
146 PWLAN_IE pItem;
147
148 pFrame->pHdr = (PUWLAN_80211HDR)pFrame->pBuf;
149
150 // Fixed Fields
151 pFrame->pqwTimestamp = (PQWORD)(WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3))
152 + WLAN_BEACON_OFF_TS);
153 pFrame->pwBeaconInterval = (PWORD)(WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3))
154 + WLAN_BEACON_OFF_BCN_INT);
155 pFrame->pwCapInfo = (PWORD)(WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3))
156 + WLAN_BEACON_OFF_CAPINFO);
157
158 // Information elements
159 pItem = (PWLAN_IE)((PBYTE)(WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3)))
160 + WLAN_BEACON_OFF_SSID);
161 while( ((PBYTE)pItem) < (pFrame->pBuf + pFrame->len) ){
162
163 switch (pItem->byElementID) {
164 case WLAN_EID_SSID:
165 if (pFrame->pSSID == NULL)
166 pFrame->pSSID = (PWLAN_IE_SSID)pItem;
167 break;
168 case WLAN_EID_SUPP_RATES:
169 if (pFrame->pSuppRates == NULL)
170 pFrame->pSuppRates = (PWLAN_IE_SUPP_RATES)pItem;
171 break;
172 case WLAN_EID_FH_PARMS:
173 //pFrame->pFHParms = (PWLAN_IE_FH_PARMS)pItem;
174 break;
175 case WLAN_EID_DS_PARMS:
176 if (pFrame->pDSParms == NULL)
177 pFrame->pDSParms = (PWLAN_IE_DS_PARMS)pItem;
178 break;
179 case WLAN_EID_CF_PARMS:
180 if (pFrame->pCFParms == NULL)
181 pFrame->pCFParms = (PWLAN_IE_CF_PARMS)pItem;
182 break;
183 case WLAN_EID_IBSS_PARMS:
184 if (pFrame->pIBSSParms == NULL)
185 pFrame->pIBSSParms = (PWLAN_IE_IBSS_PARMS)pItem;
186 break;
187 case WLAN_EID_TIM:
188 if (pFrame->pTIM == NULL)
189 pFrame->pTIM = (PWLAN_IE_TIM)pItem;
190 break;
191
192 case WLAN_EID_RSN:
193 if (pFrame->pRSN == NULL) {
194 pFrame->pRSN = (PWLAN_IE_RSN)pItem;
195 }
196 break;
197 case WLAN_EID_RSN_WPA:
198 if (pFrame->pRSNWPA == NULL) {
199 if (WPAb_Is_RSN((PWLAN_IE_RSN_EXT)pItem) == TRUE)
200 pFrame->pRSNWPA = (PWLAN_IE_RSN_EXT)pItem;
201 }
202 break;
203
204 case WLAN_EID_ERP:
205 if (pFrame->pERP == NULL)
206 pFrame->pERP = (PWLAN_IE_ERP)pItem;
207 break;
208 case WLAN_EID_EXTSUPP_RATES:
209 if (pFrame->pExtSuppRates == NULL)
210 pFrame->pExtSuppRates = (PWLAN_IE_SUPP_RATES)pItem;
211 break;
212
213 case WLAN_EID_COUNTRY: //7
214 if (pFrame->pIE_Country == NULL)
215 pFrame->pIE_Country = (PWLAN_IE_COUNTRY)pItem;
216 break;
217
218 case WLAN_EID_PWR_CONSTRAINT: //32
219 if (pFrame->pIE_PowerConstraint == NULL)
220 pFrame->pIE_PowerConstraint = (PWLAN_IE_PW_CONST)pItem;
221 break;
222
223 case WLAN_EID_CH_SWITCH: //37
224 if (pFrame->pIE_CHSW == NULL)
225 pFrame->pIE_CHSW = (PWLAN_IE_CH_SW)pItem;
226 break;
227
228 case WLAN_EID_QUIET: //40
229 if (pFrame->pIE_Quiet == NULL)
230 pFrame->pIE_Quiet = (PWLAN_IE_QUIET)pItem;
231 break;
232
233 case WLAN_EID_IBSS_DFS:
234 if (pFrame->pIE_IBSSDFS == NULL)
235 pFrame->pIE_IBSSDFS = (PWLAN_IE_IBSS_DFS)pItem;
236 break;
237
238 default:
239 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Unrecognized EID=%dd in beacon decode.\n", pItem->byElementID);
240 break;
241
242 }
243 pItem = (PWLAN_IE)(((PBYTE)pItem) + 2 + pItem->len);
244 }
245
246 return;
247}
248
249
250/*+
251 *
252 * Routine Description:
253 * Encode IBSS ATIM
254 *
255 *
256 * Return Value:
257 * None.
258 *
259-*/
260
261
262VOID
263vMgrEncodeIBSSATIM(
264 IN PWLAN_FR_IBSSATIM pFrame
265 )
266{
267 pFrame->pHdr = (PUWLAN_80211HDR)pFrame->pBuf;
268 pFrame->len = WLAN_HDR_ADDR3_LEN;
269
270 return;
271}
272
273
274/*+
275 *
276 * Routine Description:
277 * Decode IBSS ATIM
278 *
279 *
280 * Return Value:
281 * None.
282 *
283-*/
284
285VOID
286vMgrDecodeIBSSATIM(
287 IN PWLAN_FR_IBSSATIM pFrame
288 )
289{
290 pFrame->pHdr = (PUWLAN_80211HDR)pFrame->pBuf;
291
292 return;
293}
294
295
296/*+
297 *
298 * Routine Description:
299 * Encode Disassociation
300 *
301 *
302 * Return Value:
303 * None.
304 *
305-*/
306
307VOID
308vMgrEncodeDisassociation(
309 IN PWLAN_FR_DISASSOC pFrame
310 )
311{
312 pFrame->pHdr = (PUWLAN_80211HDR)pFrame->pBuf;
313
314
315 // Fixed Fields
316 pFrame->pwReason = (PWORD)(WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3))
317 + WLAN_DISASSOC_OFF_REASON);
318 pFrame->len = WLAN_HDR_ADDR3_LEN + WLAN_DISASSOC_OFF_REASON + sizeof(*(pFrame->pwReason));
319
320 return;
321}
322
323
324/*+
325 *
326 * Routine Description:
327 * Decode Disassociation
328 *
329 *
330 * Return Value:
331 * None.
332 *
333-*/
334
335VOID
336vMgrDecodeDisassociation(
337 IN PWLAN_FR_DISASSOC pFrame
338 )
339{
340 pFrame->pHdr = (PUWLAN_80211HDR)pFrame->pBuf;
341
342 // Fixed Fields
343 pFrame->pwReason = (PWORD)(WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3))
344 + WLAN_DISASSOC_OFF_REASON);
345
346 return;
347}
348
349/*+
350 *
351 * Routine Description:
352 * Encode Association Request
353 *
354 *
355 * Return Value:
356 * None.
357 *
358-*/
359
360
361VOID
362vMgrEncodeAssocRequest(
363 IN PWLAN_FR_ASSOCREQ pFrame
364 )
365{
366 pFrame->pHdr = (PUWLAN_80211HDR)pFrame->pBuf;
367 // Fixed Fields
368 pFrame->pwCapInfo = (PWORD)(WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3))
369 + WLAN_ASSOCREQ_OFF_CAP_INFO);
370 pFrame->pwListenInterval = (PWORD)(WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3))
371 + WLAN_ASSOCREQ_OFF_LISTEN_INT);
372 pFrame->len = WLAN_HDR_ADDR3_LEN + WLAN_ASSOCREQ_OFF_LISTEN_INT + sizeof(*(pFrame->pwListenInterval));
373 return;
374}
375
376
377/*+
378 *
379 * Routine Description: (AP)
380 * Decode Association Request
381 *
382 *
383 * Return Value:
384 * None.
385 *
386-*/
387
388VOID
389vMgrDecodeAssocRequest(
390 IN PWLAN_FR_ASSOCREQ pFrame
391 )
392{
393 PWLAN_IE pItem;
394
395 pFrame->pHdr = (PUWLAN_80211HDR)pFrame->pBuf;
396 // Fixed Fields
397 pFrame->pwCapInfo = (PWORD)(WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3))
398 + WLAN_ASSOCREQ_OFF_CAP_INFO);
399 pFrame->pwListenInterval = (PWORD)(WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3))
400 + WLAN_ASSOCREQ_OFF_LISTEN_INT);
401
402 // Information elements
403 pItem = (PWLAN_IE)(WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3))
404 + WLAN_ASSOCREQ_OFF_SSID);
405
406 while (((PBYTE)pItem) < (pFrame->pBuf + pFrame->len)) {
407 switch (pItem->byElementID){
408 case WLAN_EID_SSID:
409 if (pFrame->pSSID == NULL)
410 pFrame->pSSID = (PWLAN_IE_SSID)pItem;
411 break;
412 case WLAN_EID_SUPP_RATES:
413 if (pFrame->pSuppRates == NULL)
414 pFrame->pSuppRates = (PWLAN_IE_SUPP_RATES)pItem;
415 break;
416
417 case WLAN_EID_RSN:
418 if (pFrame->pRSN == NULL) {
419 pFrame->pRSN = (PWLAN_IE_RSN)pItem;
420 }
421 break;
422 case WLAN_EID_RSN_WPA:
423 if (pFrame->pRSNWPA == NULL) {
424 if (WPAb_Is_RSN((PWLAN_IE_RSN_EXT)pItem) == TRUE)
425 pFrame->pRSNWPA = (PWLAN_IE_RSN_EXT)pItem;
426 }
427 break;
428 case WLAN_EID_EXTSUPP_RATES:
429 if (pFrame->pExtSuppRates == NULL)
430 pFrame->pExtSuppRates = (PWLAN_IE_SUPP_RATES)pItem;
431 break;
432
433 default:
434 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Unrecognized EID=%dd in assocreq decode.\n",
435 pItem->byElementID);
436 break;
437 }
438 pItem = (PWLAN_IE)(((PBYTE)pItem) + 2 + pItem->len);
439 }
440 return;
441}
442
443/*+
444 *
445 * Routine Description: (AP)
446 * Encode Association Response
447 *
448 *
449 * Return Value:
450 * None.
451 *
452-*/
453
454VOID
455vMgrEncodeAssocResponse(
456 IN PWLAN_FR_ASSOCRESP pFrame
457 )
458{
459 pFrame->pHdr = (PUWLAN_80211HDR)pFrame->pBuf;
460
461 // Fixed Fields
462 pFrame->pwCapInfo = (PWORD)(WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3))
463 + WLAN_ASSOCRESP_OFF_CAP_INFO);
464 pFrame->pwStatus = (PWORD)(WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3))
465 + WLAN_ASSOCRESP_OFF_STATUS);
466 pFrame->pwAid = (PWORD)(WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3))
467 + WLAN_ASSOCRESP_OFF_AID);
468 pFrame->len = WLAN_HDR_ADDR3_LEN + WLAN_ASSOCRESP_OFF_AID
469 + sizeof(*(pFrame->pwAid));
470
471 return;
472}
473
474
475/*+
476 *
477 * Routine Description:
478 * Decode Association Response
479 *
480 *
481 * Return Value:
482 * None.
483 *
484-*/
485
486VOID
487vMgrDecodeAssocResponse(
488 IN PWLAN_FR_ASSOCRESP pFrame
489 )
490{
491 PWLAN_IE pItem;
492
493 pFrame->pHdr = (PUWLAN_80211HDR)pFrame->pBuf;
494
495 // Fixed Fields
496 pFrame->pwCapInfo = (PWORD)(WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3))
497 + WLAN_ASSOCRESP_OFF_CAP_INFO);
498 pFrame->pwStatus = (PWORD)(WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3))
499 + WLAN_ASSOCRESP_OFF_STATUS);
500 pFrame->pwAid = (PWORD)(WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3))
501 + WLAN_ASSOCRESP_OFF_AID);
502
503 // Information elements
504 pFrame->pSuppRates = (PWLAN_IE_SUPP_RATES)(WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3))
505 + WLAN_ASSOCRESP_OFF_SUPP_RATES);
506
507 pItem = (PWLAN_IE)(pFrame->pSuppRates);
508 pItem = (PWLAN_IE)(((PBYTE)pItem) + 2 + pItem->len);
509
510 if ((((PBYTE)pItem) < (pFrame->pBuf + pFrame->len)) && (pItem->byElementID == WLAN_EID_EXTSUPP_RATES)) {
511 pFrame->pExtSuppRates = (PWLAN_IE_SUPP_RATES)pItem;
512 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "pFrame->pExtSuppRates=[%p].\n", pItem);
513 }
514 else {
515 pFrame->pExtSuppRates = NULL;
516 }
517 return;
518}
519
520
521/*+
522 *
523 * Routine Description:
524 * Encode Reassociation Request
525 *
526 *
527 * Return Value:
528 * None.
529 *
530-*/
531
532VOID
533vMgrEncodeReassocRequest(
534 IN PWLAN_FR_REASSOCREQ pFrame
535 )
536{
537 pFrame->pHdr = (PUWLAN_80211HDR)pFrame->pBuf;
538
539 // Fixed Fields
540 pFrame->pwCapInfo = (PWORD)(WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3))
541 + WLAN_REASSOCREQ_OFF_CAP_INFO);
542 pFrame->pwListenInterval = (PWORD)(WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3))
543 + WLAN_REASSOCREQ_OFF_LISTEN_INT);
544 pFrame->pAddrCurrAP = (PIEEE_ADDR)(WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3))
545 + WLAN_REASSOCREQ_OFF_CURR_AP);
546 pFrame->len = WLAN_HDR_ADDR3_LEN + WLAN_REASSOCREQ_OFF_CURR_AP + sizeof(*(pFrame->pAddrCurrAP));
547
548 return;
549}
550
551
552/*+
553 *
554 * Routine Description: (AP)
555 * Decode Reassociation Request
556 *
557 *
558 * Return Value:
559 * None.
560 *
561-*/
562
563
564VOID
565vMgrDecodeReassocRequest(
566 IN PWLAN_FR_REASSOCREQ pFrame
567 )
568{
569 PWLAN_IE pItem;
570 pFrame->pHdr = (PUWLAN_80211HDR)pFrame->pBuf;
571
572 // Fixed Fields
573 pFrame->pwCapInfo = (PWORD)(WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3))
574 + WLAN_REASSOCREQ_OFF_CAP_INFO);
575 pFrame->pwListenInterval = (PWORD)(WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3))
576 + WLAN_REASSOCREQ_OFF_LISTEN_INT);
577 pFrame->pAddrCurrAP = (PIEEE_ADDR)(WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3))
578 + WLAN_REASSOCREQ_OFF_CURR_AP);
579
580 // Information elements
581 pItem = (PWLAN_IE)(WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3))
582 + WLAN_REASSOCREQ_OFF_SSID);
583
584 while(((PBYTE)pItem) < (pFrame->pBuf + pFrame->len)) {
585
586 switch (pItem->byElementID){
587 case WLAN_EID_SSID:
588 if (pFrame->pSSID == NULL)
589 pFrame->pSSID = (PWLAN_IE_SSID)pItem;
590 break;
591 case WLAN_EID_SUPP_RATES:
592 if (pFrame->pSuppRates == NULL)
593 pFrame->pSuppRates = (PWLAN_IE_SUPP_RATES)pItem;
594 break;
595
596 case WLAN_EID_RSN:
597 if (pFrame->pRSN == NULL) {
598 pFrame->pRSN = (PWLAN_IE_RSN)pItem;
599 }
600 break;
601 case WLAN_EID_RSN_WPA:
602 if (pFrame->pRSNWPA == NULL) {
603 if (WPAb_Is_RSN((PWLAN_IE_RSN_EXT)pItem) == TRUE)
604 pFrame->pRSNWPA = (PWLAN_IE_RSN_EXT)pItem;
605 }
606 break;
607
608 case WLAN_EID_EXTSUPP_RATES:
609 if (pFrame->pExtSuppRates == NULL)
610 pFrame->pExtSuppRates = (PWLAN_IE_SUPP_RATES)pItem;
611 break;
612 default:
613 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Unrecognized EID=%dd in reassocreq decode.\n",
614 pItem->byElementID);
615 break;
616 }
617 pItem = (PWLAN_IE)(((PBYTE)pItem) + 2 + pItem->len);
618 }
619 return;
620}
621
622
623
624/*+
625 *
626 * Routine Description:
627 * Encode Probe Request
628 *
629 *
630 * Return Value:
631 * None.
632 *
633-*/
634
635
636VOID
637vMgrEncodeProbeRequest(
638 IN PWLAN_FR_PROBEREQ pFrame
639 )
640{
641 pFrame->pHdr = (PUWLAN_80211HDR)pFrame->pBuf;
642 pFrame->len = WLAN_HDR_ADDR3_LEN;
643 return;
644}
645
646/*+
647 *
648 * Routine Description:
649 * Decode Probe Request
650 *
651 *
652 * Return Value:
653 * None.
654 *
655-*/
656
657VOID
658vMgrDecodeProbeRequest(
659 IN PWLAN_FR_PROBEREQ pFrame
660 )
661{
662 PWLAN_IE pItem;
663
664 pFrame->pHdr = (PUWLAN_80211HDR)pFrame->pBuf;
665
666 // Information elements
667 pItem = (PWLAN_IE)(WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3)));
668
669 while( ((PBYTE)pItem) < (pFrame->pBuf + pFrame->len) ) {
670
671 switch (pItem->byElementID) {
672 case WLAN_EID_SSID:
673 if (pFrame->pSSID == NULL)
674 pFrame->pSSID = (PWLAN_IE_SSID)pItem;
675 break;
676
677 case WLAN_EID_SUPP_RATES:
678 if (pFrame->pSuppRates == NULL)
679 pFrame->pSuppRates = (PWLAN_IE_SUPP_RATES)pItem;
680 break;
681
682 case WLAN_EID_EXTSUPP_RATES:
683 if (pFrame->pExtSuppRates == NULL)
684 pFrame->pExtSuppRates = (PWLAN_IE_SUPP_RATES)pItem;
685 break;
686
687 default:
688 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Bad EID=%dd in probereq\n", pItem->byElementID);
689 break;
690 }
691
692 pItem = (PWLAN_IE)(((PBYTE)pItem) + 2 + pItem->len);
693 }
694 return;
695}
696
697
698/*+
699 *
700 * Routine Description:
701 * Encode Probe Response
702 *
703 *
704 * Return Value:
705 * None.
706 *
707-*/
708
709
710VOID
711vMgrEncodeProbeResponse(
712 IN PWLAN_FR_PROBERESP pFrame
713 )
714{
715 pFrame->pHdr = (PUWLAN_80211HDR)pFrame->pBuf;
716
717 // Fixed Fields
718 pFrame->pqwTimestamp = (PQWORD)(WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3))
719 + WLAN_PROBERESP_OFF_TS);
720 pFrame->pwBeaconInterval = (PWORD)(WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3))
721 + WLAN_PROBERESP_OFF_BCN_INT);
722 pFrame->pwCapInfo = (PWORD)(WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3))
723 + WLAN_PROBERESP_OFF_CAP_INFO);
724
725 pFrame->len = WLAN_HDR_ADDR3_LEN + WLAN_PROBERESP_OFF_CAP_INFO +
726 sizeof(*(pFrame->pwCapInfo));
727
728 return;
729}
730
731
732
733/*+
734 *
735 * Routine Description:
736 * Decode Probe Response
737 *
738 *
739 * Return Value:
740 * None.
741 *
742-*/
743
744VOID
745vMgrDecodeProbeResponse(
746 IN PWLAN_FR_PROBERESP pFrame
747 )
748{
749 PWLAN_IE pItem;
750// BYTE byCheckEID = 0;
751
752
753 pFrame->pHdr = (PUWLAN_80211HDR)pFrame->pBuf;
754
755 // Fixed Fields
756 pFrame->pqwTimestamp = (PQWORD)(WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3))
757 + WLAN_PROBERESP_OFF_TS);
758 pFrame->pwBeaconInterval = (PWORD)(WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3))
759 + WLAN_PROBERESP_OFF_BCN_INT);
760 pFrame->pwCapInfo = (PWORD)(WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3))
761 + WLAN_PROBERESP_OFF_CAP_INFO);
762
763 // Information elements
764 pItem = (PWLAN_IE)(WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3))
765 + WLAN_PROBERESP_OFF_SSID);
766
767 while( ((PBYTE)pItem) < (pFrame->pBuf + pFrame->len) ) {
768 /*
769 if (pItem->byElementID < byCheckEID)
770 break;
771 else
772 byCheckEID = pItem->byElementID;
773*/
774 switch (pItem->byElementID) {
775 case WLAN_EID_SSID:
776 if (pFrame->pSSID == NULL)
777 pFrame->pSSID = (PWLAN_IE_SSID)pItem;
778 break;
779 case WLAN_EID_SUPP_RATES:
780 if (pFrame->pSuppRates == NULL)
781 pFrame->pSuppRates = (PWLAN_IE_SUPP_RATES)pItem;
782 break;
783 case WLAN_EID_FH_PARMS:
784 break;
785 case WLAN_EID_DS_PARMS:
786 if (pFrame->pDSParms == NULL)
787 pFrame->pDSParms = (PWLAN_IE_DS_PARMS)pItem;
788 break;
789 case WLAN_EID_CF_PARMS:
790 if (pFrame->pCFParms == NULL)
791 pFrame->pCFParms = (PWLAN_IE_CF_PARMS)pItem;
792 break;
793 case WLAN_EID_IBSS_PARMS:
794 if (pFrame->pIBSSParms == NULL)
795 pFrame->pIBSSParms = (PWLAN_IE_IBSS_PARMS)pItem;
796 break;
797
798 case WLAN_EID_RSN:
799 if (pFrame->pRSN == NULL) {
800 pFrame->pRSN = (PWLAN_IE_RSN)pItem;
801 }
802 break;
803 case WLAN_EID_RSN_WPA:
804 if (pFrame->pRSNWPA == NULL) {
805 if (WPAb_Is_RSN((PWLAN_IE_RSN_EXT)pItem) == TRUE)
806 pFrame->pRSNWPA = (PWLAN_IE_RSN_EXT)pItem;
807 }
808 break;
809 case WLAN_EID_ERP:
810 if (pFrame->pERP == NULL)
811 pFrame->pERP = (PWLAN_IE_ERP)pItem;
812 break;
813 case WLAN_EID_EXTSUPP_RATES:
814 if (pFrame->pExtSuppRates == NULL)
815 pFrame->pExtSuppRates = (PWLAN_IE_SUPP_RATES)pItem;
816 break;
817
818 case WLAN_EID_COUNTRY: //7
819 if (pFrame->pIE_Country == NULL)
820 pFrame->pIE_Country = (PWLAN_IE_COUNTRY)pItem;
821 break;
822
823 case WLAN_EID_PWR_CONSTRAINT: //32
824 if (pFrame->pIE_PowerConstraint == NULL)
825 pFrame->pIE_PowerConstraint = (PWLAN_IE_PW_CONST)pItem;
826 break;
827
828 case WLAN_EID_CH_SWITCH: //37
829 if (pFrame->pIE_CHSW == NULL)
830 pFrame->pIE_CHSW = (PWLAN_IE_CH_SW)pItem;
831 break;
832
833 case WLAN_EID_QUIET: //40
834 if (pFrame->pIE_Quiet == NULL)
835 pFrame->pIE_Quiet = (PWLAN_IE_QUIET)pItem;
836 break;
837
838 case WLAN_EID_IBSS_DFS:
839 if (pFrame->pIE_IBSSDFS == NULL)
840 pFrame->pIE_IBSSDFS = (PWLAN_IE_IBSS_DFS)pItem;
841 break;
842
843 default:
844 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Bad EID=%dd in proberesp\n", pItem->byElementID);
845 break;
846 }
847
848 pItem = (PWLAN_IE)(((PBYTE)pItem) + 2 + pItem->len);
849 }
850 return;
851}
852
853
854/*+
855 *
856 * Routine Description:
857 * Encode Authentication frame
858 *
859 *
860 * Return Value:
861 * None.
862 *
863-*/
864
865VOID
866vMgrEncodeAuthen(
867 IN PWLAN_FR_AUTHEN pFrame
868 )
869{
870 pFrame->pHdr = (PUWLAN_80211HDR)pFrame->pBuf;
871
872 // Fixed Fields
873 pFrame->pwAuthAlgorithm = (PWORD)(WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3))
874 + WLAN_AUTHEN_OFF_AUTH_ALG);
875 pFrame->pwAuthSequence = (PWORD)(WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3))
876 + WLAN_AUTHEN_OFF_AUTH_SEQ);
877 pFrame->pwStatus = (PWORD)(WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3))
878 + WLAN_AUTHEN_OFF_STATUS);
879 pFrame->len = WLAN_HDR_ADDR3_LEN + WLAN_AUTHEN_OFF_STATUS + sizeof(*(pFrame->pwStatus));
880
881 return;
882}
883
884
885/*+
886 *
887 * Routine Description:
888 * Decode Authentication
889 *
890 *
891 * Return Value:
892 * None.
893 *
894-*/
895
896VOID
897vMgrDecodeAuthen(
898 IN PWLAN_FR_AUTHEN pFrame
899 )
900{
901 PWLAN_IE pItem;
902
903 pFrame->pHdr = (PUWLAN_80211HDR)pFrame->pBuf;
904
905 // Fixed Fields
906 pFrame->pwAuthAlgorithm = (PWORD)(WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3))
907 + WLAN_AUTHEN_OFF_AUTH_ALG);
908 pFrame->pwAuthSequence = (PWORD)(WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3))
909 + WLAN_AUTHEN_OFF_AUTH_SEQ);
910 pFrame->pwStatus = (PWORD)(WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3))
911 + WLAN_AUTHEN_OFF_STATUS);
912
913 // Information elements
914 pItem = (PWLAN_IE)(WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3))
915 + WLAN_AUTHEN_OFF_CHALLENGE);
916
917 if ((((PBYTE)pItem) < (pFrame->pBuf + pFrame->len)) && (pItem->byElementID == WLAN_EID_CHALLENGE)) {
918 pFrame->pChallenge = (PWLAN_IE_CHALLENGE)pItem;
919 }
920
921 return;
922}
923
924
925/*+
926 *
927 * Routine Description:
928 * Encode Authentication
929 *
930 *
931 * Return Value:
932 * None.
933 *
934-*/
935
936VOID
937vMgrEncodeDeauthen(
938 IN PWLAN_FR_DEAUTHEN pFrame
939 )
940{
941 pFrame->pHdr = (PUWLAN_80211HDR)pFrame->pBuf;
942
943 // Fixed Fields
944 pFrame->pwReason = (PWORD)(WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3))
945 + WLAN_DEAUTHEN_OFF_REASON);
946 pFrame->len = WLAN_HDR_ADDR3_LEN + WLAN_DEAUTHEN_OFF_REASON + sizeof(*(pFrame->pwReason));
947
948 return;
949}
950
951
952/*+
953 *
954 * Routine Description:
955 * Decode Deauthentication
956 *
957 *
958 * Return Value:
959 * None.
960 *
961-*/
962
963VOID
964vMgrDecodeDeauthen(
965 IN PWLAN_FR_DEAUTHEN pFrame
966 )
967{
968 pFrame->pHdr = (PUWLAN_80211HDR)pFrame->pBuf;
969
970 // Fixed Fields
971 pFrame->pwReason = (PWORD)(WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3))
972 + WLAN_DEAUTHEN_OFF_REASON);
973
974 return;
975}
976
977
978/*+
979 *
980 * Routine Description: (AP)
981 * Encode Reassociation Response
982 *
983 *
984 * Return Value:
985 * None.
986 *
987-*/
988
989VOID
990vMgrEncodeReassocResponse(
991 IN PWLAN_FR_REASSOCRESP pFrame
992 )
993{
994 pFrame->pHdr = (PUWLAN_80211HDR)pFrame->pBuf;
995
996 // Fixed Fields
997 pFrame->pwCapInfo = (PWORD)(WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3))
998 + WLAN_REASSOCRESP_OFF_CAP_INFO);
999 pFrame->pwStatus = (PWORD)(WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3))
1000 + WLAN_REASSOCRESP_OFF_STATUS);
1001 pFrame->pwAid = (PWORD)(WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3))
1002 + WLAN_REASSOCRESP_OFF_AID);
1003
1004 pFrame->len = WLAN_HDR_ADDR3_LEN + WLAN_REASSOCRESP_OFF_AID + sizeof(*(pFrame->pwAid));
1005
1006 return;
1007}
1008
1009
1010/*+
1011 *
1012 * Routine Description:
1013 * Decode Reassociation Response
1014 *
1015 *
1016 * Return Value:
1017 * None.
1018 *
1019-*/
1020
1021
1022VOID
1023vMgrDecodeReassocResponse(
1024 IN PWLAN_FR_REASSOCRESP pFrame
1025 )
1026{
1027 PWLAN_IE pItem;
1028
1029 pFrame->pHdr = (PUWLAN_80211HDR)pFrame->pBuf;
1030
1031 // Fixed Fields
1032 pFrame->pwCapInfo = (PWORD)(WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3))
1033 + WLAN_REASSOCRESP_OFF_CAP_INFO);
1034 pFrame->pwStatus = (PWORD)(WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3))
1035 + WLAN_REASSOCRESP_OFF_STATUS);
1036 pFrame->pwAid = (PWORD)(WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3))
1037 + WLAN_REASSOCRESP_OFF_AID);
1038
1039 //Information elements
1040 pFrame->pSuppRates = (PWLAN_IE_SUPP_RATES)(WLAN_HDR_A3_DATA_PTR(&(pFrame->pHdr->sA3))
1041 + WLAN_REASSOCRESP_OFF_SUPP_RATES);
1042
1043 pItem = (PWLAN_IE)(pFrame->pSuppRates);
1044 pItem = (PWLAN_IE)(((PBYTE)pItem) + 2 + pItem->len);
1045
1046 if ((((PBYTE)pItem) < (pFrame->pBuf + pFrame->len)) && (pItem->byElementID == WLAN_EID_EXTSUPP_RATES)) {
1047 pFrame->pExtSuppRates = (PWLAN_IE_SUPP_RATES)pItem;
1048 }
1049 return;
1050}
diff --git a/drivers/staging/vt6655/80211mgr.h b/drivers/staging/vt6655/80211mgr.h
new file mode 100644
index 000000000000..dc54a65edab5
--- /dev/null
+++ b/drivers/staging/vt6655/80211mgr.h
@@ -0,0 +1,832 @@
1/*
2 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
3 * All rights reserved.
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * File: 80211mgr.h
20 *
21 * Purpose: Defines the macros, types, and functions for dealing
22 * with 802.11 managment frames.
23 *
24 * Author: Lyndon Chen
25 *
26 * Date: May 8, 2002
27 *
28 */
29
30
31#ifndef __80211MGR_H__
32#define __80211MGR_H__
33
34#if !defined(__TTYPE_H__)
35#include "ttype.h"
36#endif
37#if !defined(__80211HDR_H__)
38#include "80211hdr.h"
39#endif
40
41
42/*--------------------- Export Definitions -------------------------*/
43
44#define WLAN_MIN_ARRAY 1
45
46// Information Element ID value
47#define WLAN_EID_SSID 0
48#define WLAN_EID_SUPP_RATES 1
49#define WLAN_EID_FH_PARMS 2
50#define WLAN_EID_DS_PARMS 3
51#define WLAN_EID_CF_PARMS 4
52#define WLAN_EID_TIM 5
53#define WLAN_EID_IBSS_PARMS 6
54#define WLAN_EID_COUNTRY 7
55#define WLAN_EID_CHALLENGE 16
56#define WLAN_EID_PWR_CONSTRAINT 32
57#define WLAN_EID_PWR_CAPABILITY 33
58#define WLAN_EID_TPC_REQ 34
59#define WLAN_EID_TPC_REP 35
60#define WLAN_EID_SUPP_CH 36
61#define WLAN_EID_CH_SWITCH 37
62#define WLAN_EID_MEASURE_REQ 38
63#define WLAN_EID_MEASURE_REP 39
64#define WLAN_EID_QUIET 40
65#define WLAN_EID_IBSS_DFS 41
66#define WLAN_EID_ERP 42
67// reference 802.11i 7.3.2 table 20
68#define WLAN_EID_RSN 48
69#define WLAN_EID_EXTSUPP_RATES 50
70// reference WiFi WPA spec.
71#define WLAN_EID_RSN_WPA 221
72
73
74#define WLAN_EID_ERP_NONERP_PRESENT 0x01
75#define WLAN_EID_ERP_USE_PROTECTION 0x02
76#define WLAN_EID_ERP_BARKER_MODE 0x04
77
78// Reason Codes
79#define WLAN_MGMT_REASON_RSVD 0
80#define WLAN_MGMT_REASON_UNSPEC 1
81#define WLAN_MGMT_REASON_PRIOR_AUTH_INVALID 2
82#define WLAN_MGMT_REASON_DEAUTH_LEAVING 3
83#define WLAN_MGMT_REASON_DISASSOC_INACTIVE 4
84#define WLAN_MGMT_REASON_DISASSOC_AP_BUSY 5
85#define WLAN_MGMT_REASON_CLASS2_NONAUTH 6
86#define WLAN_MGMT_REASON_CLASS3_NONASSOC 7
87#define WLAN_MGMT_REASON_DISASSOC_STA_HASLEFT 8
88#define WLAN_MGMT_REASON_CANT_ASSOC_NONAUTH 9
89#define WLAN_MGMT_REASON_DISASSOC_PWR_CAP_UNACCEPT 10
90#define WLAN_MGMT_REASON_DISASSOC_SUPP_CH_UNACCEPT 11
91#define WLAN_MGMT_REASON_INVALID_IE 13
92#define WLAN_MGMT_REASON_MIC_FAILURE 14
93#define WLAN_MGMT_REASON_4WAY_HANDSHAKE_TIMEOUT 15
94#define WLAN_MGMT_REASON_GRPKEY_UPDATE_TIMEOUT 16
95#define WLAN_MGMT_REASON_4WAY_INFO_DIFFERENT 17
96#define WLAN_MGMT_REASON_MULTCAST_CIPHER_INVALID 18
97#define WLAN_MGMT_REASON_UNCAST_CIPHER_INVALID 19
98#define WLAN_MGMT_REASON_AKMP_INVALID 20
99#define WLAN_MGMT_REASON_RSNE_UNSUPPORTED 21
100#define WLAN_MGMT_REASON_RSNE_CAP_INVALID 22
101#define WLAN_MGMT_REASON_80211X_AUTH_FAILED 23
102
103// Status Codes
104#define WLAN_MGMT_STATUS_SUCCESS 0
105#define WLAN_MGMT_STATUS_UNSPEC_FAILURE 1
106#define WLAN_MGMT_STATUS_CAPS_UNSUPPORTED 10
107#define WLAN_MGMT_STATUS_REASSOC_NO_ASSOC 11
108#define WLAN_MGMT_STATUS_ASSOC_DENIED_UNSPEC 12
109#define WLAN_MGMT_STATUS_UNSUPPORTED_AUTHALG 13
110#define WLAN_MGMT_STATUS_RX_AUTH_NOSEQ 14
111#define WLAN_MGMT_STATUS_CHALLENGE_FAIL 15
112#define WLAN_MGMT_STATUS_AUTH_TIMEOUT 16
113#define WLAN_MGMT_STATUS_ASSOC_DENIED_BUSY 17
114#define WLAN_MGMT_STATUS_ASSOC_DENIED_RATES 18
115#define WLAN_MGMT_STATUS_ASSOC_DENIED_SHORTPREAMBLE 19
116#define WLAN_MGMT_STATUS_ASSOC_DENIED_PBCC 20
117#define WLAN_MGMT_STATUS_ASSOC_DENIED_AGILITY 21
118
119// reference 802.11h 7.3.1.9
120//
121#define WLAN_MGMT_STATUS_ASSOC_REJECT_BCS_SPECTRUM_MNG 22
122#define WLAN_MGMT_STATUS_ASSOC_REJECT_BCS_PWR_CAP 23
123#define WLAN_MGMT_STATUS_ASSOC_REJECT_BCS_SUPP_CH 24
124//
125// reference 802.11g 7.3.1.9
126//
127#define WLAN_MGMT_STATUS_SHORTSLOTTIME_UNSUPPORTED 25
128#define WLAN_MGMT_STATUS_DSSSOFDM_UNSUPPORTED 26
129//
130// reference 802.11i 7.3.1.9 table 19
131//
132#define WLAN_MGMT_STATUS_INVALID_IE 40
133#define WLAN_MGMT_STATUS_GROUP_CIPHER_INVALID 41
134#define WLAN_MGMT_STATUS_PAIRWISE_CIPHER_INVALID 42
135#define WLAN_MGMT_STATUS_AKMP_INVALID 43
136#define WLAN_MGMT_STATUS_UNSUPPORT_RSN_IE_VER 44
137#define WLAN_MGMT_STATUS_INVALID_RSN_IE_CAP 45
138#define WLAN_MGMT_STATUS_CIPHER_REJECT 46
139
140
141
142// Auth Algorithm
143#define WLAN_AUTH_ALG_OPENSYSTEM 0
144#define WLAN_AUTH_ALG_SHAREDKEY 1
145
146
147
148// Management Frame Field Offsets
149// Note: Not all fields are listed because of variable lengths.
150// Note: These offsets are from the start of the frame data
151
152#define WLAN_BEACON_OFF_TS 0
153#define WLAN_BEACON_OFF_BCN_INT 8
154#define WLAN_BEACON_OFF_CAPINFO 10
155#define WLAN_BEACON_OFF_SSID 12
156
157#define WLAN_DISASSOC_OFF_REASON 0
158
159#define WLAN_ASSOCREQ_OFF_CAP_INFO 0
160#define WLAN_ASSOCREQ_OFF_LISTEN_INT 2
161#define WLAN_ASSOCREQ_OFF_SSID 4
162
163#define WLAN_ASSOCRESP_OFF_CAP_INFO 0
164#define WLAN_ASSOCRESP_OFF_STATUS 2
165#define WLAN_ASSOCRESP_OFF_AID 4
166#define WLAN_ASSOCRESP_OFF_SUPP_RATES 6
167
168#define WLAN_REASSOCREQ_OFF_CAP_INFO 0
169#define WLAN_REASSOCREQ_OFF_LISTEN_INT 2
170#define WLAN_REASSOCREQ_OFF_CURR_AP 4
171#define WLAN_REASSOCREQ_OFF_SSID 10
172
173#define WLAN_REASSOCRESP_OFF_CAP_INFO 0
174#define WLAN_REASSOCRESP_OFF_STATUS 2
175#define WLAN_REASSOCRESP_OFF_AID 4
176#define WLAN_REASSOCRESP_OFF_SUPP_RATES 6
177
178#define WLAN_PROBEREQ_OFF_SSID 0
179
180#define WLAN_PROBERESP_OFF_TS 0
181#define WLAN_PROBERESP_OFF_BCN_INT 8
182#define WLAN_PROBERESP_OFF_CAP_INFO 10
183#define WLAN_PROBERESP_OFF_SSID 12
184
185#define WLAN_AUTHEN_OFF_AUTH_ALG 0
186#define WLAN_AUTHEN_OFF_AUTH_SEQ 2
187#define WLAN_AUTHEN_OFF_STATUS 4
188#define WLAN_AUTHEN_OFF_CHALLENGE 6
189
190#define WLAN_DEAUTHEN_OFF_REASON 0
191
192
193//
194// Cipher Suite Selectors defiened in 802.11i
195//
196#define WLAN_11i_CSS_USE_GROUP 0
197#define WLAN_11i_CSS_WEP40 1
198#define WLAN_11i_CSS_TKIP 2
199#define WLAN_11i_CSS_CCMP 4
200#define WLAN_11i_CSS_WEP104 5
201#define WLAN_11i_CSS_UNKNOWN 255
202
203//
204// Authentication and Key Management Suite Selectors defined in 802.11i
205//
206#define WLAN_11i_AKMSS_802_1X 1
207#define WLAN_11i_AKMSS_PSK 2
208#define WLAN_11i_AKMSS_UNKNOWN 255
209
210// Measurement type definitions reference ieee 802.11h Table 20b
211#define MEASURE_TYPE_BASIC 0
212#define MEASURE_TYPE_CCA 1
213#define MEASURE_TYPE_RPI 2
214
215// Measurement request mode definitions reference ieee 802.11h Figure 46h
216#define MEASURE_MODE_ENABLE 0x02
217#define MEASURE_MODE_REQ 0x04
218#define MEASURE_MODE_REP 0x08
219
220// Measurement report mode definitions reference ieee 802.11h Figure 46m
221#define MEASURE_MODE_LATE 0x01
222#define MEASURE_MODE_INCAPABLE 0x02
223#define MEASURE_MODE_REFUSED 0x04
224
225
226
227/*--------------------- Export Classes ----------------------------*/
228
229/*--------------------- Export Variables --------------------------*/
230
231/*--------------------- Export Types ------------------------------*/
232
233
234// Information Element Types
235
236#pragma pack(1)
237typedef struct tagWLAN_IE {
238 BYTE byElementID;
239 BYTE len;
240}__attribute__ ((__packed__))
241WLAN_IE, *PWLAN_IE;
242
243
244// Service Set Identity (SSID)
245#pragma pack(1)
246typedef struct tagWLAN_IE_SSID {
247 BYTE byElementID;
248 BYTE len;
249 BYTE abySSID[1];
250}__attribute__ ((__packed__))
251WLAN_IE_SSID, *PWLAN_IE_SSID;
252
253
254// Supported Rates
255#pragma pack(1)
256typedef struct tagWLAN_IE_SUPP_RATES {
257 BYTE byElementID;
258 BYTE len;
259 BYTE abyRates[1];
260}__attribute__ ((__packed__))
261WLAN_IE_SUPP_RATES, *PWLAN_IE_SUPP_RATES;
262
263
264
265// FH Parameter Set
266#pragma pack(1)
267typedef struct _WLAN_IE_FH_PARMS {
268 BYTE byElementID;
269 BYTE len;
270 WORD wDwellTime;
271 BYTE byHopSet;
272 BYTE byHopPattern;
273 BYTE byHopIndex;
274} WLAN_IE_FH_PARMS, *PWLAN_IE_FH_PARMS;
275
276
277// DS Parameter Set
278#pragma pack(1)
279typedef struct tagWLAN_IE_DS_PARMS {
280 BYTE byElementID;
281 BYTE len;
282 BYTE byCurrChannel;
283}__attribute__ ((__packed__))
284WLAN_IE_DS_PARMS, *PWLAN_IE_DS_PARMS;
285
286
287// CF Parameter Set
288#pragma pack(1)
289typedef struct tagWLAN_IE_CF_PARMS {
290 BYTE byElementID;
291 BYTE len;
292 BYTE byCFPCount;
293 BYTE byCFPPeriod;
294 WORD wCFPMaxDuration;
295 WORD wCFPDurRemaining;
296}__attribute__ ((__packed__))
297WLAN_IE_CF_PARMS, *PWLAN_IE_CF_PARMS;
298
299
300// TIM
301#pragma pack(1)
302typedef struct tagWLAN_IE_TIM {
303 BYTE byElementID;
304 BYTE len;
305 BYTE byDTIMCount;
306 BYTE byDTIMPeriod;
307 BYTE byBitMapCtl;
308 BYTE byVirtBitMap[1];
309}__attribute__ ((__packed__))
310WLAN_IE_TIM, *PWLAN_IE_TIM;
311
312
313// IBSS Parameter Set
314#pragma pack(1)
315typedef struct tagWLAN_IE_IBSS_PARMS {
316 BYTE byElementID;
317 BYTE len;
318 WORD wATIMWindow;
319}__attribute__ ((__packed__))
320WLAN_IE_IBSS_PARMS, *PWLAN_IE_IBSS_PARMS;
321
322
323// Challenge Text
324#pragma pack(1)
325typedef struct tagWLAN_IE_CHALLENGE {
326 BYTE byElementID;
327 BYTE len;
328 BYTE abyChallenge[1];
329}__attribute__ ((__packed__))
330WLAN_IE_CHALLENGE, *PWLAN_IE_CHALLENGE;
331
332
333#pragma pack(1)
334typedef struct tagWLAN_IE_RSN_EXT {
335 BYTE byElementID;
336 BYTE len;
337 BYTE abyOUI[4];
338 WORD wVersion;
339 BYTE abyMulticast[4];
340 WORD wPKCount;
341 struct {
342 BYTE abyOUI[4];
343 } PKSList[1]; // the rest is variable so need to
344 // overlay ieauth structure
345} WLAN_IE_RSN_EXT, *PWLAN_IE_RSN_EXT;
346
347#pragma pack(1)
348typedef struct tagWLAN_IE_RSN_AUTH {
349 WORD wAuthCount;
350 struct {
351 BYTE abyOUI[4];
352 } AuthKSList[1];
353} WLAN_IE_RSN_AUTH, *PWLAN_IE_RSN_AUTH;
354
355// RSN Identity
356#pragma pack(1)
357typedef struct tagWLAN_IE_RSN {
358 BYTE byElementID;
359 BYTE len;
360 WORD wVersion;
361 BYTE abyRSN[WLAN_MIN_ARRAY];
362} WLAN_IE_RSN, *PWLAN_IE_RSN;
363
364
365// ERP
366#pragma pack(1)
367typedef struct tagWLAN_IE_ERP {
368 BYTE byElementID;
369 BYTE len;
370 BYTE byContext;
371}__attribute__ ((__packed__))
372WLAN_IE_ERP, *PWLAN_IE_ERP;
373
374
375#pragma pack(1)
376typedef struct _MEASEURE_REQ {
377 BYTE byChannel;
378 BYTE abyStartTime[8];
379 BYTE abyDuration[2];
380} MEASEURE_REQ, *PMEASEURE_REQ,
381 MEASEURE_REQ_BASIC, *PMEASEURE_REQ_BASIC,
382 MEASEURE_REQ_CCA, *PMEASEURE_REQ_CCA,
383 MEASEURE_REQ_RPI, *PMEASEURE_REQ_RPI;
384
385typedef struct _MEASEURE_REP_BASIC {
386 BYTE byChannel;
387 BYTE abyStartTime[8];
388 BYTE abyDuration[2];
389 BYTE byMap;
390} MEASEURE_REP_BASIC, *PMEASEURE_REP_BASIC;
391
392typedef struct _MEASEURE_REP_CCA {
393 BYTE byChannel;
394 BYTE abyStartTime[8];
395 BYTE abyDuration[2];
396 BYTE byCCABusyFraction;
397} MEASEURE_REP_CCA, *PMEASEURE_REP_CCA;
398
399typedef struct _MEASEURE_REP_RPI {
400 BYTE byChannel;
401 BYTE abyStartTime[8];
402 BYTE abyDuration[2];
403 BYTE abyRPIdensity[8];
404} MEASEURE_REP_RPI, *PMEASEURE_REP_RPI;
405
406typedef union _MEASEURE_REP {
407
408 MEASEURE_REP_BASIC sBasic;
409 MEASEURE_REP_CCA sCCA;
410 MEASEURE_REP_RPI sRPI;
411
412} MEASEURE_REP, *PMEASEURE_REP;
413
414typedef struct _WLAN_IE_MEASURE_REQ {
415 BYTE byElementID;
416 BYTE len;
417 BYTE byToken;
418 BYTE byMode;
419 BYTE byType;
420 MEASEURE_REQ sReq;
421} WLAN_IE_MEASURE_REQ, *PWLAN_IE_MEASURE_REQ;
422
423typedef struct _WLAN_IE_MEASURE_REP {
424 BYTE byElementID;
425 BYTE len;
426 BYTE byToken;
427 BYTE byMode;
428 BYTE byType;
429 MEASEURE_REP sRep;
430} WLAN_IE_MEASURE_REP, *PWLAN_IE_MEASURE_REP;
431
432typedef struct _WLAN_IE_CH_SW {
433 BYTE byElementID;
434 BYTE len;
435 BYTE byMode;
436 BYTE byChannel;
437 BYTE byCount;
438} WLAN_IE_CH_SW, *PWLAN_IE_CH_SW;
439
440typedef struct _WLAN_IE_QUIET {
441 BYTE byElementID;
442 BYTE len;
443 BYTE byQuietCount;
444 BYTE byQuietPeriod;
445 BYTE abyQuietDuration[2];
446 BYTE abyQuietOffset[2];
447} WLAN_IE_QUIET, *PWLAN_IE_QUIET;
448
449typedef struct _WLAN_IE_COUNTRY {
450 BYTE byElementID;
451 BYTE len;
452 BYTE abyCountryString[3];
453 BYTE abyCountryInfo[3];
454} WLAN_IE_COUNTRY, *PWLAN_IE_COUNTRY;
455
456typedef struct _WLAN_IE_PW_CONST {
457 BYTE byElementID;
458 BYTE len;
459 BYTE byPower;
460} WLAN_IE_PW_CONST, *PWLAN_IE_PW_CONST;
461
462typedef struct _WLAN_IE_PW_CAP {
463 BYTE byElementID;
464 BYTE len;
465 BYTE byMinPower;
466 BYTE byMaxPower;
467} WLAN_IE_PW_CAP, *PWLAN_IE_PW_CAP;
468
469typedef struct _WLAN_IE_SUPP_CH {
470 BYTE byElementID;
471 BYTE len;
472 BYTE abyChannelTuple[2];
473} WLAN_IE_SUPP_CH, *PWLAN_IE_SUPP_CH;
474
475typedef struct _WLAN_IE_TPC_REQ {
476 BYTE byElementID;
477 BYTE len;
478} WLAN_IE_TPC_REQ, *PWLAN_IE_TPC_REQ;
479
480typedef struct _WLAN_IE_TPC_REP {
481 BYTE byElementID;
482 BYTE len;
483 BYTE byTxPower;
484 BYTE byLinkMargin;
485} WLAN_IE_TPC_REP, *PWLAN_IE_TPC_REP;
486
487
488typedef struct _WLAN_IE_IBSS_DFS {
489 BYTE byElementID;
490 BYTE len;
491 BYTE abyDFSOwner[6];
492 BYTE byDFSRecovery;
493 BYTE abyChannelMap[2];
494} WLAN_IE_IBSS_DFS, *PWLAN_IE_IBSS_DFS;
495
496#pragma pack()
497
498
499
500// Frame Types
501// prototype structure, all mgmt frame types will start with these members
502typedef struct tagWLAN_FR_MGMT {
503
504 UINT uType;
505 UINT len;
506 PBYTE pBuf;
507 PUWLAN_80211HDR pHdr;
508
509} WLAN_FR_MGMT, *PWLAN_FR_MGMT;
510
511// Beacon frame
512typedef struct tagWLAN_FR_BEACON {
513
514 UINT uType;
515 UINT len;
516 PBYTE pBuf;
517 PUWLAN_80211HDR pHdr;
518 // fixed fields
519 PQWORD pqwTimestamp;
520 PWORD pwBeaconInterval;
521 PWORD pwCapInfo;
522 /*-- info elements ----------*/
523 PWLAN_IE_SSID pSSID;
524 PWLAN_IE_SUPP_RATES pSuppRates;
525// PWLAN_IE_FH_PARMS pFHParms;
526 PWLAN_IE_DS_PARMS pDSParms;
527 PWLAN_IE_CF_PARMS pCFParms;
528 PWLAN_IE_TIM pTIM;
529 PWLAN_IE_IBSS_PARMS pIBSSParms;
530 PWLAN_IE_RSN pRSN;
531 PWLAN_IE_RSN_EXT pRSNWPA;
532 PWLAN_IE_ERP pERP;
533 PWLAN_IE_SUPP_RATES pExtSuppRates;
534 PWLAN_IE_COUNTRY pIE_Country;
535 PWLAN_IE_PW_CONST pIE_PowerConstraint;
536 PWLAN_IE_CH_SW pIE_CHSW;
537 PWLAN_IE_IBSS_DFS pIE_IBSSDFS;
538 PWLAN_IE_QUIET pIE_Quiet;
539
540} WLAN_FR_BEACON, *PWLAN_FR_BEACON;
541
542
543// IBSS ATIM frame
544typedef struct tagWLAN_FR_IBSSATIM {
545
546 UINT uType;
547 UINT len;
548 PBYTE pBuf;
549 PUWLAN_80211HDR pHdr;
550
551 // fixed fields
552 // info elements
553 // this frame type has a null body
554
555} WLAN_FR_IBSSATIM, *PWLAN_FR_IBSSATIM;
556
557// Disassociation
558typedef struct tagWLAN_FR_DISASSOC {
559
560 UINT uType;
561 UINT len;
562 PBYTE pBuf;
563 PUWLAN_80211HDR pHdr;
564 /*-- fixed fields -----------*/
565 PWORD pwReason;
566 /*-- info elements ----------*/
567
568} WLAN_FR_DISASSOC, *PWLAN_FR_DISASSOC;
569
570// Association Request
571typedef struct tagWLAN_FR_ASSOCREQ {
572
573 UINT uType;
574 UINT len;
575 PBYTE pBuf;
576 PUWLAN_80211HDR pHdr;
577 /*-- fixed fields -----------*/
578 PWORD pwCapInfo;
579 PWORD pwListenInterval;
580 /*-- info elements ----------*/
581 PWLAN_IE_SSID pSSID;
582 PWLAN_IE_SUPP_RATES pSuppRates;
583 PWLAN_IE_RSN pRSN;
584 PWLAN_IE_RSN_EXT pRSNWPA;
585 PWLAN_IE_SUPP_RATES pExtSuppRates;
586 PWLAN_IE_PW_CAP pCurrPowerCap;
587 PWLAN_IE_SUPP_CH pCurrSuppCh;
588
589} WLAN_FR_ASSOCREQ, *PWLAN_FR_ASSOCREQ;
590
591// Association Response
592typedef struct tagWLAN_FR_ASSOCRESP {
593
594 UINT uType;
595 UINT len;
596 PBYTE pBuf;
597 PUWLAN_80211HDR pHdr;
598 /*-- fixed fields -----------*/
599 PWORD pwCapInfo;
600 PWORD pwStatus;
601 PWORD pwAid;
602 /*-- info elements ----------*/
603 PWLAN_IE_SUPP_RATES pSuppRates;
604 PWLAN_IE_SUPP_RATES pExtSuppRates;
605
606} WLAN_FR_ASSOCRESP, *PWLAN_FR_ASSOCRESP;
607
608// Reassociation Request
609typedef struct tagWLAN_FR_REASSOCREQ {
610
611 UINT uType;
612 UINT len;
613 PBYTE pBuf;
614 PUWLAN_80211HDR pHdr;
615
616 /*-- fixed fields -----------*/
617 PWORD pwCapInfo;
618 PWORD pwListenInterval;
619 PIEEE_ADDR pAddrCurrAP;
620
621 /*-- info elements ----------*/
622 PWLAN_IE_SSID pSSID;
623 PWLAN_IE_SUPP_RATES pSuppRates;
624 PWLAN_IE_RSN pRSN;
625 PWLAN_IE_RSN_EXT pRSNWPA;
626 PWLAN_IE_SUPP_RATES pExtSuppRates;
627
628} WLAN_FR_REASSOCREQ, *PWLAN_FR_REASSOCREQ;
629
630// Reassociation Response
631typedef struct tagWLAN_FR_REASSOCRESP {
632
633 UINT uType;
634 UINT len;
635 PBYTE pBuf;
636 PUWLAN_80211HDR pHdr;
637 /*-- fixed fields -----------*/
638 PWORD pwCapInfo;
639 PWORD pwStatus;
640 PWORD pwAid;
641 /*-- info elements ----------*/
642 PWLAN_IE_SUPP_RATES pSuppRates;
643 PWLAN_IE_SUPP_RATES pExtSuppRates;
644
645} WLAN_FR_REASSOCRESP, *PWLAN_FR_REASSOCRESP;
646
647// Probe Request
648typedef struct tagWLAN_FR_PROBEREQ {
649
650 UINT uType;
651 UINT len;
652 PBYTE pBuf;
653 PUWLAN_80211HDR pHdr;
654 /*-- fixed fields -----------*/
655 /*-- info elements ----------*/
656 PWLAN_IE_SSID pSSID;
657 PWLAN_IE_SUPP_RATES pSuppRates;
658 PWLAN_IE_SUPP_RATES pExtSuppRates;
659
660} WLAN_FR_PROBEREQ, *PWLAN_FR_PROBEREQ;
661
662// Probe Response
663typedef struct tagWLAN_FR_PROBERESP {
664
665 UINT uType;
666 UINT len;
667 PBYTE pBuf;
668 PUWLAN_80211HDR pHdr;
669 /*-- fixed fields -----------*/
670 PQWORD pqwTimestamp;
671 PWORD pwBeaconInterval;
672 PWORD pwCapInfo;
673 /*-- info elements ----------*/
674 PWLAN_IE_SSID pSSID;
675 PWLAN_IE_SUPP_RATES pSuppRates;
676 PWLAN_IE_DS_PARMS pDSParms;
677 PWLAN_IE_CF_PARMS pCFParms;
678 PWLAN_IE_IBSS_PARMS pIBSSParms;
679 PWLAN_IE_RSN pRSN;
680 PWLAN_IE_RSN_EXT pRSNWPA;
681 PWLAN_IE_ERP pERP;
682 PWLAN_IE_SUPP_RATES pExtSuppRates;
683 PWLAN_IE_COUNTRY pIE_Country;
684 PWLAN_IE_PW_CONST pIE_PowerConstraint;
685 PWLAN_IE_CH_SW pIE_CHSW;
686 PWLAN_IE_IBSS_DFS pIE_IBSSDFS;
687 PWLAN_IE_QUIET pIE_Quiet;
688
689} WLAN_FR_PROBERESP, *PWLAN_FR_PROBERESP;
690
691// Authentication
692typedef struct tagWLAN_FR_AUTHEN {
693
694 UINT uType;
695 UINT len;
696 PBYTE pBuf;
697 PUWLAN_80211HDR pHdr;
698 /*-- fixed fields -----------*/
699 PWORD pwAuthAlgorithm;
700 PWORD pwAuthSequence;
701 PWORD pwStatus;
702 /*-- info elements ----------*/
703 PWLAN_IE_CHALLENGE pChallenge;
704
705} WLAN_FR_AUTHEN, *PWLAN_FR_AUTHEN;
706
707// Deauthenication
708typedef struct tagWLAN_FR_DEAUTHEN {
709
710 UINT uType;
711 UINT len;
712 PBYTE pBuf;
713 PUWLAN_80211HDR pHdr;
714 /*-- fixed fields -----------*/
715 PWORD pwReason;
716
717 /*-- info elements ----------*/
718
719} WLAN_FR_DEAUTHEN, *PWLAN_FR_DEAUTHEN;
720
721/*--------------------- Export Functions --------------------------*/
722VOID
723vMgrEncodeBeacon(
724 IN PWLAN_FR_BEACON pFrame
725 );
726
727VOID
728vMgrDecodeBeacon(
729 IN PWLAN_FR_BEACON pFrame
730 );
731
732VOID
733vMgrEncodeIBSSATIM(
734 IN PWLAN_FR_IBSSATIM pFrame
735 );
736
737VOID
738vMgrDecodeIBSSATIM(
739 IN PWLAN_FR_IBSSATIM pFrame
740 );
741
742VOID
743vMgrEncodeDisassociation(
744 IN PWLAN_FR_DISASSOC pFrame
745 );
746
747VOID
748vMgrDecodeDisassociation(
749 IN PWLAN_FR_DISASSOC pFrame
750 );
751
752VOID
753vMgrEncodeAssocRequest(
754 IN PWLAN_FR_ASSOCREQ pFrame
755 );
756
757VOID
758vMgrDecodeAssocRequest(
759 IN PWLAN_FR_ASSOCREQ pFrame
760 );
761
762VOID
763vMgrEncodeAssocResponse(
764 IN PWLAN_FR_ASSOCRESP pFrame
765 );
766
767VOID
768vMgrDecodeAssocResponse(
769 IN PWLAN_FR_ASSOCRESP pFrame
770 );
771
772VOID
773vMgrEncodeReassocRequest(
774 IN PWLAN_FR_REASSOCREQ pFrame
775 );
776
777VOID
778vMgrDecodeReassocRequest(
779 IN PWLAN_FR_REASSOCREQ pFrame
780 );
781
782VOID
783vMgrEncodeProbeRequest(
784 IN PWLAN_FR_PROBEREQ pFrame
785 );
786
787VOID
788vMgrDecodeProbeRequest(
789 IN PWLAN_FR_PROBEREQ pFrame
790 );
791
792VOID
793vMgrEncodeProbeResponse(
794 IN PWLAN_FR_PROBERESP pFrame
795 );
796
797VOID
798vMgrDecodeProbeResponse(
799 IN PWLAN_FR_PROBERESP pFrame
800 );
801
802VOID
803vMgrEncodeAuthen(
804 IN PWLAN_FR_AUTHEN pFrame
805 );
806
807VOID
808vMgrDecodeAuthen(
809 IN PWLAN_FR_AUTHEN pFrame
810 );
811
812VOID
813vMgrEncodeDeauthen(
814 IN PWLAN_FR_DEAUTHEN pFrame
815 );
816
817VOID
818vMgrDecodeDeauthen(
819 IN PWLAN_FR_DEAUTHEN pFrame
820 );
821
822VOID
823vMgrEncodeReassocResponse(
824 IN PWLAN_FR_REASSOCRESP pFrame
825 );
826
827VOID
828vMgrDecodeReassocResponse(
829 IN PWLAN_FR_REASSOCRESP pFrame
830 );
831
832#endif// __80211MGR_H__
diff --git a/drivers/staging/vt6655/IEEE11h.c b/drivers/staging/vt6655/IEEE11h.c
new file mode 100644
index 000000000000..5f25b8e88bd9
--- /dev/null
+++ b/drivers/staging/vt6655/IEEE11h.c
@@ -0,0 +1,324 @@
1/*
2 * Copyright (c) 1996, 2005 VIA Networking Technologies, Inc.
3 * All rights reserved.
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 *
20 * File: IEEE11h.c
21 *
22 * Purpose:
23 *
24 * Functions:
25 *
26 * Revision History:
27 *
28 * Author: Yiching Chen
29 *
30 * Date: Mar. 31, 2005
31 *
32 */
33
34
35#if !defined(__TTYPE_H__)
36#include "ttype.h"
37#endif
38#if !defined(__UMEM_H__)
39#include "umem.h"
40#endif
41#if !defined(__TMACRO_H__)
42#include "tmacro.h"
43#endif
44#if !defined(__TETHER_H__)
45#include "tether.h"
46#endif
47#if !defined(__IEEE11h_H__)
48#include "IEEE11h.h"
49#endif
50
51#if !defined(__DEVICE_H__)
52#include "device.h"
53#endif
54#if !defined(__WMGR_H__)
55#include "wmgr.h"
56#endif
57#if !defined(__RXTX_H__)
58#include "rxtx.h"
59#endif
60
61
62
63/*--------------------- Static Definitions -------------------------*/
64static int msglevel =MSG_LEVEL_INFO;
65
66#pragma pack(1)
67
68typedef struct _WLAN_FRAME_ACTION {
69 WLAN_80211HDR_A3 Header;
70 BYTE byCategory;
71 BYTE byAction;
72 BYTE abyVars[1];
73} WLAN_FRAME_ACTION, *PWLAN_FRAME_ACTION;
74
75typedef struct _WLAN_FRAME_MSRREQ {
76 WLAN_80211HDR_A3 Header;
77 BYTE byCategory;
78 BYTE byAction;
79 BYTE byDialogToken;
80 WLAN_IE_MEASURE_REQ sMSRReqEIDs[1];
81} WLAN_FRAME_MSRREQ, *PWLAN_FRAME_MSRREQ;
82
83typedef struct _WLAN_FRAME_MSRREP {
84 WLAN_80211HDR_A3 Header;
85 BYTE byCategory;
86 BYTE byAction;
87 BYTE byDialogToken;
88 WLAN_IE_MEASURE_REP sMSRRepEIDs[1];
89} WLAN_FRAME_MSRREP, *PWLAN_FRAME_MSRREP;
90
91typedef struct _WLAN_FRAME_TPCREQ {
92 WLAN_80211HDR_A3 Header;
93 BYTE byCategory;
94 BYTE byAction;
95 BYTE byDialogToken;
96 WLAN_IE_TPC_REQ sTPCReqEIDs;
97} WLAN_FRAME_TPCREQ, *PWLAN_FRAME_TPCREQ;
98
99typedef struct _WLAN_FRAME_TPCREP {
100 WLAN_80211HDR_A3 Header;
101 BYTE byCategory;
102 BYTE byAction;
103 BYTE byDialogToken;
104 WLAN_IE_TPC_REP sTPCRepEIDs;
105} WLAN_FRAME_TPCREP, *PWLAN_FRAME_TPCREP;
106
107#pragma pack()
108
109// action field reference ieee 802.11h Table 20e
110#define ACTION_MSRREQ 0
111#define ACTION_MSRREP 1
112#define ACTION_TPCREQ 2
113#define ACTION_TPCREP 3
114#define ACTION_CHSW 4
115
116/*--------------------- Static Classes ----------------------------*/
117
118/*--------------------- Static Variables --------------------------*/
119
120/*--------------------- Static Functions --------------------------*/
121static BOOL s_bRxMSRReq(PSMgmtObject pMgmt, PWLAN_FRAME_MSRREQ pMSRReq, UINT uLength)
122{
123 UINT uNumOfEIDs = 0;
124 BOOL bResult = TRUE;
125
126 if (uLength <= WLAN_A3FR_MAXLEN) {
127 MEMvCopy(pMgmt->abyCurrentMSRReq, pMSRReq, uLength);
128 }
129 uNumOfEIDs = ((uLength - OFFSET(WLAN_FRAME_MSRREQ, sMSRReqEIDs))/ (sizeof(WLAN_IE_MEASURE_REQ)));
130 pMgmt->pCurrMeasureEIDRep = &(((PWLAN_FRAME_MSRREP) (pMgmt->abyCurrentMSRRep))->sMSRRepEIDs[0]);
131 pMgmt->uLengthOfRepEIDs = 0;
132 bResult = CARDbStartMeasure(pMgmt->pAdapter,
133 ((PWLAN_FRAME_MSRREQ) (pMgmt->abyCurrentMSRReq))->sMSRReqEIDs,
134 uNumOfEIDs
135 );
136 return (bResult);
137}
138
139
140static BOOL s_bRxTPCReq(PSMgmtObject pMgmt, PWLAN_FRAME_TPCREQ pTPCReq, BYTE byRate, BYTE byRSSI)
141{
142 PWLAN_FRAME_TPCREP pFrame;
143 PSTxMgmtPacket pTxPacket = NULL;
144
145
146 pTxPacket = (PSTxMgmtPacket)pMgmt->pbyMgmtPacketPool;
147 memset(pTxPacket, 0, sizeof(STxMgmtPacket) + WLAN_A3FR_MAXLEN);
148 pTxPacket->p80211Header = (PUWLAN_80211HDR)((PBYTE)pTxPacket + sizeof(STxMgmtPacket));
149
150 pFrame = (PWLAN_FRAME_TPCREP)((PBYTE)pTxPacket + sizeof(STxMgmtPacket));
151
152 pFrame->Header.wFrameCtl = ( WLAN_SET_FC_FTYPE(WLAN_FTYPE_MGMT) |
153 WLAN_SET_FC_FSTYPE(WLAN_FSTYPE_ACTION)
154 );
155
156 MEMvCopy( pFrame->Header.abyAddr1, pTPCReq->Header.abyAddr2, WLAN_ADDR_LEN);
157 MEMvCopy( pFrame->Header.abyAddr2, CARDpGetCurrentAddress(pMgmt->pAdapter), WLAN_ADDR_LEN);
158 MEMvCopy( pFrame->Header.abyAddr3, pMgmt->abyCurrBSSID, WLAN_BSSID_LEN);
159
160 pFrame->byCategory = 0;
161 pFrame->byAction = 3;
162 pFrame->byDialogToken = ((PWLAN_FRAME_MSRREQ) (pMgmt->abyCurrentMSRReq))->byDialogToken;
163
164 pFrame->sTPCRepEIDs.byElementID = WLAN_EID_TPC_REP;
165 pFrame->sTPCRepEIDs.len = 2;
166 pFrame->sTPCRepEIDs.byTxPower = CARDbyGetTransmitPower(pMgmt->pAdapter);
167 switch (byRate) {
168 case RATE_54M:
169 pFrame->sTPCRepEIDs.byLinkMargin = 65 - byRSSI;
170 break;
171 case RATE_48M:
172 pFrame->sTPCRepEIDs.byLinkMargin = 66 - byRSSI;
173 break;
174 case RATE_36M:
175 pFrame->sTPCRepEIDs.byLinkMargin = 70 - byRSSI;
176 break;
177 case RATE_24M:
178 pFrame->sTPCRepEIDs.byLinkMargin = 74 - byRSSI;
179 break;
180 case RATE_18M:
181 pFrame->sTPCRepEIDs.byLinkMargin = 77 - byRSSI;
182 break;
183 case RATE_12M:
184 pFrame->sTPCRepEIDs.byLinkMargin = 79 - byRSSI;
185 break;
186 case RATE_9M:
187 pFrame->sTPCRepEIDs.byLinkMargin = 81 - byRSSI;
188 break;
189 case RATE_6M:
190 default:
191 pFrame->sTPCRepEIDs.byLinkMargin = 82 - byRSSI;
192 break;
193 }
194
195 pTxPacket->cbMPDULen = sizeof(WLAN_FRAME_TPCREP);
196 pTxPacket->cbPayloadLen = sizeof(WLAN_FRAME_TPCREP) - WLAN_HDR_ADDR3_LEN;
197 if (csMgmt_xmit(pMgmt->pAdapter, pTxPacket) != CMD_STATUS_PENDING)
198 return (FALSE);
199 return (TRUE);
200// return (CARDbSendPacket(pMgmt->pAdapter, pFrame, PKT_TYPE_802_11_MNG, sizeof(WLAN_FRAME_TPCREP)));
201
202}
203
204
205/*--------------------- Export Variables --------------------------*/
206
207/*--------------------- Export Functions --------------------------*/
208
209
210/*+
211 *
212 * Description:
213 * Handles action management frames.
214 *
215 * Parameters:
216 * In:
217 * pMgmt - Management Object structure
218 * pRxPacket - Received packet
219 * Out:
220 * none
221 *
222 * Return Value: None.
223 *
224-*/
225BOOL
226IEEE11hbMgrRxAction (
227 IN PVOID pMgmtHandle,
228 IN PVOID pRxPacket
229 )
230{
231 PSMgmtObject pMgmt = (PSMgmtObject) pMgmtHandle;
232 PWLAN_FRAME_ACTION pAction = NULL;
233 UINT uLength = 0;
234 PWLAN_IE_CH_SW pChannelSwitch = NULL;
235
236
237 // decode the frame
238 uLength = ((PSRxMgmtPacket)pRxPacket)->cbMPDULen;
239 if (uLength > WLAN_A3FR_MAXLEN) {
240 return (FALSE);
241 }
242
243
244 pAction = (PWLAN_FRAME_ACTION) (((PSRxMgmtPacket)pRxPacket)->p80211Header);
245
246 if (pAction->byCategory == 0) {
247 switch (pAction->byAction) {
248 case ACTION_MSRREQ:
249 return (s_bRxMSRReq(pMgmt, (PWLAN_FRAME_MSRREQ) pAction, uLength));
250 break;
251 case ACTION_MSRREP:
252 break;
253 case ACTION_TPCREQ:
254 return (s_bRxTPCReq(pMgmt,
255 (PWLAN_FRAME_TPCREQ) pAction,
256 ((PSRxMgmtPacket)pRxPacket)->byRxRate,
257 (BYTE) ((PSRxMgmtPacket)pRxPacket)->uRSSI));
258 break;
259 case ACTION_TPCREP:
260 break;
261 case ACTION_CHSW:
262 pChannelSwitch = (PWLAN_IE_CH_SW) (pAction->abyVars);
263 if ((pChannelSwitch->byElementID == WLAN_EID_CH_SWITCH) &&
264 (pChannelSwitch->len == 3)) {
265 // valid element id
266 CARDbChannelSwitch( pMgmt->pAdapter,
267 pChannelSwitch->byMode,
268 CARDbyGetChannelMapping(pMgmt->pAdapter, pChannelSwitch->byChannel, pMgmt->eCurrentPHYMode),
269 pChannelSwitch->byCount
270 );
271 }
272 break;
273 default:
274 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Unknown Action = %d\n", pAction->byAction);
275 break;
276 }
277 } else {
278 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Unknown Category = %d\n", pAction->byCategory);
279 pAction->byCategory |= 0x80;
280
281 //return (CARDbSendPacket(pMgmt->pAdapter, pAction, PKT_TYPE_802_11_MNG, uLength));
282 return (TRUE);
283 }
284 return (TRUE);
285}
286
287
288BOOL IEEE11hbMSRRepTx (
289 IN PVOID pMgmtHandle
290 )
291{
292 PSMgmtObject pMgmt = (PSMgmtObject) pMgmtHandle;
293 PWLAN_FRAME_MSRREP pMSRRep = (PWLAN_FRAME_MSRREP) (pMgmt->abyCurrentMSRRep + sizeof(STxMgmtPacket));
294 UINT uLength = 0;
295 PSTxMgmtPacket pTxPacket = NULL;
296
297 pTxPacket = (PSTxMgmtPacket)pMgmt->abyCurrentMSRRep;
298 memset(pTxPacket, 0, sizeof(STxMgmtPacket) + WLAN_A3FR_MAXLEN);
299 pTxPacket->p80211Header = (PUWLAN_80211HDR)((PBYTE)pTxPacket + sizeof(STxMgmtPacket));
300
301
302 pMSRRep->Header.wFrameCtl = ( WLAN_SET_FC_FTYPE(WLAN_FTYPE_MGMT) |
303 WLAN_SET_FC_FSTYPE(WLAN_FSTYPE_ACTION)
304 );
305
306 MEMvCopy( pMSRRep->Header.abyAddr1, ((PWLAN_FRAME_MSRREQ) (pMgmt->abyCurrentMSRReq))->Header.abyAddr2, WLAN_ADDR_LEN);
307 MEMvCopy( pMSRRep->Header.abyAddr2, CARDpGetCurrentAddress(pMgmt->pAdapter), WLAN_ADDR_LEN);
308 MEMvCopy( pMSRRep->Header.abyAddr3, pMgmt->abyCurrBSSID, WLAN_BSSID_LEN);
309
310 pMSRRep->byCategory = 0;
311 pMSRRep->byAction = 1;
312 pMSRRep->byDialogToken = ((PWLAN_FRAME_MSRREQ) (pMgmt->abyCurrentMSRReq))->byDialogToken;
313
314 uLength = pMgmt->uLengthOfRepEIDs + OFFSET(WLAN_FRAME_MSRREP, sMSRRepEIDs);
315
316 pTxPacket->cbMPDULen = uLength;
317 pTxPacket->cbPayloadLen = uLength - WLAN_HDR_ADDR3_LEN;
318 if (csMgmt_xmit(pMgmt->pAdapter, pTxPacket) != CMD_STATUS_PENDING)
319 return (FALSE);
320 return (TRUE);
321// return (CARDbSendPacket(pMgmt->pAdapter, pMSRRep, PKT_TYPE_802_11_MNG, uLength));
322
323}
324
diff --git a/drivers/staging/vt6655/IEEE11h.h b/drivers/staging/vt6655/IEEE11h.h
new file mode 100644
index 000000000000..22bcaf1f6817
--- /dev/null
+++ b/drivers/staging/vt6655/IEEE11h.h
@@ -0,0 +1,68 @@
1/*
2 * Copyright (c) 1996, 2005 VIA Networking Technologies, Inc.
3 * All rights reserved.
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 *
20 * File: IEEE11h.h
21 *
22 * Purpose: Defines the macros, types, and functions for dealing
23 * with IEEE 802.11h.
24 *
25 * Author: Yiching Chen
26 *
27 * Date: Mar. 31, 2005
28 *
29 */
30
31#ifndef __IEEE11h_H__
32#define __IEEE11h_H__
33
34
35#if !defined(__TTYPE_H__)
36#include "ttype.h"
37#endif
38#if !defined(__80211HDR_H__)
39#include "80211hdr.h"
40#endif
41#if !defined(__80211MGR_H__)
42#include "80211mgr.h"
43#endif
44
45
46/*--------------------- Export Definitions -------------------------*/
47
48/*--------------------- Export Classes ----------------------------*/
49
50/*--------------------- Export Variables --------------------------*/
51
52/*--------------------- Export Types ------------------------------*/
53
54/*--------------------- Export Functions --------------------------*/
55#ifdef __cplusplus
56extern "C" { /* Assume C declarations for C++ */
57#endif /* __cplusplus */
58
59BOOL IEEE11hbMSRRepTx (
60 IN PVOID pMgmtHandle
61 );
62
63#ifdef __cplusplus
64} /* End of extern "C" { */
65#endif /* __cplusplus */
66
67
68#endif // __IEEE11h_H__
diff --git a/drivers/staging/vt6655/Makefile b/drivers/staging/vt6655/Makefile
new file mode 100644
index 000000000000..be44423c117b
--- /dev/null
+++ b/drivers/staging/vt6655/Makefile
@@ -0,0 +1,218 @@
1#
2# Build options:
3# PRIV_OBJ := 1 for object version
4#
5
6IO_MAP := 0
7HOSTAP := 1
8PRIV_OBJ := 0
9
10
11
12#KSP : = 0
13KSP := /lib/modules/$(shell uname -r)/build \
14# /usr/src/linux-$(shell uname -r) \
15# /usr/src/linux-$(shell uname -r | sed 's/-.*//') \
16# /usr/src/kernel-headers-$(shell uname -r) \
17# /usr/src/kernel-source-$(shell uname -r) \
18# /usr/src/linux-$(shell uname -r | sed 's/\([0-9]*\.[0-9]*\)\..*/\1/') \
19# /usr/src/linux /home/plice
20
21#test_dir = $(shell [ -e $(dir)/include/linux ] && echo $(dir))
22
23#KSP := $(foreach dir, $(KSP), $(test_dir))
24
25
26KSRC := $(firstword $(KSP))
27
28#ifeq (,$(KSRC))
29# $( error Linux kernel source not found)
30#endif
31
32# check kernel version
33KVER := $(shell uname -r | cut -c1-3 | sed 's/2\.[56]/2\.6/')
34KERVER2=$(shell uname -r | cut -d. -f2)
35
36ifeq ($(KVER), 2.6)
37# 2.6 kernel
38TARGET = viawget.ko
39
40else
41TARGET = viawget.o
42
43endif
44
45INSTDIR := $(shell find /lib/modules/$(shell uname -r) -name $(TARGET) -printf "%h\n" | sort | head -1)
46ifeq (,$(INSTDIR))
47 ifeq (,$(KERVER2))
48 ifneq (,$(wildcard /lib/modules/$(shell uname -r)/kernel))
49 INSTDIR := /lib/modules/$(shell uname -r)/kernel/drivers/net
50 else
51 INSTDIR := /lib/modules/$(shell uname -r)/net
52 endif
53 else
54 ifneq ($(KERVER2),2)
55 INSTDIR := /lib/modules/$(shell uname -r)/kernel/drivers/net
56 else
57 INSTDIR := /lib/modules/$(shell uname -r)/net
58 endif
59 endif
60endif
61
62
63SRC = device_main.c card.c mac.c baseband.c wctl.c 80211mgr.c \
64 wcmd.c wmgr.c bssdb.c wpa2.c rxtx.c dpc.c power.c datarate.c \
65 srom.c mib.c rc4.c tether.c tcrc.c ioctl.c hostap.c wpa.c key.c \
66 tkip.c michael.c wroute.c rf.c iwctl.c wpactl.c aes_ccmp.c \
67 vntwifi.c IEEE11h.c
68
69ifeq ($(IO_MAP), 1)
70 EXTRA_CFLAGS += -DIO_MAP
71endif
72
73ifeq ($(HOSTAP), 1)
74 EXTRA_CFLAGS += -DHOSTAP
75endif
76
77ifeq ($(PRIV_OBJ), 1)
78 EXTRA_CFLAGS += -DPRIVATE_OBJ
79endif
80
81EXTRA_CFLAGS += -I$(PWD) -I$(PWD)/../include -I$(PWD)/../solomon
82
83EXTRA_CFLAGS += -I$(PWD)/include -I$(PWD)/solomon
84
85# build rule
86ifeq ($(KVER), 2.6)
87# 2.6 kernel
88
89ifndef KERNEL_CONF
90KERNEL_CONF= $(KSRC)/.config
91endif
92
93include ${KERNEL_CONF}
94
95obj-m += viawget.o
96
97viawget-objs := device_main.o card.o mac.o baseband.o wctl.o 80211mgr.o \
98 wcmd.o wmgr.o bssdb.o rxtx.o dpc.o power.o datarate.o srom.o \
99 mib.o rc4.o tether.o tcrc.o ioctl.o hostap.o wpa.o key.o tkip.o \
100 michael.o wroute.o rf.o iwctl.o wpactl.o wpa2.o aes_ccmp.o \
101 vntwifi.o IEEE11h.o
102
103.c.o:
104 $(CC) $(CFLAGS) -o $@ $<
105
106default:
107 make -C $(KSRC) SUBDIRS=$(shell pwd) modules
108
109else
110
111# 2.2/2.4 kernel
112OBJS := device_main.o card.o mac.o baseband.o wctl.o 80211mgr.o \
113 wcmd.o wmgr.o bssdb.o rxtx.o dpc.o power.o datarate.o srom.o \
114 mib.o rc4.o tether.o tcrc.o ioctl.o hostap.o wpa.o key.o tkip.o \
115 michael.o wroute.o rf.o iwctl.o wpactl.o wpa2.o aes_ccmp.o \
116 vntwifi.o IEEE11h.o
117
118VERSION_FILE := $(KSRC)/include/linux/version.h
119CONFIG_FILE := $(KSRC)/include/linux/config.h
120
121
122ifeq (,$(wildcard $(VERSION_FILE)))
123 $(error Linux kernel source not configured - missing version.h)
124endif
125
126ifeq (,$(wildcard $(CONFIG_FILE)))
127 $(error Linux kernel source not configured - missing config.h)
128endif
129
130ifneq (,$(findstring egcs-2.91.66, $(shell cat /proc/version)))
131 CC := kgcc gcc cc
132else
133 CC := gcc cc
134endif
135
136test_cc = $(shell which $(cc) > /dev/null 2>&1 && echo $(cc))
137CC := $(foreach cc, $(CC), $(test_cc))
138CC := $(firstword $(CC))
139
140EXTRA_CFLAGS += -Wall -DLINUX -D__KERNEL__ -DMODULE -DEXPORT_SYMTAB -D__NO_VERSION__ -O2 -pipe
141EXTRA_CFLAGS += -I$(KSRC)/include -Wstrict-prototypes -fomit-frame-pointer -fno-strict-aliasing
142EXTRA_CFLAGS += $(shell [ -f $(KSRC)/include/linux/modversions.h ] && \
143 echo "-DMODVERSIONS -include $(KSRC)/include/linux/modversions.h")
144
145.SILENT: $(TARGET) clean
146
147
148# look for SMP in config.h
149SMP := $(shell $(CC) $(CFLAGS) -E -dM $(CONFIG_FILE) | \
150 grep CONFIG_SMP | awk '{ print $$3 }')
151
152ifneq ($(SMP),1)
153 SMP := 0
154endif
155
156
157ifeq ($(SMP), 1)
158 EXTRA_CFLAGS += -D__SMP__
159endif
160
161
162ifeq ($(PRIV_OBJ), 1)
163 EXTRA_CFLAGS += -DPRIVATE_OBJ
164 TARGET = x86g_up.o
165
166ifeq ($(SMP), 1)
167 TARGET = x86g_smp.o
168endif
169
170endif
171
172
173# check x86_64
174SUBARCH := $(shell uname -m)
175ifeq ($(SUBARCH),x86_64)
176 EXTRA_CFLAGS += -mcmodel=kernel -mno-red-zone
177endif
178
179
180$(TARGET): $(filter-out $(TARGET), $(SRC:.c=.o))
181 $(LD) -r $^ -o $@
182 echo; echo
183 echo "**************************************************"
184 echo "Build options:"
185 echo " VERSION $(KVER)"
186 echo -n " SMP "
187 if [ "$(SMP)" = "1" ]; \
188 then echo "Enabled"; else echo "Disabled"; fi
189
190
191
192endif # ifeq ($(KVER),2.6)
193
194
195ifeq ($(KVER), 2.6)
196install: default
197else
198install: clean $(TARGET)
199endif
200 mkdir -p $(MOD_ROOT)$(INSTDIR)
201 install -m 644 -o root $(TARGET) $(MOD_ROOT)$(INSTDIR)
202
203ifeq (,$(MOD_ROOT))
204 /sbin/depmod -a || true
205else
206 /sbin/depmod -b $(MOD_ROOT) -a || true
207endif
208
209
210uninstall:
211 rm -f $(INSTDIR)/$(TARGET)
212 /sbin/depmod -a
213
214clean:
215 rm -f $(TARGET) $(SRC:.c=.o) *.o *~
216 rm -f .*.o.d .*.o.cmd .*.ko.cmd *.mod.c *.mod.o
217
218-include .depend.mak
diff --git a/drivers/staging/vt6655/Makefile.arm b/drivers/staging/vt6655/Makefile.arm
new file mode 100644
index 000000000000..2d2ccaded6ac
--- /dev/null
+++ b/drivers/staging/vt6655/Makefile.arm
@@ -0,0 +1,181 @@
1#
2#
3# Build options:
4# PRIV_OBJ := 1 for object version
5# BIG_ENDIAN := 1 for big-endian mode
6#
7# arm-linux-tools chain are located at:
8# /usr/local/bin/arm-linux-gcc
9# /usr/local/bin/arm-linux-ld
10#
11
12IO_MAP := 0
13HOSTAP := 1
14PRIV_OBJ := 1
15BIG_ENDIAN := 1
16
17test_dir = $(shell [ -e $(dir)/include/linux ] && echo $(dir))
18KSP := $(foreach dir, $(KSP), $(test_dir))
19
20KSRC := $(firstword $(KSP))
21
22#ifeq (,$(KSRC))
23# $(error Linux kernel source not found)
24#endif
25
26# check kernel version
27KVER := $(shell uname -r | cut -c1-3 | sed 's/2\.[56]/2\.6/')
28KERVER2=$(shell uname -r | cut -d. -f2)
29
30ifeq ($(KVER), 2.6)
31# 2.6 kernel
32TARGET = viawget.ko
33
34else
35TARGET = viawget.o
36
37endif
38
39INSTDIR := $(shell find /lib/modules/$(shell uname -r) -name $(TARGET) -printf "%h\n" | sort | head -1)
40ifeq (,$(INSTDIR))
41 ifeq (,$(KERVER2))
42 ifneq (,$(wildcard /lib/modules/$(shell uname -r)/kernel))
43 INSTDIR := /lib/modules/$(shell uname -r)/kernel/drivers/net
44 else
45 INSTDIR := /lib/modules/$(shell uname -r)/net
46 endif
47 else
48 ifneq ($(KERVER2),2)
49 INSTDIR := /lib/modules/$(shell uname -r)/kernel/drivers/net
50 else
51 INSTDIR := /lib/modules/$(shell uname -r)/net
52 endif
53 endif
54endif
55
56
57SRC = device_main.c card.c mac.c baseband.c wctl.c 80211mgr.c \
58 wcmd.c wmgr.c bssdb.c rxtx.c dpc.c power.c datarate.c srom.c \
59 mib.c rc4.c tether.c tcrc.c ioctl.c hostap.c wpa.c key.c tkip.c \
60 michael.c wroute.c rf.c iwctl.c wpactl.c wpa2.c aes_ccmp.c
61
62ifeq ($(IO_MAP), 1)
63 CFLAGS += -DIO_MAP
64endif
65
66ifeq ($(HOSTAP), 1)
67 CFLAGS += -DHOSTAP
68endif
69
70ifeq ($(PRIV_OBJ), 1)
71 CFLAGS += -DPRIVATE_OBJ
72endif
73
74ifeq ($(BIG_ENDIAN), 1)
75 CFLAGS += -D__BIG_ENDIAN
76 CFLAGS += -mbig-endian
77 LDOPTS += -EB
78else
79 CFLAGS += -mlittle-endian
80 LDOPTS += -EL
81endif
82
83CFLAGS += -I$(PWD) -I$(PWD)/../include -I$(PWD)/../solomon
84
85
86# build rule
87ifeq ($(KVER), 2.6)
88# 2.6 kernel
89
90ifndef KERNEL_CONF
91KERNEL_CONF= $(KSRC)/.config
92endif
93
94include ${KERNEL_CONF}
95
96obj-m += viawget.o
97
98viawget-objs := device_main.o card.o mac.o baseband.o wctl.o 80211mgr.o \
99 wcmd.o wmgr.o bssdb.o rxtx.o dpc.o power.o datarate.o srom.o \
100 mib.o rc4.o tether.o tcrc.o ioctl.o hostap.o wpa.o key.o tkip.o \
101 michael.o wroute.o rf.o iwctl.o wpactl.o wpa2.o aes_ccmp.o
102
103.c.o:
104 $(CC) $(CFLAGS) -o $@ $<
105
106default:
107 make -C $(KSRC) SUBDIRS=$(shell pwd) modules
108
109else
110
111# 2.2/2.4 kernel
112OBJS := device_main.o card.o mac.o baseband.o wctl.o 80211mgr.o \
113 wcmd.o wmgr.o bssdb.o rxtx.o dpc.o power.o datarate.o srom.o \
114 mib.o rc4.o tether.o tcrc.o ioctl.o hostap.o wpa.o key.o tkip.o \
115 michael.o wroute.o rf.o iwctl.o wpactl.o wpa2.o
116
117
118CC := /usr/local/bin/arm-linux-gcc
119LD := /usr/local/bin/arm-linux-ld
120
121CFLAGS += -Wall -DLINUX -D__KERNEL__ -DMODULE -DEXPORT_SYMTAB -D__NO_VERSION__ -O2 -pipe
122#CFLAGS += -Wstrict-prototypes -fomit-frame-pointer
123COPTS+= -march=armv4 -fno-strict-aliasing -fno-common
124#COPTS+= -mapcs-32 -mtune=xscale -mshort-load-bytes -msoft-float -mfp=2
125#COPTS+= -mthumb -mcpu=arm9 -ffunction-sections -fdata-sections
126
127
128.SILENT: $(TARGET) clean
129
130
131
132ifeq ($(PRIV_OBJ), 1)
133
134ifeq ($(BIG_ENDIAN), 1)
135 TARGET = arm_be_g.o
136else
137 TARGET = arm_le_g.o
138endif
139
140endif
141
142
143
144$(TARGET): $(filter-out $(TARGET), $(SRC:.c=.o))
145 $(LD) $(LDOPTS) -r $^ -o $@
146 echo
147 echo "***********************************"
148 echo "Build options:"
149 echo " VERSION $(KVER)"
150 echo -n " SMP "
151 if [ "$(SMP)" = "1" ]; \
152 then echo "Enabled"; else echo "Disabled"; fi
153
154
155endif # ifeq ($(KVER),2.6)
156
157
158ifeq ($(KVER), 2.6)
159install: default
160else
161install: clean $(TARGET)
162endif
163 mkdir -p $(MOD_ROOT)$(INSTDIR)
164 install -m 644 -o root $(TARGET) $(MOD_ROOT)$(INSTDIR)
165
166ifeq (,$(MOD_ROOT))
167 /sbin/depmod -a || true
168else
169 /sbin/depmod -b $(MOD_ROOT) -a || true
170endif
171
172
173uninstall:
174 rm -f $(INSTDIR)/$(TARGET)
175 /sbin/depmod -a
176
177clean:
178 rm -f $(TARGET) $(SRC:.c=.o) *~
179 rm -f .*.o.d .*.o.cmd .*.ko.cmd *.mod.c *.mod.o
180
181-include .depend.mak
diff --git a/drivers/staging/vt6655/Makefile.x86 b/drivers/staging/vt6655/Makefile.x86
new file mode 100644
index 000000000000..69082f09ba73
--- /dev/null
+++ b/drivers/staging/vt6655/Makefile.x86
@@ -0,0 +1,209 @@
1#
2# Build options:
3# PRIV_OBJ := 1 for object version
4#
5
6IO_MAP := 0
7HOSTAP := 1
8PRIV_OBJ := 1
9
10KSP := /lib/modules/$(shell uname -r)/build \
11 /usr/src/linux-$(shell uname -r) \
12 /usr/src/linux-$(shell uname -r | sed 's/-.*//') \
13 /usr/src/kernel-headers-$(shell uname -r) \
14 /usr/src/kernel-source-$(shell uname -r) \
15 /usr/src/linux-$(shell uname -r | sed 's/\([0-9]*\.[0-9]*\)\..*/\1/') \
16 /usr/src/linux
17
18test_dir = $(shell [ -e $(dir)/include/linux ] && echo $(dir))
19KSP := $(foreach dir, $(KSP), $(test_dir))
20
21KSRC := $(firstword $(KSP))
22
23ifeq (,$(KSRC))
24 $(error Linux kernel source not found)
25endif
26
27# check kernel version
28KVER := $(shell uname -r | cut -c1-3 | sed 's/2\.[56]/2\.6/')
29KERVER2=$(shell uname -r | cut -d. -f2)
30
31ifeq ($(KVER), 2.6)
32# 2.6 kernel
33TARGET = viawget.ko
34
35else
36TARGET = viawget.o
37
38endif
39
40INSTDIR := $(shell find /lib/modules/$(shell uname -r) -name $(TARGET) -printf "%h\n" | sort | head -1)
41ifeq (,$(INSTDIR))
42 ifeq (,$(KERVER2))
43 ifneq (,$(wildcard /lib/modules/$(shell uname -r)/kernel))
44 INSTDIR := /lib/modules/$(shell uname -r)/kernel/drivers/net
45 else
46 INSTDIR := /lib/modules/$(shell uname -r)/net
47 endif
48 else
49 ifneq ($(KERVER2),2)
50 INSTDIR := /lib/modules/$(shell uname -r)/kernel/drivers/net
51 else
52 INSTDIR := /lib/modules/$(shell uname -r)/net
53 endif
54 endif
55endif
56
57
58SRC = device_main.c card.c mac.c baseband.c wctl.c 80211mgr.c \
59 wcmd.c wmgr.c bssdb.c wpa2.c rxtx.c dpc.c power.c datarate.c \
60 srom.c mib.c rc4.c tether.c tcrc.c ioctl.c hostap.c wpa.c key.c \
61 tkip.c michael.c wroute.c rf.c iwctl.c wpactl.c aes_ccmp.c
62
63ifeq ($(IO_MAP), 1)
64 CFLAGS += -DIO_MAP
65endif
66
67ifeq ($(HOSTAP), 1)
68 CFLAGS += -DHOSTAP
69endif
70
71ifeq ($(PRIV_OBJ), 1)
72 CFLAGS += -DPRIVATE_OBJ
73endif
74
75CFLAGS += -I$(PWD) -I$(PWD)/../include -I$(PWD)/../solomon
76
77
78# build rule
79ifeq ($(KVER), 2.6)
80# 2.6 kernel
81
82ifndef KERNEL_CONF
83KERNEL_CONF= $(KSRC)/.config
84endif
85
86include ${KERNEL_CONF}
87
88obj-m += viawget.o
89
90viawget-objs := device_main.o card.o mac.o baseband.o wctl.o 80211mgr.o \
91 wcmd.o wmgr.o bssdb.o rxtx.o dpc.o power.o datarate.o srom.o \
92 mib.o rc4.o tether.o tcrc.o ioctl.o hostap.o wpa.o key.o tkip.o \
93 michael.o wroute.o rf.o iwctl.o wpactl.o wpa2.o aes_ccmp.o
94
95.c.o:
96 $(CC) $(CFLAGS) -o $@ $<
97
98default:
99 make -C $(KSRC) SUBDIRS=$(shell pwd) modules
100
101else
102
103# 2.2/2.4 kernel
104OBJS := device_main.o card.o mac.o baseband.o wctl.o 80211mgr.o \
105 wcmd.o wmgr.o bssdb.o rxtx.o dpc.o power.o datarate.o srom.o \
106 mib.o rc4.o tether.o tcrc.o ioctl.o hostap.o wpa.o key.o tkip.o \
107 michael.o wroute.o rf.o iwctl.o wpactl.o wpa2.o aes_ccmp.o
108
109VERSION_FILE := $(KSRC)/include/linux/version.h
110CONFIG_FILE := $(KSRC)/include/linux/config.h
111
112
113ifeq (,$(wildcard $(VERSION_FILE)))
114 $(error Linux kernel source not configured - missing version.h)
115endif
116
117ifeq (,$(wildcard $(CONFIG_FILE)))
118 $(error Linux kernel source not configured - missing config.h)
119endif
120
121ifneq (,$(findstring egcs-2.91.66, $(shell cat /proc/version)))
122 CC := kgcc gcc cc
123else
124 CC := gcc cc
125endif
126
127test_cc = $(shell which $(cc) > /dev/null 2>&1 && echo $(cc))
128CC := $(foreach cc, $(CC), $(test_cc))
129CC := $(firstword $(CC))
130
131CFLAGS += -Wall -DLINUX -D__KERNEL__ -DMODULE -DEXPORT_SYMTAB -D__NO_VERSION__ -O2 -pipe
132CFLAGS += -I$(KSRC)/include -Wstrict-prototypes -fomit-frame-pointer
133CFLAGS += $(shell [ -f $(KSRC)/include/linux/modversions.h ] && \
134 echo "-DMODVERSIONS -include $(KSRC)/include/linux/modversions.h")
135
136.SILENT: $(TARGET) clean
137
138
139# look for SMP in config.h
140SMP := $(shell $(CC) $(CFLAGS) -E -dM $(CONFIG_FILE) | \
141 grep CONFIG_SMP | awk '{ print $$3 }')
142
143ifneq ($(SMP),1)
144 SMP := 0
145endif
146
147
148ifeq ($(SMP), 1)
149 CFLAGS += -D__SMP__
150endif
151
152
153ifeq ($(PRIV_OBJ), 1)
154 CFLAGS += -DPRIVATE_OBJ
155 TARGET = x86g_up.o
156
157ifeq ($(SMP), 1)
158 TARGET = x86g_smp.o
159endif
160
161endif
162
163
164# check x86_64
165SUBARCH := $(shell uname -m)
166ifeq ($(SUBARCH),x86_64)
167 CFLAGS += -mcmodel=kernel -mno-red-zone
168endif
169
170
171$(TARGET): $(filter-out $(TARGET), $(SRC:.c=.o))
172 $(LD) -r $^ -o $@
173 echo; echo
174 echo "**************************************************"
175 echo "Build options:"
176 echo " VERSION $(KVER)"
177 echo -n " SMP "
178 if [ "$(SMP)" = "1" ]; \
179 then echo "Enabled"; else echo "Disabled"; fi
180
181
182
183endif # ifeq ($(KVER),2.6)
184
185
186ifeq ($(KVER), 2.6)
187install: default
188else
189install: clean $(TARGET)
190endif
191 mkdir -p $(MOD_ROOT)$(INSTDIR)
192 install -m 644 -o root $(TARGET) $(MOD_ROOT)$(INSTDIR)
193
194ifeq (,$(MOD_ROOT))
195 /sbin/depmod -a || true
196else
197 /sbin/depmod -b $(MOD_ROOT) -a || true
198endif
199
200
201uninstall:
202 rm -f $(INSTDIR)/$(TARGET)
203 /sbin/depmod -a
204
205clean:
206 rm -f $(TARGET) $(SRC:.c=.o) *~
207 rm -f .*.o.d .*.o.cmd .*.ko.cmd *.mod.c *.mod.o
208
209-include .depend.mak
diff --git a/drivers/staging/vt6655/aes_ccmp.c b/drivers/staging/vt6655/aes_ccmp.c
new file mode 100644
index 000000000000..59cc018d48a2
--- /dev/null
+++ b/drivers/staging/vt6655/aes_ccmp.c
@@ -0,0 +1,410 @@
1/*
2 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
3 * All rights reserved.
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 *
20 * File: aes_ccmp.c
21 *
22 * Purpose: AES_CCMP decryption
23 *
24 * Author: Warren Hsu
25 *
26 * Date: Feb 15, 2005
27 *
28 * Functions:
29 * AESbGenCCMP - Parsing RX-packet
30 *
31 *
32 * Revision History:
33 *
34 */
35
36#if !defined(__UMEM_H__)
37#include "umem.h"
38#endif
39#if !defined(__DEVICE_H__)
40#include "device.h"
41#endif
42#if !defined(__80211HDR_H__)
43#include "80211hdr.h"
44#endif
45
46
47/*--------------------- Static Definitions -------------------------*/
48
49/*--------------------- Static Classes ----------------------------*/
50
51/*--------------------- Static Variables --------------------------*/
52
53/*
54 * SBOX Table
55 */
56
57BYTE sbox_table[256] =
58{
590x63, 0x7c, 0x77, 0x7b, 0xf2, 0x6b, 0x6f, 0xc5, 0x30, 0x01, 0x67, 0x2b, 0xfe, 0xd7, 0xab, 0x76,
600xca, 0x82, 0xc9, 0x7d, 0xfa, 0x59, 0x47, 0xf0, 0xad, 0xd4, 0xa2, 0xaf, 0x9c, 0xa4, 0x72, 0xc0,
610xb7, 0xfd, 0x93, 0x26, 0x36, 0x3f, 0xf7, 0xcc, 0x34, 0xa5, 0xe5, 0xf1, 0x71, 0xd8, 0x31, 0x15,
620x04, 0xc7, 0x23, 0xc3, 0x18, 0x96, 0x05, 0x9a, 0x07, 0x12, 0x80, 0xe2, 0xeb, 0x27, 0xb2, 0x75,
630x09, 0x83, 0x2c, 0x1a, 0x1b, 0x6e, 0x5a, 0xa0, 0x52, 0x3b, 0xd6, 0xb3, 0x29, 0xe3, 0x2f, 0x84,
640x53, 0xd1, 0x00, 0xed, 0x20, 0xfc, 0xb1, 0x5b, 0x6a, 0xcb, 0xbe, 0x39, 0x4a, 0x4c, 0x58, 0xcf,
650xd0, 0xef, 0xaa, 0xfb, 0x43, 0x4d, 0x33, 0x85, 0x45, 0xf9, 0x02, 0x7f, 0x50, 0x3c, 0x9f, 0xa8,
660x51, 0xa3, 0x40, 0x8f, 0x92, 0x9d, 0x38, 0xf5, 0xbc, 0xb6, 0xda, 0x21, 0x10, 0xff, 0xf3, 0xd2,
670xcd, 0x0c, 0x13, 0xec, 0x5f, 0x97, 0x44, 0x17, 0xc4, 0xa7, 0x7e, 0x3d, 0x64, 0x5d, 0x19, 0x73,
680x60, 0x81, 0x4f, 0xdc, 0x22, 0x2a, 0x90, 0x88, 0x46, 0xee, 0xb8, 0x14, 0xde, 0x5e, 0x0b, 0xdb,
690xe0, 0x32, 0x3a, 0x0a, 0x49, 0x06, 0x24, 0x5c, 0xc2, 0xd3, 0xac, 0x62, 0x91, 0x95, 0xe4, 0x79,
700xe7, 0xc8, 0x37, 0x6d, 0x8d, 0xd5, 0x4e, 0xa9, 0x6c, 0x56, 0xf4, 0xea, 0x65, 0x7a, 0xae, 0x08,
710xba, 0x78, 0x25, 0x2e, 0x1c, 0xa6, 0xb4, 0xc6, 0xe8, 0xdd, 0x74, 0x1f, 0x4b, 0xbd, 0x8b, 0x8a,
720x70, 0x3e, 0xb5, 0x66, 0x48, 0x03, 0xf6, 0x0e, 0x61, 0x35, 0x57, 0xb9, 0x86, 0xc1, 0x1d, 0x9e,
730xe1, 0xf8, 0x98, 0x11, 0x69, 0xd9, 0x8e, 0x94, 0x9b, 0x1e, 0x87, 0xe9, 0xce, 0x55, 0x28, 0xdf,
740x8c, 0xa1, 0x89, 0x0d, 0xbf, 0xe6, 0x42, 0x68, 0x41, 0x99, 0x2d, 0x0f, 0xb0, 0x54, 0xbb, 0x16
75};
76
77BYTE dot2_table[256] = {
780x00, 0x02, 0x04, 0x06, 0x08, 0x0a, 0x0c, 0x0e, 0x10, 0x12, 0x14, 0x16, 0x18, 0x1a, 0x1c, 0x1e,
790x20, 0x22, 0x24, 0x26, 0x28, 0x2a, 0x2c, 0x2e, 0x30, 0x32, 0x34, 0x36, 0x38, 0x3a, 0x3c, 0x3e,
800x40, 0x42, 0x44, 0x46, 0x48, 0x4a, 0x4c, 0x4e, 0x50, 0x52, 0x54, 0x56, 0x58, 0x5a, 0x5c, 0x5e,
810x60, 0x62, 0x64, 0x66, 0x68, 0x6a, 0x6c, 0x6e, 0x70, 0x72, 0x74, 0x76, 0x78, 0x7a, 0x7c, 0x7e,
820x80, 0x82, 0x84, 0x86, 0x88, 0x8a, 0x8c, 0x8e, 0x90, 0x92, 0x94, 0x96, 0x98, 0x9a, 0x9c, 0x9e,
830xa0, 0xa2, 0xa4, 0xa6, 0xa8, 0xaa, 0xac, 0xae, 0xb0, 0xb2, 0xb4, 0xb6, 0xb8, 0xba, 0xbc, 0xbe,
840xc0, 0xc2, 0xc4, 0xc6, 0xc8, 0xca, 0xcc, 0xce, 0xd0, 0xd2, 0xd4, 0xd6, 0xd8, 0xda, 0xdc, 0xde,
850xe0, 0xe2, 0xe4, 0xe6, 0xe8, 0xea, 0xec, 0xee, 0xf0, 0xf2, 0xf4, 0xf6, 0xf8, 0xfa, 0xfc, 0xfe,
860x1b, 0x19, 0x1f, 0x1d, 0x13, 0x11, 0x17, 0x15, 0x0b, 0x09, 0x0f, 0x0d, 0x03, 0x01, 0x07, 0x05,
870x3b, 0x39, 0x3f, 0x3d, 0x33, 0x31, 0x37, 0x35, 0x2b, 0x29, 0x2f, 0x2d, 0x23, 0x21, 0x27, 0x25,
880x5b, 0x59, 0x5f, 0x5d, 0x53, 0x51, 0x57, 0x55, 0x4b, 0x49, 0x4f, 0x4d, 0x43, 0x41, 0x47, 0x45,
890x7b, 0x79, 0x7f, 0x7d, 0x73, 0x71, 0x77, 0x75, 0x6b, 0x69, 0x6f, 0x6d, 0x63, 0x61, 0x67, 0x65,
900x9b, 0x99, 0x9f, 0x9d, 0x93, 0x91, 0x97, 0x95, 0x8b, 0x89, 0x8f, 0x8d, 0x83, 0x81, 0x87, 0x85,
910xbb, 0xb9, 0xbf, 0xbd, 0xb3, 0xb1, 0xb7, 0xb5, 0xab, 0xa9, 0xaf, 0xad, 0xa3, 0xa1, 0xa7, 0xa5,
920xdb, 0xd9, 0xdf, 0xdd, 0xd3, 0xd1, 0xd7, 0xd5, 0xcb, 0xc9, 0xcf, 0xcd, 0xc3, 0xc1, 0xc7, 0xc5,
930xfb, 0xf9, 0xff, 0xfd, 0xf3, 0xf1, 0xf7, 0xf5, 0xeb, 0xe9, 0xef, 0xed, 0xe3, 0xe1, 0xe7, 0xe5
94};
95
96BYTE dot3_table[256] = {
970x00, 0x03, 0x06, 0x05, 0x0c, 0x0f, 0x0a, 0x09, 0x18, 0x1b, 0x1e, 0x1d, 0x14, 0x17, 0x12, 0x11,
980x30, 0x33, 0x36, 0x35, 0x3c, 0x3f, 0x3a, 0x39, 0x28, 0x2b, 0x2e, 0x2d, 0x24, 0x27, 0x22, 0x21,
990x60, 0x63, 0x66, 0x65, 0x6c, 0x6f, 0x6a, 0x69, 0x78, 0x7b, 0x7e, 0x7d, 0x74, 0x77, 0x72, 0x71,
1000x50, 0x53, 0x56, 0x55, 0x5c, 0x5f, 0x5a, 0x59, 0x48, 0x4b, 0x4e, 0x4d, 0x44, 0x47, 0x42, 0x41,
1010xc0, 0xc3, 0xc6, 0xc5, 0xcc, 0xcf, 0xca, 0xc9, 0xd8, 0xdb, 0xde, 0xdd, 0xd4, 0xd7, 0xd2, 0xd1,
1020xf0, 0xf3, 0xf6, 0xf5, 0xfc, 0xff, 0xfa, 0xf9, 0xe8, 0xeb, 0xee, 0xed, 0xe4, 0xe7, 0xe2, 0xe1,
1030xa0, 0xa3, 0xa6, 0xa5, 0xac, 0xaf, 0xaa, 0xa9, 0xb8, 0xbb, 0xbe, 0xbd, 0xb4, 0xb7, 0xb2, 0xb1,
1040x90, 0x93, 0x96, 0x95, 0x9c, 0x9f, 0x9a, 0x99, 0x88, 0x8b, 0x8e, 0x8d, 0x84, 0x87, 0x82, 0x81,
1050x9b, 0x98, 0x9d, 0x9e, 0x97, 0x94, 0x91, 0x92, 0x83, 0x80, 0x85, 0x86, 0x8f, 0x8c, 0x89, 0x8a,
1060xab, 0xa8, 0xad, 0xae, 0xa7, 0xa4, 0xa1, 0xa2, 0xb3, 0xb0, 0xb5, 0xb6, 0xbf, 0xbc, 0xb9, 0xba,
1070xfb, 0xf8, 0xfd, 0xfe, 0xf7, 0xf4, 0xf1, 0xf2, 0xe3, 0xe0, 0xe5, 0xe6, 0xef, 0xec, 0xe9, 0xea,
1080xcb, 0xc8, 0xcd, 0xce, 0xc7, 0xc4, 0xc1, 0xc2, 0xd3, 0xd0, 0xd5, 0xd6, 0xdf, 0xdc, 0xd9, 0xda,
1090x5b, 0x58, 0x5d, 0x5e, 0x57, 0x54, 0x51, 0x52, 0x43, 0x40, 0x45, 0x46, 0x4f, 0x4c, 0x49, 0x4a,
1100x6b, 0x68, 0x6d, 0x6e, 0x67, 0x64, 0x61, 0x62, 0x73, 0x70, 0x75, 0x76, 0x7f, 0x7c, 0x79, 0x7a,
1110x3b, 0x38, 0x3d, 0x3e, 0x37, 0x34, 0x31, 0x32, 0x23, 0x20, 0x25, 0x26, 0x2f, 0x2c, 0x29, 0x2a,
1120x0b, 0x08, 0x0d, 0x0e, 0x07, 0x04, 0x01, 0x02, 0x13, 0x10, 0x15, 0x16, 0x1f, 0x1c, 0x19, 0x1a
113};
114
115/*--------------------- Static Functions --------------------------*/
116
117/*--------------------- Export Variables --------------------------*/
118
119/*--------------------- Export Functions --------------------------*/
120
121void xor_128(BYTE *a, BYTE *b, BYTE *out)
122{
123PDWORD dwPtrA = (PDWORD) a;
124PDWORD dwPtrB = (PDWORD) b;
125PDWORD dwPtrOut =(PDWORD) out;
126
127 (*dwPtrOut++) = (*dwPtrA++) ^ (*dwPtrB++);
128 (*dwPtrOut++) = (*dwPtrA++) ^ (*dwPtrB++);
129 (*dwPtrOut++) = (*dwPtrA++) ^ (*dwPtrB++);
130 (*dwPtrOut++) = (*dwPtrA++) ^ (*dwPtrB++);
131}
132
133
134void xor_32(BYTE *a, BYTE *b, BYTE *out)
135{
136PDWORD dwPtrA = (PDWORD) a;
137PDWORD dwPtrB = (PDWORD) b;
138PDWORD dwPtrOut =(PDWORD) out;
139
140 (*dwPtrOut++) = (*dwPtrA++) ^ (*dwPtrB++);
141}
142
143void AddRoundKey(BYTE *key, int round)
144{
145BYTE sbox_key[4];
146BYTE rcon_table[10] = { 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36};
147
148 sbox_key[0] = sbox_table[key[13]];
149 sbox_key[1] = sbox_table[key[14]];
150 sbox_key[2] = sbox_table[key[15]];
151 sbox_key[3] = sbox_table[key[12]];
152
153 key[0] = key[0] ^ rcon_table[round];
154 xor_32(&key[0], sbox_key, &key[0]);
155
156 xor_32(&key[4], &key[0], &key[4]);
157 xor_32(&key[8], &key[4], &key[8]);
158 xor_32(&key[12], &key[8], &key[12]);
159}
160
161void SubBytes(BYTE *in, BYTE *out)
162{
163int i;
164
165 for (i=0; i< 16; i++)
166 {
167 out[i] = sbox_table[in[i]];
168 }
169}
170
171void ShiftRows(BYTE *in, BYTE *out)
172{
173 out[0] = in[0];
174 out[1] = in[5];
175 out[2] = in[10];
176 out[3] = in[15];
177 out[4] = in[4];
178 out[5] = in[9];
179 out[6] = in[14];
180 out[7] = in[3];
181 out[8] = in[8];
182 out[9] = in[13];
183 out[10] = in[2];
184 out[11] = in[7];
185 out[12] = in[12];
186 out[13] = in[1];
187 out[14] = in[6];
188 out[15] = in[11];
189}
190
191void MixColumns(BYTE *in, BYTE *out)
192{
193
194 out[0] = dot2_table[in[0]] ^ dot3_table[in[1]] ^ in[2] ^ in[3];
195 out[1] = in[0] ^ dot2_table[in[1]] ^ dot3_table[in[2]] ^ in[3];
196 out[2] = in[0] ^ in[1] ^ dot2_table[in[2]] ^ dot3_table[in[3]];
197 out[3] = dot3_table[in[0]] ^ in[1] ^ in[2] ^ dot2_table[in[3]];
198}
199
200
201void AESv128(BYTE *key, BYTE *data, BYTE *ciphertext)
202{
203int i;
204int round;
205BYTE TmpdataA[16];
206BYTE TmpdataB[16];
207BYTE abyRoundKey[16];
208
209 for(i=0; i<16; i++)
210 abyRoundKey[i] = key[i];
211
212 for (round = 0; round < 11; round++)
213 {
214 if (round == 0)
215 {
216 xor_128(abyRoundKey, data, ciphertext);
217 AddRoundKey(abyRoundKey, round);
218 }
219 else if (round == 10)
220 {
221 SubBytes(ciphertext, TmpdataA);
222 ShiftRows(TmpdataA, TmpdataB);
223 xor_128(TmpdataB, abyRoundKey, ciphertext);
224 }
225 else // round 1 ~ 9
226 {
227 SubBytes(ciphertext, TmpdataA);
228 ShiftRows(TmpdataA, TmpdataB);
229 MixColumns(&TmpdataB[0], &TmpdataA[0]);
230 MixColumns(&TmpdataB[4], &TmpdataA[4]);
231 MixColumns(&TmpdataB[8], &TmpdataA[8]);
232 MixColumns(&TmpdataB[12], &TmpdataA[12]);
233 xor_128(TmpdataA, abyRoundKey, ciphertext);
234 AddRoundKey(abyRoundKey, round);
235 }
236 }
237
238}
239
240/*
241 * Description: AES decryption
242 *
243 * Parameters:
244 * In:
245 * pbyRxKey - The key used to decrypt
246 * pbyFrame - Starting address of packet header
247 * wFrameSize - Total packet size including CRC
248 * Out:
249 * none
250 *
251 * Return Value: MIC compare result
252 *
253 */
254BOOL AESbGenCCMP(PBYTE pbyRxKey, PBYTE pbyFrame, WORD wFrameSize)
255{
256BYTE abyNonce[13];
257BYTE MIC_IV[16];
258BYTE MIC_HDR1[16];
259BYTE MIC_HDR2[16];
260BYTE abyMIC[16];
261BYTE abyCTRPLD[16];
262BYTE abyTmp[16];
263BYTE abyPlainText[16];
264BYTE abyLastCipher[16];
265
266PS802_11Header pMACHeader = (PS802_11Header) pbyFrame;
267PBYTE pbyIV;
268PBYTE pbyPayload;
269WORD wHLen = 22;
270WORD wPayloadSize = wFrameSize - 8 - 8 - 4 - WLAN_HDR_ADDR3_LEN;//8 is IV, 8 is MIC, 4 is CRC
271BOOL bA4 = FALSE;
272BYTE byTmp;
273WORD wCnt;
274int ii,jj,kk;
275
276
277 pbyIV = pbyFrame + WLAN_HDR_ADDR3_LEN;
278 if ( WLAN_GET_FC_TODS(*(PWORD)pbyFrame) &&
279 WLAN_GET_FC_FROMDS(*(PWORD)pbyFrame) ) {
280 bA4 = TRUE;
281 pbyIV += 6; // 6 is 802.11 address4
282 wHLen += 6;
283 wPayloadSize -= 6;
284 }
285 pbyPayload = pbyIV + 8; //IV-length
286
287 abyNonce[0] = 0x00; //now is 0, if Qos here will be priority
288 MEMvCopy(&(abyNonce[1]), pMACHeader->abyAddr2, U_ETHER_ADDR_LEN);
289 abyNonce[7] = pbyIV[7];
290 abyNonce[8] = pbyIV[6];
291 abyNonce[9] = pbyIV[5];
292 abyNonce[10] = pbyIV[4];
293 abyNonce[11] = pbyIV[1];
294 abyNonce[12] = pbyIV[0];
295
296 //MIC_IV
297 MIC_IV[0] = 0x59;
298 MEMvCopy(&(MIC_IV[1]), &(abyNonce[0]), 13);
299 MIC_IV[14] = (BYTE)(wPayloadSize >> 8);
300 MIC_IV[15] = (BYTE)(wPayloadSize & 0xff);
301
302 //MIC_HDR1
303 MIC_HDR1[0] = (BYTE)(wHLen >> 8);
304 MIC_HDR1[1] = (BYTE)(wHLen & 0xff);
305 byTmp = (BYTE)(pMACHeader->wFrameCtl & 0xff);
306 MIC_HDR1[2] = byTmp & 0x8f;
307 byTmp = (BYTE)(pMACHeader->wFrameCtl >> 8);
308 byTmp &= 0x87;
309 MIC_HDR1[3] = byTmp | 0x40;
310 MEMvCopy(&(MIC_HDR1[4]), pMACHeader->abyAddr1, U_ETHER_ADDR_LEN);
311 MEMvCopy(&(MIC_HDR1[10]), pMACHeader->abyAddr2, U_ETHER_ADDR_LEN);
312
313 //MIC_HDR2
314 MEMvCopy(&(MIC_HDR2[0]), pMACHeader->abyAddr3, U_ETHER_ADDR_LEN);
315 byTmp = (BYTE)(pMACHeader->wSeqCtl & 0xff);
316 MIC_HDR2[6] = byTmp & 0x0f;
317 MIC_HDR2[7] = 0;
318 if ( bA4 ) {
319 MEMvCopy(&(MIC_HDR2[8]), pMACHeader->abyAddr4, U_ETHER_ADDR_LEN);
320 } else {
321 MIC_HDR2[8] = 0x00;
322 MIC_HDR2[9] = 0x00;
323 MIC_HDR2[10] = 0x00;
324 MIC_HDR2[11] = 0x00;
325 MIC_HDR2[12] = 0x00;
326 MIC_HDR2[13] = 0x00;
327 }
328 MIC_HDR2[14] = 0x00;
329 MIC_HDR2[15] = 0x00;
330
331 //CCMP
332 AESv128(pbyRxKey,MIC_IV,abyMIC);
333 for ( kk=0; kk<16; kk++ ) {
334 abyTmp[kk] = MIC_HDR1[kk] ^ abyMIC[kk];
335 }
336 AESv128(pbyRxKey,abyTmp,abyMIC);
337 for ( kk=0; kk<16; kk++ ) {
338 abyTmp[kk] = MIC_HDR2[kk] ^ abyMIC[kk];
339 }
340 AESv128(pbyRxKey,abyTmp,abyMIC);
341
342 wCnt = 1;
343 abyCTRPLD[0] = 0x01;
344 MEMvCopy(&(abyCTRPLD[1]), &(abyNonce[0]), 13);
345
346 for(jj=wPayloadSize; jj>16; jj=jj-16) {
347
348 abyCTRPLD[14] = (BYTE) (wCnt >> 8);
349 abyCTRPLD[15] = (BYTE) (wCnt & 0xff);
350
351 AESv128(pbyRxKey,abyCTRPLD,abyTmp);
352
353 for ( kk=0; kk<16; kk++ ) {
354 abyPlainText[kk] = abyTmp[kk] ^ pbyPayload[kk];
355 }
356 for ( kk=0; kk<16; kk++ ) {
357 abyTmp[kk] = abyMIC[kk] ^ abyPlainText[kk];
358 }
359 AESv128(pbyRxKey,abyTmp,abyMIC);
360
361 MEMvCopy(pbyPayload, abyPlainText, 16);
362 wCnt++;
363 pbyPayload += 16;
364 } //for wPayloadSize
365
366 //last payload
367 MEMvCopy(&(abyLastCipher[0]), pbyPayload, jj);
368 for ( ii=jj; ii<16; ii++ ) {
369 abyLastCipher[ii] = 0x00;
370 }
371
372 abyCTRPLD[14] = (BYTE) (wCnt >> 8);
373 abyCTRPLD[15] = (BYTE) (wCnt & 0xff);
374
375 AESv128(pbyRxKey,abyCTRPLD,abyTmp);
376 for ( kk=0; kk<16; kk++ ) {
377 abyPlainText[kk] = abyTmp[kk] ^ abyLastCipher[kk];
378 }
379 MEMvCopy(pbyPayload, abyPlainText, jj);
380 pbyPayload += jj;
381
382 //for MIC calculation
383 for ( ii=jj; ii<16; ii++ ) {
384 abyPlainText[ii] = 0x00;
385 }
386 for ( kk=0; kk<16; kk++ ) {
387 abyTmp[kk] = abyMIC[kk] ^ abyPlainText[kk];
388 }
389 AESv128(pbyRxKey,abyTmp,abyMIC);
390
391 //=>above is the calculate MIC
392 //--------------------------------------------
393
394 wCnt = 0;
395 abyCTRPLD[14] = (BYTE) (wCnt >> 8);
396 abyCTRPLD[15] = (BYTE) (wCnt & 0xff);
397 AESv128(pbyRxKey,abyCTRPLD,abyTmp);
398 for ( kk=0; kk<8; kk++ ) {
399 abyTmp[kk] = abyTmp[kk] ^ pbyPayload[kk];
400 }
401 //=>above is the dec-MIC from packet
402 //--------------------------------------------
403
404 if ( MEMEqualMemory(abyMIC,abyTmp,8) ) {
405 return TRUE;
406 } else {
407 return FALSE;
408 }
409
410}
diff --git a/drivers/staging/vt6655/aes_ccmp.h b/drivers/staging/vt6655/aes_ccmp.h
new file mode 100644
index 000000000000..2b1920f28609
--- /dev/null
+++ b/drivers/staging/vt6655/aes_ccmp.h
@@ -0,0 +1,48 @@
1/*
2 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
3 * All rights reserved.
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 *
20 * File: aes_ccmp.h
21 *
22 * Purpose: AES_CCMP Decryption
23 *
24 * Author: Warren Hsu
25 *
26 * Date: Feb 15, 2005
27 *
28 */
29
30#ifndef __AES_H__
31#define __AES_H__
32
33#if !defined(__TTYPE_H__)
34#include "ttype.h"
35#endif
36
37/*--------------------- Export Definitions -------------------------*/
38
39/*--------------------- Export Types ------------------------------*/
40
41/*--------------------- Export Classes ----------------------------*/
42
43/*--------------------- Export Variables --------------------------*/
44
45/*--------------------- Export Functions --------------------------*/
46BOOL AESbGenCCMP(PBYTE pbyRxKey, PBYTE pbyFrame, WORD wFrameSize);
47
48#endif //__AES_H__
diff --git a/drivers/staging/vt6655/baseband.c b/drivers/staging/vt6655/baseband.c
new file mode 100644
index 000000000000..bc6db8699539
--- /dev/null
+++ b/drivers/staging/vt6655/baseband.c
@@ -0,0 +1,2990 @@
1/*
2 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
3 * All rights reserved.
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * File: baseband.c
20 *
21 * Purpose: Implement functions to access baseband
22 *
23 * Author: Kyle Hsu
24 *
25 * Date: Aug.22, 2002
26 *
27 * Functions:
28 * BBuGetFrameTime - Calculate data frame transmitting time
29 * BBvCaculateParameter - Caculate PhyLength, PhyService and Phy Signal parameter for baseband Tx
30 * BBbReadEmbeded - Embeded read baseband register via MAC
31 * BBbWriteEmbeded - Embeded write baseband register via MAC
32 * BBbIsRegBitsOn - Test if baseband register bits on
33 * BBbIsRegBitsOff - Test if baseband register bits off
34 * BBbVT3253Init - VIA VT3253 baseband chip init code
35 * BBvReadAllRegs - Read All Baseband Registers
36 * BBvLoopbackOn - Turn on BaseBand Loopback mode
37 * BBvLoopbackOff - Turn off BaseBand Loopback mode
38 *
39 * Revision History:
40 * 06-10-2003 Bryan YC Fan: Re-write codes to support VT3253 spec.
41 * 08-07-2003 Bryan YC Fan: Add MAXIM2827/2825 and RFMD2959 support.
42 * 08-26-2003 Kyle Hsu : Modify BBuGetFrameTime() and BBvCaculateParameter().
43 * cancel the setting of MAC_REG_SOFTPWRCTL on BBbVT3253Init().
44 * Add the comments.
45 * 09-01-2003 Bryan YC Fan: RF & BB tables updated.
46 * Modified BBvLoopbackOn & BBvLoopbackOff().
47 */
48
49#if !defined(__TMACRO_H__)
50#include "tmacro.h"
51#endif
52#if !defined(__TBIT_H__)
53#include "tbit.h"
54#endif
55#if !defined(__TETHER_H__)
56#include "tether.h"
57#endif
58#if !defined(__MAC_H__)
59#include "mac.h"
60#endif
61#if !defined(__BASEBAND_H__)
62#include "baseband.h"
63#endif
64#if !defined(__SROM_H__)
65#include "srom.h"
66#endif
67#if !defined(__UMEM_H__)
68#include "umem.h"
69#endif
70#if !defined(__RF_H__)
71#include "rf.h"
72#endif
73
74/*--------------------- Static Definitions -------------------------*/
75//static int msglevel =MSG_LEVEL_DEBUG;
76static int msglevel =MSG_LEVEL_INFO;
77
78//#define PLICE_DEBUG
79
80/*--------------------- Static Classes ----------------------------*/
81
82/*--------------------- Static Variables --------------------------*/
83/*--------------------- Static Functions --------------------------*/
84
85/*--------------------- Export Variables --------------------------*/
86
87/*--------------------- Static Definitions -------------------------*/
88
89/*--------------------- Static Classes ----------------------------*/
90
91/*--------------------- Static Variables --------------------------*/
92
93
94
95#define CB_VT3253_INIT_FOR_RFMD 446
96BYTE byVT3253InitTab_RFMD[CB_VT3253_INIT_FOR_RFMD][2] = {
97 {0x00, 0x30},
98 {0x01, 0x00},
99 {0x02, 0x00},
100 {0x03, 0x00},
101 {0x04, 0x00},
102 {0x05, 0x00},
103 {0x06, 0x00},
104 {0x07, 0x00},
105 {0x08, 0x70},
106 {0x09, 0x45},
107 {0x0a, 0x2a},
108 {0x0b, 0x76},
109 {0x0c, 0x00},
110 {0x0d, 0x01},
111 {0x0e, 0x80},
112 {0x0f, 0x00},
113 {0x10, 0x00},
114 {0x11, 0x00},
115 {0x12, 0x00},
116 {0x13, 0x00},
117 {0x14, 0x00},
118 {0x15, 0x00},
119 {0x16, 0x00},
120 {0x17, 0x00},
121 {0x18, 0x00},
122 {0x19, 0x00},
123 {0x1a, 0x00},
124 {0x1b, 0x9d},
125 {0x1c, 0x05},
126 {0x1d, 0x00},
127 {0x1e, 0x00},
128 {0x1f, 0x00},
129 {0x20, 0x00},
130 {0x21, 0x00},
131 {0x22, 0x00},
132 {0x23, 0x00},
133 {0x24, 0x00},
134 {0x25, 0x4a},
135 {0x26, 0x00},
136 {0x27, 0x00},
137 {0x28, 0x00},
138 {0x29, 0x00},
139 {0x2a, 0x00},
140 {0x2b, 0x00},
141 {0x2c, 0x00},
142 {0x2d, 0xa8},
143 {0x2e, 0x1a},
144 {0x2f, 0x0c},
145 {0x30, 0x26},
146 {0x31, 0x5b},
147 {0x32, 0x00},
148 {0x33, 0x00},
149 {0x34, 0x00},
150 {0x35, 0x00},
151 {0x36, 0xaa},
152 {0x37, 0xaa},
153 {0x38, 0xff},
154 {0x39, 0xff},
155 {0x3a, 0x00},
156 {0x3b, 0x00},
157 {0x3c, 0x00},
158 {0x3d, 0x0d},
159 {0x3e, 0x51},
160 {0x3f, 0x04},
161 {0x40, 0x00},
162 {0x41, 0x08},
163 {0x42, 0x00},
164 {0x43, 0x08},
165 {0x44, 0x06},
166 {0x45, 0x14},
167 {0x46, 0x05},
168 {0x47, 0x08},
169 {0x48, 0x00},
170 {0x49, 0x00},
171 {0x4a, 0x00},
172 {0x4b, 0x00},
173 {0x4c, 0x09},
174 {0x4d, 0x80},
175 {0x4e, 0x00},
176 {0x4f, 0xc5},
177 {0x50, 0x14},
178 {0x51, 0x19},
179 {0x52, 0x00},
180 {0x53, 0x00},
181 {0x54, 0x00},
182 {0x55, 0x00},
183 {0x56, 0x00},
184 {0x57, 0x00},
185 {0x58, 0x00},
186 {0x59, 0xb0},
187 {0x5a, 0x00},
188 {0x5b, 0x00},
189 {0x5c, 0x00},
190 {0x5d, 0x00},
191 {0x5e, 0x00},
192 {0x5f, 0x00},
193 {0x60, 0x44},
194 {0x61, 0x04},
195 {0x62, 0x00},
196 {0x63, 0x00},
197 {0x64, 0x00},
198 {0x65, 0x00},
199 {0x66, 0x04},
200 {0x67, 0xb7},
201 {0x68, 0x00},
202 {0x69, 0x00},
203 {0x6a, 0x00},
204 {0x6b, 0x00},
205 {0x6c, 0x00},
206 {0x6d, 0x03},
207 {0x6e, 0x01},
208 {0x6f, 0x00},
209 {0x70, 0x00},
210 {0x71, 0x00},
211 {0x72, 0x00},
212 {0x73, 0x00},
213 {0x74, 0x00},
214 {0x75, 0x00},
215 {0x76, 0x00},
216 {0x77, 0x00},
217 {0x78, 0x00},
218 {0x79, 0x00},
219 {0x7a, 0x00},
220 {0x7b, 0x00},
221 {0x7c, 0x00},
222 {0x7d, 0x00},
223 {0x7e, 0x00},
224 {0x7f, 0x00},
225 {0x80, 0x0b},
226 {0x81, 0x00},
227 {0x82, 0x3c},
228 {0x83, 0x00},
229 {0x84, 0x00},
230 {0x85, 0x00},
231 {0x86, 0x00},
232 {0x87, 0x00},
233 {0x88, 0x08},
234 {0x89, 0x00},
235 {0x8a, 0x08},
236 {0x8b, 0xa6},
237 {0x8c, 0x84},
238 {0x8d, 0x47},
239 {0x8e, 0xbb},
240 {0x8f, 0x02},
241 {0x90, 0x21},
242 {0x91, 0x0c},
243 {0x92, 0x04},
244 {0x93, 0x22},
245 {0x94, 0x00},
246 {0x95, 0x00},
247 {0x96, 0x00},
248 {0x97, 0xeb},
249 {0x98, 0x00},
250 {0x99, 0x00},
251 {0x9a, 0x00},
252 {0x9b, 0x00},
253 {0x9c, 0x00},
254 {0x9d, 0x00},
255 {0x9e, 0x00},
256 {0x9f, 0x00},
257 {0xa0, 0x00},
258 {0xa1, 0x00},
259 {0xa2, 0x00},
260 {0xa3, 0x00},
261 {0xa4, 0x00},
262 {0xa5, 0x00},
263 {0xa6, 0x10},
264 {0xa7, 0x04},
265 {0xa8, 0x10},
266 {0xa9, 0x00},
267 {0xaa, 0x8f},
268 {0xab, 0x00},
269 {0xac, 0x00},
270 {0xad, 0x00},
271 {0xae, 0x00},
272 {0xaf, 0x80},
273 {0xb0, 0x38},
274 {0xb1, 0x00},
275 {0xb2, 0x00},
276 {0xb3, 0x00},
277 {0xb4, 0xee},
278 {0xb5, 0xff},
279 {0xb6, 0x10},
280 {0xb7, 0x00},
281 {0xb8, 0x00},
282 {0xb9, 0x00},
283 {0xba, 0x00},
284 {0xbb, 0x03},
285 {0xbc, 0x00},
286 {0xbd, 0x00},
287 {0xbe, 0x00},
288 {0xbf, 0x00},
289 {0xc0, 0x10},
290 {0xc1, 0x10},
291 {0xc2, 0x18},
292 {0xc3, 0x20},
293 {0xc4, 0x10},
294 {0xc5, 0x00},
295 {0xc6, 0x22},
296 {0xc7, 0x14},
297 {0xc8, 0x0f},
298 {0xc9, 0x08},
299 {0xca, 0xa4},
300 {0xcb, 0xa7},
301 {0xcc, 0x3c},
302 {0xcd, 0x10},
303 {0xce, 0x20},
304 {0xcf, 0x00},
305 {0xd0, 0x00},
306 {0xd1, 0x10},
307 {0xd2, 0x00},
308 {0xd3, 0x00},
309 {0xd4, 0x10},
310 {0xd5, 0x33},
311 {0xd6, 0x70},
312 {0xd7, 0x01},
313 {0xd8, 0x00},
314 {0xd9, 0x00},
315 {0xda, 0x00},
316 {0xdb, 0x00},
317 {0xdc, 0x00},
318 {0xdd, 0x00},
319 {0xde, 0x00},
320 {0xdf, 0x00},
321 {0xe0, 0x00},
322 {0xe1, 0x00},
323 {0xe2, 0xcc},
324 {0xe3, 0x04},
325 {0xe4, 0x08},
326 {0xe5, 0x10},
327 {0xe6, 0x00},
328 {0xe7, 0x0e},
329 {0xe8, 0x88},
330 {0xe9, 0xd4},
331 {0xea, 0x05},
332 {0xeb, 0xf0},
333 {0xec, 0x79},
334 {0xed, 0x0f},
335 {0xee, 0x04},
336 {0xef, 0x04},
337 {0xf0, 0x00},
338 {0xf1, 0x00},
339 {0xf2, 0x00},
340 {0xf3, 0x00},
341 {0xf4, 0x00},
342 {0xf5, 0x00},
343 {0xf6, 0x00},
344 {0xf7, 0x00},
345 {0xf8, 0x00},
346 {0xf9, 0x00},
347 {0xF0, 0x00},
348 {0xF1, 0xF8},
349 {0xF0, 0x80},
350 {0xF0, 0x00},
351 {0xF1, 0xF4},
352 {0xF0, 0x81},
353 {0xF0, 0x01},
354 {0xF1, 0xF0},
355 {0xF0, 0x82},
356 {0xF0, 0x02},
357 {0xF1, 0xEC},
358 {0xF0, 0x83},
359 {0xF0, 0x03},
360 {0xF1, 0xE8},
361 {0xF0, 0x84},
362 {0xF0, 0x04},
363 {0xF1, 0xE4},
364 {0xF0, 0x85},
365 {0xF0, 0x05},
366 {0xF1, 0xE0},
367 {0xF0, 0x86},
368 {0xF0, 0x06},
369 {0xF1, 0xDC},
370 {0xF0, 0x87},
371 {0xF0, 0x07},
372 {0xF1, 0xD8},
373 {0xF0, 0x88},
374 {0xF0, 0x08},
375 {0xF1, 0xD4},
376 {0xF0, 0x89},
377 {0xF0, 0x09},
378 {0xF1, 0xD0},
379 {0xF0, 0x8A},
380 {0xF0, 0x0A},
381 {0xF1, 0xCC},
382 {0xF0, 0x8B},
383 {0xF0, 0x0B},
384 {0xF1, 0xC8},
385 {0xF0, 0x8C},
386 {0xF0, 0x0C},
387 {0xF1, 0xC4},
388 {0xF0, 0x8D},
389 {0xF0, 0x0D},
390 {0xF1, 0xC0},
391 {0xF0, 0x8E},
392 {0xF0, 0x0E},
393 {0xF1, 0xBC},
394 {0xF0, 0x8F},
395 {0xF0, 0x0F},
396 {0xF1, 0xB8},
397 {0xF0, 0x90},
398 {0xF0, 0x10},
399 {0xF1, 0xB4},
400 {0xF0, 0x91},
401 {0xF0, 0x11},
402 {0xF1, 0xB0},
403 {0xF0, 0x92},
404 {0xF0, 0x12},
405 {0xF1, 0xAC},
406 {0xF0, 0x93},
407 {0xF0, 0x13},
408 {0xF1, 0xA8},
409 {0xF0, 0x94},
410 {0xF0, 0x14},
411 {0xF1, 0xA4},
412 {0xF0, 0x95},
413 {0xF0, 0x15},
414 {0xF1, 0xA0},
415 {0xF0, 0x96},
416 {0xF0, 0x16},
417 {0xF1, 0x9C},
418 {0xF0, 0x97},
419 {0xF0, 0x17},
420 {0xF1, 0x98},
421 {0xF0, 0x98},
422 {0xF0, 0x18},
423 {0xF1, 0x94},
424 {0xF0, 0x99},
425 {0xF0, 0x19},
426 {0xF1, 0x90},
427 {0xF0, 0x9A},
428 {0xF0, 0x1A},
429 {0xF1, 0x8C},
430 {0xF0, 0x9B},
431 {0xF0, 0x1B},
432 {0xF1, 0x88},
433 {0xF0, 0x9C},
434 {0xF0, 0x1C},
435 {0xF1, 0x84},
436 {0xF0, 0x9D},
437 {0xF0, 0x1D},
438 {0xF1, 0x80},
439 {0xF0, 0x9E},
440 {0xF0, 0x1E},
441 {0xF1, 0x7C},
442 {0xF0, 0x9F},
443 {0xF0, 0x1F},
444 {0xF1, 0x78},
445 {0xF0, 0xA0},
446 {0xF0, 0x20},
447 {0xF1, 0x74},
448 {0xF0, 0xA1},
449 {0xF0, 0x21},
450 {0xF1, 0x70},
451 {0xF0, 0xA2},
452 {0xF0, 0x22},
453 {0xF1, 0x6C},
454 {0xF0, 0xA3},
455 {0xF0, 0x23},
456 {0xF1, 0x68},
457 {0xF0, 0xA4},
458 {0xF0, 0x24},
459 {0xF1, 0x64},
460 {0xF0, 0xA5},
461 {0xF0, 0x25},
462 {0xF1, 0x60},
463 {0xF0, 0xA6},
464 {0xF0, 0x26},
465 {0xF1, 0x5C},
466 {0xF0, 0xA7},
467 {0xF0, 0x27},
468 {0xF1, 0x58},
469 {0xF0, 0xA8},
470 {0xF0, 0x28},
471 {0xF1, 0x54},
472 {0xF0, 0xA9},
473 {0xF0, 0x29},
474 {0xF1, 0x50},
475 {0xF0, 0xAA},
476 {0xF0, 0x2A},
477 {0xF1, 0x4C},
478 {0xF0, 0xAB},
479 {0xF0, 0x2B},
480 {0xF1, 0x48},
481 {0xF0, 0xAC},
482 {0xF0, 0x2C},
483 {0xF1, 0x44},
484 {0xF0, 0xAD},
485 {0xF0, 0x2D},
486 {0xF1, 0x40},
487 {0xF0, 0xAE},
488 {0xF0, 0x2E},
489 {0xF1, 0x3C},
490 {0xF0, 0xAF},
491 {0xF0, 0x2F},
492 {0xF1, 0x38},
493 {0xF0, 0xB0},
494 {0xF0, 0x30},
495 {0xF1, 0x34},
496 {0xF0, 0xB1},
497 {0xF0, 0x31},
498 {0xF1, 0x30},
499 {0xF0, 0xB2},
500 {0xF0, 0x32},
501 {0xF1, 0x2C},
502 {0xF0, 0xB3},
503 {0xF0, 0x33},
504 {0xF1, 0x28},
505 {0xF0, 0xB4},
506 {0xF0, 0x34},
507 {0xF1, 0x24},
508 {0xF0, 0xB5},
509 {0xF0, 0x35},
510 {0xF1, 0x20},
511 {0xF0, 0xB6},
512 {0xF0, 0x36},
513 {0xF1, 0x1C},
514 {0xF0, 0xB7},
515 {0xF0, 0x37},
516 {0xF1, 0x18},
517 {0xF0, 0xB8},
518 {0xF0, 0x38},
519 {0xF1, 0x14},
520 {0xF0, 0xB9},
521 {0xF0, 0x39},
522 {0xF1, 0x10},
523 {0xF0, 0xBA},
524 {0xF0, 0x3A},
525 {0xF1, 0x0C},
526 {0xF0, 0xBB},
527 {0xF0, 0x3B},
528 {0xF1, 0x08},
529 {0xF0, 0x00},
530 {0xF0, 0x3C},
531 {0xF1, 0x04},
532 {0xF0, 0xBD},
533 {0xF0, 0x3D},
534 {0xF1, 0x00},
535 {0xF0, 0xBE},
536 {0xF0, 0x3E},
537 {0xF1, 0x00},
538 {0xF0, 0xBF},
539 {0xF0, 0x3F},
540 {0xF1, 0x00},
541 {0xF0, 0xC0},
542 {0xF0, 0x00},
543};
544
545#define CB_VT3253B0_INIT_FOR_RFMD 256
546BYTE byVT3253B0_RFMD[CB_VT3253B0_INIT_FOR_RFMD][2] = {
547 {0x00, 0x31},
548 {0x01, 0x00},
549 {0x02, 0x00},
550 {0x03, 0x00},
551 {0x04, 0x00},
552 {0x05, 0x81},
553 {0x06, 0x00},
554 {0x07, 0x00},
555 {0x08, 0x38},
556 {0x09, 0x45},
557 {0x0a, 0x2a},
558 {0x0b, 0x76},
559 {0x0c, 0x00},
560 {0x0d, 0x00},
561 {0x0e, 0x80},
562 {0x0f, 0x00},
563 {0x10, 0x00},
564 {0x11, 0x00},
565 {0x12, 0x00},
566 {0x13, 0x00},
567 {0x14, 0x00},
568 {0x15, 0x00},
569 {0x16, 0x00},
570 {0x17, 0x00},
571 {0x18, 0x00},
572 {0x19, 0x00},
573 {0x1a, 0x00},
574 {0x1b, 0x8e},
575 {0x1c, 0x06},
576 {0x1d, 0x00},
577 {0x1e, 0x00},
578 {0x1f, 0x00},
579 {0x20, 0x00},
580 {0x21, 0x00},
581 {0x22, 0x00},
582 {0x23, 0x00},
583 {0x24, 0x00},
584 {0x25, 0x4a},
585 {0x26, 0x00},
586 {0x27, 0x00},
587 {0x28, 0x00},
588 {0x29, 0x00},
589 {0x2a, 0x00},
590 {0x2b, 0x00},
591 {0x2c, 0x00},
592 {0x2d, 0x34},
593 {0x2e, 0x18},
594 {0x2f, 0x0c},
595 {0x30, 0x26},
596 {0x31, 0x5b},
597 {0x32, 0x00},
598 {0x33, 0x00},
599 {0x34, 0x00},
600 {0x35, 0x00},
601 {0x36, 0xaa},
602 {0x37, 0xaa},
603 {0x38, 0xff},
604 {0x39, 0xff},
605 {0x3a, 0xf8},
606 {0x3b, 0x00},
607 {0x3c, 0x00},
608 {0x3d, 0x09},
609 {0x3e, 0x0d},
610 {0x3f, 0x04},
611 {0x40, 0x00},
612 {0x41, 0x08},
613 {0x42, 0x00},
614 {0x43, 0x08},
615 {0x44, 0x08},
616 {0x45, 0x14},
617 {0x46, 0x05},
618 {0x47, 0x08},
619 {0x48, 0x00},
620 {0x49, 0x00},
621 {0x4a, 0x00},
622 {0x4b, 0x00},
623 {0x4c, 0x09},
624 {0x4d, 0x80},
625 {0x4e, 0x00},
626 {0x4f, 0xc5},
627 {0x50, 0x14},
628 {0x51, 0x19},
629 {0x52, 0x00},
630 {0x53, 0x00},
631 {0x54, 0x00},
632 {0x55, 0x00},
633 {0x56, 0x00},
634 {0x57, 0x00},
635 {0x58, 0x00},
636 {0x59, 0xb0},
637 {0x5a, 0x00},
638 {0x5b, 0x00},
639 {0x5c, 0x00},
640 {0x5d, 0x00},
641 {0x5e, 0x00},
642 {0x5f, 0x00},
643 {0x60, 0x39},
644 {0x61, 0x83},
645 {0x62, 0x00},
646 {0x63, 0x00},
647 {0x64, 0x00},
648 {0x65, 0x00},
649 {0x66, 0xc0},
650 {0x67, 0x49},
651 {0x68, 0x00},
652 {0x69, 0x00},
653 {0x6a, 0x00},
654 {0x6b, 0x00},
655 {0x6c, 0x00},
656 {0x6d, 0x03},
657 {0x6e, 0x01},
658 {0x6f, 0x00},
659 {0x70, 0x00},
660 {0x71, 0x00},
661 {0x72, 0x00},
662 {0x73, 0x00},
663 {0x74, 0x00},
664 {0x75, 0x00},
665 {0x76, 0x00},
666 {0x77, 0x00},
667 {0x78, 0x00},
668 {0x79, 0x00},
669 {0x7a, 0x00},
670 {0x7b, 0x00},
671 {0x7c, 0x00},
672 {0x7d, 0x00},
673 {0x7e, 0x00},
674 {0x7f, 0x00},
675 {0x80, 0x89},
676 {0x81, 0x00},
677 {0x82, 0x0e},
678 {0x83, 0x00},
679 {0x84, 0x00},
680 {0x85, 0x00},
681 {0x86, 0x00},
682 {0x87, 0x00},
683 {0x88, 0x08},
684 {0x89, 0x00},
685 {0x8a, 0x0e},
686 {0x8b, 0xa7},
687 {0x8c, 0x88},
688 {0x8d, 0x47},
689 {0x8e, 0xaa},
690 {0x8f, 0x02},
691 {0x90, 0x23},
692 {0x91, 0x0c},
693 {0x92, 0x06},
694 {0x93, 0x08},
695 {0x94, 0x00},
696 {0x95, 0x00},
697 {0x96, 0x00},
698 {0x97, 0xeb},
699 {0x98, 0x00},
700 {0x99, 0x00},
701 {0x9a, 0x00},
702 {0x9b, 0x00},
703 {0x9c, 0x00},
704 {0x9d, 0x00},
705 {0x9e, 0x00},
706 {0x9f, 0x00},
707 {0xa0, 0x00},
708 {0xa1, 0x00},
709 {0xa2, 0x00},
710 {0xa3, 0xcd},
711 {0xa4, 0x07},
712 {0xa5, 0x33},
713 {0xa6, 0x18},
714 {0xa7, 0x00},
715 {0xa8, 0x18},
716 {0xa9, 0x00},
717 {0xaa, 0x28},
718 {0xab, 0x00},
719 {0xac, 0x00},
720 {0xad, 0x00},
721 {0xae, 0x00},
722 {0xaf, 0x18},
723 {0xb0, 0x38},
724 {0xb1, 0x30},
725 {0xb2, 0x00},
726 {0xb3, 0x00},
727 {0xb4, 0x00},
728 {0xb5, 0x00},
729 {0xb6, 0x84},
730 {0xb7, 0xfd},
731 {0xb8, 0x00},
732 {0xb9, 0x00},
733 {0xba, 0x00},
734 {0xbb, 0x03},
735 {0xbc, 0x00},
736 {0xbd, 0x00},
737 {0xbe, 0x00},
738 {0xbf, 0x00},
739 {0xc0, 0x10},
740 {0xc1, 0x20},
741 {0xc2, 0x18},
742 {0xc3, 0x20},
743 {0xc4, 0x10},
744 {0xc5, 0x2c},
745 {0xc6, 0x1e},
746 {0xc7, 0x10},
747 {0xc8, 0x12},
748 {0xc9, 0x01},
749 {0xca, 0x6f},
750 {0xcb, 0xa7},
751 {0xcc, 0x3c},
752 {0xcd, 0x10},
753 {0xce, 0x00},
754 {0xcf, 0x22},
755 {0xd0, 0x00},
756 {0xd1, 0x10},
757 {0xd2, 0x00},
758 {0xd3, 0x00},
759 {0xd4, 0x10},
760 {0xd5, 0x33},
761 {0xd6, 0x80},
762 {0xd7, 0x21},
763 {0xd8, 0x00},
764 {0xd9, 0x00},
765 {0xda, 0x00},
766 {0xdb, 0x00},
767 {0xdc, 0x00},
768 {0xdd, 0x00},
769 {0xde, 0x00},
770 {0xdf, 0x00},
771 {0xe0, 0x00},
772 {0xe1, 0xB3},
773 {0xe2, 0x00},
774 {0xe3, 0x00},
775 {0xe4, 0x00},
776 {0xe5, 0x10},
777 {0xe6, 0x00},
778 {0xe7, 0x18},
779 {0xe8, 0x08},
780 {0xe9, 0xd4},
781 {0xea, 0x00},
782 {0xeb, 0xff},
783 {0xec, 0x79},
784 {0xed, 0x10},
785 {0xee, 0x30},
786 {0xef, 0x02},
787 {0xf0, 0x00},
788 {0xf1, 0x09},
789 {0xf2, 0x00},
790 {0xf3, 0x00},
791 {0xf4, 0x00},
792 {0xf5, 0x00},
793 {0xf6, 0x00},
794 {0xf7, 0x00},
795 {0xf8, 0x00},
796 {0xf9, 0x00},
797 {0xfa, 0x00},
798 {0xfb, 0x00},
799 {0xfc, 0x00},
800 {0xfd, 0x00},
801 {0xfe, 0x00},
802 {0xff, 0x00},
803};
804
805#define CB_VT3253B0_AGC_FOR_RFMD2959 195
806// For RFMD2959
807BYTE byVT3253B0_AGC4_RFMD2959[CB_VT3253B0_AGC_FOR_RFMD2959][2] = {
808 {0xF0, 0x00},
809 {0xF1, 0x3E},
810 {0xF0, 0x80},
811 {0xF0, 0x00},
812 {0xF1, 0x3E},
813 {0xF0, 0x81},
814 {0xF0, 0x01},
815 {0xF1, 0x3E},
816 {0xF0, 0x82},
817 {0xF0, 0x02},
818 {0xF1, 0x3E},
819 {0xF0, 0x83},
820 {0xF0, 0x03},
821 {0xF1, 0x3B},
822 {0xF0, 0x84},
823 {0xF0, 0x04},
824 {0xF1, 0x39},
825 {0xF0, 0x85},
826 {0xF0, 0x05},
827 {0xF1, 0x38},
828 {0xF0, 0x86},
829 {0xF0, 0x06},
830 {0xF1, 0x37},
831 {0xF0, 0x87},
832 {0xF0, 0x07},
833 {0xF1, 0x36},
834 {0xF0, 0x88},
835 {0xF0, 0x08},
836 {0xF1, 0x35},
837 {0xF0, 0x89},
838 {0xF0, 0x09},
839 {0xF1, 0x35},
840 {0xF0, 0x8A},
841 {0xF0, 0x0A},
842 {0xF1, 0x34},
843 {0xF0, 0x8B},
844 {0xF0, 0x0B},
845 {0xF1, 0x34},
846 {0xF0, 0x8C},
847 {0xF0, 0x0C},
848 {0xF1, 0x33},
849 {0xF0, 0x8D},
850 {0xF0, 0x0D},
851 {0xF1, 0x32},
852 {0xF0, 0x8E},
853 {0xF0, 0x0E},
854 {0xF1, 0x31},
855 {0xF0, 0x8F},
856 {0xF0, 0x0F},
857 {0xF1, 0x30},
858 {0xF0, 0x90},
859 {0xF0, 0x10},
860 {0xF1, 0x2F},
861 {0xF0, 0x91},
862 {0xF0, 0x11},
863 {0xF1, 0x2F},
864 {0xF0, 0x92},
865 {0xF0, 0x12},
866 {0xF1, 0x2E},
867 {0xF0, 0x93},
868 {0xF0, 0x13},
869 {0xF1, 0x2D},
870 {0xF0, 0x94},
871 {0xF0, 0x14},
872 {0xF1, 0x2C},
873 {0xF0, 0x95},
874 {0xF0, 0x15},
875 {0xF1, 0x2B},
876 {0xF0, 0x96},
877 {0xF0, 0x16},
878 {0xF1, 0x2B},
879 {0xF0, 0x97},
880 {0xF0, 0x17},
881 {0xF1, 0x2A},
882 {0xF0, 0x98},
883 {0xF0, 0x18},
884 {0xF1, 0x29},
885 {0xF0, 0x99},
886 {0xF0, 0x19},
887 {0xF1, 0x28},
888 {0xF0, 0x9A},
889 {0xF0, 0x1A},
890 {0xF1, 0x27},
891 {0xF0, 0x9B},
892 {0xF0, 0x1B},
893 {0xF1, 0x26},
894 {0xF0, 0x9C},
895 {0xF0, 0x1C},
896 {0xF1, 0x25},
897 {0xF0, 0x9D},
898 {0xF0, 0x1D},
899 {0xF1, 0x24},
900 {0xF0, 0x9E},
901 {0xF0, 0x1E},
902 {0xF1, 0x24},
903 {0xF0, 0x9F},
904 {0xF0, 0x1F},
905 {0xF1, 0x23},
906 {0xF0, 0xA0},
907 {0xF0, 0x20},
908 {0xF1, 0x22},
909 {0xF0, 0xA1},
910 {0xF0, 0x21},
911 {0xF1, 0x21},
912 {0xF0, 0xA2},
913 {0xF0, 0x22},
914 {0xF1, 0x20},
915 {0xF0, 0xA3},
916 {0xF0, 0x23},
917 {0xF1, 0x20},
918 {0xF0, 0xA4},
919 {0xF0, 0x24},
920 {0xF1, 0x1F},
921 {0xF0, 0xA5},
922 {0xF0, 0x25},
923 {0xF1, 0x1E},
924 {0xF0, 0xA6},
925 {0xF0, 0x26},
926 {0xF1, 0x1D},
927 {0xF0, 0xA7},
928 {0xF0, 0x27},
929 {0xF1, 0x1C},
930 {0xF0, 0xA8},
931 {0xF0, 0x28},
932 {0xF1, 0x1B},
933 {0xF0, 0xA9},
934 {0xF0, 0x29},
935 {0xF1, 0x1B},
936 {0xF0, 0xAA},
937 {0xF0, 0x2A},
938 {0xF1, 0x1A},
939 {0xF0, 0xAB},
940 {0xF0, 0x2B},
941 {0xF1, 0x1A},
942 {0xF0, 0xAC},
943 {0xF0, 0x2C},
944 {0xF1, 0x19},
945 {0xF0, 0xAD},
946 {0xF0, 0x2D},
947 {0xF1, 0x18},
948 {0xF0, 0xAE},
949 {0xF0, 0x2E},
950 {0xF1, 0x17},
951 {0xF0, 0xAF},
952 {0xF0, 0x2F},
953 {0xF1, 0x16},
954 {0xF0, 0xB0},
955 {0xF0, 0x30},
956 {0xF1, 0x15},
957 {0xF0, 0xB1},
958 {0xF0, 0x31},
959 {0xF1, 0x15},
960 {0xF0, 0xB2},
961 {0xF0, 0x32},
962 {0xF1, 0x15},
963 {0xF0, 0xB3},
964 {0xF0, 0x33},
965 {0xF1, 0x14},
966 {0xF0, 0xB4},
967 {0xF0, 0x34},
968 {0xF1, 0x13},
969 {0xF0, 0xB5},
970 {0xF0, 0x35},
971 {0xF1, 0x12},
972 {0xF0, 0xB6},
973 {0xF0, 0x36},
974 {0xF1, 0x11},
975 {0xF0, 0xB7},
976 {0xF0, 0x37},
977 {0xF1, 0x10},
978 {0xF0, 0xB8},
979 {0xF0, 0x38},
980 {0xF1, 0x0F},
981 {0xF0, 0xB9},
982 {0xF0, 0x39},
983 {0xF1, 0x0E},
984 {0xF0, 0xBA},
985 {0xF0, 0x3A},
986 {0xF1, 0x0D},
987 {0xF0, 0xBB},
988 {0xF0, 0x3B},
989 {0xF1, 0x0C},
990 {0xF0, 0xBC},
991 {0xF0, 0x3C},
992 {0xF1, 0x0B},
993 {0xF0, 0xBD},
994 {0xF0, 0x3D},
995 {0xF1, 0x0B},
996 {0xF0, 0xBE},
997 {0xF0, 0x3E},
998 {0xF1, 0x0A},
999 {0xF0, 0xBF},
1000 {0xF0, 0x3F},
1001 {0xF1, 0x09},
1002 {0xF0, 0x00},
1003};
1004
1005#define CB_VT3253B0_INIT_FOR_AIROHA2230 256
1006// For AIROHA
1007BYTE byVT3253B0_AIROHA2230[CB_VT3253B0_INIT_FOR_AIROHA2230][2] = {
1008 {0x00, 0x31},
1009 {0x01, 0x00},
1010 {0x02, 0x00},
1011 {0x03, 0x00},
1012 {0x04, 0x00},
1013 {0x05, 0x80},
1014 {0x06, 0x00},
1015 {0x07, 0x00},
1016 {0x08, 0x70},
1017 {0x09, 0x41},
1018 {0x0a, 0x2A},
1019 {0x0b, 0x76},
1020 {0x0c, 0x00},
1021 {0x0d, 0x00},
1022 {0x0e, 0x80},
1023 {0x0f, 0x00},
1024 {0x10, 0x00},
1025 {0x11, 0x00},
1026 {0x12, 0x00},
1027 {0x13, 0x00},
1028 {0x14, 0x00},
1029 {0x15, 0x00},
1030 {0x16, 0x00},
1031 {0x17, 0x00},
1032 {0x18, 0x00},
1033 {0x19, 0x00},
1034 {0x1a, 0x00},
1035 {0x1b, 0x8f},
1036 {0x1c, 0x09},
1037 {0x1d, 0x00},
1038 {0x1e, 0x00},
1039 {0x1f, 0x00},
1040 {0x20, 0x00},
1041 {0x21, 0x00},
1042 {0x22, 0x00},
1043 {0x23, 0x00},
1044 {0x24, 0x00},
1045 {0x25, 0x4a},
1046 {0x26, 0x00},
1047 {0x27, 0x00},
1048 {0x28, 0x00},
1049 {0x29, 0x00},
1050 {0x2a, 0x00},
1051 {0x2b, 0x00},
1052 {0x2c, 0x00},
1053 {0x2d, 0x4a},
1054 {0x2e, 0x00},
1055 {0x2f, 0x0a},
1056 {0x30, 0x26},
1057 {0x31, 0x5b},
1058 {0x32, 0x00},
1059 {0x33, 0x00},
1060 {0x34, 0x00},
1061 {0x35, 0x00},
1062 {0x36, 0xaa},
1063 {0x37, 0xaa},
1064 {0x38, 0xff},
1065 {0x39, 0xff},
1066 {0x3a, 0x79},
1067 {0x3b, 0x00},
1068 {0x3c, 0x00},
1069 {0x3d, 0x0b},
1070 {0x3e, 0x48},
1071 {0x3f, 0x04},
1072 {0x40, 0x00},
1073 {0x41, 0x08},
1074 {0x42, 0x00},
1075 {0x43, 0x08},
1076 {0x44, 0x08},
1077 {0x45, 0x14},
1078 {0x46, 0x05},
1079 {0x47, 0x09},
1080 {0x48, 0x00},
1081 {0x49, 0x00},
1082 {0x4a, 0x00},
1083 {0x4b, 0x00},
1084 {0x4c, 0x09},
1085 {0x4d, 0x73},
1086 {0x4e, 0x00},
1087 {0x4f, 0xc5},
1088 {0x50, 0x15},
1089 {0x51, 0x19},
1090 {0x52, 0x00},
1091 {0x53, 0x00},
1092 {0x54, 0x00},
1093 {0x55, 0x00},
1094 {0x56, 0x00},
1095 {0x57, 0x00},
1096 {0x58, 0x00},
1097 {0x59, 0xb0},
1098 {0x5a, 0x00},
1099 {0x5b, 0x00},
1100 {0x5c, 0x00},
1101 {0x5d, 0x00},
1102 {0x5e, 0x00},
1103 {0x5f, 0x00},
1104 {0x60, 0xe4},
1105 {0x61, 0x80},
1106 {0x62, 0x00},
1107 {0x63, 0x00},
1108 {0x64, 0x00},
1109 {0x65, 0x00},
1110 {0x66, 0x98},
1111 {0x67, 0x0a},
1112 {0x68, 0x00},
1113 {0x69, 0x00},
1114 {0x6a, 0x00},
1115 {0x6b, 0x00},
1116 //{0x6c, 0x80},
1117 {0x6c, 0x00}, //RobertYu:20050125, request by JJSue
1118 {0x6d, 0x03},
1119 {0x6e, 0x01},
1120 {0x6f, 0x00},
1121 {0x70, 0x00},
1122 {0x71, 0x00},
1123 {0x72, 0x00},
1124 {0x73, 0x00},
1125 {0x74, 0x00},
1126 {0x75, 0x00},
1127 {0x76, 0x00},
1128 {0x77, 0x00},
1129 {0x78, 0x00},
1130 {0x79, 0x00},
1131 {0x7a, 0x00},
1132 {0x7b, 0x00},
1133 {0x7c, 0x00},
1134 {0x7d, 0x00},
1135 {0x7e, 0x00},
1136 {0x7f, 0x00},
1137 {0x80, 0x8c},
1138 {0x81, 0x01},
1139 {0x82, 0x09},
1140 {0x83, 0x00},
1141 {0x84, 0x00},
1142 {0x85, 0x00},
1143 {0x86, 0x00},
1144 {0x87, 0x00},
1145 {0x88, 0x08},
1146 {0x89, 0x00},
1147 {0x8a, 0x0f},
1148 {0x8b, 0xb7},
1149 {0x8c, 0x88},
1150 {0x8d, 0x47},
1151 {0x8e, 0xaa},
1152 {0x8f, 0x02},
1153 {0x90, 0x22},
1154 {0x91, 0x00},
1155 {0x92, 0x00},
1156 {0x93, 0x00},
1157 {0x94, 0x00},
1158 {0x95, 0x00},
1159 {0x96, 0x00},
1160 {0x97, 0xeb},
1161 {0x98, 0x00},
1162 {0x99, 0x00},
1163 {0x9a, 0x00},
1164 {0x9b, 0x00},
1165 {0x9c, 0x00},
1166 {0x9d, 0x00},
1167 {0x9e, 0x00},
1168 {0x9f, 0x01},
1169 {0xa0, 0x00},
1170 {0xa1, 0x00},
1171 {0xa2, 0x00},
1172 {0xa3, 0x00},
1173 {0xa4, 0x00},
1174 {0xa5, 0x00},
1175 {0xa6, 0x10},
1176 {0xa7, 0x00},
1177 {0xa8, 0x18},
1178 {0xa9, 0x00},
1179 {0xaa, 0x00},
1180 {0xab, 0x00},
1181 {0xac, 0x00},
1182 {0xad, 0x00},
1183 {0xae, 0x00},
1184 {0xaf, 0x18},
1185 {0xb0, 0x38},
1186 {0xb1, 0x30},
1187 {0xb2, 0x00},
1188 {0xb3, 0x00},
1189 {0xb4, 0xff},
1190 {0xb5, 0x0f},
1191 {0xb6, 0xe4},
1192 {0xb7, 0xe2},
1193 {0xb8, 0x00},
1194 {0xb9, 0x00},
1195 {0xba, 0x00},
1196 {0xbb, 0x03},
1197 {0xbc, 0x01},
1198 {0xbd, 0x00},
1199 {0xbe, 0x00},
1200 {0xbf, 0x00},
1201 {0xc0, 0x18},
1202 {0xc1, 0x20},
1203 {0xc2, 0x07},
1204 {0xc3, 0x18},
1205 {0xc4, 0xff},
1206 {0xc5, 0x2c},
1207 {0xc6, 0x0c},
1208 {0xc7, 0x0a},
1209 {0xc8, 0x0e},
1210 {0xc9, 0x01},
1211 {0xca, 0x68},
1212 {0xcb, 0xa7},
1213 {0xcc, 0x3c},
1214 {0xcd, 0x10},
1215 {0xce, 0x00},
1216 {0xcf, 0x25},
1217 {0xd0, 0x40},
1218 {0xd1, 0x12},
1219 {0xd2, 0x00},
1220 {0xd3, 0x00},
1221 {0xd4, 0x10},
1222 {0xd5, 0x28},
1223 {0xd6, 0x80},
1224 {0xd7, 0x2A},
1225 {0xd8, 0x00},
1226 {0xd9, 0x00},
1227 {0xda, 0x00},
1228 {0xdb, 0x00},
1229 {0xdc, 0x00},
1230 {0xdd, 0x00},
1231 {0xde, 0x00},
1232 {0xdf, 0x00},
1233 {0xe0, 0x00},
1234 {0xe1, 0xB3},
1235 {0xe2, 0x00},
1236 {0xe3, 0x00},
1237 {0xe4, 0x00},
1238 {0xe5, 0x10},
1239 {0xe6, 0x00},
1240 {0xe7, 0x1C},
1241 {0xe8, 0x00},
1242 {0xe9, 0xf4},
1243 {0xea, 0x00},
1244 {0xeb, 0xff},
1245 {0xec, 0x79},
1246 {0xed, 0x20},
1247 {0xee, 0x30},
1248 {0xef, 0x01},
1249 {0xf0, 0x00},
1250 {0xf1, 0x3e},
1251 {0xf2, 0x00},
1252 {0xf3, 0x00},
1253 {0xf4, 0x00},
1254 {0xf5, 0x00},
1255 {0xf6, 0x00},
1256 {0xf7, 0x00},
1257 {0xf8, 0x00},
1258 {0xf9, 0x00},
1259 {0xfa, 0x00},
1260 {0xfb, 0x00},
1261 {0xfc, 0x00},
1262 {0xfd, 0x00},
1263 {0xfe, 0x00},
1264 {0xff, 0x00},
1265};
1266
1267
1268
1269#define CB_VT3253B0_INIT_FOR_UW2451 256
1270//For UW2451
1271BYTE byVT3253B0_UW2451[CB_VT3253B0_INIT_FOR_UW2451][2] = {
1272 {0x00, 0x31},
1273 {0x01, 0x00},
1274 {0x02, 0x00},
1275 {0x03, 0x00},
1276 {0x04, 0x00},
1277 {0x05, 0x81},
1278 {0x06, 0x00},
1279 {0x07, 0x00},
1280 {0x08, 0x38},
1281 {0x09, 0x45},
1282 {0x0a, 0x28},
1283 {0x0b, 0x76},
1284 {0x0c, 0x00},
1285 {0x0d, 0x00},
1286 {0x0e, 0x80},
1287 {0x0f, 0x00},
1288 {0x10, 0x00},
1289 {0x11, 0x00},
1290 {0x12, 0x00},
1291 {0x13, 0x00},
1292 {0x14, 0x00},
1293 {0x15, 0x00},
1294 {0x16, 0x00},
1295 {0x17, 0x00},
1296 {0x18, 0x00},
1297 {0x19, 0x00},
1298 {0x1a, 0x00},
1299 {0x1b, 0x8f},
1300 {0x1c, 0x0f},
1301 {0x1d, 0x00},
1302 {0x1e, 0x00},
1303 {0x1f, 0x00},
1304 {0x20, 0x00},
1305 {0x21, 0x00},
1306 {0x22, 0x00},
1307 {0x23, 0x00},
1308 {0x24, 0x00},
1309 {0x25, 0x4a},
1310 {0x26, 0x00},
1311 {0x27, 0x00},
1312 {0x28, 0x00},
1313 {0x29, 0x00},
1314 {0x2a, 0x00},
1315 {0x2b, 0x00},
1316 {0x2c, 0x00},
1317 {0x2d, 0x18},
1318 {0x2e, 0x00},
1319 {0x2f, 0x0a},
1320 {0x30, 0x26},
1321 {0x31, 0x5b},
1322 {0x32, 0x00},
1323 {0x33, 0x00},
1324 {0x34, 0x00},
1325 {0x35, 0x00},
1326 {0x36, 0xaa},
1327 {0x37, 0xaa},
1328 {0x38, 0xff},
1329 {0x39, 0xff},
1330 {0x3a, 0x00},
1331 {0x3b, 0x00},
1332 {0x3c, 0x00},
1333 {0x3d, 0x03},
1334 {0x3e, 0x1d},
1335 {0x3f, 0x04},
1336 {0x40, 0x00},
1337 {0x41, 0x08},
1338 {0x42, 0x00},
1339 {0x43, 0x08},
1340 {0x44, 0x08},
1341 {0x45, 0x14},
1342 {0x46, 0x05},
1343 {0x47, 0x09},
1344 {0x48, 0x00},
1345 {0x49, 0x00},
1346 {0x4a, 0x00},
1347 {0x4b, 0x00},
1348 {0x4c, 0x09},
1349 {0x4d, 0x90},
1350 {0x4e, 0x00},
1351 {0x4f, 0xc5},
1352 {0x50, 0x15},
1353 {0x51, 0x19},
1354 {0x52, 0x00},
1355 {0x53, 0x00},
1356 {0x54, 0x00},
1357 {0x55, 0x00},
1358 {0x56, 0x00},
1359 {0x57, 0x00},
1360 {0x58, 0x00},
1361 {0x59, 0xb0},
1362 {0x5a, 0x00},
1363 {0x5b, 0x00},
1364 {0x5c, 0x00},
1365 {0x5d, 0x00},
1366 {0x5e, 0x00},
1367 {0x5f, 0x00},
1368 {0x60, 0xb3},
1369 {0x61, 0x81},
1370 {0x62, 0x00},
1371 {0x63, 0x00},
1372 {0x64, 0x00},
1373 {0x65, 0x00},
1374 {0x66, 0x57},
1375 {0x67, 0x6c},
1376 {0x68, 0x00},
1377 {0x69, 0x00},
1378 {0x6a, 0x00},
1379 {0x6b, 0x00},
1380 //{0x6c, 0x80},
1381 {0x6c, 0x00}, //RobertYu:20050125, request by JJSue
1382 {0x6d, 0x03},
1383 {0x6e, 0x01},
1384 {0x6f, 0x00},
1385 {0x70, 0x00},
1386 {0x71, 0x00},
1387 {0x72, 0x00},
1388 {0x73, 0x00},
1389 {0x74, 0x00},
1390 {0x75, 0x00},
1391 {0x76, 0x00},
1392 {0x77, 0x00},
1393 {0x78, 0x00},
1394 {0x79, 0x00},
1395 {0x7a, 0x00},
1396 {0x7b, 0x00},
1397 {0x7c, 0x00},
1398 {0x7d, 0x00},
1399 {0x7e, 0x00},
1400 {0x7f, 0x00},
1401 {0x80, 0x8c},
1402 {0x81, 0x00},
1403 {0x82, 0x0e},
1404 {0x83, 0x00},
1405 {0x84, 0x00},
1406 {0x85, 0x00},
1407 {0x86, 0x00},
1408 {0x87, 0x00},
1409 {0x88, 0x08},
1410 {0x89, 0x00},
1411 {0x8a, 0x0e},
1412 {0x8b, 0xa7},
1413 {0x8c, 0x88},
1414 {0x8d, 0x47},
1415 {0x8e, 0xaa},
1416 {0x8f, 0x02},
1417 {0x90, 0x00},
1418 {0x91, 0x00},
1419 {0x92, 0x00},
1420 {0x93, 0x00},
1421 {0x94, 0x00},
1422 {0x95, 0x00},
1423 {0x96, 0x00},
1424 {0x97, 0xe3},
1425 {0x98, 0x00},
1426 {0x99, 0x00},
1427 {0x9a, 0x00},
1428 {0x9b, 0x00},
1429 {0x9c, 0x00},
1430 {0x9d, 0x00},
1431 {0x9e, 0x00},
1432 {0x9f, 0x00},
1433 {0xa0, 0x00},
1434 {0xa1, 0x00},
1435 {0xa2, 0x00},
1436 {0xa3, 0x00},
1437 {0xa4, 0x00},
1438 {0xa5, 0x00},
1439 {0xa6, 0x10},
1440 {0xa7, 0x00},
1441 {0xa8, 0x18},
1442 {0xa9, 0x00},
1443 {0xaa, 0x00},
1444 {0xab, 0x00},
1445 {0xac, 0x00},
1446 {0xad, 0x00},
1447 {0xae, 0x00},
1448 {0xaf, 0x18},
1449 {0xb0, 0x18},
1450 {0xb1, 0x30},
1451 {0xb2, 0x00},
1452 {0xb3, 0x00},
1453 {0xb4, 0x00},
1454 {0xb5, 0x00},
1455 {0xb6, 0x00},
1456 {0xb7, 0x00},
1457 {0xb8, 0x00},
1458 {0xb9, 0x00},
1459 {0xba, 0x00},
1460 {0xbb, 0x03},
1461 {0xbc, 0x01},
1462 {0xbd, 0x00},
1463 {0xbe, 0x00},
1464 {0xbf, 0x00},
1465 {0xc0, 0x10},
1466 {0xc1, 0x20},
1467 {0xc2, 0x00},
1468 {0xc3, 0x20},
1469 {0xc4, 0x00},
1470 {0xc5, 0x2c},
1471 {0xc6, 0x1c},
1472 {0xc7, 0x10},
1473 {0xc8, 0x10},
1474 {0xc9, 0x01},
1475 {0xca, 0x68},
1476 {0xcb, 0xa7},
1477 {0xcc, 0x3c},
1478 {0xcd, 0x09},
1479 {0xce, 0x00},
1480 {0xcf, 0x20},
1481 {0xd0, 0x40},
1482 {0xd1, 0x10},
1483 {0xd2, 0x00},
1484 {0xd3, 0x00},
1485 {0xd4, 0x20},
1486 {0xd5, 0x28},
1487 {0xd6, 0xa0},
1488 {0xd7, 0x2a},
1489 {0xd8, 0x00},
1490 {0xd9, 0x00},
1491 {0xda, 0x00},
1492 {0xdb, 0x00},
1493 {0xdc, 0x00},
1494 {0xdd, 0x00},
1495 {0xde, 0x00},
1496 {0xdf, 0x00},
1497 {0xe0, 0x00},
1498 {0xe1, 0xd3},
1499 {0xe2, 0xc0},
1500 {0xe3, 0x00},
1501 {0xe4, 0x00},
1502 {0xe5, 0x10},
1503 {0xe6, 0x00},
1504 {0xe7, 0x12},
1505 {0xe8, 0x12},
1506 {0xe9, 0x34},
1507 {0xea, 0x00},
1508 {0xeb, 0xff},
1509 {0xec, 0x79},
1510 {0xed, 0x20},
1511 {0xee, 0x30},
1512 {0xef, 0x01},
1513 {0xf0, 0x00},
1514 {0xf1, 0x3e},
1515 {0xf2, 0x00},
1516 {0xf3, 0x00},
1517 {0xf4, 0x00},
1518 {0xf5, 0x00},
1519 {0xf6, 0x00},
1520 {0xf7, 0x00},
1521 {0xf8, 0x00},
1522 {0xf9, 0x00},
1523 {0xfa, 0x00},
1524 {0xfb, 0x00},
1525 {0xfc, 0x00},
1526 {0xfd, 0x00},
1527 {0xfe, 0x00},
1528 {0xff, 0x00},
1529};
1530
1531#define CB_VT3253B0_AGC 193
1532// For AIROHA
1533BYTE byVT3253B0_AGC[CB_VT3253B0_AGC][2] = {
1534 {0xF0, 0x00},
1535 {0xF1, 0x00},
1536 {0xF0, 0x80},
1537 {0xF0, 0x01},
1538 {0xF1, 0x00},
1539 {0xF0, 0x81},
1540 {0xF0, 0x02},
1541 {0xF1, 0x02},
1542 {0xF0, 0x82},
1543 {0xF0, 0x03},
1544 {0xF1, 0x04},
1545 {0xF0, 0x83},
1546 {0xF0, 0x03},
1547 {0xF1, 0x04},
1548 {0xF0, 0x84},
1549 {0xF0, 0x04},
1550 {0xF1, 0x06},
1551 {0xF0, 0x85},
1552 {0xF0, 0x05},
1553 {0xF1, 0x06},
1554 {0xF0, 0x86},
1555 {0xF0, 0x06},
1556 {0xF1, 0x06},
1557 {0xF0, 0x87},
1558 {0xF0, 0x07},
1559 {0xF1, 0x08},
1560 {0xF0, 0x88},
1561 {0xF0, 0x08},
1562 {0xF1, 0x08},
1563 {0xF0, 0x89},
1564 {0xF0, 0x09},
1565 {0xF1, 0x0A},
1566 {0xF0, 0x8A},
1567 {0xF0, 0x0A},
1568 {0xF1, 0x0A},
1569 {0xF0, 0x8B},
1570 {0xF0, 0x0B},
1571 {0xF1, 0x0C},
1572 {0xF0, 0x8C},
1573 {0xF0, 0x0C},
1574 {0xF1, 0x0C},
1575 {0xF0, 0x8D},
1576 {0xF0, 0x0D},
1577 {0xF1, 0x0E},
1578 {0xF0, 0x8E},
1579 {0xF0, 0x0E},
1580 {0xF1, 0x0E},
1581 {0xF0, 0x8F},
1582 {0xF0, 0x0F},
1583 {0xF1, 0x10},
1584 {0xF0, 0x90},
1585 {0xF0, 0x10},
1586 {0xF1, 0x10},
1587 {0xF0, 0x91},
1588 {0xF0, 0x11},
1589 {0xF1, 0x12},
1590 {0xF0, 0x92},
1591 {0xF0, 0x12},
1592 {0xF1, 0x12},
1593 {0xF0, 0x93},
1594 {0xF0, 0x13},
1595 {0xF1, 0x14},
1596 {0xF0, 0x94},
1597 {0xF0, 0x14},
1598 {0xF1, 0x14},
1599 {0xF0, 0x95},
1600 {0xF0, 0x15},
1601 {0xF1, 0x16},
1602 {0xF0, 0x96},
1603 {0xF0, 0x16},
1604 {0xF1, 0x16},
1605 {0xF0, 0x97},
1606 {0xF0, 0x17},
1607 {0xF1, 0x18},
1608 {0xF0, 0x98},
1609 {0xF0, 0x18},
1610 {0xF1, 0x18},
1611 {0xF0, 0x99},
1612 {0xF0, 0x19},
1613 {0xF1, 0x1A},
1614 {0xF0, 0x9A},
1615 {0xF0, 0x1A},
1616 {0xF1, 0x1A},
1617 {0xF0, 0x9B},
1618 {0xF0, 0x1B},
1619 {0xF1, 0x1C},
1620 {0xF0, 0x9C},
1621 {0xF0, 0x1C},
1622 {0xF1, 0x1C},
1623 {0xF0, 0x9D},
1624 {0xF0, 0x1D},
1625 {0xF1, 0x1E},
1626 {0xF0, 0x9E},
1627 {0xF0, 0x1E},
1628 {0xF1, 0x1E},
1629 {0xF0, 0x9F},
1630 {0xF0, 0x1F},
1631 {0xF1, 0x20},
1632 {0xF0, 0xA0},
1633 {0xF0, 0x20},
1634 {0xF1, 0x20},
1635 {0xF0, 0xA1},
1636 {0xF0, 0x21},
1637 {0xF1, 0x22},
1638 {0xF0, 0xA2},
1639 {0xF0, 0x22},
1640 {0xF1, 0x22},
1641 {0xF0, 0xA3},
1642 {0xF0, 0x23},
1643 {0xF1, 0x24},
1644 {0xF0, 0xA4},
1645 {0xF0, 0x24},
1646 {0xF1, 0x24},
1647 {0xF0, 0xA5},
1648 {0xF0, 0x25},
1649 {0xF1, 0x26},
1650 {0xF0, 0xA6},
1651 {0xF0, 0x26},
1652 {0xF1, 0x26},
1653 {0xF0, 0xA7},
1654 {0xF0, 0x27},
1655 {0xF1, 0x28},
1656 {0xF0, 0xA8},
1657 {0xF0, 0x28},
1658 {0xF1, 0x28},
1659 {0xF0, 0xA9},
1660 {0xF0, 0x29},
1661 {0xF1, 0x2A},
1662 {0xF0, 0xAA},
1663 {0xF0, 0x2A},
1664 {0xF1, 0x2A},
1665 {0xF0, 0xAB},
1666 {0xF0, 0x2B},
1667 {0xF1, 0x2C},
1668 {0xF0, 0xAC},
1669 {0xF0, 0x2C},
1670 {0xF1, 0x2C},
1671 {0xF0, 0xAD},
1672 {0xF0, 0x2D},
1673 {0xF1, 0x2E},
1674 {0xF0, 0xAE},
1675 {0xF0, 0x2E},
1676 {0xF1, 0x2E},
1677 {0xF0, 0xAF},
1678 {0xF0, 0x2F},
1679 {0xF1, 0x30},
1680 {0xF0, 0xB0},
1681 {0xF0, 0x30},
1682 {0xF1, 0x30},
1683 {0xF0, 0xB1},
1684 {0xF0, 0x31},
1685 {0xF1, 0x32},
1686 {0xF0, 0xB2},
1687 {0xF0, 0x32},
1688 {0xF1, 0x32},
1689 {0xF0, 0xB3},
1690 {0xF0, 0x33},
1691 {0xF1, 0x34},
1692 {0xF0, 0xB4},
1693 {0xF0, 0x34},
1694 {0xF1, 0x34},
1695 {0xF0, 0xB5},
1696 {0xF0, 0x35},
1697 {0xF1, 0x36},
1698 {0xF0, 0xB6},
1699 {0xF0, 0x36},
1700 {0xF1, 0x36},
1701 {0xF0, 0xB7},
1702 {0xF0, 0x37},
1703 {0xF1, 0x38},
1704 {0xF0, 0xB8},
1705 {0xF0, 0x38},
1706 {0xF1, 0x38},
1707 {0xF0, 0xB9},
1708 {0xF0, 0x39},
1709 {0xF1, 0x3A},
1710 {0xF0, 0xBA},
1711 {0xF0, 0x3A},
1712 {0xF1, 0x3A},
1713 {0xF0, 0xBB},
1714 {0xF0, 0x3B},
1715 {0xF1, 0x3C},
1716 {0xF0, 0xBC},
1717 {0xF0, 0x3C},
1718 {0xF1, 0x3C},
1719 {0xF0, 0xBD},
1720 {0xF0, 0x3D},
1721 {0xF1, 0x3E},
1722 {0xF0, 0xBE},
1723 {0xF0, 0x3E},
1724 {0xF1, 0x3E},
1725 {0xF0, 0xBF},
1726 {0xF0, 0x00},
1727};
1728
1729const WORD awcFrameTime[MAX_RATE] =
1730{10, 20, 55, 110, 24, 36, 48, 72, 96, 144, 192, 216};
1731
1732
1733/*--------------------- Static Functions --------------------------*/
1734
1735static
1736ULONG
1737s_ulGetRatio(PSDevice pDevice);
1738
1739static
1740VOID
1741s_vChangeAntenna(
1742 IN PSDevice pDevice
1743 );
1744
1745static
1746VOID
1747s_vChangeAntenna (
1748 IN PSDevice pDevice
1749 )
1750{
1751
1752#ifdef PLICE_DEBUG
1753 //printk("Enter s_vChangeAntenna:original RxMode is %d,TxMode is %d\n",pDevice->byRxAntennaMode,pDevice->byTxAntennaMode);
1754#endif
1755 if ( pDevice->dwRxAntennaSel == 0) {
1756 pDevice->dwRxAntennaSel=1;
1757 if (pDevice->bTxRxAntInv == TRUE)
1758 BBvSetRxAntennaMode(pDevice->PortOffset, ANT_A);
1759 else
1760 BBvSetRxAntennaMode(pDevice->PortOffset, ANT_B);
1761 } else {
1762 pDevice->dwRxAntennaSel=0;
1763 if (pDevice->bTxRxAntInv == TRUE)
1764 BBvSetRxAntennaMode(pDevice->PortOffset, ANT_B);
1765 else
1766 BBvSetRxAntennaMode(pDevice->PortOffset, ANT_A);
1767 }
1768 if ( pDevice->dwTxAntennaSel == 0) {
1769 pDevice->dwTxAntennaSel=1;
1770 BBvSetTxAntennaMode(pDevice->PortOffset, ANT_B);
1771 } else {
1772 pDevice->dwTxAntennaSel=0;
1773 BBvSetTxAntennaMode(pDevice->PortOffset, ANT_A);
1774 }
1775}
1776
1777
1778/*--------------------- Export Variables --------------------------*/
1779/*
1780 * Description: Calculate data frame transmitting time
1781 *
1782 * Parameters:
1783 * In:
1784 * byPreambleType - Preamble Type
1785 * byPktType - PK_TYPE_11A, PK_TYPE_11B, PK_TYPE_11GB, PK_TYPE_11GA
1786 * cbFrameLength - Baseband Type
1787 * wRate - Tx Rate
1788 * Out:
1789 *
1790 * Return Value: FrameTime
1791 *
1792 */
1793UINT
1794BBuGetFrameTime (
1795 IN BYTE byPreambleType,
1796 IN BYTE byPktType,
1797 IN UINT cbFrameLength,
1798 IN WORD wRate
1799 )
1800{
1801 UINT uFrameTime;
1802 UINT uPreamble;
1803 UINT uTmp;
1804 UINT uRateIdx = (UINT)wRate;
1805 UINT uRate = 0;
1806
1807
1808 if (uRateIdx > RATE_54M) {
1809 return 0;
1810 }
1811
1812 uRate = (UINT)awcFrameTime[uRateIdx];
1813
1814 if (uRateIdx <= 3) { //CCK mode
1815
1816 if (byPreambleType == 1) {//Short
1817 uPreamble = 96;
1818 } else {
1819 uPreamble = 192;
1820 }
1821 uFrameTime = (cbFrameLength * 80) / uRate; //?????
1822 uTmp = (uFrameTime * uRate) / 80;
1823 if (cbFrameLength != uTmp) {
1824 uFrameTime ++;
1825 }
1826
1827 return (uPreamble + uFrameTime);
1828 }
1829 else {
1830 uFrameTime = (cbFrameLength * 8 + 22) / uRate; //????????
1831 uTmp = ((uFrameTime * uRate) - 22) / 8;
1832 if(cbFrameLength != uTmp) {
1833 uFrameTime ++;
1834 }
1835 uFrameTime = uFrameTime * 4; //???????
1836 if(byPktType != PK_TYPE_11A) {
1837 uFrameTime += 6; //??????
1838 }
1839 return (20 + uFrameTime); //??????
1840 }
1841}
1842
1843/*
1844 * Description: Caculate Length, Service, and Signal fields of Phy for Tx
1845 *
1846 * Parameters:
1847 * In:
1848 * pDevice - Device Structure
1849 * cbFrameLength - Tx Frame Length
1850 * wRate - Tx Rate
1851 * Out:
1852 * pwPhyLen - pointer to Phy Length field
1853 * pbyPhySrv - pointer to Phy Service field
1854 * pbyPhySgn - pointer to Phy Signal field
1855 *
1856 * Return Value: none
1857 *
1858 */
1859VOID
1860BBvCaculateParameter (
1861 IN PSDevice pDevice,
1862 IN UINT cbFrameLength,
1863 IN WORD wRate,
1864 IN BYTE byPacketType,
1865 OUT PWORD pwPhyLen,
1866 OUT PBYTE pbyPhySrv,
1867 OUT PBYTE pbyPhySgn
1868 )
1869{
1870 UINT cbBitCount;
1871 UINT cbUsCount = 0;
1872 UINT cbTmp;
1873 BOOL bExtBit;
1874 BYTE byPreambleType = pDevice->byPreambleType;
1875 BOOL bCCK = pDevice->bCCK;
1876
1877 cbBitCount = cbFrameLength * 8;
1878 bExtBit = FALSE;
1879
1880 switch (wRate) {
1881 case RATE_1M :
1882 cbUsCount = cbBitCount;
1883 *pbyPhySgn = 0x00;
1884 break;
1885
1886 case RATE_2M :
1887 cbUsCount = cbBitCount / 2;
1888 if (byPreambleType == 1)
1889 *pbyPhySgn = 0x09;
1890 else // long preamble
1891 *pbyPhySgn = 0x01;
1892 break;
1893
1894 case RATE_5M :
1895 if (bCCK == FALSE)
1896 cbBitCount ++;
1897 cbUsCount = (cbBitCount * 10) / 55;
1898 cbTmp = (cbUsCount * 55) / 10;
1899 if (cbTmp != cbBitCount)
1900 cbUsCount ++;
1901 if (byPreambleType == 1)
1902 *pbyPhySgn = 0x0a;
1903 else // long preamble
1904 *pbyPhySgn = 0x02;
1905 break;
1906
1907 case RATE_11M :
1908
1909 if (bCCK == FALSE)
1910 cbBitCount ++;
1911 cbUsCount = cbBitCount / 11;
1912 cbTmp = cbUsCount * 11;
1913 if (cbTmp != cbBitCount) {
1914 cbUsCount ++;
1915 if ((cbBitCount - cbTmp) <= 3)
1916 bExtBit = TRUE;
1917 }
1918 if (byPreambleType == 1)
1919 *pbyPhySgn = 0x0b;
1920 else // long preamble
1921 *pbyPhySgn = 0x03;
1922 break;
1923
1924 case RATE_6M :
1925 if(byPacketType == PK_TYPE_11A) {//11a, 5GHZ
1926 *pbyPhySgn = 0x9B; //1001 1011
1927 }
1928 else {//11g, 2.4GHZ
1929 *pbyPhySgn = 0x8B; //1000 1011
1930 }
1931 break;
1932
1933 case RATE_9M :
1934 if(byPacketType == PK_TYPE_11A) {//11a, 5GHZ
1935 *pbyPhySgn = 0x9F; //1001 1111
1936 }
1937 else {//11g, 2.4GHZ
1938 *pbyPhySgn = 0x8F; //1000 1111
1939 }
1940 break;
1941
1942 case RATE_12M :
1943 if(byPacketType == PK_TYPE_11A) {//11a, 5GHZ
1944 *pbyPhySgn = 0x9A; //1001 1010
1945 }
1946 else {//11g, 2.4GHZ
1947 *pbyPhySgn = 0x8A; //1000 1010
1948 }
1949 break;
1950
1951 case RATE_18M :
1952 if(byPacketType == PK_TYPE_11A) {//11a, 5GHZ
1953 *pbyPhySgn = 0x9E; //1001 1110
1954 }
1955 else {//11g, 2.4GHZ
1956 *pbyPhySgn = 0x8E; //1000 1110
1957 }
1958 break;
1959
1960 case RATE_24M :
1961 if(byPacketType == PK_TYPE_11A) {//11a, 5GHZ
1962 *pbyPhySgn = 0x99; //1001 1001
1963 }
1964 else {//11g, 2.4GHZ
1965 *pbyPhySgn = 0x89; //1000 1001
1966 }
1967 break;
1968
1969 case RATE_36M :
1970 if(byPacketType == PK_TYPE_11A) {//11a, 5GHZ
1971 *pbyPhySgn = 0x9D; //1001 1101
1972 }
1973 else {//11g, 2.4GHZ
1974 *pbyPhySgn = 0x8D; //1000 1101
1975 }
1976 break;
1977
1978 case RATE_48M :
1979 if(byPacketType == PK_TYPE_11A) {//11a, 5GHZ
1980 *pbyPhySgn = 0x98; //1001 1000
1981 }
1982 else {//11g, 2.4GHZ
1983 *pbyPhySgn = 0x88; //1000 1000
1984 }
1985 break;
1986
1987 case RATE_54M :
1988 if (byPacketType == PK_TYPE_11A) {//11a, 5GHZ
1989 *pbyPhySgn = 0x9C; //1001 1100
1990 }
1991 else {//11g, 2.4GHZ
1992 *pbyPhySgn = 0x8C; //1000 1100
1993 }
1994 break;
1995
1996 default :
1997 if (byPacketType == PK_TYPE_11A) {//11a, 5GHZ
1998 *pbyPhySgn = 0x9C; //1001 1100
1999 }
2000 else {//11g, 2.4GHZ
2001 *pbyPhySgn = 0x8C; //1000 1100
2002 }
2003 break;
2004 }
2005
2006 if (byPacketType == PK_TYPE_11B) {
2007 *pbyPhySrv = 0x00;
2008 if (bExtBit)
2009 *pbyPhySrv = *pbyPhySrv | 0x80;
2010 *pwPhyLen = (WORD)cbUsCount;
2011 }
2012 else {
2013 *pbyPhySrv = 0x00;
2014 *pwPhyLen = (WORD)cbFrameLength;
2015 }
2016}
2017
2018/*
2019 * Description: Read a byte from BASEBAND, by embeded programming
2020 *
2021 * Parameters:
2022 * In:
2023 * dwIoBase - I/O base address
2024 * byBBAddr - address of register in Baseband
2025 * Out:
2026 * pbyData - data read
2027 *
2028 * Return Value: TRUE if succeeded; FALSE if failed.
2029 *
2030 */
2031BOOL BBbReadEmbeded (DWORD_PTR dwIoBase, BYTE byBBAddr, PBYTE pbyData)
2032{
2033 WORD ww;
2034 BYTE byValue;
2035
2036 // BB reg offset
2037 VNSvOutPortB(dwIoBase + MAC_REG_BBREGADR, byBBAddr);
2038
2039 // turn on REGR
2040 MACvRegBitsOn(dwIoBase, MAC_REG_BBREGCTL, BBREGCTL_REGR);
2041 // W_MAX_TIMEOUT is the timeout period
2042 for (ww = 0; ww < W_MAX_TIMEOUT; ww++) {
2043 VNSvInPortB(dwIoBase + MAC_REG_BBREGCTL, &byValue);
2044 if (BITbIsBitOn(byValue, BBREGCTL_DONE))
2045 break;
2046 }
2047
2048 // get BB data
2049 VNSvInPortB(dwIoBase + MAC_REG_BBREGDATA, pbyData);
2050
2051 if (ww == W_MAX_TIMEOUT) {
2052 DBG_PORT80(0x30);
2053 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO" DBG_PORT80(0x30)\n");
2054 return FALSE;
2055 }
2056 return TRUE;
2057}
2058
2059
2060/*
2061 * Description: Write a Byte to BASEBAND, by embeded programming
2062 *
2063 * Parameters:
2064 * In:
2065 * dwIoBase - I/O base address
2066 * byBBAddr - address of register in Baseband
2067 * byData - data to write
2068 * Out:
2069 * none
2070 *
2071 * Return Value: TRUE if succeeded; FALSE if failed.
2072 *
2073 */
2074BOOL BBbWriteEmbeded (DWORD_PTR dwIoBase, BYTE byBBAddr, BYTE byData)
2075{
2076 WORD ww;
2077 BYTE byValue;
2078
2079 // BB reg offset
2080 VNSvOutPortB(dwIoBase + MAC_REG_BBREGADR, byBBAddr);
2081 // set BB data
2082 VNSvOutPortB(dwIoBase + MAC_REG_BBREGDATA, byData);
2083
2084 // turn on BBREGCTL_REGW
2085 MACvRegBitsOn(dwIoBase, MAC_REG_BBREGCTL, BBREGCTL_REGW);
2086 // W_MAX_TIMEOUT is the timeout period
2087 for (ww = 0; ww < W_MAX_TIMEOUT; ww++) {
2088 VNSvInPortB(dwIoBase + MAC_REG_BBREGCTL, &byValue);
2089 if (BITbIsBitOn(byValue, BBREGCTL_DONE))
2090 break;
2091 }
2092
2093 if (ww == W_MAX_TIMEOUT) {
2094 DBG_PORT80(0x31);
2095 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO" DBG_PORT80(0x31)\n");
2096 return FALSE;
2097 }
2098 return TRUE;
2099}
2100
2101
2102/*
2103 * Description: Test if all bits are set for the Baseband register
2104 *
2105 * Parameters:
2106 * In:
2107 * dwIoBase - I/O base address
2108 * byBBAddr - address of register in Baseband
2109 * byTestBits - TestBits
2110 * Out:
2111 * none
2112 *
2113 * Return Value: TRUE if all TestBits are set; FALSE otherwise.
2114 *
2115 */
2116BOOL BBbIsRegBitsOn (DWORD_PTR dwIoBase, BYTE byBBAddr, BYTE byTestBits)
2117{
2118 BYTE byOrgData;
2119
2120 BBbReadEmbeded(dwIoBase, byBBAddr, &byOrgData);
2121 return BITbIsAllBitsOn(byOrgData, byTestBits);
2122}
2123
2124
2125/*
2126 * Description: Test if all bits are clear for the Baseband register
2127 *
2128 * Parameters:
2129 * In:
2130 * dwIoBase - I/O base address
2131 * byBBAddr - address of register in Baseband
2132 * byTestBits - TestBits
2133 * Out:
2134 * none
2135 *
2136 * Return Value: TRUE if all TestBits are clear; FALSE otherwise.
2137 *
2138 */
2139BOOL BBbIsRegBitsOff (DWORD_PTR dwIoBase, BYTE byBBAddr, BYTE byTestBits)
2140{
2141 BYTE byOrgData;
2142
2143 BBbReadEmbeded(dwIoBase, byBBAddr, &byOrgData);
2144 return BITbIsAllBitsOff(byOrgData, byTestBits);
2145}
2146
2147/*
2148 * Description: VIA VT3253 Baseband chip init function
2149 *
2150 * Parameters:
2151 * In:
2152 * dwIoBase - I/O base address
2153 * byRevId - Revision ID
2154 * byRFType - RF type
2155 * Out:
2156 * none
2157 *
2158 * Return Value: TRUE if succeeded; FALSE if failed.
2159 *
2160 */
2161
2162BOOL BBbVT3253Init (PSDevice pDevice)
2163{
2164 BOOL bResult = TRUE;
2165 int ii;
2166 DWORD_PTR dwIoBase = pDevice->PortOffset;
2167 BYTE byRFType = pDevice->byRFType;
2168 BYTE byLocalID = pDevice->byLocalID;
2169
2170 if (byRFType == RF_RFMD2959) {
2171 if (byLocalID <= REV_ID_VT3253_A1) {
2172 for (ii = 0; ii < CB_VT3253_INIT_FOR_RFMD; ii++) {
2173 bResult &= BBbWriteEmbeded(dwIoBase,byVT3253InitTab_RFMD[ii][0],byVT3253InitTab_RFMD[ii][1]);
2174 }
2175 } else {
2176 for (ii = 0; ii < CB_VT3253B0_INIT_FOR_RFMD; ii++) {
2177 bResult &= BBbWriteEmbeded(dwIoBase,byVT3253B0_RFMD[ii][0],byVT3253B0_RFMD[ii][1]);
2178 }
2179 for (ii = 0; ii < CB_VT3253B0_AGC_FOR_RFMD2959; ii++) {
2180 bResult &= BBbWriteEmbeded(dwIoBase,byVT3253B0_AGC4_RFMD2959[ii][0],byVT3253B0_AGC4_RFMD2959[ii][1]);
2181 }
2182 VNSvOutPortD(dwIoBase + MAC_REG_ITRTMSET, 0x23);
2183 MACvRegBitsOn(dwIoBase, MAC_REG_PAPEDELAY, BIT0);
2184 }
2185 pDevice->abyBBVGA[0] = 0x18;
2186 pDevice->abyBBVGA[1] = 0x0A;
2187 pDevice->abyBBVGA[2] = 0x0;
2188 pDevice->abyBBVGA[3] = 0x0;
2189 pDevice->ldBmThreshold[0] = -70;
2190 pDevice->ldBmThreshold[1] = -50;
2191 pDevice->ldBmThreshold[2] = 0;
2192 pDevice->ldBmThreshold[3] = 0;
2193 } else if ((byRFType == RF_AIROHA) || (byRFType == RF_AL2230S) ) {
2194 for (ii = 0; ii < CB_VT3253B0_INIT_FOR_AIROHA2230; ii++) {
2195 bResult &= BBbWriteEmbeded(dwIoBase,byVT3253B0_AIROHA2230[ii][0],byVT3253B0_AIROHA2230[ii][1]);
2196 }
2197 for (ii = 0; ii < CB_VT3253B0_AGC; ii++) {
2198 bResult &= BBbWriteEmbeded(dwIoBase,byVT3253B0_AGC[ii][0],byVT3253B0_AGC[ii][1]);
2199 }
2200 pDevice->abyBBVGA[0] = 0x1C;
2201 pDevice->abyBBVGA[1] = 0x10;
2202 pDevice->abyBBVGA[2] = 0x0;
2203 pDevice->abyBBVGA[3] = 0x0;
2204 pDevice->ldBmThreshold[0] = -70;
2205 pDevice->ldBmThreshold[1] = -48;
2206 pDevice->ldBmThreshold[2] = 0;
2207 pDevice->ldBmThreshold[3] = 0;
2208 } else if (byRFType == RF_UW2451) {
2209 for (ii = 0; ii < CB_VT3253B0_INIT_FOR_UW2451; ii++) {
2210 bResult &= BBbWriteEmbeded(dwIoBase,byVT3253B0_UW2451[ii][0],byVT3253B0_UW2451[ii][1]);
2211 }
2212 for (ii = 0; ii < CB_VT3253B0_AGC; ii++) {
2213 bResult &= BBbWriteEmbeded(dwIoBase,byVT3253B0_AGC[ii][0],byVT3253B0_AGC[ii][1]);
2214 }
2215 VNSvOutPortB(dwIoBase + MAC_REG_ITRTMSET, 0x23);
2216 MACvRegBitsOn(dwIoBase, MAC_REG_PAPEDELAY, BIT0);
2217
2218 pDevice->abyBBVGA[0] = 0x14;
2219 pDevice->abyBBVGA[1] = 0x0A;
2220 pDevice->abyBBVGA[2] = 0x0;
2221 pDevice->abyBBVGA[3] = 0x0;
2222 pDevice->ldBmThreshold[0] = -60;
2223 pDevice->ldBmThreshold[1] = -50;
2224 pDevice->ldBmThreshold[2] = 0;
2225 pDevice->ldBmThreshold[3] = 0;
2226 } else if (byRFType == RF_UW2452) {
2227 for (ii = 0; ii < CB_VT3253B0_INIT_FOR_UW2451; ii++) {
2228 bResult &= BBbWriteEmbeded(dwIoBase,byVT3253B0_UW2451[ii][0],byVT3253B0_UW2451[ii][1]);
2229 }
2230 // Init ANT B select,TX Config CR09 = 0x61->0x45, 0x45->0x41(VC1/VC2 define, make the ANT_A, ANT_B inverted)
2231 //bResult &= BBbWriteEmbeded(dwIoBase,0x09,0x41);
2232 // Init ANT B select,RX Config CR10 = 0x28->0x2A, 0x2A->0x28(VC1/VC2 define, make the ANT_A, ANT_B inverted)
2233 //bResult &= BBbWriteEmbeded(dwIoBase,0x0a,0x28);
2234 // Select VC1/VC2, CR215 = 0x02->0x06
2235 bResult &= BBbWriteEmbeded(dwIoBase,0xd7,0x06);
2236
2237 //{{RobertYu:20050125, request by Jack
2238 bResult &= BBbWriteEmbeded(dwIoBase,0x90,0x20);
2239 bResult &= BBbWriteEmbeded(dwIoBase,0x97,0xeb);
2240 //}}
2241
2242 //{{RobertYu:20050221, request by Jack
2243 bResult &= BBbWriteEmbeded(dwIoBase,0xa6,0x00);
2244 bResult &= BBbWriteEmbeded(dwIoBase,0xa8,0x30);
2245 //}}
2246 bResult &= BBbWriteEmbeded(dwIoBase,0xb0,0x58);
2247
2248 for (ii = 0; ii < CB_VT3253B0_AGC; ii++) {
2249 bResult &= BBbWriteEmbeded(dwIoBase,byVT3253B0_AGC[ii][0],byVT3253B0_AGC[ii][1]);
2250 }
2251 //VNSvOutPortB(dwIoBase + MAC_REG_ITRTMSET, 0x23); // RobertYu: 20050104, 20050131 disable PA_Delay
2252 //MACvRegBitsOn(dwIoBase, MAC_REG_PAPEDELAY, BIT0); // RobertYu: 20050104, 20050131 disable PA_Delay
2253
2254 pDevice->abyBBVGA[0] = 0x14;
2255 pDevice->abyBBVGA[1] = 0x0A;
2256 pDevice->abyBBVGA[2] = 0x0;
2257 pDevice->abyBBVGA[3] = 0x0;
2258 pDevice->ldBmThreshold[0] = -60;
2259 pDevice->ldBmThreshold[1] = -50;
2260 pDevice->ldBmThreshold[2] = 0;
2261 pDevice->ldBmThreshold[3] = 0;
2262 //}} RobertYu
2263
2264 } else if (byRFType == RF_VT3226) {
2265 for (ii = 0; ii < CB_VT3253B0_INIT_FOR_AIROHA2230; ii++) {
2266 bResult &= BBbWriteEmbeded(dwIoBase,byVT3253B0_AIROHA2230[ii][0],byVT3253B0_AIROHA2230[ii][1]);
2267 }
2268 for (ii = 0; ii < CB_VT3253B0_AGC; ii++) {
2269 bResult &= BBbWriteEmbeded(dwIoBase,byVT3253B0_AGC[ii][0],byVT3253B0_AGC[ii][1]);
2270 }
2271 pDevice->abyBBVGA[0] = 0x1C;
2272 pDevice->abyBBVGA[1] = 0x10;
2273 pDevice->abyBBVGA[2] = 0x0;
2274 pDevice->abyBBVGA[3] = 0x0;
2275 pDevice->ldBmThreshold[0] = -70;
2276 pDevice->ldBmThreshold[1] = -48;
2277 pDevice->ldBmThreshold[2] = 0;
2278 pDevice->ldBmThreshold[3] = 0;
2279 // Fix VT3226 DFC system timing issue
2280 MACvSetRFLE_LatchBase(dwIoBase);
2281 //{{ RobertYu: 20050104
2282 } else if (byRFType == RF_AIROHA7230) {
2283 for (ii = 0; ii < CB_VT3253B0_INIT_FOR_AIROHA2230; ii++) {
2284 bResult &= BBbWriteEmbeded(dwIoBase,byVT3253B0_AIROHA2230[ii][0],byVT3253B0_AIROHA2230[ii][1]);
2285 }
2286
2287 //{{ RobertYu:20050223, request by JerryChung
2288 // Init ANT B select,TX Config CR09 = 0x61->0x45, 0x45->0x41(VC1/VC2 define, make the ANT_A, ANT_B inverted)
2289 //bResult &= BBbWriteEmbeded(dwIoBase,0x09,0x41);
2290 // Init ANT B select,RX Config CR10 = 0x28->0x2A, 0x2A->0x28(VC1/VC2 define, make the ANT_A, ANT_B inverted)
2291 //bResult &= BBbWriteEmbeded(dwIoBase,0x0a,0x28);
2292 // Select VC1/VC2, CR215 = 0x02->0x06
2293 bResult &= BBbWriteEmbeded(dwIoBase,0xd7,0x06);
2294 //}}
2295
2296 for (ii = 0; ii < CB_VT3253B0_AGC; ii++) {
2297 bResult &= BBbWriteEmbeded(dwIoBase,byVT3253B0_AGC[ii][0],byVT3253B0_AGC[ii][1]);
2298 }
2299 pDevice->abyBBVGA[0] = 0x1C;
2300 pDevice->abyBBVGA[1] = 0x10;
2301 pDevice->abyBBVGA[2] = 0x0;
2302 pDevice->abyBBVGA[3] = 0x0;
2303 pDevice->ldBmThreshold[0] = -70;
2304 pDevice->ldBmThreshold[1] = -48;
2305 pDevice->ldBmThreshold[2] = 0;
2306 pDevice->ldBmThreshold[3] = 0;
2307 //}} RobertYu
2308 } else {
2309 // No VGA Table now
2310 pDevice->bUpdateBBVGA = FALSE;
2311 pDevice->abyBBVGA[0] = 0x1C;
2312 }
2313
2314 if (byLocalID > REV_ID_VT3253_A1) {
2315 BBbWriteEmbeded(dwIoBase, 0x04, 0x7F);
2316 BBbWriteEmbeded(dwIoBase, 0x0D, 0x01);
2317 }
2318
2319 return bResult;
2320}
2321
2322
2323
2324/*
2325 * Description: Read All Baseband Registers
2326 *
2327 * Parameters:
2328 * In:
2329 * dwIoBase - I/O base address
2330 * pbyBBRegs - Point to struct that stores Baseband Registers
2331 * Out:
2332 * none
2333 *
2334 * Return Value: none
2335 *
2336 */
2337VOID BBvReadAllRegs (DWORD_PTR dwIoBase, PBYTE pbyBBRegs)
2338{
2339 int ii;
2340 BYTE byBase = 1;
2341 for (ii = 0; ii < BB_MAX_CONTEXT_SIZE; ii++) {
2342 BBbReadEmbeded(dwIoBase, (BYTE)(ii*byBase), pbyBBRegs);
2343 pbyBBRegs += byBase;
2344 }
2345}
2346
2347/*
2348 * Description: Turn on BaseBand Loopback mode
2349 *
2350 * Parameters:
2351 * In:
2352 * dwIoBase - I/O base address
2353 * bCCK - If CCK is set
2354 * Out:
2355 * none
2356 *
2357 * Return Value: none
2358 *
2359 */
2360
2361
2362void BBvLoopbackOn (PSDevice pDevice)
2363{
2364 BYTE byData;
2365 DWORD_PTR dwIoBase = pDevice->PortOffset;
2366
2367 //CR C9 = 0x00
2368 BBbReadEmbeded(dwIoBase, 0xC9, &pDevice->byBBCRc9);//CR201
2369 BBbWriteEmbeded(dwIoBase, 0xC9, 0);
2370 BBbReadEmbeded(dwIoBase, 0x4D, &pDevice->byBBCR4d);//CR77
2371 BBbWriteEmbeded(dwIoBase, 0x4D, 0x90);
2372
2373 //CR 88 = 0x02(CCK), 0x03(OFDM)
2374 BBbReadEmbeded(dwIoBase, 0x88, &pDevice->byBBCR88);//CR136
2375
2376 if (pDevice->uConnectionRate <= RATE_11M) { //CCK
2377 // Enable internal digital loopback: CR33 |= 0000 0001
2378 BBbReadEmbeded(dwIoBase, 0x21, &byData);//CR33
2379 BBbWriteEmbeded(dwIoBase, 0x21, (BYTE)(byData | 0x01));//CR33
2380 // CR154 = 0x00
2381 BBbWriteEmbeded(dwIoBase, 0x9A, 0); //CR154
2382
2383 BBbWriteEmbeded(dwIoBase, 0x88, 0x02);//CR239
2384 }
2385 else { //OFDM
2386 // Enable internal digital loopback:CR154 |= 0000 0001
2387 BBbReadEmbeded(dwIoBase, 0x9A, &byData);//CR154
2388 BBbWriteEmbeded(dwIoBase, 0x9A, (BYTE)(byData | 0x01));//CR154
2389 // CR33 = 0x00
2390 BBbWriteEmbeded(dwIoBase, 0x21, 0); //CR33
2391
2392 BBbWriteEmbeded(dwIoBase, 0x88, 0x03);//CR239
2393 }
2394
2395 //CR14 = 0x00
2396 BBbWriteEmbeded(dwIoBase, 0x0E, 0);//CR14
2397
2398 // Disable TX_IQUN
2399 BBbReadEmbeded(pDevice->PortOffset, 0x09, &pDevice->byBBCR09);
2400 BBbWriteEmbeded(pDevice->PortOffset, 0x09, (BYTE)(pDevice->byBBCR09 & 0xDE));
2401}
2402
2403/*
2404 * Description: Turn off BaseBand Loopback mode
2405 *
2406 * Parameters:
2407 * In:
2408 * pDevice - Device Structure
2409 *
2410 * Out:
2411 * none
2412 *
2413 * Return Value: none
2414 *
2415 */
2416void BBvLoopbackOff (PSDevice pDevice)
2417{
2418 BYTE byData;
2419 DWORD_PTR dwIoBase = pDevice->PortOffset;
2420
2421 BBbWriteEmbeded(dwIoBase, 0xC9, pDevice->byBBCRc9);//CR201
2422 BBbWriteEmbeded(dwIoBase, 0x88, pDevice->byBBCR88);//CR136
2423 BBbWriteEmbeded(dwIoBase, 0x09, pDevice->byBBCR09);//CR136
2424 BBbWriteEmbeded(dwIoBase, 0x4D, pDevice->byBBCR4d);//CR77
2425
2426 if (pDevice->uConnectionRate <= RATE_11M) { // CCK
2427 // Set the CR33 Bit2 to disable internal Loopback.
2428 BBbReadEmbeded(dwIoBase, 0x21, &byData);//CR33
2429 BBbWriteEmbeded(dwIoBase, 0x21, (BYTE)(byData & 0xFE));//CR33
2430 }
2431 else { // OFDM
2432 BBbReadEmbeded(dwIoBase, 0x9A, &byData);//CR154
2433 BBbWriteEmbeded(dwIoBase, 0x9A, (BYTE)(byData & 0xFE));//CR154
2434 }
2435 BBbReadEmbeded(dwIoBase, 0x0E, &byData);//CR14
2436 BBbWriteEmbeded(dwIoBase, 0x0E, (BYTE)(byData | 0x80));//CR14
2437
2438}
2439
2440
2441
2442/*
2443 * Description: Set ShortSlotTime mode
2444 *
2445 * Parameters:
2446 * In:
2447 * pDevice - Device Structure
2448 * Out:
2449 * none
2450 *
2451 * Return Value: none
2452 *
2453 */
2454VOID
2455BBvSetShortSlotTime (PSDevice pDevice)
2456{
2457 BYTE byBBRxConf=0;
2458 BYTE byBBVGA=0;
2459
2460 BBbReadEmbeded(pDevice->PortOffset, 0x0A, &byBBRxConf);//CR10
2461
2462 if (pDevice->bShortSlotTime) {
2463 byBBRxConf &= 0xDF;//1101 1111
2464 } else {
2465 byBBRxConf |= 0x20;//0010 0000
2466 }
2467
2468 // patch for 3253B0 Baseband with Cardbus module
2469 BBbReadEmbeded(pDevice->PortOffset, 0xE7, &byBBVGA);
2470 if (byBBVGA == pDevice->abyBBVGA[0]) {
2471 byBBRxConf |= 0x20;//0010 0000
2472 }
2473
2474 BBbWriteEmbeded(pDevice->PortOffset, 0x0A, byBBRxConf);//CR10
2475
2476}
2477
2478VOID BBvSetVGAGainOffset(PSDevice pDevice, BYTE byData)
2479{
2480 BYTE byBBRxConf=0;
2481
2482 BBbWriteEmbeded(pDevice->PortOffset, 0xE7, byData);
2483
2484 BBbReadEmbeded(pDevice->PortOffset, 0x0A, &byBBRxConf);//CR10
2485 // patch for 3253B0 Baseband with Cardbus module
2486 if (byData == pDevice->abyBBVGA[0]) {
2487 byBBRxConf |= 0x20;//0010 0000
2488 } else if (pDevice->bShortSlotTime) {
2489 byBBRxConf &= 0xDF;//1101 1111
2490 } else {
2491 byBBRxConf |= 0x20;//0010 0000
2492 }
2493 pDevice->byBBVGACurrent = byData;
2494 BBbWriteEmbeded(pDevice->PortOffset, 0x0A, byBBRxConf);//CR10
2495}
2496
2497
2498/*
2499 * Description: Baseband SoftwareReset
2500 *
2501 * Parameters:
2502 * In:
2503 * dwIoBase - I/O base address
2504 * Out:
2505 * none
2506 *
2507 * Return Value: none
2508 *
2509 */
2510VOID
2511BBvSoftwareReset (DWORD_PTR dwIoBase)
2512{
2513 BBbWriteEmbeded(dwIoBase, 0x50, 0x40);
2514 BBbWriteEmbeded(dwIoBase, 0x50, 0);
2515 BBbWriteEmbeded(dwIoBase, 0x9C, 0x01);
2516 BBbWriteEmbeded(dwIoBase, 0x9C, 0);
2517}
2518
2519/*
2520 * Description: Baseband Power Save Mode ON
2521 *
2522 * Parameters:
2523 * In:
2524 * dwIoBase - I/O base address
2525 * Out:
2526 * none
2527 *
2528 * Return Value: none
2529 *
2530 */
2531VOID
2532BBvPowerSaveModeON (DWORD_PTR dwIoBase)
2533{
2534 BYTE byOrgData;
2535
2536 BBbReadEmbeded(dwIoBase, 0x0D, &byOrgData);
2537 byOrgData |= BIT0;
2538 BBbWriteEmbeded(dwIoBase, 0x0D, byOrgData);
2539}
2540
2541/*
2542 * Description: Baseband Power Save Mode OFF
2543 *
2544 * Parameters:
2545 * In:
2546 * dwIoBase - I/O base address
2547 * Out:
2548 * none
2549 *
2550 * Return Value: none
2551 *
2552 */
2553VOID
2554BBvPowerSaveModeOFF (DWORD_PTR dwIoBase)
2555{
2556 BYTE byOrgData;
2557
2558 BBbReadEmbeded(dwIoBase, 0x0D, &byOrgData);
2559 byOrgData &= ~(BIT0);
2560 BBbWriteEmbeded(dwIoBase, 0x0D, byOrgData);
2561}
2562
2563/*
2564 * Description: Set Tx Antenna mode
2565 *
2566 * Parameters:
2567 * In:
2568 * pDevice - Device Structure
2569 * byAntennaMode - Antenna Mode
2570 * Out:
2571 * none
2572 *
2573 * Return Value: none
2574 *
2575 */
2576
2577VOID
2578BBvSetTxAntennaMode (DWORD_PTR dwIoBase, BYTE byAntennaMode)
2579{
2580 BYTE byBBTxConf;
2581
2582#ifdef PLICE_DEBUG
2583 //printk("Enter BBvSetTxAntennaMode\n");
2584#endif
2585 BBbReadEmbeded(dwIoBase, 0x09, &byBBTxConf);//CR09
2586 if (byAntennaMode == ANT_DIVERSITY) {
2587 // bit 1 is diversity
2588 byBBTxConf |= 0x02;
2589 } else if (byAntennaMode == ANT_A) {
2590 // bit 2 is ANTSEL
2591 byBBTxConf &= 0xF9; // 1111 1001
2592 } else if (byAntennaMode == ANT_B) {
2593#ifdef PLICE_DEBUG
2594 //printk("BBvSetTxAntennaMode:ANT_B\n");
2595#endif
2596 byBBTxConf &= 0xFD; // 1111 1101
2597 byBBTxConf |= 0x04;
2598 }
2599 BBbWriteEmbeded(dwIoBase, 0x09, byBBTxConf);//CR09
2600}
2601
2602
2603
2604
2605/*
2606 * Description: Set Rx Antenna mode
2607 *
2608 * Parameters:
2609 * In:
2610 * pDevice - Device Structure
2611 * byAntennaMode - Antenna Mode
2612 * Out:
2613 * none
2614 *
2615 * Return Value: none
2616 *
2617 */
2618
2619VOID
2620BBvSetRxAntennaMode (DWORD_PTR dwIoBase, BYTE byAntennaMode)
2621{
2622 BYTE byBBRxConf;
2623
2624 BBbReadEmbeded(dwIoBase, 0x0A, &byBBRxConf);//CR10
2625 if (byAntennaMode == ANT_DIVERSITY) {
2626 byBBRxConf |= 0x01;
2627
2628 } else if (byAntennaMode == ANT_A) {
2629 byBBRxConf &= 0xFC; // 1111 1100
2630 } else if (byAntennaMode == ANT_B) {
2631 byBBRxConf &= 0xFE; // 1111 1110
2632 byBBRxConf |= 0x02;
2633 }
2634 BBbWriteEmbeded(dwIoBase, 0x0A, byBBRxConf);//CR10
2635}
2636
2637
2638/*
2639 * Description: BBvSetDeepSleep
2640 *
2641 * Parameters:
2642 * In:
2643 * pDevice - Device Structure
2644 * Out:
2645 * none
2646 *
2647 * Return Value: none
2648 *
2649 */
2650VOID
2651BBvSetDeepSleep (DWORD_PTR dwIoBase, BYTE byLocalID)
2652{
2653 BBbWriteEmbeded(dwIoBase, 0x0C, 0x17);//CR12
2654 BBbWriteEmbeded(dwIoBase, 0x0D, 0xB9);//CR13
2655}
2656
2657VOID
2658BBvExitDeepSleep (DWORD_PTR dwIoBase, BYTE byLocalID)
2659{
2660 BBbWriteEmbeded(dwIoBase, 0x0C, 0x00);//CR12
2661 BBbWriteEmbeded(dwIoBase, 0x0D, 0x01);//CR13
2662}
2663
2664
2665
2666static
2667ULONG
2668s_ulGetRatio (PSDevice pDevice)
2669{
2670ULONG ulRatio = 0;
2671ULONG ulMaxPacket;
2672ULONG ulPacketNum;
2673
2674 //This is a thousand-ratio
2675 ulMaxPacket = pDevice->uNumSQ3[RATE_54M];
2676 if ( pDevice->uNumSQ3[RATE_54M] != 0 ) {
2677 ulPacketNum = pDevice->uNumSQ3[RATE_54M];
2678 ulRatio = (ulPacketNum * 1000 / pDevice->uDiversityCnt);
2679 //ulRatio = (pDevice->uNumSQ3[RATE_54M] * 1000 / pDevice->uDiversityCnt);
2680 ulRatio += TOP_RATE_54M;
2681 }
2682 if ( pDevice->uNumSQ3[RATE_48M] > ulMaxPacket ) {
2683 ulPacketNum = pDevice->uNumSQ3[RATE_54M] + pDevice->uNumSQ3[RATE_48M];
2684 ulRatio = (ulPacketNum * 1000 / pDevice->uDiversityCnt);
2685 //ulRatio = (pDevice->uNumSQ3[RATE_48M] * 1000 / pDevice->uDiversityCnt);
2686 ulRatio += TOP_RATE_48M;
2687 ulMaxPacket = pDevice->uNumSQ3[RATE_48M];
2688 }
2689 if ( pDevice->uNumSQ3[RATE_36M] > ulMaxPacket ) {
2690 ulPacketNum = pDevice->uNumSQ3[RATE_54M] + pDevice->uNumSQ3[RATE_48M] +
2691 pDevice->uNumSQ3[RATE_36M];
2692 ulRatio = (ulPacketNum * 1000 / pDevice->uDiversityCnt);
2693 //ulRatio = (pDevice->uNumSQ3[RATE_36M] * 1000 / pDevice->uDiversityCnt);
2694 ulRatio += TOP_RATE_36M;
2695 ulMaxPacket = pDevice->uNumSQ3[RATE_36M];
2696 }
2697 if ( pDevice->uNumSQ3[RATE_24M] > ulMaxPacket ) {
2698 ulPacketNum = pDevice->uNumSQ3[RATE_54M] + pDevice->uNumSQ3[RATE_48M] +
2699 pDevice->uNumSQ3[RATE_36M] + pDevice->uNumSQ3[RATE_24M];
2700 ulRatio = (ulPacketNum * 1000 / pDevice->uDiversityCnt);
2701 //ulRatio = (pDevice->uNumSQ3[RATE_24M] * 1000 / pDevice->uDiversityCnt);
2702 ulRatio += TOP_RATE_24M;
2703 ulMaxPacket = pDevice->uNumSQ3[RATE_24M];
2704 }
2705 if ( pDevice->uNumSQ3[RATE_18M] > ulMaxPacket ) {
2706 ulPacketNum = pDevice->uNumSQ3[RATE_54M] + pDevice->uNumSQ3[RATE_48M] +
2707 pDevice->uNumSQ3[RATE_36M] + pDevice->uNumSQ3[RATE_24M] +
2708 pDevice->uNumSQ3[RATE_18M];
2709 ulRatio = (ulPacketNum * 1000 / pDevice->uDiversityCnt);
2710 //ulRatio = (pDevice->uNumSQ3[RATE_18M] * 1000 / pDevice->uDiversityCnt);
2711 ulRatio += TOP_RATE_18M;
2712 ulMaxPacket = pDevice->uNumSQ3[RATE_18M];
2713 }
2714 if ( pDevice->uNumSQ3[RATE_12M] > ulMaxPacket ) {
2715 ulPacketNum = pDevice->uNumSQ3[RATE_54M] + pDevice->uNumSQ3[RATE_48M] +
2716 pDevice->uNumSQ3[RATE_36M] + pDevice->uNumSQ3[RATE_24M] +
2717 pDevice->uNumSQ3[RATE_18M] + pDevice->uNumSQ3[RATE_12M];
2718 ulRatio = (ulPacketNum * 1000 / pDevice->uDiversityCnt);
2719 //ulRatio = (pDevice->uNumSQ3[RATE_12M] * 1000 / pDevice->uDiversityCnt);
2720 ulRatio += TOP_RATE_12M;
2721 ulMaxPacket = pDevice->uNumSQ3[RATE_12M];
2722 }
2723 if ( pDevice->uNumSQ3[RATE_11M] > ulMaxPacket ) {
2724 ulPacketNum = pDevice->uDiversityCnt - pDevice->uNumSQ3[RATE_1M] -
2725 pDevice->uNumSQ3[RATE_2M] - pDevice->uNumSQ3[RATE_5M] -
2726 pDevice->uNumSQ3[RATE_6M] - pDevice->uNumSQ3[RATE_9M];
2727 ulRatio = (ulPacketNum * 1000 / pDevice->uDiversityCnt);
2728 //ulRatio = (pDevice->uNumSQ3[RATE_11M] * 1000 / pDevice->uDiversityCnt);
2729 ulRatio += TOP_RATE_11M;
2730 ulMaxPacket = pDevice->uNumSQ3[RATE_11M];
2731 }
2732 if ( pDevice->uNumSQ3[RATE_9M] > ulMaxPacket ) {
2733 ulPacketNum = pDevice->uDiversityCnt - pDevice->uNumSQ3[RATE_1M] -
2734 pDevice->uNumSQ3[RATE_2M] - pDevice->uNumSQ3[RATE_5M] -
2735 pDevice->uNumSQ3[RATE_6M];
2736 ulRatio = (ulPacketNum * 1000 / pDevice->uDiversityCnt);
2737 //ulRatio = (pDevice->uNumSQ3[RATE_9M] * 1000 / pDevice->uDiversityCnt);
2738 ulRatio += TOP_RATE_9M;
2739 ulMaxPacket = pDevice->uNumSQ3[RATE_9M];
2740 }
2741 if ( pDevice->uNumSQ3[RATE_6M] > ulMaxPacket ) {
2742 ulPacketNum = pDevice->uDiversityCnt - pDevice->uNumSQ3[RATE_1M] -
2743 pDevice->uNumSQ3[RATE_2M] - pDevice->uNumSQ3[RATE_5M];
2744 ulRatio = (ulPacketNum * 1000 / pDevice->uDiversityCnt);
2745 //ulRatio = (pDevice->uNumSQ3[RATE_6M] * 1000 / pDevice->uDiversityCnt);
2746 ulRatio += TOP_RATE_6M;
2747 ulMaxPacket = pDevice->uNumSQ3[RATE_6M];
2748 }
2749 if ( pDevice->uNumSQ3[RATE_5M] > ulMaxPacket ) {
2750 ulPacketNum = pDevice->uDiversityCnt - pDevice->uNumSQ3[RATE_1M] -
2751 pDevice->uNumSQ3[RATE_2M];
2752 ulRatio = (ulPacketNum * 1000 / pDevice->uDiversityCnt);
2753 //ulRatio = (pDevice->uNumSQ3[RATE_5M] * 1000 / pDevice->uDiversityCnt);
2754 ulRatio += TOP_RATE_55M;
2755 ulMaxPacket = pDevice->uNumSQ3[RATE_5M];
2756 }
2757 if ( pDevice->uNumSQ3[RATE_2M] > ulMaxPacket ) {
2758 ulPacketNum = pDevice->uDiversityCnt - pDevice->uNumSQ3[RATE_1M];
2759 ulRatio = (ulPacketNum * 1000 / pDevice->uDiversityCnt);
2760 //ulRatio = (pDevice->uNumSQ3[RATE_2M] * 1000 / pDevice->uDiversityCnt);
2761 ulRatio += TOP_RATE_2M;
2762 ulMaxPacket = pDevice->uNumSQ3[RATE_2M];
2763 }
2764 if ( pDevice->uNumSQ3[RATE_1M] > ulMaxPacket ) {
2765 ulPacketNum = pDevice->uDiversityCnt;
2766 ulRatio = (ulPacketNum * 1000 / pDevice->uDiversityCnt);
2767 //ulRatio = (pDevice->uNumSQ3[RATE_1M] * 1000 / pDevice->uDiversityCnt);
2768 ulRatio += TOP_RATE_1M;
2769 }
2770
2771 return ulRatio;
2772}
2773
2774
2775VOID
2776BBvClearAntDivSQ3Value (PSDevice pDevice)
2777{
2778 UINT ii;
2779
2780 pDevice->uDiversityCnt = 0;
2781 for (ii = 0; ii < MAX_RATE; ii++) {
2782 pDevice->uNumSQ3[ii] = 0;
2783 }
2784}
2785
2786
2787/*
2788 * Description: Antenna Diversity
2789 *
2790 * Parameters:
2791 * In:
2792 * pDevice - Device Structure
2793 * byRSR - RSR from received packet
2794 * bySQ3 - SQ3 value from received packet
2795 * Out:
2796 * none
2797 *
2798 * Return Value: none
2799 *
2800 */
2801
2802VOID
2803BBvAntennaDiversity (PSDevice pDevice, BYTE byRxRate, BYTE bySQ3)
2804{
2805
2806 if ((byRxRate >= MAX_RATE) || (pDevice->wAntDiversityMaxRate >= MAX_RATE)) {
2807 return;
2808 }
2809 pDevice->uDiversityCnt++;
2810 // DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "pDevice->uDiversityCnt = %d\n", (int)pDevice->uDiversityCnt);
2811
2812 pDevice->uNumSQ3[byRxRate]++;
2813
2814 if (pDevice->byAntennaState == 0) {
2815
2816 if (pDevice->uDiversityCnt > pDevice->ulDiversityNValue) {
2817 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"ulDiversityNValue=[%d],54M-[%d]\n",
2818 (int)pDevice->ulDiversityNValue, (int)pDevice->uNumSQ3[(int)pDevice->wAntDiversityMaxRate]);
2819
2820 if (pDevice->uNumSQ3[pDevice->wAntDiversityMaxRate] < pDevice->uDiversityCnt/2) {
2821
2822 pDevice->ulRatio_State0 = s_ulGetRatio(pDevice);
2823 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"SQ3_State0, rate = [%08x]\n", (int)pDevice->ulRatio_State0);
2824
2825 if ( pDevice->byTMax == 0 )
2826 return;
2827 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"1.[%08x], uNumSQ3[%d]=%d, %d\n",
2828 (int)pDevice->ulRatio_State0, (int)pDevice->wAntDiversityMaxRate,
2829 (int)pDevice->uNumSQ3[(int)pDevice->wAntDiversityMaxRate], (int)pDevice->uDiversityCnt);
2830#ifdef PLICE_DEBUG
2831 //printk("BBvAntennaDiversity1:call s_vChangeAntenna\n");
2832#endif
2833 s_vChangeAntenna(pDevice);
2834 pDevice->byAntennaState = 1;
2835 del_timer(&pDevice->TimerSQ3Tmax3);
2836 del_timer(&pDevice->TimerSQ3Tmax2);
2837 pDevice->TimerSQ3Tmax1.expires = RUN_AT(pDevice->byTMax * HZ);
2838 add_timer(&pDevice->TimerSQ3Tmax1);
2839
2840 } else {
2841
2842 pDevice->TimerSQ3Tmax3.expires = RUN_AT(pDevice->byTMax3 * HZ);
2843 add_timer(&pDevice->TimerSQ3Tmax3);
2844 }
2845 BBvClearAntDivSQ3Value(pDevice);
2846
2847 }
2848 } else { //byAntennaState == 1
2849
2850 if (pDevice->uDiversityCnt > pDevice->ulDiversityMValue) {
2851
2852 del_timer(&pDevice->TimerSQ3Tmax1);
2853
2854 pDevice->ulRatio_State1 = s_ulGetRatio(pDevice);
2855 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"RX:SQ3_State1, rate0 = %08x,rate1 = %08x\n",
2856 (int)pDevice->ulRatio_State0,(int)pDevice->ulRatio_State1);
2857
2858 if (pDevice->ulRatio_State1 < pDevice->ulRatio_State0) {
2859 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"2.[%08x][%08x], uNumSQ3[%d]=%d, %d\n",
2860 (int)pDevice->ulRatio_State0, (int)pDevice->ulRatio_State1,
2861 (int)pDevice->wAntDiversityMaxRate,
2862 (int)pDevice->uNumSQ3[(int)pDevice->wAntDiversityMaxRate], (int)pDevice->uDiversityCnt);
2863#ifdef PLICE_DEBUG
2864 //printk("BBvAntennaDiversity2:call s_vChangeAntenna\n");
2865#endif
2866 s_vChangeAntenna(pDevice);
2867 pDevice->TimerSQ3Tmax3.expires = RUN_AT(pDevice->byTMax3 * HZ);
2868 pDevice->TimerSQ3Tmax2.expires = RUN_AT(pDevice->byTMax2 * HZ);
2869 add_timer(&pDevice->TimerSQ3Tmax3);
2870 add_timer(&pDevice->TimerSQ3Tmax2);
2871 }
2872 pDevice->byAntennaState = 0;
2873 BBvClearAntDivSQ3Value(pDevice);
2874 }
2875 } //byAntennaState
2876}
2877
2878/*+
2879 *
2880 * Description:
2881 * Timer for SQ3 antenna diversity
2882 *
2883 * Parameters:
2884 * In:
2885 * Out:
2886 * none
2887 *
2888 * Return Value: none
2889 *
2890-*/
2891
2892VOID
2893TimerSQ3CallBack (
2894 IN HANDLE hDeviceContext
2895 )
2896{
2897 PSDevice pDevice = (PSDevice)hDeviceContext;
2898
2899 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"TimerSQ3CallBack...");
2900
2901
2902 spin_lock_irq(&pDevice->lock);
2903
2904 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"3.[%08x][%08x], %d\n",(int)pDevice->ulRatio_State0, (int)pDevice->ulRatio_State1, (int)pDevice->uDiversityCnt);
2905#ifdef PLICE_DEBUG
2906 //printk("TimerSQ3CallBack1:call s_vChangeAntenna\n");
2907#endif
2908
2909 s_vChangeAntenna(pDevice);
2910 pDevice->byAntennaState = 0;
2911 BBvClearAntDivSQ3Value(pDevice);
2912
2913 pDevice->TimerSQ3Tmax3.expires = RUN_AT(pDevice->byTMax3 * HZ);
2914 pDevice->TimerSQ3Tmax2.expires = RUN_AT(pDevice->byTMax2 * HZ);
2915 add_timer(&pDevice->TimerSQ3Tmax3);
2916 add_timer(&pDevice->TimerSQ3Tmax2);
2917
2918 spin_unlock_irq(&pDevice->lock);
2919
2920 return;
2921}
2922
2923
2924/*+
2925 *
2926 * Description:
2927 * Timer for SQ3 antenna diversity
2928 *
2929 * Parameters:
2930 * In:
2931 * pvSysSpec1
2932 * hDeviceContext - Pointer to the adapter
2933 * pvSysSpec2
2934 * pvSysSpec3
2935 * Out:
2936 * none
2937 *
2938 * Return Value: none
2939 *
2940-*/
2941
2942VOID
2943TimerState1CallBack (
2944 IN HANDLE hDeviceContext
2945 )
2946{
2947 PSDevice pDevice = (PSDevice)hDeviceContext;
2948
2949 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"TimerState1CallBack...");
2950
2951 spin_lock_irq(&pDevice->lock);
2952 if (pDevice->uDiversityCnt < pDevice->ulDiversityMValue/100) {
2953#ifdef PLICE_DEBUG
2954 //printk("TimerSQ3CallBack2:call s_vChangeAntenna\n");
2955#endif
2956
2957 s_vChangeAntenna(pDevice);
2958 pDevice->TimerSQ3Tmax3.expires = RUN_AT(pDevice->byTMax3 * HZ);
2959 pDevice->TimerSQ3Tmax2.expires = RUN_AT(pDevice->byTMax2 * HZ);
2960 add_timer(&pDevice->TimerSQ3Tmax3);
2961 add_timer(&pDevice->TimerSQ3Tmax2);
2962 } else {
2963 pDevice->ulRatio_State1 = s_ulGetRatio(pDevice);
2964 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"SQ3_State1, rate0 = %08x,rate1 = %08x\n",
2965 (int)pDevice->ulRatio_State0,(int)pDevice->ulRatio_State1);
2966
2967 if ( pDevice->ulRatio_State1 < pDevice->ulRatio_State0 ) {
2968 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"2.[%08x][%08x], uNumSQ3[%d]=%d, %d\n",
2969 (int)pDevice->ulRatio_State0, (int)pDevice->ulRatio_State1,
2970 (int)pDevice->wAntDiversityMaxRate,
2971 (int)pDevice->uNumSQ3[(int)pDevice->wAntDiversityMaxRate], (int)pDevice->uDiversityCnt);
2972#ifdef PLICE_DEBUG
2973 //printk("TimerSQ3CallBack3:call s_vChangeAntenna\n");
2974#endif
2975
2976 s_vChangeAntenna(pDevice);
2977
2978 pDevice->TimerSQ3Tmax3.expires = RUN_AT(pDevice->byTMax3 * HZ);
2979 pDevice->TimerSQ3Tmax2.expires = RUN_AT(pDevice->byTMax2 * HZ);
2980 add_timer(&pDevice->TimerSQ3Tmax3);
2981 add_timer(&pDevice->TimerSQ3Tmax2);
2982 }
2983 }
2984 pDevice->byAntennaState = 0;
2985 BBvClearAntDivSQ3Value(pDevice);
2986 spin_unlock_irq(&pDevice->lock);
2987
2988 return;
2989}
2990
diff --git a/drivers/staging/vt6655/baseband.h b/drivers/staging/vt6655/baseband.h
new file mode 100644
index 000000000000..09cf4f961ac2
--- /dev/null
+++ b/drivers/staging/vt6655/baseband.h
@@ -0,0 +1,198 @@
1/*
2 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
3 * All rights reserved.
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * File: baseband.h
20 *
21 * Purpose: Implement functions to access baseband
22 *
23 * Author: Jerry Chen
24 *
25 * Date: Jun. 5, 2002
26 *
27 */
28
29
30#ifndef __BASEBAND_H__
31#define __BASEBAND_H__
32
33
34#if !defined(__TTYPE_H__)
35#include "ttype.h"
36#endif
37
38#if !defined(__TETHER_H__)
39#include "tether.h"
40#endif
41
42#if !defined(__DEVICE_H__)
43#include "device.h"
44#endif
45
46
47/*--------------------- Export Definitions -------------------------*/
48
49//
50// Registers in the BASEBAND
51//
52#define BB_MAX_CONTEXT_SIZE 256
53
54
55//
56// Baseband RF pair definition in eeprom (Bits 6..0)
57//
58
59/*
60#define RATE_1M 0
61#define RATE_2M 1
62#define RATE_5M 2
63#define RATE_11M 3
64#define RATE_6M 4
65#define RATE_9M 5
66#define RATE_12M 6
67#define RATE_18M 7
68#define RATE_24M 8
69#define RATE_36M 9
70#define RATE_48M 10
71#define RATE_54M 11
72#define RATE_AUTO 12
73#define MAX_RATE 12
74
75
76//0:11A 1:11B 2:11G
77#define BB_TYPE_11A 0
78#define BB_TYPE_11B 1
79#define BB_TYPE_11G 2
80
81//0:11a,1:11b,2:11gb(only CCK in BasicRate),3:11ga(OFDM in Basic Rate)
82#define PK_TYPE_11A 0
83#define PK_TYPE_11B 1
84#define PK_TYPE_11GB 2
85#define PK_TYPE_11GA 3
86*/
87
88
89#define PREAMBLE_LONG 0
90#define PREAMBLE_SHORT 1
91
92
93#define F5G 0
94#define F2_4G 1
95
96#define TOP_RATE_54M 0x80000000
97#define TOP_RATE_48M 0x40000000
98#define TOP_RATE_36M 0x20000000
99#define TOP_RATE_24M 0x10000000
100#define TOP_RATE_18M 0x08000000
101#define TOP_RATE_12M 0x04000000
102#define TOP_RATE_11M 0x02000000
103#define TOP_RATE_9M 0x01000000
104#define TOP_RATE_6M 0x00800000
105#define TOP_RATE_55M 0x00400000
106#define TOP_RATE_2M 0x00200000
107#define TOP_RATE_1M 0x00100000
108
109/*--------------------- Export Types ------------------------------*/
110
111/*--------------------- Export Macros ------------------------------*/
112
113
114
115#define BBvClearFOE(dwIoBase) \
116{ \
117 BBbWriteEmbeded(dwIoBase, 0xB1, 0); \
118}
119
120#define BBvSetFOE(dwIoBase) \
121{ \
122 BBbWriteEmbeded(dwIoBase, 0xB1, 0x0C); \
123}
124
125
126/*--------------------- Export Classes ----------------------------*/
127
128/*--------------------- Export Variables --------------------------*/
129
130/*--------------------- Export Functions --------------------------*/
131#ifdef __cplusplus
132extern "C" { /* Assume C declarations for C++ */
133#endif /* __cplusplus */
134
135UINT
136BBuGetFrameTime(
137 IN BYTE byPreambleType,
138 IN BYTE byPktType,
139 IN UINT cbFrameLength,
140 IN WORD wRate
141 );
142
143VOID
144BBvCaculateParameter (
145 IN PSDevice pDevice,
146 IN UINT cbFrameLength,
147 IN WORD wRate,
148 IN BYTE byPacketType,
149 OUT PWORD pwPhyLen,
150 OUT PBYTE pbyPhySrv,
151 OUT PBYTE pbyPhySgn
152 );
153
154BOOL BBbReadEmbeded(DWORD_PTR dwIoBase, BYTE byBBAddr, PBYTE pbyData);
155BOOL BBbWriteEmbeded(DWORD_PTR dwIoBase, BYTE byBBAddr, BYTE byData);
156
157VOID BBvReadAllRegs(DWORD_PTR dwIoBase, PBYTE pbyBBRegs);
158void BBvLoopbackOn(PSDevice pDevice);
159void BBvLoopbackOff(PSDevice pDevice);
160void BBvSetShortSlotTime(PSDevice pDevice);
161BOOL BBbIsRegBitsOn(DWORD_PTR dwIoBase, BYTE byBBAddr, BYTE byTestBits);
162BOOL BBbIsRegBitsOff(DWORD_PTR dwIoBase, BYTE byBBAddr, BYTE byTestBits);
163VOID BBvSetVGAGainOffset(PSDevice pDevice, BYTE byData);
164
165// VT3253 Baseband
166BOOL BBbVT3253Init(PSDevice pDevice);
167VOID BBvSoftwareReset(DWORD_PTR dwIoBase);
168VOID BBvPowerSaveModeON(DWORD_PTR dwIoBase);
169VOID BBvPowerSaveModeOFF(DWORD_PTR dwIoBase);
170VOID BBvSetTxAntennaMode(DWORD_PTR dwIoBase, BYTE byAntennaMode);
171VOID BBvSetRxAntennaMode(DWORD_PTR dwIoBase, BYTE byAntennaMode);
172VOID BBvSetDeepSleep(DWORD_PTR dwIoBase, BYTE byLocalID);
173VOID BBvExitDeepSleep(DWORD_PTR dwIoBase, BYTE byLocalID);
174
175// timer for antenna diversity
176VOID
177TimerSQ3CallBack(
178 IN HANDLE hDeviceContext
179 );
180VOID
181TimerState1CallBack(
182 IN HANDLE hDeviceContext
183 );
184
185void BBvAntennaDiversity(PSDevice pDevice, BYTE byRxRate, BYTE bySQ3);
186VOID
187BBvClearAntDivSQ3Value (PSDevice pDevice);
188
189
190#ifdef __cplusplus
191} /* End of extern "C" { */
192#endif /* __cplusplus */
193
194
195#endif // __BASEBAND_H__
196
197
198
diff --git a/drivers/staging/vt6655/bssdb.c b/drivers/staging/vt6655/bssdb.c
new file mode 100644
index 000000000000..4bac7b694452
--- /dev/null
+++ b/drivers/staging/vt6655/bssdb.c
@@ -0,0 +1,1791 @@
1/*
2 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
3 * All rights reserved.
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * File: bssdb.c
20 *
21 * Purpose: Handles the Basic Service Set & Node Database functions
22 *
23 * Functions:
24 * BSSpSearchBSSList - Search known BSS list for Desire SSID or BSSID
25 * BSSvClearBSSList - Clear BSS List
26 * BSSbInsertToBSSList - Insert a BSS set into known BSS list
27 * BSSbUpdateToBSSList - Update BSS set in known BSS list
28 * BSSDBbIsSTAInNodeDB - Search Node DB table to find the index of matched DstAddr
29 * BSSvCreateOneNode - Allocate an Node for Node DB
30 * BSSvUpdateAPNode - Update AP Node content in Index 0 of KnownNodeDB
31 * BSSvSecondCallBack - One second timer callback function to update Node DB info & AP link status
32 * BSSvUpdateNodeTxCounter - Update Tx attemps, Tx failure counter in Node DB for auto-fall back rate control
33 *
34 * Revision History:
35 *
36 * Author: Lyndon Chen
37 *
38 * Date: July 17, 2002
39 *
40 */
41
42
43#if !defined(__TBIT_H__)
44#include "tbit.h"
45#endif//chester
46#if !defined(__TTYPE_H__)
47#include "ttype.h"
48#endif
49#if !defined(__TMACRO_H__)
50#include "tmacro.h"
51#endif
52#if !defined(__TETHER_H__)
53#include "tether.h"
54#endif
55#if !defined(__DEVICE_H__)
56#include "device.h"
57#endif
58#if !defined(__80211HDR_H__)
59#include "80211hdr.h"
60#endif
61#if !defined(__BSSDB_H__)
62#include "bssdb.h"
63#endif
64#if !defined(__WMGR_H__)
65#include "wmgr.h"
66#endif
67#if !defined(__DATARATE_H__)
68#include "datarate.h"
69#endif
70#if !defined(__DESC_H__)
71#include "desc.h"
72#endif
73#if !defined(__WCMD_H__)
74#include "wcmd.h"
75#endif
76#if !defined(__WPA_H__)
77#include "wpa.h"
78#endif
79#if !defined(__BASEBAND_H__)
80#include "baseband.h"
81#endif
82#if !defined(__RF_H__)
83#include "rf.h"
84#endif
85#if !defined(__CARD_H__)
86#include "card.h"
87#endif
88#if !defined(__MAC_H__)
89#include "mac.h"
90#endif
91#if !defined(__WPA2_H__)
92#include "wpa2.h"
93#endif
94#if !defined(__UMEM_H__)
95#include "umem.h"
96#endif
97//DavidWang
98#if !defined(__IOWPA_H__)
99#include "iowpa.h"
100#endif
101
102//#define PLICE_DEBUG
103/*--------------------- Static Definitions -------------------------*/
104
105
106
107
108/*--------------------- Static Classes ----------------------------*/
109
110/*--------------------- Static Variables --------------------------*/
111static int msglevel =MSG_LEVEL_INFO;
112//static int msglevel =MSG_LEVEL_DEBUG;
113
114
115
116const WORD awHWRetry0[5][5] = {
117 {RATE_18M, RATE_18M, RATE_12M, RATE_12M, RATE_12M},
118 {RATE_24M, RATE_24M, RATE_18M, RATE_12M, RATE_12M},
119 {RATE_36M, RATE_36M, RATE_24M, RATE_18M, RATE_18M},
120 {RATE_48M, RATE_48M, RATE_36M, RATE_24M, RATE_24M},
121 {RATE_54M, RATE_54M, RATE_48M, RATE_36M, RATE_36M}
122 };
123const WORD awHWRetry1[5][5] = {
124 {RATE_18M, RATE_18M, RATE_12M, RATE_6M, RATE_6M},
125 {RATE_24M, RATE_24M, RATE_18M, RATE_6M, RATE_6M},
126 {RATE_36M, RATE_36M, RATE_24M, RATE_12M, RATE_12M},
127 {RATE_48M, RATE_48M, RATE_24M, RATE_12M, RATE_12M},
128 {RATE_54M, RATE_54M, RATE_36M, RATE_18M, RATE_18M}
129 };
130
131
132
133/*--------------------- Static Functions --------------------------*/
134
135VOID s_vCheckSensitivity(
136 IN HANDLE hDeviceContext
137 );
138
139#ifdef Calcu_LinkQual
140VOID s_uCalculateLinkQual(
141 IN HANDLE hDeviceContext
142 );
143#endif
144
145
146VOID s_vCheckPreEDThreshold(
147 IN HANDLE hDeviceContext
148 );
149/*--------------------- Export Variables --------------------------*/
150
151
152/*--------------------- Export Functions --------------------------*/
153
154
155
156
157
158/*+
159 *
160 * Routine Description:
161 * Search known BSS list for Desire SSID or BSSID.
162 *
163 * Return Value:
164 * PTR to KnownBSS or NULL
165 *
166-*/
167
168PKnownBSS
169BSSpSearchBSSList(
170 IN HANDLE hDeviceContext,
171 IN PBYTE pbyDesireBSSID,
172 IN PBYTE pbyDesireSSID,
173 IN CARD_PHY_TYPE ePhyType
174 )
175{
176 PSDevice pDevice = (PSDevice)hDeviceContext;
177 PSMgmtObject pMgmt = pDevice->pMgmt;
178 PBYTE pbyBSSID = NULL;
179 PWLAN_IE_SSID pSSID = NULL;
180 PKnownBSS pCurrBSS = NULL;
181 PKnownBSS pSelect = NULL;
182BYTE ZeroBSSID[WLAN_BSSID_LEN]={0x00,0x00,0x00,0x00,0x00,0x00};
183 UINT ii = 0;
184// UINT jj = 0; //DavidWang
185 if (pbyDesireBSSID != NULL) {
186 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"BSSpSearchBSSList BSSID[%02X %02X %02X-%02X %02X %02X]\n",
187 *pbyDesireBSSID,*(pbyDesireBSSID+1),*(pbyDesireBSSID+2),
188 *(pbyDesireBSSID+3),*(pbyDesireBSSID+4),*(pbyDesireBSSID+5));
189 if ((!IS_BROADCAST_ADDRESS(pbyDesireBSSID)) &&
190 (memcmp(pbyDesireBSSID, ZeroBSSID, 6)!= 0)) {
191 pbyBSSID = pbyDesireBSSID;
192 }
193 }
194 if (pbyDesireSSID != NULL) {
195 if (((PWLAN_IE_SSID)pbyDesireSSID)->len != 0) {
196 pSSID = (PWLAN_IE_SSID) pbyDesireSSID;
197 }
198 }
199
200 if (pbyBSSID != NULL) {
201 // match BSSID first
202 for (ii = 0; ii <MAX_BSS_NUM; ii++) {
203 pCurrBSS = &(pMgmt->sBSSList[ii]);
204if(pDevice->bLinkPass==FALSE) pCurrBSS->bSelected = FALSE;
205 if ((pCurrBSS->bActive) &&
206 (pCurrBSS->bSelected == FALSE)) {
207 if (IS_ETH_ADDRESS_EQUAL(pCurrBSS->abyBSSID, pbyBSSID)) {
208 if (pSSID != NULL) {
209 // compare ssid
210 if (MEMEqualMemory(pSSID->abySSID,
211 ((PWLAN_IE_SSID)pCurrBSS->abySSID)->abySSID,
212 pSSID->len)) {
213 if ((pMgmt->eConfigMode == WMAC_CONFIG_AUTO) ||
214 ((pMgmt->eConfigMode == WMAC_CONFIG_IBSS_STA) && WLAN_GET_CAP_INFO_IBSS(pCurrBSS->wCapInfo)) ||
215 ((pMgmt->eConfigMode == WMAC_CONFIG_ESS_STA) && WLAN_GET_CAP_INFO_ESS(pCurrBSS->wCapInfo))
216 ) {
217 pCurrBSS->bSelected = TRUE;
218 return(pCurrBSS);
219 }
220 }
221 } else {
222 if ((pMgmt->eConfigMode == WMAC_CONFIG_AUTO) ||
223 ((pMgmt->eConfigMode == WMAC_CONFIG_IBSS_STA) && WLAN_GET_CAP_INFO_IBSS(pCurrBSS->wCapInfo)) ||
224 ((pMgmt->eConfigMode == WMAC_CONFIG_ESS_STA) && WLAN_GET_CAP_INFO_ESS(pCurrBSS->wCapInfo))
225 ) {
226 pCurrBSS->bSelected = TRUE;
227 return(pCurrBSS);
228 }
229 }
230 }
231 }
232 }
233 } else {
234 // ignore BSSID
235 for (ii = 0; ii <MAX_BSS_NUM; ii++) {
236 pCurrBSS = &(pMgmt->sBSSList[ii]);
237 //2007-0721-01<Add>by MikeLiu
238 pCurrBSS->bSelected = FALSE;
239 if (pCurrBSS->bActive) {
240
241 if (pSSID != NULL) {
242 // matched SSID
243 if (!MEMEqualMemory(pSSID->abySSID,
244 ((PWLAN_IE_SSID)pCurrBSS->abySSID)->abySSID,
245 pSSID->len) ||
246 (pSSID->len != ((PWLAN_IE_SSID)pCurrBSS->abySSID)->len)) {
247 // SSID not match skip this BSS
248 continue;
249 }
250 }
251 if (((pMgmt->eConfigMode == WMAC_CONFIG_IBSS_STA) && WLAN_GET_CAP_INFO_ESS(pCurrBSS->wCapInfo)) ||
252 ((pMgmt->eConfigMode == WMAC_CONFIG_ESS_STA) && WLAN_GET_CAP_INFO_IBSS(pCurrBSS->wCapInfo))
253 ) {
254 // Type not match skip this BSS
255 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"BSS type mismatch.... Config[%d] BSS[0x%04x]\n", pMgmt->eConfigMode, pCurrBSS->wCapInfo);
256 continue;
257 }
258
259 if (ePhyType != PHY_TYPE_AUTO) {
260 if (((ePhyType == PHY_TYPE_11A) && (PHY_TYPE_11A != pCurrBSS->eNetworkTypeInUse)) ||
261 ((ePhyType != PHY_TYPE_11A) && (PHY_TYPE_11A == pCurrBSS->eNetworkTypeInUse))) {
262 // PhyType not match skip this BSS
263 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Physical type mismatch.... ePhyType[%d] BSS[%d]\n", ePhyType, pCurrBSS->eNetworkTypeInUse);
264 continue;
265 }
266 }
267/*
268 if (pMgmt->eAuthenMode < WMAC_AUTH_WPA) {
269 if (pCurrBSS->bWPAValid == TRUE) {
270 // WPA AP will reject connection of station without WPA enable.
271 continue;
272 }
273 } else if ((pMgmt->eAuthenMode == WMAC_AUTH_WPA) ||
274 (pMgmt->eAuthenMode == WMAC_AUTH_WPAPSK)) {
275 if (pCurrBSS->bWPAValid == FALSE) {
276 // station with WPA enable can't join NonWPA AP.
277 continue;
278 }
279 } else if ((pMgmt->eAuthenMode == WMAC_AUTH_WPA2) ||
280 (pMgmt->eAuthenMode == WMAC_AUTH_WPA2PSK)) {
281 if (pCurrBSS->bWPA2Valid == FALSE) {
282 // station with WPA2 enable can't join NonWPA2 AP.
283 continue;
284 }
285 }
286*/
287 if (pSelect == NULL) {
288 pSelect = pCurrBSS;
289 } else {
290 // compare RSSI, select signal strong one
291 if (pCurrBSS->uRSSI < pSelect->uRSSI) {
292 pSelect = pCurrBSS;
293 }
294 }
295 }
296 }
297 if (pSelect != NULL) {
298 pSelect->bSelected = TRUE;
299/*
300 if (pDevice->bRoaming == FALSE) {
301 // Einsn Add @20070907
302 ZERO_MEMORY(pbyDesireSSID, WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1);
303 MEMvCopy(pbyDesireSSID,pCurrBSS->abySSID,WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1) ;
304 }*/
305
306 return(pSelect);
307 }
308 }
309 return(NULL);
310
311}
312
313
314/*+
315 *
316 * Routine Description:
317 * Clear BSS List
318 *
319 * Return Value:
320 * None.
321 *
322-*/
323
324
325VOID
326BSSvClearBSSList(
327 IN HANDLE hDeviceContext,
328 IN BOOL bKeepCurrBSSID
329 )
330{
331 PSDevice pDevice = (PSDevice)hDeviceContext;
332 PSMgmtObject pMgmt = pDevice->pMgmt;
333 UINT ii;
334
335 for (ii = 0; ii < MAX_BSS_NUM; ii++) {
336 if (bKeepCurrBSSID) {
337 if (pMgmt->sBSSList[ii].bActive &&
338 IS_ETH_ADDRESS_EQUAL(pMgmt->sBSSList[ii].abyBSSID, pMgmt->abyCurrBSSID)) {
339 // bKeepCurrBSSID = FALSE;
340 continue;
341 }
342 }
343
344 if ((pMgmt->sBSSList[ii].bActive) && (pMgmt->sBSSList[ii].uClearCount < BSS_CLEAR_COUNT)) {
345 pMgmt->sBSSList[ii].uClearCount ++;
346 continue;
347 }
348
349 pMgmt->sBSSList[ii].bActive = FALSE;
350 memset(&pMgmt->sBSSList[ii], 0, sizeof(KnownBSS));
351 }
352 BSSvClearAnyBSSJoinRecord(pDevice);
353
354 return;
355}
356
357
358
359/*+
360 *
361 * Routine Description:
362 * search BSS list by BSSID & SSID if matched
363 *
364 * Return Value:
365 * TRUE if found.
366 *
367-*/
368PKnownBSS
369BSSpAddrIsInBSSList(
370 IN HANDLE hDeviceContext,
371 IN PBYTE abyBSSID,
372 IN PWLAN_IE_SSID pSSID
373 )
374{
375 PSDevice pDevice = (PSDevice)hDeviceContext;
376 PSMgmtObject pMgmt = pDevice->pMgmt;
377 PKnownBSS pBSSList = NULL;
378 UINT ii;
379
380 for (ii = 0; ii < MAX_BSS_NUM; ii++) {
381 pBSSList = &(pMgmt->sBSSList[ii]);
382 if (pBSSList->bActive) {
383 if (IS_ETH_ADDRESS_EQUAL(pBSSList->abyBSSID, abyBSSID)) {
384// if (pSSID == NULL)
385// return pBSSList;
386 if (pSSID->len == ((PWLAN_IE_SSID)pBSSList->abySSID)->len){
387 if (memcmp(pSSID->abySSID,
388 ((PWLAN_IE_SSID)pBSSList->abySSID)->abySSID,
389 pSSID->len) == 0)
390 return pBSSList;
391 }
392 }
393 }
394 }
395
396 return NULL;
397};
398
399
400
401
402/*+
403 *
404 * Routine Description:
405 * Insert a BSS set into known BSS list
406 *
407 * Return Value:
408 * TRUE if success.
409 *
410-*/
411
412BOOL
413BSSbInsertToBSSList (
414 IN HANDLE hDeviceContext,
415 IN PBYTE abyBSSIDAddr,
416 IN QWORD qwTimestamp,
417 IN WORD wBeaconInterval,
418 IN WORD wCapInfo,
419 IN BYTE byCurrChannel,
420 IN PWLAN_IE_SSID pSSID,
421 IN PWLAN_IE_SUPP_RATES pSuppRates,
422 IN PWLAN_IE_SUPP_RATES pExtSuppRates,
423 IN PERPObject psERP,
424 IN PWLAN_IE_RSN pRSN,
425 IN PWLAN_IE_RSN_EXT pRSNWPA,
426 IN PWLAN_IE_COUNTRY pIE_Country,
427 IN PWLAN_IE_QUIET pIE_Quiet,
428 IN UINT uIELength,
429 IN PBYTE pbyIEs,
430 IN HANDLE pRxPacketContext
431 )
432{
433
434 PSDevice pDevice = (PSDevice)hDeviceContext;
435 PSMgmtObject pMgmt = pDevice->pMgmt;
436 PSRxMgmtPacket pRxPacket = (PSRxMgmtPacket)pRxPacketContext;
437 PKnownBSS pBSSList = NULL;
438 UINT ii;
439 BOOL bParsingQuiet = FALSE;
440 PWLAN_IE_QUIET pQuiet = NULL;
441
442
443
444 pBSSList = (PKnownBSS)&(pMgmt->sBSSList[0]);
445
446 for (ii = 0; ii < MAX_BSS_NUM; ii++) {
447 pBSSList = (PKnownBSS)&(pMgmt->sBSSList[ii]);
448 if (!pBSSList->bActive)
449 break;
450 }
451
452 if (ii == MAX_BSS_NUM){
453 DEVICE_PRT(MSG_LEVEL_NOTICE, KERN_INFO "Get free KnowBSS node failed.\n");
454 return FALSE;
455 }
456 // save the BSS info
457 pBSSList->bActive = TRUE;
458 memcpy( pBSSList->abyBSSID, abyBSSIDAddr, WLAN_BSSID_LEN);
459 HIDWORD(pBSSList->qwBSSTimestamp) = cpu_to_le32(HIDWORD(qwTimestamp));
460 LODWORD(pBSSList->qwBSSTimestamp) = cpu_to_le32(LODWORD(qwTimestamp));
461 pBSSList->wBeaconInterval = cpu_to_le16(wBeaconInterval);
462 pBSSList->wCapInfo = cpu_to_le16(wCapInfo);
463 pBSSList->uClearCount = 0;
464
465 if (pSSID->len > WLAN_SSID_MAXLEN)
466 pSSID->len = WLAN_SSID_MAXLEN;
467 memcpy( pBSSList->abySSID, pSSID, pSSID->len + WLAN_IEHDR_LEN);
468
469 pBSSList->uChannel = byCurrChannel;
470
471 if (pSuppRates->len > WLAN_RATES_MAXLEN)
472 pSuppRates->len = WLAN_RATES_MAXLEN;
473 memcpy( pBSSList->abySuppRates, pSuppRates, pSuppRates->len + WLAN_IEHDR_LEN);
474
475 if (pExtSuppRates != NULL) {
476 if (pExtSuppRates->len > WLAN_RATES_MAXLEN)
477 pExtSuppRates->len = WLAN_RATES_MAXLEN;
478 memcpy(pBSSList->abyExtSuppRates, pExtSuppRates, pExtSuppRates->len + WLAN_IEHDR_LEN);
479 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"BSSbInsertToBSSList: pExtSuppRates->len = %d\n", pExtSuppRates->len);
480
481 } else {
482 memset(pBSSList->abyExtSuppRates, 0, WLAN_IEHDR_LEN + WLAN_RATES_MAXLEN + 1);
483 }
484 pBSSList->sERP.byERP = psERP->byERP;
485 pBSSList->sERP.bERPExist = psERP->bERPExist;
486
487 // Check if BSS is 802.11a/b/g
488 if (pBSSList->uChannel > CB_MAX_CHANNEL_24G) {
489 pBSSList->eNetworkTypeInUse = PHY_TYPE_11A;
490 } else {
491 if (pBSSList->sERP.bERPExist == TRUE) {
492 pBSSList->eNetworkTypeInUse = PHY_TYPE_11G;
493 } else {
494 pBSSList->eNetworkTypeInUse = PHY_TYPE_11B;
495 }
496 }
497
498 pBSSList->byRxRate = pRxPacket->byRxRate;
499 pBSSList->qwLocalTSF = pRxPacket->qwLocalTSF;
500 pBSSList->uRSSI = pRxPacket->uRSSI;
501 pBSSList->bySQ = pRxPacket->bySQ;
502
503 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_STA) &&
504 (pMgmt->eCurrState == WMAC_STATE_ASSOC)) {
505 // assoc with BSS
506 if (pBSSList == pMgmt->pCurrBSS) {
507 bParsingQuiet = TRUE;
508 }
509 }
510
511 WPA_ClearRSN(pBSSList);
512
513 if (pRSNWPA != NULL) {
514 UINT uLen = pRSNWPA->len + 2;
515
516 if (uLen <= (uIELength - (UINT)(ULONG_PTR)((PBYTE)pRSNWPA - pbyIEs))) {
517 pBSSList->wWPALen = uLen;
518 memcpy(pBSSList->byWPAIE, pRSNWPA, uLen);
519 WPA_ParseRSN(pBSSList, pRSNWPA);
520 }
521 }
522
523 WPA2_ClearRSN(pBSSList);
524
525 if (pRSN != NULL) {
526 UINT uLen = pRSN->len + 2;
527 if (uLen <= (uIELength - (UINT)(ULONG_PTR)((PBYTE)pRSN - pbyIEs))) {
528 pBSSList->wRSNLen = uLen;
529 memcpy(pBSSList->byRSNIE, pRSN, uLen);
530 WPA2vParseRSN(pBSSList, pRSN);
531 }
532 }
533
534 if ((pMgmt->eAuthenMode == WMAC_AUTH_WPA2) || (pBSSList->bWPA2Valid == TRUE)) {
535
536 PSKeyItem pTransmitKey = NULL;
537 BOOL bIs802_1x = FALSE;
538
539 for (ii = 0; ii < pBSSList->wAKMSSAuthCount; ii ++) {
540 if (pBSSList->abyAKMSSAuthType[ii] == WLAN_11i_AKMSS_802_1X) {
541 bIs802_1x = TRUE;
542 break;
543 }
544 }
545 if ((bIs802_1x == TRUE) && (pSSID->len == ((PWLAN_IE_SSID)pMgmt->abyDesireSSID)->len) &&
546 (MEMEqualMemory(pSSID->abySSID, ((PWLAN_IE_SSID)pMgmt->abyDesireSSID)->abySSID, pSSID->len))) {
547
548 bAdd_PMKID_Candidate((HANDLE)pDevice, pBSSList->abyBSSID, &pBSSList->sRSNCapObj);
549
550 if ((pDevice->bLinkPass == TRUE) && (pMgmt->eCurrState == WMAC_STATE_ASSOC)) {
551 if ((KeybGetTransmitKey(&(pDevice->sKey), pDevice->abyBSSID, PAIRWISE_KEY, &pTransmitKey) == TRUE) ||
552 (KeybGetTransmitKey(&(pDevice->sKey), pDevice->abyBSSID, GROUP_KEY, &pTransmitKey) == TRUE)) {
553 pDevice->gsPMKIDCandidate.StatusType = Ndis802_11StatusType_PMKID_CandidateList;
554 pDevice->gsPMKIDCandidate.Version = 1;
555
556 }
557
558 }
559 }
560 }
561
562 if (pDevice->bUpdateBBVGA) {
563 // Moniter if RSSI is too strong.
564 pBSSList->byRSSIStatCnt = 0;
565 RFvRSSITodBm(pDevice, (BYTE)(pRxPacket->uRSSI), &pBSSList->ldBmMAX);
566 pBSSList->ldBmAverage[0] = pBSSList->ldBmMAX;
567 for (ii = 1; ii < RSSI_STAT_COUNT; ii++)
568 pBSSList->ldBmAverage[ii] = 0;
569 }
570
571 if ((pIE_Country != NULL) &&
572 (pMgmt->b11hEnable == TRUE)) {
573 CARDvSetCountryInfo(pMgmt->pAdapter,
574 pBSSList->eNetworkTypeInUse,
575 pIE_Country);
576 }
577
578
579
580 if ((bParsingQuiet == TRUE) && (pIE_Quiet != NULL)) {
581 if ((((PWLAN_IE_QUIET)pIE_Quiet)->len == 8) &&
582 (((PWLAN_IE_QUIET)pIE_Quiet)->byQuietCount != 0)) {
583 // valid EID
584 if (pQuiet == NULL) {
585 pQuiet = (PWLAN_IE_QUIET)pIE_Quiet;
586 CARDbSetQuiet( pMgmt->pAdapter,
587 TRUE,
588 pQuiet->byQuietCount,
589 pQuiet->byQuietPeriod,
590 *((PWORD)pQuiet->abyQuietDuration),
591 *((PWORD)pQuiet->abyQuietOffset)
592 );
593 } else {
594 pQuiet = (PWLAN_IE_QUIET)pIE_Quiet;
595 CARDbSetQuiet( pMgmt->pAdapter,
596 FALSE,
597 pQuiet->byQuietCount,
598 pQuiet->byQuietPeriod,
599 *((PWORD)pQuiet->abyQuietDuration),
600 *((PWORD)pQuiet->abyQuietOffset)
601 );
602 }
603 }
604 }
605
606 if ((bParsingQuiet == TRUE) &&
607 (pQuiet != NULL)) {
608 CARDbStartQuiet(pMgmt->pAdapter);
609 }
610
611 pBSSList->uIELength = uIELength;
612 if (pBSSList->uIELength > WLAN_BEACON_FR_MAXLEN)
613 pBSSList->uIELength = WLAN_BEACON_FR_MAXLEN;
614 MEMvCopy(pBSSList->abyIEs, pbyIEs, pBSSList->uIELength);
615
616 return TRUE;
617}
618
619
620/*+
621 *
622 * Routine Description:
623 * Update BSS set in known BSS list
624 *
625 * Return Value:
626 * TRUE if success.
627 *
628-*/
629// TODO: input structure modify
630
631BOOL
632BSSbUpdateToBSSList (
633 IN HANDLE hDeviceContext,
634 IN QWORD qwTimestamp,
635 IN WORD wBeaconInterval,
636 IN WORD wCapInfo,
637 IN BYTE byCurrChannel,
638 IN BOOL bChannelHit,
639 IN PWLAN_IE_SSID pSSID,
640 IN PWLAN_IE_SUPP_RATES pSuppRates,
641 IN PWLAN_IE_SUPP_RATES pExtSuppRates,
642 IN PERPObject psERP,
643 IN PWLAN_IE_RSN pRSN,
644 IN PWLAN_IE_RSN_EXT pRSNWPA,
645 IN PWLAN_IE_COUNTRY pIE_Country,
646 IN PWLAN_IE_QUIET pIE_Quiet,
647 IN PKnownBSS pBSSList,
648 IN UINT uIELength,
649 IN PBYTE pbyIEs,
650 IN HANDLE pRxPacketContext
651 )
652{
653 int ii;
654 PSDevice pDevice = (PSDevice)hDeviceContext;
655 PSMgmtObject pMgmt = pDevice->pMgmt;
656 PSRxMgmtPacket pRxPacket = (PSRxMgmtPacket)pRxPacketContext;
657 LONG ldBm;
658 BOOL bParsingQuiet = FALSE;
659 PWLAN_IE_QUIET pQuiet = NULL;
660
661
662
663 if (pBSSList == NULL)
664 return FALSE;
665
666 HIDWORD(pBSSList->qwBSSTimestamp) = cpu_to_le32(HIDWORD(qwTimestamp));
667 LODWORD(pBSSList->qwBSSTimestamp) = cpu_to_le32(LODWORD(qwTimestamp));
668 pBSSList->wBeaconInterval = cpu_to_le16(wBeaconInterval);
669 pBSSList->wCapInfo = cpu_to_le16(wCapInfo);
670 pBSSList->uClearCount = 0;
671 pBSSList->uChannel = byCurrChannel;
672// DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"BSSbUpdateToBSSList: pBSSList->uChannel: %d\n", pBSSList->uChannel);
673
674 if (pSSID->len > WLAN_SSID_MAXLEN)
675 pSSID->len = WLAN_SSID_MAXLEN;
676
677 if ((pSSID->len != 0) && (pSSID->abySSID[0] != 0))
678 memcpy(pBSSList->abySSID, pSSID, pSSID->len + WLAN_IEHDR_LEN);
679 memcpy(pBSSList->abySuppRates, pSuppRates,pSuppRates->len + WLAN_IEHDR_LEN);
680
681 if (pExtSuppRates != NULL) {
682 memcpy(pBSSList->abyExtSuppRates, pExtSuppRates,pExtSuppRates->len + WLAN_IEHDR_LEN);
683 } else {
684 memset(pBSSList->abyExtSuppRates, 0, WLAN_IEHDR_LEN + WLAN_RATES_MAXLEN + 1);
685 }
686 pBSSList->sERP.byERP = psERP->byERP;
687 pBSSList->sERP.bERPExist = psERP->bERPExist;
688
689 // Check if BSS is 802.11a/b/g
690 if (pBSSList->uChannel > CB_MAX_CHANNEL_24G) {
691 pBSSList->eNetworkTypeInUse = PHY_TYPE_11A;
692 } else {
693 if (pBSSList->sERP.bERPExist == TRUE) {
694 pBSSList->eNetworkTypeInUse = PHY_TYPE_11G;
695 } else {
696 pBSSList->eNetworkTypeInUse = PHY_TYPE_11B;
697 }
698 }
699
700 pBSSList->byRxRate = pRxPacket->byRxRate;
701 pBSSList->qwLocalTSF = pRxPacket->qwLocalTSF;
702 if(bChannelHit)
703 pBSSList->uRSSI = pRxPacket->uRSSI;
704 pBSSList->bySQ = pRxPacket->bySQ;
705
706 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_STA) &&
707 (pMgmt->eCurrState == WMAC_STATE_ASSOC)) {
708 // assoc with BSS
709 if (pBSSList == pMgmt->pCurrBSS) {
710 bParsingQuiet = TRUE;
711 }
712 }
713
714 WPA_ClearRSN(pBSSList); //mike update
715
716 if (pRSNWPA != NULL) {
717 UINT uLen = pRSNWPA->len + 2;
718 if (uLen <= (uIELength - (UINT)(ULONG_PTR)((PBYTE)pRSNWPA - pbyIEs))) {
719 pBSSList->wWPALen = uLen;
720 memcpy(pBSSList->byWPAIE, pRSNWPA, uLen);
721 WPA_ParseRSN(pBSSList, pRSNWPA);
722 }
723 }
724
725 WPA2_ClearRSN(pBSSList); //mike update
726
727 if (pRSN != NULL) {
728 UINT uLen = pRSN->len + 2;
729 if (uLen <= (uIELength - (UINT)(ULONG_PTR)((PBYTE)pRSN - pbyIEs))) {
730 pBSSList->wRSNLen = uLen;
731 memcpy(pBSSList->byRSNIE, pRSN, uLen);
732 WPA2vParseRSN(pBSSList, pRSN);
733 }
734 }
735
736 if (pRxPacket->uRSSI != 0) {
737 RFvRSSITodBm(pDevice, (BYTE)(pRxPacket->uRSSI), &ldBm);
738 // Moniter if RSSI is too strong.
739 pBSSList->byRSSIStatCnt++;
740 pBSSList->byRSSIStatCnt %= RSSI_STAT_COUNT;
741 pBSSList->ldBmAverage[pBSSList->byRSSIStatCnt] = ldBm;
742 for(ii=0;ii<RSSI_STAT_COUNT;ii++) {
743 if (pBSSList->ldBmAverage[ii] != 0) {
744 pBSSList->ldBmMAX = max(pBSSList->ldBmAverage[ii], ldBm);
745 }
746 }
747 }
748
749 if ((pIE_Country != NULL) &&
750 (pMgmt->b11hEnable == TRUE)) {
751 CARDvSetCountryInfo(pMgmt->pAdapter,
752 pBSSList->eNetworkTypeInUse,
753 pIE_Country);
754 }
755
756 if ((bParsingQuiet == TRUE) && (pIE_Quiet != NULL)) {
757 if ((((PWLAN_IE_QUIET)pIE_Quiet)->len == 8) &&
758 (((PWLAN_IE_QUIET)pIE_Quiet)->byQuietCount != 0)) {
759 // valid EID
760 if (pQuiet == NULL) {
761 pQuiet = (PWLAN_IE_QUIET)pIE_Quiet;
762 CARDbSetQuiet( pMgmt->pAdapter,
763 TRUE,
764 pQuiet->byQuietCount,
765 pQuiet->byQuietPeriod,
766 *((PWORD)pQuiet->abyQuietDuration),
767 *((PWORD)pQuiet->abyQuietOffset)
768 );
769 } else {
770 pQuiet = (PWLAN_IE_QUIET)pIE_Quiet;
771 CARDbSetQuiet( pMgmt->pAdapter,
772 FALSE,
773 pQuiet->byQuietCount,
774 pQuiet->byQuietPeriod,
775 *((PWORD)pQuiet->abyQuietDuration),
776 *((PWORD)pQuiet->abyQuietOffset)
777 );
778 }
779 }
780 }
781
782 if ((bParsingQuiet == TRUE) &&
783 (pQuiet != NULL)) {
784 CARDbStartQuiet(pMgmt->pAdapter);
785 }
786
787 pBSSList->uIELength = uIELength;
788 if (pBSSList->uIELength > WLAN_BEACON_FR_MAXLEN)
789 pBSSList->uIELength = WLAN_BEACON_FR_MAXLEN;
790 memcpy(pBSSList->abyIEs, pbyIEs, pBSSList->uIELength);
791
792 return TRUE;
793}
794
795
796
797
798
799/*+
800 *
801 * Routine Description:
802 * Search Node DB table to find the index of matched DstAddr
803 *
804 * Return Value:
805 * None
806 *
807-*/
808
809BOOL
810BSSDBbIsSTAInNodeDB(
811 IN PVOID pMgmtObject,
812 IN PBYTE abyDstAddr,
813 OUT PUINT puNodeIndex
814 )
815{
816 PSMgmtObject pMgmt = (PSMgmtObject) pMgmtObject;
817 UINT ii;
818
819 // Index = 0 reserved for AP Node
820 for (ii = 1; ii < (MAX_NODE_NUM + 1); ii++) {
821 if (pMgmt->sNodeDBTable[ii].bActive) {
822 if (IS_ETH_ADDRESS_EQUAL(abyDstAddr, pMgmt->sNodeDBTable[ii].abyMACAddr)) {
823 *puNodeIndex = ii;
824 return TRUE;
825 }
826 }
827 }
828
829 return FALSE;
830};
831
832
833
834/*+
835 *
836 * Routine Description:
837 * Find an empty node and allocated; if no empty found,
838 * instand used of most inactive one.
839 *
840 * Return Value:
841 * None
842 *
843-*/
844VOID
845BSSvCreateOneNode(
846 IN HANDLE hDeviceContext,
847 OUT PUINT puNodeIndex
848 )
849{
850
851 PSDevice pDevice = (PSDevice)hDeviceContext;
852 PSMgmtObject pMgmt = pDevice->pMgmt;
853 UINT ii;
854 UINT BigestCount = 0;
855 UINT SelectIndex;
856 struct sk_buff *skb;
857 // Index = 0 reserved for AP Node (In STA mode)
858 // Index = 0 reserved for Broadcast/MultiCast (In AP mode)
859 SelectIndex = 1;
860 for (ii = 1; ii < (MAX_NODE_NUM + 1); ii++) {
861 if (pMgmt->sNodeDBTable[ii].bActive) {
862 if (pMgmt->sNodeDBTable[ii].uInActiveCount > BigestCount) {
863 BigestCount = pMgmt->sNodeDBTable[ii].uInActiveCount;
864 SelectIndex = ii;
865 }
866 }
867 else {
868 break;
869 }
870 }
871
872 // if not found replace uInActiveCount is largest one.
873 if ( ii == (MAX_NODE_NUM + 1)) {
874 *puNodeIndex = SelectIndex;
875 DEVICE_PRT(MSG_LEVEL_NOTICE, KERN_INFO "Replace inactive node = %d\n", SelectIndex);
876 // clear ps buffer
877 if (pMgmt->sNodeDBTable[*puNodeIndex].sTxPSQueue.next != NULL) {
878 while ((skb = skb_dequeue(&pMgmt->sNodeDBTable[*puNodeIndex].sTxPSQueue)) != NULL)
879 dev_kfree_skb(skb);
880 }
881 }
882 else {
883 *puNodeIndex = ii;
884 }
885
886 memset(&pMgmt->sNodeDBTable[*puNodeIndex], 0, sizeof(KnownNodeDB));
887 pMgmt->sNodeDBTable[*puNodeIndex].bActive = TRUE;
888 pMgmt->sNodeDBTable[*puNodeIndex].uRatePollTimeout = FALLBACK_POLL_SECOND;
889 // for AP mode PS queue
890 skb_queue_head_init(&pMgmt->sNodeDBTable[*puNodeIndex].sTxPSQueue);
891 pMgmt->sNodeDBTable[*puNodeIndex].byAuthSequence = 0;
892 pMgmt->sNodeDBTable[*puNodeIndex].wEnQueueCnt = 0;
893 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Create node index = %d\n", ii);
894 return;
895};
896
897
898
899/*+
900 *
901 * Routine Description:
902 * Remove Node by NodeIndex
903 *
904 *
905 * Return Value:
906 * None
907 *
908-*/
909VOID
910BSSvRemoveOneNode(
911 IN HANDLE hDeviceContext,
912 IN UINT uNodeIndex
913 )
914{
915
916 PSDevice pDevice = (PSDevice)hDeviceContext;
917 PSMgmtObject pMgmt = pDevice->pMgmt;
918 BYTE byMask[8] = {1, 2, 4, 8, 0x10, 0x20, 0x40, 0x80};
919 struct sk_buff *skb;
920
921
922 while ((skb = skb_dequeue(&pMgmt->sNodeDBTable[uNodeIndex].sTxPSQueue)) != NULL)
923 dev_kfree_skb(skb);
924 // clear context
925 memset(&pMgmt->sNodeDBTable[uNodeIndex], 0, sizeof(KnownNodeDB));
926 // clear tx bit map
927 pMgmt->abyPSTxMap[pMgmt->sNodeDBTable[uNodeIndex].wAID >> 3] &= ~byMask[pMgmt->sNodeDBTable[uNodeIndex].wAID & 7];
928
929 return;
930};
931/*+
932 *
933 * Routine Description:
934 * Update AP Node content in Index 0 of KnownNodeDB
935 *
936 *
937 * Return Value:
938 * None
939 *
940-*/
941
942VOID
943BSSvUpdateAPNode(
944 IN HANDLE hDeviceContext,
945 IN PWORD pwCapInfo,
946 IN PWLAN_IE_SUPP_RATES pSuppRates,
947 IN PWLAN_IE_SUPP_RATES pExtSuppRates
948 )
949{
950 PSDevice pDevice = (PSDevice)hDeviceContext;
951 PSMgmtObject pMgmt = pDevice->pMgmt;
952 UINT uRateLen = WLAN_RATES_MAXLEN;
953
954 memset(&pMgmt->sNodeDBTable[0], 0, sizeof(KnownNodeDB));
955
956 pMgmt->sNodeDBTable[0].bActive = TRUE;
957 if (pDevice->eCurrentPHYType == PHY_TYPE_11B) {
958 uRateLen = WLAN_RATES_MAXLEN_11B;
959 }
960 pMgmt->abyCurrSuppRates[1] = RATEuSetIE((PWLAN_IE_SUPP_RATES)pSuppRates,
961 (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates,
962 uRateLen);
963 pMgmt->abyCurrExtSuppRates[1] = RATEuSetIE((PWLAN_IE_SUPP_RATES)pExtSuppRates,
964 (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates,
965 uRateLen);
966 RATEvParseMaxRate((PVOID) pDevice,
967 (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates,
968 (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates,
969 TRUE,
970 &(pMgmt->sNodeDBTable[0].wMaxBasicRate),
971 &(pMgmt->sNodeDBTable[0].wMaxSuppRate),
972 &(pMgmt->sNodeDBTable[0].wSuppRate),
973 &(pMgmt->sNodeDBTable[0].byTopCCKBasicRate),
974 &(pMgmt->sNodeDBTable[0].byTopOFDMBasicRate)
975 );
976 memcpy(pMgmt->sNodeDBTable[0].abyMACAddr, pMgmt->abyCurrBSSID, WLAN_ADDR_LEN);
977 pMgmt->sNodeDBTable[0].wTxDataRate = pMgmt->sNodeDBTable[0].wMaxSuppRate;
978 pMgmt->sNodeDBTable[0].bShortPreamble = WLAN_GET_CAP_INFO_SHORTPREAMBLE(*pwCapInfo);
979 pMgmt->sNodeDBTable[0].uRatePollTimeout = FALLBACK_POLL_SECOND;
980#ifdef PLICE_DEBUG
981 printk("BSSvUpdateAPNode:MaxSuppRate is %d\n",pMgmt->sNodeDBTable[0].wMaxSuppRate);
982#endif
983 // Auto rate fallback function initiation.
984 // RATEbInit(pDevice);
985 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"pMgmt->sNodeDBTable[0].wTxDataRate = %d \n", pMgmt->sNodeDBTable[0].wTxDataRate);
986
987};
988
989
990
991
992
993/*+
994 *
995 * Routine Description:
996 * Add Multicast Node content in Index 0 of KnownNodeDB
997 *
998 *
999 * Return Value:
1000 * None
1001 *
1002-*/
1003
1004
1005VOID
1006BSSvAddMulticastNode(
1007 IN HANDLE hDeviceContext
1008 )
1009{
1010 PSDevice pDevice = (PSDevice)hDeviceContext;
1011 PSMgmtObject pMgmt = pDevice->pMgmt;
1012
1013 if (!pDevice->bEnableHostWEP)
1014 memset(&pMgmt->sNodeDBTable[0], 0, sizeof(KnownNodeDB));
1015 memset(pMgmt->sNodeDBTable[0].abyMACAddr, 0xff, WLAN_ADDR_LEN);
1016 pMgmt->sNodeDBTable[0].bActive = TRUE;
1017 pMgmt->sNodeDBTable[0].bPSEnable = FALSE;
1018 skb_queue_head_init(&pMgmt->sNodeDBTable[0].sTxPSQueue);
1019 RATEvParseMaxRate((PVOID) pDevice,
1020 (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates,
1021 (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates,
1022 TRUE,
1023 &(pMgmt->sNodeDBTable[0].wMaxBasicRate),
1024 &(pMgmt->sNodeDBTable[0].wMaxSuppRate),
1025 &(pMgmt->sNodeDBTable[0].wSuppRate),
1026 &(pMgmt->sNodeDBTable[0].byTopCCKBasicRate),
1027 &(pMgmt->sNodeDBTable[0].byTopOFDMBasicRate)
1028 );
1029 pMgmt->sNodeDBTable[0].wTxDataRate = pMgmt->sNodeDBTable[0].wMaxBasicRate;
1030#ifdef PLICE_DEBUG
1031 printk("BSSvAddMultiCastNode:pMgmt->sNodeDBTable[0].wTxDataRate is %d\n",pMgmt->sNodeDBTable[0].wTxDataRate);
1032#endif
1033 pMgmt->sNodeDBTable[0].uRatePollTimeout = FALLBACK_POLL_SECOND;
1034
1035};
1036
1037
1038
1039
1040
1041/*+
1042 *
1043 * Routine Description:
1044 *
1045 *
1046 * Second call back function to update Node DB info & AP link status
1047 *
1048 *
1049 * Return Value:
1050 * none.
1051 *
1052-*/
1053 //2008-4-14 <add> by chester for led issue
1054 #ifdef FOR_LED_ON_NOTEBOOK
1055BOOL cc=FALSE;
1056UINT status;
1057#endif
1058VOID
1059BSSvSecondCallBack(
1060 IN HANDLE hDeviceContext
1061 )
1062{
1063 PSDevice pDevice = (PSDevice)hDeviceContext;
1064 PSMgmtObject pMgmt = pDevice->pMgmt;
1065 UINT ii;
1066 PWLAN_IE_SSID pItemSSID, pCurrSSID;
1067 UINT uSleepySTACnt = 0;
1068 UINT uNonShortSlotSTACnt = 0;
1069 UINT uLongPreambleSTACnt = 0;
1070viawget_wpa_header* wpahdr;
1071
1072 spin_lock_irq(&pDevice->lock);
1073
1074 pDevice->uAssocCount = 0;
1075
1076 pDevice->byERPFlag &=
1077 ~(WLAN_SET_ERP_BARKER_MODE(1) | WLAN_SET_ERP_NONERP_PRESENT(1));
1078 //2008-4-14 <add> by chester for led issue
1079#ifdef FOR_LED_ON_NOTEBOOK
1080MACvGPIOIn(pDevice->PortOffset, &pDevice->byGPIO);
1081if (((BITbIsBitOff(pDevice->byGPIO,GPIO0_DATA)&&(pDevice->bHWRadioOff == FALSE))||(BITbIsBitOn(pDevice->byGPIO,GPIO0_DATA)&&(pDevice->bHWRadioOff == TRUE)))&&(cc==FALSE)){
1082cc=TRUE;
1083}
1084else if(cc==TRUE){
1085
1086if(pDevice->bHWRadioOff == TRUE){
1087 if (BITbIsBitOff(pDevice->byGPIO,GPIO0_DATA))
1088//||(BITbIsBitOff(pDevice->byGPIO,GPIO0_DATA) && BITbIsBitOn(pDevice->byRadioCtl, EEP_RADIOCTL_INV)))
1089{if(status==1) goto start;
1090status=1;
1091CARDbRadioPowerOff(pDevice);
1092 pMgmt->sNodeDBTable[0].bActive = FALSE;
1093 pMgmt->eCurrMode = WMAC_MODE_STANDBY;
1094 pMgmt->eCurrState = WMAC_STATE_IDLE;
1095 //netif_stop_queue(pDevice->dev);
1096 pDevice->bLinkPass = FALSE;
1097
1098}
1099 if (BITbIsBitOn(pDevice->byGPIO,GPIO0_DATA))
1100//||(BITbIsBitOff(pDevice->byGPIO,GPIO0_DATA) && BITbIsBitOn(pDevice->byRadioCtl, EEP_RADIOCTL_INV)))
1101{if(status==2) goto start;
1102status=2;
1103CARDbRadioPowerOn(pDevice);
1104} }
1105else{
1106 if (BITbIsBitOn(pDevice->byGPIO,GPIO0_DATA))
1107//||(BITbIsBitOff(pDevice->byGPIO,GPIO0_DATA) && BITbIsBitOn(pDevice->byRadioCtl, EEP_RADIOCTL_INV)))
1108{if(status==3) goto start;
1109status=3;
1110CARDbRadioPowerOff(pDevice);
1111 pMgmt->sNodeDBTable[0].bActive = FALSE;
1112 pMgmt->eCurrMode = WMAC_MODE_STANDBY;
1113 pMgmt->eCurrState = WMAC_STATE_IDLE;
1114 //netif_stop_queue(pDevice->dev);
1115 pDevice->bLinkPass = FALSE;
1116
1117}
1118 if (BITbIsBitOff(pDevice->byGPIO,GPIO0_DATA))
1119//||(BITbIsBitOff(pDevice->byGPIO,GPIO0_DATA) && BITbIsBitOn(pDevice->byRadioCtl, EEP_RADIOCTL_INV)))
1120{if(status==4) goto start;
1121status=4;
1122CARDbRadioPowerOn(pDevice);
1123} }
1124}
1125start:
1126#endif
1127
1128
1129 if (pDevice->wUseProtectCntDown > 0) {
1130 pDevice->wUseProtectCntDown --;
1131 }
1132 else {
1133 // disable protect mode
1134 pDevice->byERPFlag &= ~(WLAN_SET_ERP_USE_PROTECTION(1));
1135 }
1136
1137{
1138 pDevice->byReAssocCount++;
1139 if((pDevice->byReAssocCount > 10) && (pDevice->bLinkPass != TRUE)) { //10 sec timeout
1140 printk("Re-association timeout!!!\n");
1141 pDevice->byReAssocCount = 0;
1142 #ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
1143 // if(pDevice->bWPASuppWextEnabled == TRUE)
1144 {
1145 union iwreq_data wrqu;
1146 memset(&wrqu, 0, sizeof (wrqu));
1147 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
1148 printk("wireless_send_event--->SIOCGIWAP(disassociated)\n");
1149 wireless_send_event(pDevice->dev, SIOCGIWAP, &wrqu, NULL);
1150 }
1151 #endif
1152 }
1153 else if(pDevice->bLinkPass == TRUE)
1154 pDevice->byReAssocCount = 0;
1155}
1156
1157#ifdef Calcu_LinkQual
1158 s_uCalculateLinkQual((HANDLE)pDevice);
1159#endif
1160
1161 for (ii = 0; ii < (MAX_NODE_NUM + 1); ii++) {
1162
1163 if (pMgmt->sNodeDBTable[ii].bActive) {
1164
1165 // Increase in-activity counter
1166 pMgmt->sNodeDBTable[ii].uInActiveCount++;
1167
1168 if (ii > 0) {
1169 if (pMgmt->sNodeDBTable[ii].uInActiveCount > MAX_INACTIVE_COUNT) {
1170 BSSvRemoveOneNode(pDevice, ii);
1171 DEVICE_PRT(MSG_LEVEL_NOTICE, KERN_INFO
1172 "Inactive timeout [%d] sec, STA index = [%d] remove\n", MAX_INACTIVE_COUNT, ii);
1173 continue;
1174 }
1175
1176 if (pMgmt->sNodeDBTable[ii].eNodeState >= NODE_ASSOC) {
1177
1178 pDevice->uAssocCount++;
1179
1180 // check if Non ERP exist
1181 if (pMgmt->sNodeDBTable[ii].uInActiveCount < ERP_RECOVER_COUNT) {
1182 if (!pMgmt->sNodeDBTable[ii].bShortPreamble) {
1183 pDevice->byERPFlag |= WLAN_SET_ERP_BARKER_MODE(1);
1184 uLongPreambleSTACnt ++;
1185 }
1186 if (!pMgmt->sNodeDBTable[ii].bERPExist) {
1187 pDevice->byERPFlag |= WLAN_SET_ERP_NONERP_PRESENT(1);
1188 pDevice->byERPFlag |= WLAN_SET_ERP_USE_PROTECTION(1);
1189 }
1190 if (!pMgmt->sNodeDBTable[ii].bShortSlotTime)
1191 uNonShortSlotSTACnt++;
1192 }
1193 }
1194
1195 // check if any STA in PS mode
1196 if (pMgmt->sNodeDBTable[ii].bPSEnable)
1197 uSleepySTACnt++;
1198
1199
1200 }
1201
1202 // Rate fallback check
1203
1204 if (!pDevice->bFixRate) {
1205/*
1206 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_STA) && (ii == 0))
1207 RATEvTxRateFallBack(pDevice, &(pMgmt->sNodeDBTable[ii]));
1208*/
1209 if (ii > 0) {
1210 // ii = 0 for multicast node (AP & Adhoc)
1211 RATEvTxRateFallBack((PVOID)pDevice, &(pMgmt->sNodeDBTable[ii]));
1212 }
1213 else {
1214 // ii = 0 reserved for unicast AP node (Infra STA)
1215 if (pMgmt->eCurrMode == WMAC_MODE_ESS_STA)
1216#ifdef PLICE_DEBUG
1217 printk("SecondCallback:Before:TxDataRate is %d\n",pMgmt->sNodeDBTable[0].wTxDataRate);
1218#endif
1219 RATEvTxRateFallBack((PVOID)pDevice, &(pMgmt->sNodeDBTable[ii]));
1220#ifdef PLICE_DEBUG
1221 printk("SecondCallback:After:TxDataRate is %d\n",pMgmt->sNodeDBTable[0].wTxDataRate);
1222#endif
1223
1224 }
1225
1226 }
1227
1228 // check if pending PS queue
1229 if (pMgmt->sNodeDBTable[ii].wEnQueueCnt != 0) {
1230 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Index= %d, Queue = %d pending \n",
1231 ii, pMgmt->sNodeDBTable[ii].wEnQueueCnt);
1232 if ((ii >0) && (pMgmt->sNodeDBTable[ii].wEnQueueCnt > 15)) {
1233 BSSvRemoveOneNode(pDevice, ii);
1234 DEVICE_PRT(MSG_LEVEL_NOTICE, KERN_INFO "Pending many queues PS STA Index = %d remove \n", ii);
1235 continue;
1236 }
1237 }
1238 }
1239
1240 }
1241
1242
1243 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_AP) && (pDevice->eCurrentPHYType == PHY_TYPE_11G)) {
1244
1245 // on/off protect mode
1246 if (WLAN_GET_ERP_USE_PROTECTION(pDevice->byERPFlag)) {
1247 if (!pDevice->bProtectMode) {
1248 MACvEnableProtectMD(pDevice->PortOffset);
1249 pDevice->bProtectMode = TRUE;
1250 }
1251 }
1252 else {
1253 if (pDevice->bProtectMode) {
1254 MACvDisableProtectMD(pDevice->PortOffset);
1255 pDevice->bProtectMode = FALSE;
1256 }
1257 }
1258 // on/off short slot time
1259
1260 if (uNonShortSlotSTACnt > 0) {
1261 if (pDevice->bShortSlotTime) {
1262 pDevice->bShortSlotTime = FALSE;
1263 BBvSetShortSlotTime(pDevice);
1264 vUpdateIFS((PVOID)pDevice);
1265 }
1266 }
1267 else {
1268 if (!pDevice->bShortSlotTime) {
1269 pDevice->bShortSlotTime = TRUE;
1270 BBvSetShortSlotTime(pDevice);
1271 vUpdateIFS((PVOID)pDevice);
1272 }
1273 }
1274
1275 // on/off barker long preamble mode
1276
1277 if (uLongPreambleSTACnt > 0) {
1278 if (!pDevice->bBarkerPreambleMd) {
1279 MACvEnableBarkerPreambleMd(pDevice->PortOffset);
1280 pDevice->bBarkerPreambleMd = TRUE;
1281 }
1282 }
1283 else {
1284 if (pDevice->bBarkerPreambleMd) {
1285 MACvDisableBarkerPreambleMd(pDevice->PortOffset);
1286 pDevice->bBarkerPreambleMd = FALSE;
1287 }
1288 }
1289
1290 }
1291
1292
1293 // Check if any STA in PS mode, enable DTIM multicast deliver
1294 if (pMgmt->eCurrMode == WMAC_MODE_ESS_AP) {
1295 if (uSleepySTACnt > 0)
1296 pMgmt->sNodeDBTable[0].bPSEnable = TRUE;
1297 else
1298 pMgmt->sNodeDBTable[0].bPSEnable = FALSE;
1299 }
1300
1301 pItemSSID = (PWLAN_IE_SSID)pMgmt->abyDesireSSID;
1302 pCurrSSID = (PWLAN_IE_SSID)pMgmt->abyCurrSSID;
1303//printk("pCurrSSID=%s\n",pCurrSSID->abySSID);
1304 if ((pMgmt->eCurrMode == WMAC_MODE_STANDBY) ||
1305 (pMgmt->eCurrMode == WMAC_MODE_ESS_STA)) {
1306
1307 if (pMgmt->sNodeDBTable[0].bActive) { // Assoc with BSS
1308 // DEVICE_PRT(MSG_LEVEL_INFO, KERN_INFO "Callback inactive Count = [%d]\n", pMgmt->sNodeDBTable[0].uInActiveCount);
1309 //if (pDevice->bUpdateBBVGA) {
1310 // s_vCheckSensitivity((HANDLE) pDevice);
1311 //}
1312 if (pDevice->bUpdateBBVGA) {
1313 // s_vCheckSensitivity((HANDLE) pDevice);
1314 s_vCheckPreEDThreshold((HANDLE)pDevice);
1315 }
1316 if ((pMgmt->sNodeDBTable[0].uInActiveCount >= (LOST_BEACON_COUNT/2)) &&
1317 (pDevice->byBBVGACurrent != pDevice->abyBBVGA[0]) ) {
1318 pDevice->byBBVGANew = pDevice->abyBBVGA[0];
1319 bScheduleCommand((HANDLE) pDevice, WLAN_CMD_CHANGE_BBSENSITIVITY, NULL);
1320 }
1321
1322
1323 if (pMgmt->sNodeDBTable[0].uInActiveCount >= LOST_BEACON_COUNT) {
1324 pMgmt->sNodeDBTable[0].bActive = FALSE;
1325 pMgmt->eCurrMode = WMAC_MODE_STANDBY;
1326 pMgmt->eCurrState = WMAC_STATE_IDLE;
1327 netif_stop_queue(pDevice->dev);
1328 pDevice->bLinkPass = FALSE;
1329 pDevice->bRoaming = TRUE;
1330 DEVICE_PRT(MSG_LEVEL_NOTICE, KERN_INFO "Lost AP beacon [%d] sec, disconnected !\n", pMgmt->sNodeDBTable[0].uInActiveCount);
1331 if ((pDevice->bWPADEVUp) && (pDevice->skb != NULL)) {
1332 wpahdr = (viawget_wpa_header *)pDevice->skb->data;
1333 wpahdr->type = VIAWGET_DISASSOC_MSG;
1334 wpahdr->resp_ie_len = 0;
1335 wpahdr->req_ie_len = 0;
1336 skb_put(pDevice->skb, sizeof(viawget_wpa_header));
1337 pDevice->skb->dev = pDevice->wpadev;
1338//2008-4-3 modify by Chester for wpa
1339#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,22)
1340 pDevice->skb->mac_header = pDevice->skb->data;
1341#else
1342 pDevice->skb->mac.raw = pDevice->skb->data;
1343#endif
1344 pDevice->skb->pkt_type = PACKET_HOST;
1345 pDevice->skb->protocol = htons(ETH_P_802_2);
1346 memset(pDevice->skb->cb, 0, sizeof(pDevice->skb->cb));
1347 netif_rx(pDevice->skb);
1348 pDevice->skb = dev_alloc_skb((int)pDevice->rx_buf_sz);
1349 };
1350 #ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
1351 // if(pDevice->bWPASuppWextEnabled == TRUE)
1352 {
1353 union iwreq_data wrqu;
1354 memset(&wrqu, 0, sizeof (wrqu));
1355 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
1356 printk("wireless_send_event--->SIOCGIWAP(disassociated)\n");
1357 wireless_send_event(pDevice->dev, SIOCGIWAP, &wrqu, NULL);
1358 }
1359 #endif
1360 }
1361 }
1362 else if (pItemSSID->len != 0) {
1363 if (pDevice->uAutoReConnectTime < 10) {
1364 pDevice->uAutoReConnectTime++;
1365 #ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
1366 //network manager support need not do Roaming scan???
1367 if(pDevice->bWPASuppWextEnabled ==TRUE)
1368 pDevice->uAutoReConnectTime = 0;
1369 #endif
1370
1371 }
1372 else {
1373 //mike use old encryption status for wpa reauthen
1374 if(pDevice->bWPADEVUp)
1375 pDevice->eEncryptionStatus = pDevice->eOldEncryptionStatus;
1376 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Roaming ...\n");
1377 BSSvClearBSSList((HANDLE)pDevice, pDevice->bLinkPass);
1378 pMgmt->eScanType = WMAC_SCAN_ACTIVE;
1379 bScheduleCommand((HANDLE) pDevice, WLAN_CMD_BSSID_SCAN, pMgmt->abyDesireSSID);
1380 bScheduleCommand((HANDLE) pDevice, WLAN_CMD_SSID, pMgmt->abyDesireSSID);
1381 pDevice->uAutoReConnectTime = 0;
1382 }
1383 }
1384 }
1385
1386 if (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) {
1387 // if adhoc started which essid is NULL string, rescaning.
1388 if ((pMgmt->eCurrState == WMAC_STATE_STARTED) && (pCurrSSID->len == 0)) {
1389 if (pDevice->uAutoReConnectTime < 10) {
1390 pDevice->uAutoReConnectTime++;
1391 }
1392 else {
1393 DEVICE_PRT(MSG_LEVEL_NOTICE, KERN_INFO "Adhoc re-scaning ...\n");
1394 pMgmt->eScanType = WMAC_SCAN_ACTIVE;
1395 bScheduleCommand((HANDLE) pDevice, WLAN_CMD_BSSID_SCAN, NULL);
1396 bScheduleCommand((HANDLE) pDevice, WLAN_CMD_SSID, NULL);
1397 pDevice->uAutoReConnectTime = 0;
1398 };
1399 }
1400 if (pMgmt->eCurrState == WMAC_STATE_JOINTED) {
1401 if (pDevice->bUpdateBBVGA) {
1402 //s_vCheckSensitivity((HANDLE) pDevice);
1403 s_vCheckPreEDThreshold((HANDLE)pDevice);
1404 }
1405 if (pMgmt->sNodeDBTable[0].uInActiveCount >=ADHOC_LOST_BEACON_COUNT) {
1406 DEVICE_PRT(MSG_LEVEL_NOTICE, KERN_INFO "Lost other STA beacon [%d] sec, started !\n", pMgmt->sNodeDBTable[0].uInActiveCount);
1407 pMgmt->sNodeDBTable[0].uInActiveCount = 0;
1408 pMgmt->eCurrState = WMAC_STATE_STARTED;
1409 netif_stop_queue(pDevice->dev);
1410 pDevice->bLinkPass = FALSE;
1411 }
1412 }
1413 }
1414
1415 spin_unlock_irq(&pDevice->lock);
1416
1417 pMgmt->sTimerSecondCallback.expires = RUN_AT(HZ);
1418 add_timer(&pMgmt->sTimerSecondCallback);
1419 return;
1420}
1421
1422
1423
1424
1425/*+
1426 *
1427 * Routine Description:
1428 *
1429 *
1430 * Update Tx attemps, Tx failure counter in Node DB
1431 *
1432 *
1433 * Return Value:
1434 * none.
1435 *
1436-*/
1437
1438
1439
1440VOID
1441BSSvUpdateNodeTxCounter(
1442 IN HANDLE hDeviceContext,
1443 IN BYTE byTsr0,
1444 IN BYTE byTsr1,
1445 IN PBYTE pbyBuffer,
1446 IN UINT uFIFOHeaderSize
1447 )
1448{
1449 PSDevice pDevice = (PSDevice)hDeviceContext;
1450 PSMgmtObject pMgmt = pDevice->pMgmt;
1451 UINT uNodeIndex = 0;
1452 BYTE byTxRetry = (byTsr0 & TSR0_NCR);
1453 PSTxBufHead pTxBufHead;
1454 PS802_11Header pMACHeader;
1455 WORD wRate;
1456 WORD wFallBackRate = RATE_1M;
1457 BYTE byFallBack;
1458 UINT ii;
1459// UINT txRetryTemp;
1460//PLICE_DEBUG->
1461 //txRetryTemp = byTxRetry;
1462 //if (txRetryTemp== 8)
1463 //txRetryTemp -=3;
1464//PLICE_DEBUG <-
1465 pTxBufHead = (PSTxBufHead) pbyBuffer;
1466 if (pTxBufHead->wFIFOCtl & FIFOCTL_AUTO_FB_0) {
1467 byFallBack = AUTO_FB_0;
1468 } else if (pTxBufHead->wFIFOCtl & FIFOCTL_AUTO_FB_1) {
1469 byFallBack = AUTO_FB_1;
1470 } else {
1471 byFallBack = AUTO_FB_NONE;
1472 }
1473 wRate = pTxBufHead->wReserved; //?wRate
1474 //printk("BSSvUpdateNodeTxCounter:byTxRetry is %d\n",byTxRetry);
1475
1476//printk("BSSvUpdateNodeTx:wRate is %d,byFallback is %d\n",wRate,byFallBack);
1477//#ifdef PLICE_DEBUG
1478 //printk("BSSvUpdateNodeTx: wRate is %d\n",wRate);
1479////#endif
1480 // Only Unicast using support rates
1481 if (pTxBufHead->wFIFOCtl & FIFOCTL_NEEDACK) {
1482 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"wRate %04X, byTsr0 %02X, byTsr1 %02X\n", wRate, byTsr0, byTsr1);
1483 if (pMgmt->eCurrMode == WMAC_MODE_ESS_STA) {
1484 pMgmt->sNodeDBTable[0].uTxAttempts += 1;
1485 if ((byTsr1 & TSR1_TERR) == 0) {
1486 // transmit success, TxAttempts at least plus one
1487 pMgmt->sNodeDBTable[0].uTxOk[MAX_RATE]++;
1488 if ( (byFallBack == AUTO_FB_NONE) ||
1489 (wRate < RATE_18M) ) {
1490 wFallBackRate = wRate;
1491 } else if (byFallBack == AUTO_FB_0) {
1492//PLICE_DEBUG
1493 if (byTxRetry < 5)
1494 //if (txRetryTemp < 5)
1495 wFallBackRate = awHWRetry0[wRate-RATE_18M][byTxRetry];
1496 //wFallBackRate = awHWRetry0[wRate-RATE_12M][byTxRetry];
1497 //wFallBackRate = awHWRetry0[wRate-RATE_18M][txRetryTemp] +1;
1498 else
1499 wFallBackRate = awHWRetry0[wRate-RATE_18M][4];
1500 //wFallBackRate = awHWRetry0[wRate-RATE_12M][4];
1501 } else if (byFallBack == AUTO_FB_1) {
1502 if (byTxRetry < 5)
1503 wFallBackRate = awHWRetry1[wRate-RATE_18M][byTxRetry];
1504 else
1505 wFallBackRate = awHWRetry1[wRate-RATE_18M][4];
1506 }
1507 pMgmt->sNodeDBTable[0].uTxOk[wFallBackRate]++;
1508 } else {
1509 pMgmt->sNodeDBTable[0].uTxFailures ++;
1510 }
1511 pMgmt->sNodeDBTable[0].uTxRetry += byTxRetry;
1512 if (byTxRetry != 0) {
1513 pMgmt->sNodeDBTable[0].uTxFail[MAX_RATE]+=byTxRetry;
1514 if ( (byFallBack == AUTO_FB_NONE) ||
1515 (wRate < RATE_18M) ) {
1516 pMgmt->sNodeDBTable[0].uTxFail[wRate]+=byTxRetry;
1517 } else if (byFallBack == AUTO_FB_0) {
1518//PLICE_DEBUG
1519 for(ii=0;ii<byTxRetry;ii++)
1520 //for (ii=0;ii<txRetryTemp;ii++)
1521 {
1522 if (ii < 5)
1523 {
1524
1525//PLICE_DEBUG
1526 wFallBackRate = awHWRetry0[wRate-RATE_18M][ii];
1527 //printk(" II is %d:BSSvUpdateNodeTx:wFallBackRate is %d\n",ii,wFallBackRate);
1528 //wFallBackRate = awHWRetry0[wRate-RATE_12M][ii];
1529 }
1530 else
1531 {
1532 wFallBackRate = awHWRetry0[wRate-RATE_18M][4];
1533 //printk("ii is %d BSSvUpdateNodeTx:wFallBackRate is %d\n",ii,wFallBackRate);
1534 //wFallBackRate = awHWRetry0[wRate-RATE_12M][4];
1535 }
1536 pMgmt->sNodeDBTable[0].uTxFail[wFallBackRate]++;
1537 }
1538 } else if (byFallBack == AUTO_FB_1) {
1539 for(ii=0;ii<byTxRetry;ii++) {
1540 if (ii < 5)
1541 wFallBackRate = awHWRetry1[wRate-RATE_18M][ii];
1542 else
1543 wFallBackRate = awHWRetry1[wRate-RATE_18M][4];
1544 pMgmt->sNodeDBTable[0].uTxFail[wFallBackRate]++;
1545 }
1546 }
1547 }
1548 };
1549
1550 if ((pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) ||
1551 (pMgmt->eCurrMode == WMAC_MODE_ESS_AP)) {
1552
1553 pMACHeader = (PS802_11Header)(pbyBuffer + uFIFOHeaderSize);
1554
1555 if (BSSDBbIsSTAInNodeDB((HANDLE)pMgmt, &(pMACHeader->abyAddr1[0]), &uNodeIndex)){
1556 pMgmt->sNodeDBTable[uNodeIndex].uTxAttempts += 1;
1557 if ((byTsr1 & TSR1_TERR) == 0) {
1558 // transmit success, TxAttempts at least plus one
1559 pMgmt->sNodeDBTable[uNodeIndex].uTxOk[MAX_RATE]++;
1560 if ( (byFallBack == AUTO_FB_NONE) ||
1561 (wRate < RATE_18M) ) {
1562 wFallBackRate = wRate;
1563 } else if (byFallBack == AUTO_FB_0) {
1564 if (byTxRetry < 5)
1565 wFallBackRate = awHWRetry0[wRate-RATE_18M][byTxRetry];
1566 else
1567 wFallBackRate = awHWRetry0[wRate-RATE_18M][4];
1568 } else if (byFallBack == AUTO_FB_1) {
1569 if (byTxRetry < 5)
1570 wFallBackRate = awHWRetry1[wRate-RATE_18M][byTxRetry];
1571 else
1572 wFallBackRate = awHWRetry1[wRate-RATE_18M][4];
1573 }
1574 pMgmt->sNodeDBTable[uNodeIndex].uTxOk[wFallBackRate]++;
1575 } else {
1576 pMgmt->sNodeDBTable[uNodeIndex].uTxFailures ++;
1577 }
1578 pMgmt->sNodeDBTable[uNodeIndex].uTxRetry += byTxRetry;
1579 if (byTxRetry != 0) {
1580 pMgmt->sNodeDBTable[uNodeIndex].uTxFail[MAX_RATE]+=byTxRetry;
1581 if ( (byFallBack == AUTO_FB_NONE) ||
1582 (wRate < RATE_18M) ) {
1583 pMgmt->sNodeDBTable[uNodeIndex].uTxFail[wRate]+=byTxRetry;
1584 } else if (byFallBack == AUTO_FB_0) {
1585 for(ii=0;ii<byTxRetry;ii++) {
1586 if (ii < 5)
1587 wFallBackRate = awHWRetry0[wRate-RATE_18M][ii];
1588 else
1589 wFallBackRate = awHWRetry0[wRate-RATE_18M][4];
1590 pMgmt->sNodeDBTable[uNodeIndex].uTxFail[wFallBackRate]++;
1591 }
1592 } else if (byFallBack == AUTO_FB_1) {
1593 for(ii=0;ii<byTxRetry;ii++) {
1594 if (ii < 5)
1595 wFallBackRate = awHWRetry1[wRate-RATE_18M][ii];
1596 else
1597 wFallBackRate = awHWRetry1[wRate-RATE_18M][4];
1598 pMgmt->sNodeDBTable[uNodeIndex].uTxFail[wFallBackRate]++;
1599 }
1600 }
1601 }
1602 };
1603 }
1604 };
1605
1606 return;
1607
1608}
1609
1610
1611
1612
1613/*+
1614 *
1615 * Routine Description:
1616 * Clear Nodes & skb in DB Table
1617 *
1618 *
1619 * Parameters:
1620 * In:
1621 * hDeviceContext - The adapter context.
1622 * uStartIndex - starting index
1623 * Out:
1624 * none
1625 *
1626 * Return Value:
1627 * None.
1628 *
1629-*/
1630
1631
1632VOID
1633BSSvClearNodeDBTable(
1634 IN HANDLE hDeviceContext,
1635 IN UINT uStartIndex
1636 )
1637
1638{
1639 PSDevice pDevice = (PSDevice)hDeviceContext;
1640 PSMgmtObject pMgmt = pDevice->pMgmt;
1641 struct sk_buff *skb;
1642 UINT ii;
1643
1644 for (ii = uStartIndex; ii < (MAX_NODE_NUM + 1); ii++) {
1645 if (pMgmt->sNodeDBTable[ii].bActive) {
1646 // check if sTxPSQueue has been initial
1647 if (pMgmt->sNodeDBTable[ii].sTxPSQueue.next != NULL) {
1648 while ((skb = skb_dequeue(&pMgmt->sNodeDBTable[ii].sTxPSQueue)) != NULL){
1649 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "PS skb != NULL %d\n", ii);
1650 dev_kfree_skb(skb);
1651 }
1652 }
1653 memset(&pMgmt->sNodeDBTable[ii], 0, sizeof(KnownNodeDB));
1654 }
1655 }
1656
1657 return;
1658};
1659
1660
1661VOID s_vCheckSensitivity(
1662 IN HANDLE hDeviceContext
1663 )
1664{
1665 PSDevice pDevice = (PSDevice)hDeviceContext;
1666 PKnownBSS pBSSList = NULL;
1667 PSMgmtObject pMgmt = pDevice->pMgmt;
1668 int ii;
1669
1670 if ((pDevice->byLocalID <= REV_ID_VT3253_A1) && (pDevice->byRFType == RF_RFMD2959) &&
1671 (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA)) {
1672 return;
1673 }
1674
1675 if ((pMgmt->eCurrState == WMAC_STATE_ASSOC) ||
1676 ((pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) && (pMgmt->eCurrState == WMAC_STATE_JOINTED))) {
1677 pBSSList = BSSpAddrIsInBSSList(pDevice, pMgmt->abyCurrBSSID, (PWLAN_IE_SSID)pMgmt->abyCurrSSID);
1678 if (pBSSList != NULL) {
1679 // Updata BB Reg if RSSI is too strong.
1680 LONG LocalldBmAverage = 0;
1681 LONG uNumofdBm = 0;
1682 for (ii = 0; ii < RSSI_STAT_COUNT; ii++) {
1683 if (pBSSList->ldBmAverage[ii] != 0) {
1684 uNumofdBm ++;
1685 LocalldBmAverage += pBSSList->ldBmAverage[ii];
1686 }
1687 }
1688 if (uNumofdBm > 0) {
1689 LocalldBmAverage = LocalldBmAverage/uNumofdBm;
1690 for (ii=0;ii<BB_VGA_LEVEL;ii++) {
1691 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"LocalldBmAverage:%ld, %ld %02x\n", LocalldBmAverage, pDevice->ldBmThreshold[ii], pDevice->abyBBVGA[ii]);
1692 if (LocalldBmAverage < pDevice->ldBmThreshold[ii]) {
1693 pDevice->byBBVGANew = pDevice->abyBBVGA[ii];
1694 break;
1695 }
1696 }
1697 if (pDevice->byBBVGANew != pDevice->byBBVGACurrent) {
1698 pDevice->uBBVGADiffCount++;
1699 if (pDevice->uBBVGADiffCount >= BB_VGA_CHANGE_THRESHOLD)
1700 bScheduleCommand((HANDLE) pDevice, WLAN_CMD_CHANGE_BBSENSITIVITY, NULL);
1701 } else {
1702 pDevice->uBBVGADiffCount = 0;
1703 }
1704 }
1705 }
1706 }
1707}
1708
1709
1710VOID
1711BSSvClearAnyBSSJoinRecord (
1712 IN HANDLE hDeviceContext
1713 )
1714{
1715 PSDevice pDevice = (PSDevice)hDeviceContext;
1716 PSMgmtObject pMgmt = pDevice->pMgmt;
1717 UINT ii;
1718
1719 for (ii = 0; ii < MAX_BSS_NUM; ii++) {
1720 pMgmt->sBSSList[ii].bSelected = FALSE;
1721 }
1722 return;
1723}
1724
1725#ifdef Calcu_LinkQual
1726VOID s_uCalculateLinkQual(
1727 IN HANDLE hDeviceContext
1728 )
1729{
1730 PSDevice pDevice = (PSDevice)hDeviceContext;
1731 ULONG TxOkRatio, TxCnt;
1732 ULONG RxOkRatio,RxCnt;
1733 ULONG RssiRatio;
1734 long ldBm;
1735
1736TxCnt = pDevice->scStatistic.TxNoRetryOkCount +
1737 pDevice->scStatistic.TxRetryOkCount +
1738 pDevice->scStatistic.TxFailCount;
1739RxCnt = pDevice->scStatistic.RxFcsErrCnt +
1740 pDevice->scStatistic.RxOkCnt;
1741TxOkRatio = (TxCnt < 6) ? 4000:((pDevice->scStatistic.TxNoRetryOkCount * 4000) / TxCnt);
1742RxOkRatio = (RxCnt < 6) ? 2000:((pDevice->scStatistic.RxOkCnt * 2000) / RxCnt);
1743//decide link quality
1744if(pDevice->bLinkPass !=TRUE)
1745{
1746 // printk("s_uCalculateLinkQual-->Link disconnect and Poor quality**\n");
1747 pDevice->scStatistic.LinkQuality = 0;
1748 pDevice->scStatistic.SignalStren = 0;
1749}
1750else
1751{
1752 RFvRSSITodBm(pDevice, (BYTE)(pDevice->uCurrRSSI), &ldBm);
1753 if(-ldBm < 50) {
1754 RssiRatio = 4000;
1755 }
1756 else if(-ldBm > 90) {
1757 RssiRatio = 0;
1758 }
1759 else {
1760 RssiRatio = (40-(-ldBm-50))*4000/40;
1761 }
1762 pDevice->scStatistic.SignalStren = RssiRatio/40;
1763 pDevice->scStatistic.LinkQuality = (RssiRatio+TxOkRatio+RxOkRatio)/100;
1764}
1765 pDevice->scStatistic.RxFcsErrCnt = 0;
1766 pDevice->scStatistic.RxOkCnt = 0;
1767 pDevice->scStatistic.TxFailCount = 0;
1768 pDevice->scStatistic.TxNoRetryOkCount = 0;
1769 pDevice->scStatistic.TxRetryOkCount = 0;
1770 return;
1771}
1772#endif
1773
1774VOID s_vCheckPreEDThreshold(
1775 IN HANDLE hDeviceContext
1776 )
1777{
1778 PSDevice pDevice = (PSDevice)hDeviceContext;
1779 PKnownBSS pBSSList = NULL;
1780 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
1781
1782 if ((pMgmt->eCurrState == WMAC_STATE_ASSOC) ||
1783 ((pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) && (pMgmt->eCurrState == WMAC_STATE_JOINTED))) {
1784 pBSSList = BSSpAddrIsInBSSList(pDevice, pMgmt->abyCurrBSSID, (PWLAN_IE_SSID)pMgmt->abyCurrSSID);
1785 if (pBSSList != NULL) {
1786 pDevice->byBBPreEDRSSI = (BYTE) (~(pBSSList->ldBmAverRange) + 1);
1787 //BBvUpdatePreEDThreshold(pDevice, FALSE);
1788 }
1789 }
1790 return;
1791}
diff --git a/drivers/staging/vt6655/bssdb.h b/drivers/staging/vt6655/bssdb.h
new file mode 100644
index 000000000000..d35616d4883d
--- /dev/null
+++ b/drivers/staging/vt6655/bssdb.h
@@ -0,0 +1,380 @@
1/*
2 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
3 * All rights reserved.
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 *
20 * File: bssdb.h
21 *
22 * Purpose: Handles the Basic Service Set & Node Database functions
23 *
24 * Author: Lyndon Chen
25 *
26 * Date: July 16, 2002
27 *
28 */
29
30#ifndef __BSSDB_H__
31#define __BSSDB_H__
32
33//#if !defined(__DEVICE_H__)
34//#include "device.h"
35//#endif
36#include <linux/skbuff.h>
37#if !defined(__80211HDR_H__)
38#include "80211hdr.h"
39#endif
40#if !defined(__80211MGR_H__)
41#include "80211mgr.h"
42#endif
43#if !defined(__CARD_H__)
44#include "card.h"
45#endif
46
47
48
49/*--------------------- Export Definitions -------------------------*/
50
51#define MAX_NODE_NUM 64
52#define MAX_BSS_NUM 42
53#define LOST_BEACON_COUNT 10 // 10 sec, XP defined
54#define MAX_PS_TX_BUF 32 // sta max power saving tx buf
55#define ADHOC_LOST_BEACON_COUNT 30 // 30 sec, beacon lost for adhoc only
56#define MAX_INACTIVE_COUNT 300 // 300 sec, inactive STA node refresh
57
58#define USE_PROTECT_PERIOD 10 // 10 sec, Use protect mode check period
59#define ERP_RECOVER_COUNT 30 // 30 sec, ERP support callback check
60#define BSS_CLEAR_COUNT 1
61
62#define RSSI_STAT_COUNT 10
63#define MAX_CHECK_RSSI_COUNT 8
64
65// STA dwflags
66#define WLAN_STA_AUTH BIT0
67#define WLAN_STA_ASSOC BIT1
68#define WLAN_STA_PS BIT2
69#define WLAN_STA_TIM BIT3
70// permanent; do not remove entry on expiration
71#define WLAN_STA_PERM BIT4
72// If 802.1X is used, this flag is
73// controlling whether STA is authorized to
74// send and receive non-IEEE 802.1X frames
75#define WLAN_STA_AUTHORIZED BIT5
76
77#define MAX_RATE 12
78
79#define MAX_WPA_IE_LEN 64
80
81
82/*--------------------- Export Classes ----------------------------*/
83
84/*--------------------- Export Variables --------------------------*/
85
86
87/*--------------------- Export Types ------------------------------*/
88
89//
90// IEEE 802.11 Structures and definitions
91//
92
93typedef enum _NDIS_802_11_NETWORK_TYPE
94{
95 Ndis802_11FH,
96 Ndis802_11DS,
97 Ndis802_11OFDM5,
98 Ndis802_11OFDM24,
99 Ndis802_11NetworkTypeMax // not a real type, defined as an upper bound
100} NDIS_802_11_NETWORK_TYPE, *PNDIS_802_11_NETWORK_TYPE;
101
102
103typedef struct tagSERPObject {
104 BOOL bERPExist;
105 BYTE byERP;
106} ERPObject, DEF* PERPObject;
107
108
109typedef struct tagSRSNCapObject {
110 BOOL bRSNCapExist;
111 WORD wRSNCap;
112} SRSNCapObject, DEF* PSRSNCapObject;
113
114// BSS info(AP)
115#pragma pack(1)
116typedef struct tagKnownBSS {
117 // BSS info
118 BOOL bActive;
119 BYTE abyBSSID[WLAN_BSSID_LEN];
120 UINT uChannel;
121 BYTE abySuppRates[WLAN_IEHDR_LEN + WLAN_RATES_MAXLEN + 1];
122 BYTE abyExtSuppRates[WLAN_IEHDR_LEN + WLAN_RATES_MAXLEN + 1];
123 UINT uRSSI;
124 BYTE bySQ;
125 WORD wBeaconInterval;
126 WORD wCapInfo;
127 BYTE abySSID[WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1];
128 BYTE byRxRate;
129// WORD wATIMWindow;
130 BYTE byRSSIStatCnt;
131 LONG ldBmMAX;
132 LONG ldBmAverage[RSSI_STAT_COUNT];
133 LONG ldBmAverRange;
134 //For any BSSID selection improvment
135 BOOL bSelected;
136
137 //++ WPA informations
138 BOOL bWPAValid;
139 BYTE byGKType;
140 BYTE abyPKType[4];
141 WORD wPKCount;
142 BYTE abyAuthType[4];
143 WORD wAuthCount;
144 BYTE byDefaultK_as_PK;
145 BYTE byReplayIdx;
146 //--
147
148 //++ WPA2 informations
149 BOOL bWPA2Valid;
150 BYTE byCSSGK;
151 WORD wCSSPKCount;
152 BYTE abyCSSPK[4];
153 WORD wAKMSSAuthCount;
154 BYTE abyAKMSSAuthType[4];
155
156 //++ wpactl
157 BYTE byWPAIE[MAX_WPA_IE_LEN];
158 BYTE byRSNIE[MAX_WPA_IE_LEN];
159 WORD wWPALen;
160 WORD wRSNLen;
161
162 // Clear count
163 UINT uClearCount;
164// BYTE abyIEs[WLAN_BEACON_FR_MAXLEN];
165 UINT uIELength;
166 QWORD qwBSSTimestamp;
167 QWORD qwLocalTSF; // local TSF timer
168
169// NDIS_802_11_NETWORK_TYPE NetworkTypeInUse;
170 CARD_PHY_TYPE eNetworkTypeInUse;
171
172 ERPObject sERP;
173 SRSNCapObject sRSNCapObj;
174 BYTE abyIEs[1024]; // don't move this field !!
175
176}__attribute__ ((__packed__))
177KnownBSS , DEF* PKnownBSS;
178
179//2006-1116-01,<Add> by NomadZhao
180#pragma pack()
181
182typedef enum tagNODE_STATE {
183 NODE_FREE,
184 NODE_AGED,
185 NODE_KNOWN,
186 NODE_AUTH,
187 NODE_ASSOC
188} NODE_STATE, *PNODE_STATE;
189
190
191// STA node info
192typedef struct tagKnownNodeDB {
193 // STA info
194 BOOL bActive;
195 BYTE abyMACAddr[WLAN_ADDR_LEN];
196 BYTE abyCurrSuppRates[WLAN_IEHDR_LEN + WLAN_RATES_MAXLEN];
197 BYTE abyCurrExtSuppRates[WLAN_IEHDR_LEN + WLAN_RATES_MAXLEN];
198 WORD wTxDataRate;
199 BOOL bShortPreamble;
200 BOOL bERPExist;
201 BOOL bShortSlotTime;
202 UINT uInActiveCount;
203 WORD wMaxBasicRate; //Get from byTopOFDMBasicRate or byTopCCKBasicRate which depends on packetTyp.
204 WORD wMaxSuppRate; //Records the highest supported rate getting from SuppRates IE and ExtSuppRates IE in Beacon.
205 WORD wSuppRate;
206 BYTE byTopOFDMBasicRate;//Records the highest basic rate in OFDM mode
207 BYTE byTopCCKBasicRate; //Records the highest basic rate in CCK mode
208
209 // For AP mode
210 struct sk_buff_head sTxPSQueue;
211 WORD wCapInfo;
212 WORD wListenInterval;
213 WORD wAID;
214 NODE_STATE eNodeState;
215 BOOL bPSEnable;
216 BOOL bRxPSPoll;
217 BYTE byAuthSequence;
218 ULONG ulLastRxJiffer;
219 BYTE bySuppRate;
220 DWORD dwFlags;
221 WORD wEnQueueCnt;
222
223 BOOL bOnFly;
224 ULONGLONG KeyRSC;
225 BYTE byKeyIndex;
226 DWORD dwKeyIndex;
227 BYTE byCipherSuite;
228 DWORD dwTSC47_16;
229 WORD wTSC15_0;
230 UINT uWepKeyLength;
231 BYTE abyWepKey[WLAN_WEPMAX_KEYLEN];
232 //
233 // Auto rate fallback vars
234 BOOL bIsInFallback;
235 UINT uAverageRSSI;
236 UINT uRateRecoveryTimeout;
237 UINT uRatePollTimeout;
238 UINT uTxFailures;
239 UINT uTxAttempts;
240
241 UINT uTxRetry;
242 UINT uFailureRatio;
243 UINT uRetryRatio;
244 UINT uTxOk[MAX_RATE+1];
245 UINT uTxFail[MAX_RATE+1];
246 UINT uTimeCount;
247
248} KnownNodeDB, DEF* PKnownNodeDB;
249
250
251/*--------------------- Export Functions --------------------------*/
252
253
254
255PKnownBSS
256BSSpSearchBSSList(
257 IN HANDLE hDeviceContext,
258 IN PBYTE pbyDesireBSSID,
259 IN PBYTE pbyDesireSSID,
260 IN CARD_PHY_TYPE ePhyType
261 );
262
263PKnownBSS
264BSSpAddrIsInBSSList(
265 IN HANDLE hDeviceContext,
266 IN PBYTE abyBSSID,
267 IN PWLAN_IE_SSID pSSID
268 );
269
270VOID
271BSSvClearBSSList(
272 IN HANDLE hDeviceContext,
273 IN BOOL bKeepCurrBSSID
274 );
275
276BOOL
277BSSbInsertToBSSList(
278 IN HANDLE hDeviceContext,
279 IN PBYTE abyBSSIDAddr,
280 IN QWORD qwTimestamp,
281 IN WORD wBeaconInterval,
282 IN WORD wCapInfo,
283 IN BYTE byCurrChannel,
284 IN PWLAN_IE_SSID pSSID,
285 IN PWLAN_IE_SUPP_RATES pSuppRates,
286 IN PWLAN_IE_SUPP_RATES pExtSuppRates,
287 IN PERPObject psERP,
288 IN PWLAN_IE_RSN pRSN,
289 IN PWLAN_IE_RSN_EXT pRSNWPA,
290 IN PWLAN_IE_COUNTRY pIE_Country,
291 IN PWLAN_IE_QUIET pIE_Quiet,
292 IN UINT uIELength,
293 IN PBYTE pbyIEs,
294 IN HANDLE pRxPacketContext
295 );
296
297
298BOOL
299BSSbUpdateToBSSList(
300 IN HANDLE hDeviceContext,
301 IN QWORD qwTimestamp,
302 IN WORD wBeaconInterval,
303 IN WORD wCapInfo,
304 IN BYTE byCurrChannel,
305 IN BOOL bChannelHit,
306 IN PWLAN_IE_SSID pSSID,
307 IN PWLAN_IE_SUPP_RATES pSuppRates,
308 IN PWLAN_IE_SUPP_RATES pExtSuppRates,
309 IN PERPObject psERP,
310 IN PWLAN_IE_RSN pRSN,
311 IN PWLAN_IE_RSN_EXT pRSNWPA,
312 IN PWLAN_IE_COUNTRY pIE_Country,
313 IN PWLAN_IE_QUIET pIE_Quiet,
314 IN PKnownBSS pBSSList,
315 IN UINT uIELength,
316 IN PBYTE pbyIEs,
317 IN HANDLE pRxPacketContext
318 );
319
320
321BOOL
322BSSDBbIsSTAInNodeDB(
323 IN HANDLE hDeviceContext,
324 IN PBYTE abyDstAddr,
325 OUT PUINT puNodeIndex
326 );
327
328VOID
329BSSvCreateOneNode(
330 IN HANDLE hDeviceContext,
331 OUT PUINT puNodeIndex
332 );
333
334VOID
335BSSvUpdateAPNode(
336 IN HANDLE hDeviceContext,
337 IN PWORD pwCapInfo,
338 IN PWLAN_IE_SUPP_RATES pItemRates,
339 IN PWLAN_IE_SUPP_RATES pExtSuppRates
340 );
341
342
343VOID
344BSSvSecondCallBack(
345 IN HANDLE hDeviceContext
346 );
347
348VOID
349BSSvUpdateNodeTxCounter(
350 IN HANDLE hDeviceContext,
351 IN BYTE byTsr0,
352 IN BYTE byTsr1,
353 IN PBYTE pbyBuffer,
354 IN UINT uFIFOHeaderSize
355 );
356
357VOID
358BSSvRemoveOneNode(
359 IN HANDLE hDeviceContext,
360 IN UINT uNodeIndex
361 );
362
363VOID
364BSSvAddMulticastNode(
365 IN HANDLE hDeviceContext
366 );
367
368
369VOID
370BSSvClearNodeDBTable(
371 IN HANDLE hDeviceContext,
372 IN UINT uStartIndex
373 );
374
375VOID
376BSSvClearAnyBSSJoinRecord(
377 IN HANDLE hDeviceContext
378 );
379
380#endif //__BSSDB_H__
diff --git a/drivers/staging/vt6655/card.c b/drivers/staging/vt6655/card.c
new file mode 100644
index 000000000000..723f44e0bbae
--- /dev/null
+++ b/drivers/staging/vt6655/card.c
@@ -0,0 +1,3126 @@
1/*
2 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
3 * All rights reserved.
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * File: card.c
20 * Purpose: Provide functions to setup NIC operation mode
21 * Functions:
22 * s_vSafeResetTx - Rest Tx
23 * CARDvSetRSPINF - Set RSPINF
24 * vUpdateIFS - Update slotTime,SIFS,DIFS, and EIFS
25 * CARDvUpdateBasicTopRate - Update BasicTopRate
26 * CARDbAddBasicRate - Add to BasicRateSet
27 * CARDbSetBasicRate - Set Basic Tx Rate
28 * CARDbIsOFDMinBasicRate - Check if any OFDM rate is in BasicRateSet
29 * CARDvSetLoopbackMode - Set Loopback mode
30 * CARDbSoftwareReset - Sortware reset NIC
31 * CARDqGetTSFOffset - Caculate TSFOffset
32 * CARDbGetCurrentTSF - Read Current NIC TSF counter
33 * CARDqGetNextTBTT - Caculate Next Beacon TSF counter
34 * CARDvSetFirstNextTBTT - Set NIC Beacon time
35 * CARDvUpdateNextTBTT - Sync. NIC Beacon time
36 * CARDbRadioPowerOff - Turn Off NIC Radio Power
37 * CARDbRadioPowerOn - Turn On NIC Radio Power
38 * CARDbSetWEPMode - Set NIC Wep mode
39 * CARDbSetTxPower - Set NIC tx power
40 *
41 * Revision History:
42 * 06-10-2003 Bryan YC Fan: Re-write codes to support VT3253 spec.
43 * 08-26-2003 Kyle Hsu: Modify the defination type of dwIoBase.
44 * 09-01-2003 Bryan YC Fan: Add vUpdateIFS().
45 *
46 */
47
48#if !defined(__TMACRO_H__)
49#include "tmacro.h"
50#endif
51#if !defined(__CARD_H__)
52#include "card.h"
53#endif
54#if !defined(__TBIT_H__)
55#include "tbit.h"
56#endif
57#if !defined(__BASEBAND_H__)
58#include "baseband.h"
59#endif
60#if !defined(__MAC_H__)
61#include "mac.h"
62#endif
63#if !defined(__DESC_H__)
64#include "desc.h"
65#endif
66#if !defined(__RF_H__)
67#include "rf.h"
68#endif
69#if !defined(__VNTWIFI_H__)
70#include "vntwifi.h"
71#endif
72#if !defined(__POWER_H__)
73#include "power.h"
74#endif
75#if !defined(__KEY_H__)
76#include "key.h"
77#endif
78#if !defined(__RC4_H__)
79#include "rc4.h"
80#endif
81#if !defined(__COUNTRY_H__)
82#include "country.h"
83#endif
84#if !defined(__UMEM_H__)
85#include "umem.h"
86#endif
87
88
89
90/*--------------------- Static Definitions -------------------------*/
91
92//static int msglevel =MSG_LEVEL_DEBUG;
93static int msglevel =MSG_LEVEL_INFO;
94
95#define C_SIFS_A 16 // micro sec.
96#define C_SIFS_BG 10
97
98#define C_EIFS 80 // micro sec.
99
100
101#define C_SLOT_SHORT 9 // micro sec.
102#define C_SLOT_LONG 20
103
104#define C_CWMIN_A 15 // slot time
105#define C_CWMIN_B 31
106
107#define C_CWMAX 1023 // slot time
108
109#define CARD_MAX_CHANNEL_TBL 56
110
111#define WAIT_BEACON_TX_DOWN_TMO 3 // Times
112
113typedef struct tagSChannelTblElement {
114 BYTE byChannelNumber;
115 UINT uFrequency;
116 BOOL bValid;
117 BYTE byMAP;
118}SChannelTblElement, DEF* PSChannelTblElement;
119
120 //1M, 2M, 5M, 11M, 18M, 24M, 36M, 54M
121static BYTE abyDefaultSuppRatesG[] = {WLAN_EID_SUPP_RATES, 8, 0x02, 0x04, 0x0B, 0x16, 0x24, 0x30, 0x48, 0x6C};
122 //6M, 9M, 12M, 48M
123static BYTE abyDefaultExtSuppRatesG[] = {WLAN_EID_EXTSUPP_RATES, 4, 0x0C, 0x12, 0x18, 0x60};
124 //6M, 9M, 12M, 18M, 24M, 36M, 48M, 54M
125static BYTE abyDefaultSuppRatesA[] = {WLAN_EID_SUPP_RATES, 8, 0x0C, 0x12, 0x18, 0x24, 0x30, 0x48, 0x60, 0x6C};
126 //1M, 2M, 5M, 11M,
127static BYTE abyDefaultSuppRatesB[] = {WLAN_EID_SUPP_RATES, 4, 0x02, 0x04, 0x0B, 0x16};
128
129
130
131/*--------------------- Static Classes ----------------------------*/
132
133/*--------------------- Static Variables --------------------------*/
134
135
136const WORD cwRXBCNTSFOff[MAX_RATE] =
137{17, 17, 17, 17, 34, 23, 17, 11, 8, 5, 4, 3};
138
139static SChannelTblElement sChannelTbl[CARD_MAX_CHANNEL_TBL+1] =
140{
141 {0, 0, FALSE, 0},
142 {1, 2412, TRUE, 0},
143 {2, 2417, TRUE, 0},
144 {3, 2422, TRUE, 0},
145 {4, 2427, TRUE, 0},
146 {5, 2432, TRUE, 0},
147 {6, 2437, TRUE, 0},
148 {7, 2442, TRUE, 0},
149 {8, 2447, TRUE, 0},
150 {9, 2452, TRUE, 0},
151 {10, 2457, TRUE, 0},
152 {11, 2462, TRUE, 0},
153 {12, 2467, TRUE, 0},
154 {13, 2472, TRUE, 0},
155 {14, 2484, TRUE, 0},
156 {183, 4915, TRUE, 0},
157 {184, 4920, TRUE, 0},
158 {185, 4925, TRUE, 0},
159 {187, 4935, TRUE, 0},
160 {188, 4940, TRUE, 0},
161 {189, 4945, TRUE, 0},
162 {192, 4960, TRUE, 0},
163 {196, 4980, TRUE, 0},
164 {7, 5035, TRUE, 0},
165 {8, 5040, TRUE, 0},
166 {9, 5045, TRUE, 0},
167 {11, 5055, TRUE, 0},
168 {12, 5060, TRUE, 0},
169 {16, 5080, TRUE, 0},
170 {34, 5170, TRUE, 0},
171 {36, 5180, TRUE, 0},
172 {38, 5190, TRUE, 0},
173 {40, 5200, TRUE, 0},
174 {42, 5210, TRUE, 0},
175 {44, 5220, TRUE, 0},
176 {46, 5230, TRUE, 0},
177 {48, 5240, TRUE, 0},
178 {52, 5260, TRUE, 0},
179 {56, 5280, TRUE, 0},
180 {60, 5300, TRUE, 0},
181 {64, 5320, TRUE, 0},
182 {100, 5500, TRUE, 0},
183 {104, 5520, TRUE, 0},
184 {108, 5540, TRUE, 0},
185 {112, 5560, TRUE, 0},
186 {116, 5580, TRUE, 0},
187 {120, 5600, TRUE, 0},
188 {124, 5620, TRUE, 0},
189 {128, 5640, TRUE, 0},
190 {132, 5660, TRUE, 0},
191 {136, 5680, TRUE, 0},
192 {140, 5700, TRUE, 0},
193 {149, 5745, TRUE, 0},
194 {153, 5765, TRUE, 0},
195 {157, 5785, TRUE, 0},
196 {161, 5805, TRUE, 0},
197 {165, 5825, TRUE, 0}
198};
199
200
201/************************************************************************
202 * The Radar regulation rules for each country
203 ************************************************************************/
204SCountryTable ChannelRuleTab[CCODE_MAX+1] =
205{
206/************************************************************************
207 * This table is based on Athero driver rules
208 ************************************************************************/
209/* Country Available channels, ended with 0 */
210/* 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 */
211{CCODE_FCC, {'U','S'}, { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1}
212 , { 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 17, 0, 17, 0, 17, 0, 17, 23, 23, 23, 23, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 30, 30, 30, 30, 30} },
213{CCODE_TELEC, {'J','P'}, { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 0, 0, 1, 0, 1, 1, 0, 1, 0, 0, 1, 1, 1, 0, 1, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
214 , { 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 0, 23, 0, 0, 23, 0, 23, 23, 0, 23, 0, 0, 23, 23, 23, 0, 23, 0, 23, 0, 23, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} },
215{CCODE_ETSI, {'E','U'}, { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0}
216 , { 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 20, 0, 20, 0, 20, 0, 20, 20, 20, 20, 20, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 0, 0, 0, 0, 0} },
217{CCODE_RESV3, {' ',' '}, { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
218 , { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} },
219{CCODE_RESV4, {' ',' '}, { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
220 , { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} },
221{CCODE_RESV5, {' ',' '}, { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
222 , { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} },
223{CCODE_RESV6, {' ',' '}, { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
224 , { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} },
225{CCODE_RESV7, {' ',' '}, { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
226 , { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} },
227{CCODE_RESV8, {' ',' '}, { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
228 , { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} },
229{CCODE_RESV9, {' ',' '}, { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
230 , { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} },
231{CCODE_RESVa, {' ',' '}, { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
232 , { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} },
233{CCODE_RESVb, {' ',' '}, { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
234 , { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} },
235{CCODE_RESVc, {' ',' '}, { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
236 , { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} },
237{CCODE_RESVd, {' ',' '}, { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
238 , { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} },
239{CCODE_RESVe, {' ',' '}, { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
240 , { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} },
241{CCODE_ALLBAND, {' ',' '}, { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}
242 , { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} },
243{CCODE_ALBANIA, {'A','L'}, { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
244 , { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} },
245{CCODE_ALGERIA, {'D','Z'}, { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
246 , { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} },
247{CCODE_ARGENTINA, {'A','R'}, { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0}
248 , { 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 17, 17, 17, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 30, 30, 30, 30, 0} },
249{CCODE_ARMENIA, {'A','M'}, { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
250 , { 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 18, 0, 18, 0, 18, 0, 18, 18, 18, 18, 18, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} },
251{CCODE_AUSTRALIA, {'A','U'}, { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1}
252 , { 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 23, 0, 23, 0, 23, 0, 23, 23, 23, 23, 23, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 30, 30, 30, 30, 30} },
253{CCODE_AUSTRIA, {'A','T'}, { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
254 , { 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 15, 0, 15, 0, 15, 0, 15, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} },
255{CCODE_AZERBAIJAN, {'A','Z'}, { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
256 , { 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 18, 0, 18, 0, 18, 0, 18, 18, 18, 18, 18, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} },
257{CCODE_BAHRAIN, {'B','H'}, { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
258 , { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} },
259{CCODE_BELARUS, {'B','Y'}, { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
260 , { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} },
261{CCODE_BELGIUM, {'B','E'}, { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
262 , { 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 18, 0, 18, 0, 18, 0, 18, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} },
263{CCODE_BELIZE, {'B','Z'}, { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1}
264 , { 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 30, 30, 30, 30, 30} },
265{CCODE_BOLIVIA, {'B','O'}, { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1}
266 , { 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 30, 30, 30, 30, 30} },
267{CCODE_BRAZIL, {'B','R'}, { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
268 , { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} },
269{CCODE_BRUNEI_DARUSSALAM, {'B','N'}, { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1}
270 , { 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 30, 30, 30, 30, 30} },
271{CCODE_BULGARIA, {'B','G'}, { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 1, 1, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0}
272 , { 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 23, 0, 23, 0, 23, 0, 23, 23, 23, 0, 0, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 0, 0, 0, 0, 0} },
273{CCODE_CANADA, {'C','A'}, { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1}
274 , { 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 17, 0, 17, 0, 17, 0, 17, 23, 23, 23, 23, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 30, 30, 30, 30, 30} },
275{CCODE_CHILE, {'C','L'}, { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1}
276 , { 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 17, 17, 17, 17, 17} },
277{CCODE_CHINA, {'C','N'}, { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1}
278 , { 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 30, 30, 30, 30, 30} },
279{CCODE_COLOMBIA, {'C','O'}, { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1}
280 , { 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 17, 0, 17, 0, 17, 0, 17, 23, 23, 23, 23, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 30, 30, 30, 30, 30} },
281{CCODE_COSTA_RICA, {'C','R'}, { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
282 , { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} },
283{CCODE_CROATIA, {'H','R'}, { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
284 , { 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 20, 0, 20, 0, 20, 0, 20, 20, 20, 20, 20, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} },
285{CCODE_CYPRUS, {'C','Y'}, { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0}
286 , { 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 20, 0, 20, 0, 20, 0, 20, 20, 20, 20, 20, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 0, 0, 0, 0, 0} },
287{CCODE_CZECH, {'C','Z'}, { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
288 , { 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 20, 0, 20, 0, 20, 0, 20, 20, 20, 20, 20, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} },
289{CCODE_DENMARK, {'D','K'}, { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0}
290 , { 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 20, 0, 20, 0, 20, 0, 20, 20, 20, 20, 20, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 0, 0, 0, 0, 0} },
291{CCODE_DOMINICAN_REPUBLIC, {'D','O'}, { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1}
292 , { 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 17, 0, 17, 0, 17, 0, 17, 23, 23, 23, 23, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 30, 30, 30, 30, 30} },
293{CCODE_ECUADOR, {'E','C'}, { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
294 , { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} },
295{CCODE_EGYPT, {'E','G'}, { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
296 , { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} },
297{CCODE_EL_SALVADOR, {'S','V'}, { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
298 , { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} },
299{CCODE_ESTONIA, {'E','E'}, { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0}
300 , { 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 20, 0, 20, 0, 20, 0, 20, 20, 20, 20, 20, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 0, 0, 0, 0, 0} },
301{CCODE_FINLAND, {'F','I'}, { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0}
302 , { 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 20, 0, 20, 0, 20, 0, 20, 20, 20, 20, 20, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 0, 0, 0, 0, 0} },
303{CCODE_FRANCE, {'F','R'}, { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
304 , { 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 20, 0, 20, 0, 20, 0, 20, 20, 20, 20, 20, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} },
305{CCODE_GERMANY, {'D','E'}, { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0}
306 , { 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 20, 0, 20, 0, 20, 0, 20, 20, 20, 20, 20, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 0, 0, 0, 0, 0} },
307{CCODE_GREECE, {'G','R'}, { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
308 , { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} },
309{CCODE_GEORGIA, {'G','E'}, { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
310 , { 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 18, 0, 18, 0, 18, 0, 18, 18, 18, 18, 18, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} },
311{CCODE_GUATEMALA, {'G','T'}, { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1}
312 , { 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 17, 0, 17, 0, 17, 0, 17, 23, 23, 23, 23, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 30, 30, 30, 30, 30} },
313{CCODE_HONDURAS, {'H','N'}, { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
314 , { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} },
315{CCODE_HONG_KONG, {'H','K'}, { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1}
316 , { 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 23, 0, 23, 0, 23, 0, 23, 23, 23, 23, 23, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 30, 30, 30, 30, 30} },
317{CCODE_HUNGARY, {'H','U'}, { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
318 , { 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 18, 0, 18, 0, 18, 0, 18, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} },
319{CCODE_ICELAND, {'I','S'}, { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0}
320 , { 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 20, 0, 20, 0, 20, 0, 20, 20, 20, 20, 20, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 0, 0, 0, 0, 0} },
321{CCODE_INDIA, {'I','N'}, { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
322 , { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} },
323{CCODE_INDONESIA, {'I','D'}, { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
324 , { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} },
325{CCODE_IRAN, {'I','R'}, { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1}
326 , { 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 30, 30, 30, 30, 30} },
327{CCODE_IRELAND, {'I','E'}, { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0}
328 , { 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 20, 0, 20, 0, 20, 0, 20, 20, 20, 20, 20, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 0, 0, 0, 0, 0} },
329{CCODE_ITALY, {'I','T'}, { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0}
330 , { 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 20, 0, 20, 0, 20, 0, 20, 20, 20, 20, 20, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 0, 0, 0, 0, 0} },
331{CCODE_ISRAEL, {'I','L'}, { 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
332 , { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} },
333{CCODE_JAPAN, {'J','P'}, { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
334 , { 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 23, 0, 23, 0, 23, 0, 23, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} },
335{CCODE_JORDAN, {'J','O'}, { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
336 , { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} },
337{CCODE_KAZAKHSTAN, {'K','Z'}, { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
338 , { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} },
339{CCODE_KUWAIT, {'K','W'}, { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
340 , { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} },
341{CCODE_LATVIA, {'L','V'}, { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
342 , { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} },
343{CCODE_LEBANON, {'L','B'}, { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
344 , { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} },
345{CCODE_LEICHTENSTEIN, {'L','I'}, { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
346 , { 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 18, 0, 18, 0, 18, 0, 18, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} },
347{CCODE_LITHUANIA, {'L','T'}, { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0}
348 , { 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 20, 0, 20, 0, 20, 0, 20, 20, 20, 20, 20, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 0, 0, 0, 0, 0} },
349{CCODE_LUXEMBURG, {'L','U'}, { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0}
350 , { 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 20, 0, 20, 0, 20, 0, 20, 20, 20, 20, 20, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 0, 0, 0, 0, 0} },
351{CCODE_MACAU, {'M','O'}, { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1}
352 , { 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 23, 0, 23, 0, 23, 0, 23, 23, 23, 23, 23, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 30, 30, 30, 30, 30} },
353{CCODE_MACEDONIA, {'M','K'}, { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
354 , { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} },
355{CCODE_MALTA, {'M','T'}, { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0}
356 , { 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 16, 0, 16, 0, 16, 0, 16, 16, 16, 16, 16, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 16, 16, 16, 16, 0} },
357{CCODE_MALAYSIA, {'M','Y'}, { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
358 , { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} },
359{CCODE_MEXICO, {'M','X'}, { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1}
360 , { 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 17, 0, 17, 0, 17, 0, 17, 23, 23, 23, 23, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 30, 30, 30, 30, 30} },
361{CCODE_MONACO, {'M','C'}, { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
362 , { 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 18, 0, 18, 0, 18, 0, 18, 18, 18, 18, 18, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} },
363{CCODE_MOROCCO, {'M','A'}, { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
364 , { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} },
365{CCODE_NETHERLANDS, {'N','L'}, { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0}
366 , { 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 20, 0, 20, 0, 20, 0, 20, 20, 20, 20, 20, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 0, 0, 0, 0, 0} },
367{CCODE_NEW_ZEALAND, {'N','Z'}, { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1}
368 , { 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 23, 0, 23, 0, 23, 0, 23, 23, 23, 23, 23, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 30, 30, 30, 30, 30} },
369{CCODE_NORTH_KOREA, {'K','P'}, { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0}
370 , { 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 23, 23, 23, 23, 0} },
371{CCODE_NORWAY, {'N','O'}, { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0}
372 , { 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 20, 0, 20, 0, 20, 0, 20, 20, 20, 20, 20, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 0, 0, 0, 0, 0} },
373{CCODE_OMAN, {'O','M'}, { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
374 , { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} },
375{CCODE_PAKISTAN, {'P','K'}, { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
376 , { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} },
377{CCODE_PANAMA, {'P','A'}, { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1}
378 , { 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 17, 0, 17, 0, 17, 0, 17, 23, 23, 23, 23, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 30, 30, 30, 30, 30} },
379{CCODE_PERU, {'P','E'}, { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
380 , { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} },
381{CCODE_PHILIPPINES, {'P','H'}, { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1}
382 , { 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 17, 0, 17, 0, 17, 0, 17, 23, 23, 23, 23, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 30, 30, 30, 30, 30} },
383{CCODE_POLAND, {'P','L'}, { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0}
384 , { 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 20, 0, 20, 0, 20, 0, 20, 20, 20, 20, 20, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 0, 0, 0, 0, 0} },
385{CCODE_PORTUGAL, {'P','T'}, { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0}
386 , { 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 20, 0, 20, 0, 20, 0, 20, 20, 20, 20, 20, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 0, 0, 0, 0, 0} },
387{CCODE_PUERTO_RICO, {'P','R'}, { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1}
388 , { 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 17, 0, 17, 0, 17, 0, 17, 23, 23, 23, 23, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 30, 30, 30, 30, 30} },
389{CCODE_QATAR, {'Q','A'}, { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
390 , { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} },
391{CCODE_ROMANIA, {'R','O'}, { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
392 , { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} },
393{CCODE_RUSSIA, {'R','U'}, { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
394 , { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} },
395{CCODE_SAUDI_ARABIA, {'S','A'}, { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
396 , { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} },
397{CCODE_SINGAPORE, {'S','G'}, { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1}
398 , { 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 20, 0, 20, 0, 20, 0, 20, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 20, 20, 20, 20, 20} },
399{CCODE_SLOVAKIA, {'S','K'}, { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0}
400 , { 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 16, 0, 16, 0, 16, 0, 16, 16, 16, 16, 16, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 16, 16, 16, 16, 0} },
401{CCODE_SLOVENIA, {'S','I'}, { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0}
402 , { 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 20, 0, 20, 0, 20, 0, 20, 20, 20, 20, 20, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 0, 0, 0, 0, 0} },
403{CCODE_SOUTH_AFRICA, {'Z','A'}, { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0}
404 , { 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 20, 0, 20, 0, 20, 0, 20, 20, 20, 20, 20, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 0, 0, 0, 0, 0} },
405{CCODE_SOUTH_KOREA, {'K','R'}, { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0}
406 , { 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 23, 23, 23, 23, 0} },
407{CCODE_SPAIN, {'E','S'}, { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0}
408 , { 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 16, 0, 16, 0, 16, 0, 16, 16, 16, 16, 16, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 16, 16, 16, 16, 0} },
409{CCODE_SWEDEN, {'S','E'}, { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0}
410 , { 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 20, 0, 20, 0, 20, 0, 20, 20, 20, 20, 20, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 0, 0, 0, 0, 0} },
411{CCODE_SWITZERLAND, {'C','H'}, { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
412 , { 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 18, 0, 18, 0, 18, 0, 18, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} },
413{CCODE_SYRIA, {'S','Y'}, { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
414 , { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} },
415{CCODE_TAIWAN, {'T','W'}, { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0}
416 , { 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 17, 17, 17, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 30, 30, 30, 30, 0} },
417{CCODE_THAILAND, {'T','H'}, { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0}
418 , { 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 23, 23, 23, 23, 0} },
419{CCODE_TRINIDAD_TOBAGO, {'T','T'}, { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
420 , { 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 18, 0, 18, 0, 18, 0, 18, 18, 18, 18, 18, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} },
421{CCODE_TUNISIA, {'T','N'}, { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
422 , { 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 20, 0, 20, 0, 20, 0, 20, 20, 20, 20, 20, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} },
423{CCODE_TURKEY, {'T','R'}, { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
424 , { 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 20, 0, 20, 0, 20, 0, 20, 20, 20, 20, 20, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} },
425{CCODE_UK, {'G','B'}, { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0}
426 , { 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 20, 0, 20, 0, 20, 0, 20, 20, 20, 20, 20, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 0, 0, 0, 0, 0} },
427{CCODE_UKRAINE, {'U','A'}, { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
428 , { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} },
429{CCODE_UNITED_ARAB_EMIRATES, {'A','E'}, { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
430 , { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} },
431{CCODE_UNITED_STATES, {'U','S'}, { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1}
432 , { 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 17, 0, 17, 0, 17, 0, 17, 23, 23, 23, 23, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 30, 30, 30, 30, 30} },
433{CCODE_URUGUAY, {'U','Y'}, { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0}
434 , { 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 23, 23, 23, 23, 0} },
435{CCODE_UZBEKISTAN, {'U','Z'}, { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
436 , { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} },
437{CCODE_VENEZUELA, {'V','E'}, { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0}
438 , { 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 23, 23, 23, 23, 0} },
439{CCODE_VIETNAM, {'V','N'}, { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
440 , { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} },
441{CCODE_YEMEN, {'Y','E'}, { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
442 , { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} },
443{CCODE_ZIMBABWE, {'Z','W'}, { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
444 , { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} },
445{CCODE_JAPAN_W52_W53, {'J','J'}, { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
446 , { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} },
447{CCODE_MAX, {'U','N'}, { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}
448 , { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} }
449/* 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 */
450};
451
452
453/*--------------------- Static Functions --------------------------*/
454
455static
456VOID
457s_vCaculateOFDMRParameter(
458 IN BYTE byRate,
459 IN CARD_PHY_TYPE ePHYType,
460 OUT PBYTE pbyTxRate,
461 OUT PBYTE pbyRsvTime
462 );
463
464
465/*--------------------- Export Variables --------------------------*/
466
467/*--------------------- Export Functions --------------------------*/
468
469
470/*--------------------- Export function -------------------------*/
471/************************************************************************
472 * Country Channel Valid
473 * Input: CountryCode, ChannelNum
474 * ChanneIndex is defined as VT3253 MAC channel:
475 * 1 = 2.4G channel 1
476 * 2 = 2.4G channel 2
477 * ...
478 * 14 = 2.4G channel 14
479 * 15 = 4.9G channel 183
480 * 16 = 4.9G channel 184
481 * .....
482 * Output: TRUE if the specified 5GHz band is allowed to be used.
483 False otherwise.
484// 4.9G => Ch 183, 184, 185, 187, 188, 189, 192, 196 (Value:15 ~ 22)
485
486// 5G => Ch 7, 8, 9, 11, 12, 16, 34, 36, 38, 40, 42, 44, 46, 48, 52, 56, 60, 64,
487// 100, 104, 108, 112, 116, 120, 124, 128, 132, 136, 140, 149, 153, 157, 161, 165 (Value 23 ~ 56)
488 ************************************************************************/
489//2008-8-4 <add> by chester
490BOOL
491ChannelValid(UINT CountryCode, UINT ChannelIndex)
492{
493 BOOL bValid;
494
495 bValid = FALSE;
496 /*
497 * If Channel Index is invalid, return invalid
498 */
499 if ((ChannelIndex > CB_MAX_CHANNEL) ||
500 (ChannelIndex == 0))
501 {
502 bValid = FALSE;
503 goto exit;
504 }
505
506 bValid = sChannelTbl[ChannelIndex].bValid;
507
508exit:
509 return (bValid);
510
511} /* end ChannelValid */
512
513
514/*
515 * Description: Caculate TxRate and RsvTime fields for RSPINF in OFDM mode.
516 *
517 * Parameters:
518 * In:
519 * wRate - Tx Rate
520 * byPktType - Tx Packet type
521 * Out:
522 * pbyTxRate - pointer to RSPINF TxRate field
523 * pbyRsvTime - pointer to RSPINF RsvTime field
524 *
525 * Return Value: none
526 *
527 */
528static
529VOID
530s_vCaculateOFDMRParameter (
531 IN BYTE byRate,
532 IN CARD_PHY_TYPE ePHYType,
533 OUT PBYTE pbyTxRate,
534 OUT PBYTE pbyRsvTime
535 )
536{
537 switch (byRate) {
538 case RATE_6M :
539 if (ePHYType == PHY_TYPE_11A) {//5GHZ
540 *pbyTxRate = 0x9B;
541 *pbyRsvTime = 44;
542 }
543 else {
544 *pbyTxRate = 0x8B;
545 *pbyRsvTime = 50;
546 }
547 break;
548
549 case RATE_9M :
550 if (ePHYType == PHY_TYPE_11A) {//5GHZ
551 *pbyTxRate = 0x9F;
552 *pbyRsvTime = 36;
553 }
554 else {
555 *pbyTxRate = 0x8F;
556 *pbyRsvTime = 42;
557 }
558 break;
559
560 case RATE_12M :
561 if (ePHYType == PHY_TYPE_11A) {//5GHZ
562 *pbyTxRate = 0x9A;
563 *pbyRsvTime = 32;
564 }
565 else {
566 *pbyTxRate = 0x8A;
567 *pbyRsvTime = 38;
568 }
569 break;
570
571 case RATE_18M :
572 if (ePHYType == PHY_TYPE_11A) {//5GHZ
573 *pbyTxRate = 0x9E;
574 *pbyRsvTime = 28;
575 }
576 else {
577 *pbyTxRate = 0x8E;
578 *pbyRsvTime = 34;
579 }
580 break;
581
582 case RATE_36M :
583 if (ePHYType == PHY_TYPE_11A) {//5GHZ
584 *pbyTxRate = 0x9D;
585 *pbyRsvTime = 24;
586 }
587 else {
588 *pbyTxRate = 0x8D;
589 *pbyRsvTime = 30;
590 }
591 break;
592
593 case RATE_48M :
594 if (ePHYType == PHY_TYPE_11A) {//5GHZ
595 *pbyTxRate = 0x98;
596 *pbyRsvTime = 24;
597 }
598 else {
599 *pbyTxRate = 0x88;
600 *pbyRsvTime = 30;
601 }
602 break;
603
604 case RATE_54M :
605 if (ePHYType == PHY_TYPE_11A) {//5GHZ
606 *pbyTxRate = 0x9C;
607 *pbyRsvTime = 24;
608 }
609 else {
610 *pbyTxRate = 0x8C;
611 *pbyRsvTime = 30;
612 }
613 break;
614
615 case RATE_24M :
616 default :
617 if (ePHYType == PHY_TYPE_11A) {//5GHZ
618 *pbyTxRate = 0x99;
619 *pbyRsvTime = 28;
620 }
621 else {
622 *pbyTxRate = 0x89;
623 *pbyRsvTime = 34;
624 }
625 break;
626 }
627}
628
629
630
631/*
632 * Description: Set RSPINF
633 *
634 * Parameters:
635 * In:
636 * pDevice - The adapter to be set
637 * Out:
638 * none
639 *
640 * Return Value: None.
641 *
642 */
643static
644VOID
645s_vSetRSPINF (PSDevice pDevice, CARD_PHY_TYPE ePHYType, PVOID pvSupportRateIEs, PVOID pvExtSupportRateIEs)
646{
647 BYTE byServ = 0, bySignal = 0; // For CCK
648 WORD wLen = 0;
649 BYTE byTxRate = 0, byRsvTime = 0; // For OFDM
650
651 //Set to Page1
652 MACvSelectPage1(pDevice->PortOffset);
653
654 //RSPINF_b_1
655 BBvCaculateParameter(pDevice,
656 14,
657 VNTWIFIbyGetACKTxRate(RATE_1M, pvSupportRateIEs, pvExtSupportRateIEs),
658 PK_TYPE_11B,
659 &wLen,
660 &byServ,
661 &bySignal
662 );
663
664 VNSvOutPortD(pDevice->PortOffset + MAC_REG_RSPINF_B_1, MAKEDWORD(wLen,MAKEWORD(bySignal,byServ)));
665 ///RSPINF_b_2
666 BBvCaculateParameter(pDevice,
667 14,
668 VNTWIFIbyGetACKTxRate(RATE_2M, pvSupportRateIEs, pvExtSupportRateIEs),
669 PK_TYPE_11B,
670 &wLen,
671 &byServ,
672 &bySignal
673 );
674
675 VNSvOutPortD(pDevice->PortOffset + MAC_REG_RSPINF_B_2, MAKEDWORD(wLen,MAKEWORD(bySignal,byServ)));
676 //RSPINF_b_5
677 BBvCaculateParameter(pDevice,
678 14,
679 VNTWIFIbyGetACKTxRate(RATE_5M, pvSupportRateIEs, pvExtSupportRateIEs),
680 PK_TYPE_11B,
681 &wLen,
682 &byServ,
683 &bySignal
684 );
685
686 VNSvOutPortD(pDevice->PortOffset + MAC_REG_RSPINF_B_5, MAKEDWORD(wLen,MAKEWORD(bySignal,byServ)));
687 //RSPINF_b_11
688 BBvCaculateParameter(pDevice,
689 14,
690 VNTWIFIbyGetACKTxRate(RATE_11M, pvSupportRateIEs, pvExtSupportRateIEs),
691 PK_TYPE_11B,
692 &wLen,
693 &byServ,
694 &bySignal
695 );
696
697 VNSvOutPortD(pDevice->PortOffset + MAC_REG_RSPINF_B_11, MAKEDWORD(wLen,MAKEWORD(bySignal,byServ)));
698 //RSPINF_a_6
699 s_vCaculateOFDMRParameter(RATE_6M,
700 ePHYType,
701 &byTxRate,
702 &byRsvTime);
703 VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_6, MAKEWORD(byTxRate,byRsvTime));
704 //RSPINF_a_9
705 s_vCaculateOFDMRParameter(RATE_9M,
706 ePHYType,
707 &byTxRate,
708 &byRsvTime);
709 VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_9, MAKEWORD(byTxRate,byRsvTime));
710 //RSPINF_a_12
711 s_vCaculateOFDMRParameter(RATE_12M,
712 ePHYType,
713 &byTxRate,
714 &byRsvTime);
715 VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_12, MAKEWORD(byTxRate,byRsvTime));
716 //RSPINF_a_18
717 s_vCaculateOFDMRParameter(RATE_18M,
718 ePHYType,
719 &byTxRate,
720 &byRsvTime);
721 VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_18, MAKEWORD(byTxRate,byRsvTime));
722 //RSPINF_a_24
723 s_vCaculateOFDMRParameter(RATE_24M,
724 ePHYType,
725 &byTxRate,
726 &byRsvTime);
727 VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_24, MAKEWORD(byTxRate,byRsvTime));
728 //RSPINF_a_36
729 s_vCaculateOFDMRParameter(
730 VNTWIFIbyGetACKTxRate(RATE_36M, pvSupportRateIEs, pvExtSupportRateIEs),
731 ePHYType,
732 &byTxRate,
733 &byRsvTime);
734 VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_36, MAKEWORD(byTxRate,byRsvTime));
735 //RSPINF_a_48
736 s_vCaculateOFDMRParameter(
737 VNTWIFIbyGetACKTxRate(RATE_48M, pvSupportRateIEs, pvExtSupportRateIEs),
738 ePHYType,
739 &byTxRate,
740 &byRsvTime);
741 VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_48, MAKEWORD(byTxRate,byRsvTime));
742 //RSPINF_a_54
743 s_vCaculateOFDMRParameter(
744 VNTWIFIbyGetACKTxRate(RATE_54M, pvSupportRateIEs, pvExtSupportRateIEs),
745 ePHYType,
746 &byTxRate,
747 &byRsvTime);
748 VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_54, MAKEWORD(byTxRate,byRsvTime));
749 //RSPINF_a_72
750 VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_72, MAKEWORD(byTxRate,byRsvTime));
751 //Set to Page0
752 MACvSelectPage0(pDevice->PortOffset);
753}
754
755
756
757
758/*--------------------- Export Variables --------------------------*/
759
760/*--------------------- Export Functions --------------------------*/
761BYTE CARDbyGetChannelMapping (PVOID pDeviceHandler, BYTE byChannelNumber, CARD_PHY_TYPE ePhyType)
762{
763 UINT ii;
764
765 if ((ePhyType == PHY_TYPE_11B) || (ePhyType == PHY_TYPE_11G)) {
766 return (byChannelNumber);
767 }
768
769 for(ii = (CB_MAX_CHANNEL_24G + 1); ii <= CB_MAX_CHANNEL; ) {
770 if (sChannelTbl[ii].byChannelNumber == byChannelNumber) {
771 return ((BYTE) ii);
772 }
773 ii++;
774 }
775 return (0);
776}
777
778
779BYTE CARDbyGetChannelNumber (PVOID pDeviceHandler, BYTE byChannelIndex)
780{
781// PSDevice pDevice = (PSDevice) pDeviceHandler;
782 return(sChannelTbl[byChannelIndex].byChannelNumber);
783}
784
785/*
786 * Description: Set NIC media channel
787 *
788 * Parameters:
789 * In:
790 * pDeviceHandler - The adapter to be set
791 * uConnectionChannel - Channel to be set
792 * Out:
793 * none
794 *
795 * Return Value: TRUE if succeeded; FALSE if failed.
796 *
797 */
798BOOL CARDbSetChannel (PVOID pDeviceHandler, UINT uConnectionChannel)
799{
800 PSDevice pDevice = (PSDevice) pDeviceHandler;
801 BOOL bResult = TRUE;
802
803
804 if (pDevice->byCurrentCh == uConnectionChannel) {
805 return bResult;
806 }
807
808 if (sChannelTbl[uConnectionChannel].bValid == FALSE) {
809 return (FALSE);
810 }
811
812 if ((uConnectionChannel > CB_MAX_CHANNEL_24G) &&
813 (pDevice->eCurrentPHYType != PHY_TYPE_11A)) {
814 CARDbSetPhyParameter(pDevice, PHY_TYPE_11A, 0, 0, NULL, NULL);
815 } else if ((uConnectionChannel <= CB_MAX_CHANNEL_24G) &&
816 (pDevice->eCurrentPHYType == PHY_TYPE_11A)) {
817 CARDbSetPhyParameter(pDevice, PHY_TYPE_11G, 0, 0, NULL, NULL);
818 }
819 // clear NAV
820 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_MACCR, MACCR_CLRNAV);
821
822 //{{ RobertYu: 20041202
823 //// TX_PE will reserve 3 us for MAX2829 A mode only, it is for better TX throughput
824
825 if ( pDevice->byRFType == RF_AIROHA7230 )
826 {
827 RFbAL7230SelectChannelPostProcess(pDevice->PortOffset, pDevice->byCurrentCh, (BYTE)uConnectionChannel);
828 }
829 //}} RobertYu
830
831
832 pDevice->byCurrentCh = (BYTE)uConnectionChannel;
833 bResult &= RFbSelectChannel(pDevice->PortOffset, pDevice->byRFType, (BYTE)uConnectionChannel);
834
835 // Init Synthesizer Table
836 if (pDevice->bEnablePSMode == TRUE)
837 RFvWriteWakeProgSyn(pDevice->PortOffset, pDevice->byRFType, uConnectionChannel);
838
839
840 //DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"CARDbSetMediaChannel: %d\n", (BYTE)uConnectionChannel);
841 BBvSoftwareReset(pDevice->PortOffset);
842
843 if (pDevice->byLocalID > REV_ID_VT3253_B1) {
844 // set HW default power register
845 MACvSelectPage1(pDevice->PortOffset);
846 RFbSetPower(pDevice, RATE_1M, pDevice->byCurrentCh);
847 VNSvOutPortB(pDevice->PortOffset + MAC_REG_PWRCCK, pDevice->byCurPwr);
848 RFbSetPower(pDevice, RATE_6M, pDevice->byCurrentCh);
849 VNSvOutPortB(pDevice->PortOffset + MAC_REG_PWROFDM, pDevice->byCurPwr);
850 MACvSelectPage0(pDevice->PortOffset);
851 }
852
853 if (pDevice->eCurrentPHYType == PHY_TYPE_11B) {
854#ifdef PLICE_DEBUG
855 //printk("Func:CARDbSetChannel:call RFbSetPower:11B\n");
856#endif
857 RFbSetPower(pDevice, RATE_1M, pDevice->byCurrentCh);
858 } else {
859#ifdef PLICE_DEBUG
860 //printk("Func:CARDbSetChannel:call RFbSetPower\n");
861#endif
862 RFbSetPower(pDevice, RATE_6M, pDevice->byCurrentCh);
863 }
864
865 return(bResult);
866}
867
868
869
870/*
871 * Description: Card Send packet function
872 *
873 * Parameters:
874 * In:
875 * pDeviceHandler - The adapter to be set
876 * pPacket - Packet buffer pointer
877 * ePktType - Packet type
878 * uLength - Packet length
879 * Out:
880 * none
881 *
882 * Return Value: TRUE if succeeded; FALSE if failed.
883 *
884 */
885/*
886BOOL CARDbSendPacket (PVOID pDeviceHandler, PVOID pPacket, CARD_PKT_TYPE ePktType, UINT uLength)
887{
888 PSDevice pDevice = (PSDevice) pDeviceHandler;
889 if (ePktType == PKT_TYPE_802_11_MNG) {
890 return TXbTD0Send(pDevice, pPacket, uLength);
891 } else if (ePktType == PKT_TYPE_802_11_BCN) {
892 return TXbBeaconSend(pDevice, pPacket, uLength);
893 } if (ePktType == PKT_TYPE_802_11_DATA) {
894 return TXbTD1Send(pDevice, pPacket, uLength);
895 }
896
897 return (TRUE);
898}
899*/
900
901
902/*
903 * Description: Get Card short preamble option value
904 *
905 * Parameters:
906 * In:
907 * pDevice - The adapter to be set
908 * Out:
909 * none
910 *
911 * Return Value: TRUE if short preamble; otherwise FALSE
912 *
913 */
914BOOL CARDbIsShortPreamble (PVOID pDeviceHandler)
915{
916 PSDevice pDevice = (PSDevice) pDeviceHandler;
917 if (pDevice->byPreambleType == 0) {
918 return(FALSE);
919 }
920 return(TRUE);
921}
922
923/*
924 * Description: Get Card short slot time option value
925 *
926 * Parameters:
927 * In:
928 * pDevice - The adapter to be set
929 * Out:
930 * none
931 *
932 * Return Value: TRUE if short slot time; otherwise FALSE
933 *
934 */
935BOOL CARDbIsShorSlotTime (PVOID pDeviceHandler)
936{
937 PSDevice pDevice = (PSDevice) pDeviceHandler;
938 return(pDevice->bShortSlotTime);
939}
940
941
942/*
943 * Description: Update IFS
944 *
945 * Parameters:
946 * In:
947 * pDevice - The adapter to be set
948 * Out:
949 * none
950 *
951 * Return Value: None.
952 *
953 */
954BOOL CARDbSetPhyParameter (PVOID pDeviceHandler, CARD_PHY_TYPE ePHYType, WORD wCapInfo, BYTE byERPField, PVOID pvSupportRateIEs, PVOID pvExtSupportRateIEs)
955{
956 PSDevice pDevice = (PSDevice) pDeviceHandler;
957 BYTE byCWMaxMin = 0;
958 BYTE bySlot = 0;
959 BYTE bySIFS = 0;
960 BYTE byDIFS = 0;
961 BYTE byData;
962// PWLAN_IE_SUPP_RATES pRates = NULL;
963 PWLAN_IE_SUPP_RATES pSupportRates = (PWLAN_IE_SUPP_RATES) pvSupportRateIEs;
964 PWLAN_IE_SUPP_RATES pExtSupportRates = (PWLAN_IE_SUPP_RATES) pvExtSupportRateIEs;
965
966
967 //Set SIFS, DIFS, EIFS, SlotTime, CwMin
968 if (ePHYType == PHY_TYPE_11A) {
969 if (pSupportRates == NULL) {
970 pSupportRates = (PWLAN_IE_SUPP_RATES) abyDefaultSuppRatesA;
971 }
972 if (pDevice->byRFType == RF_AIROHA7230) {
973 // AL7230 use single PAPE and connect to PAPE_2.4G
974 MACvSetBBType(pDevice->PortOffset, BB_TYPE_11G);
975 pDevice->abyBBVGA[0] = 0x20;
976 pDevice->abyBBVGA[2] = 0x10;
977 pDevice->abyBBVGA[3] = 0x10;
978 BBbReadEmbeded(pDevice->PortOffset, 0xE7, &byData);
979 if (byData == 0x1C) {
980 BBbWriteEmbeded(pDevice->PortOffset, 0xE7, pDevice->abyBBVGA[0]);
981 }
982 } else if (pDevice->byRFType == RF_UW2452) {
983 MACvSetBBType(pDevice->PortOffset, BB_TYPE_11A);
984 pDevice->abyBBVGA[0] = 0x18;
985 BBbReadEmbeded(pDevice->PortOffset, 0xE7, &byData);
986 if (byData == 0x14) {
987 BBbWriteEmbeded(pDevice->PortOffset, 0xE7, pDevice->abyBBVGA[0]);
988 BBbWriteEmbeded(pDevice->PortOffset, 0xE1, 0x57);
989 }
990 } else {
991 MACvSetBBType(pDevice->PortOffset, BB_TYPE_11A);
992 }
993 BBbWriteEmbeded(pDevice->PortOffset, 0x88, 0x03);
994 bySlot = C_SLOT_SHORT;
995 bySIFS = C_SIFS_A;
996 byDIFS = C_SIFS_A + 2*C_SLOT_SHORT;
997 byCWMaxMin = 0xA4;
998 } else if (ePHYType == PHY_TYPE_11B) {
999 if (pSupportRates == NULL) {
1000 pSupportRates = (PWLAN_IE_SUPP_RATES) abyDefaultSuppRatesB;
1001 }
1002 MACvSetBBType(pDevice->PortOffset, BB_TYPE_11B);
1003 if (pDevice->byRFType == RF_AIROHA7230) {
1004 pDevice->abyBBVGA[0] = 0x1C;
1005 pDevice->abyBBVGA[2] = 0x00;
1006 pDevice->abyBBVGA[3] = 0x00;
1007 BBbReadEmbeded(pDevice->PortOffset, 0xE7, &byData);
1008 if (byData == 0x20) {
1009 BBbWriteEmbeded(pDevice->PortOffset, 0xE7, pDevice->abyBBVGA[0]);
1010 }
1011 } else if (pDevice->byRFType == RF_UW2452) {
1012 pDevice->abyBBVGA[0] = 0x14;
1013 BBbReadEmbeded(pDevice->PortOffset, 0xE7, &byData);
1014 if (byData == 0x18) {
1015 BBbWriteEmbeded(pDevice->PortOffset, 0xE7, pDevice->abyBBVGA[0]);
1016 BBbWriteEmbeded(pDevice->PortOffset, 0xE1, 0xD3);
1017 }
1018 }
1019 BBbWriteEmbeded(pDevice->PortOffset, 0x88, 0x02);
1020 bySlot = C_SLOT_LONG;
1021 bySIFS = C_SIFS_BG;
1022 byDIFS = C_SIFS_BG + 2*C_SLOT_LONG;
1023 byCWMaxMin = 0xA5;
1024 } else {// PK_TYPE_11GA & PK_TYPE_11GB
1025 if (pSupportRates == NULL) {
1026 pSupportRates = (PWLAN_IE_SUPP_RATES) abyDefaultSuppRatesG;
1027 pExtSupportRates = (PWLAN_IE_SUPP_RATES) abyDefaultExtSuppRatesG;
1028 }
1029 MACvSetBBType(pDevice->PortOffset, BB_TYPE_11G);
1030 if (pDevice->byRFType == RF_AIROHA7230) {
1031 pDevice->abyBBVGA[0] = 0x1C;
1032 pDevice->abyBBVGA[2] = 0x00;
1033 pDevice->abyBBVGA[3] = 0x00;
1034 BBbReadEmbeded(pDevice->PortOffset, 0xE7, &byData);
1035 if (byData == 0x20) {
1036 BBbWriteEmbeded(pDevice->PortOffset, 0xE7, pDevice->abyBBVGA[0]);
1037 }
1038 } else if (pDevice->byRFType == RF_UW2452) {
1039 pDevice->abyBBVGA[0] = 0x14;
1040 BBbReadEmbeded(pDevice->PortOffset, 0xE7, &byData);
1041 if (byData == 0x18) {
1042 BBbWriteEmbeded(pDevice->PortOffset, 0xE7, pDevice->abyBBVGA[0]);
1043 BBbWriteEmbeded(pDevice->PortOffset, 0xE1, 0xD3);
1044 }
1045 }
1046 BBbWriteEmbeded(pDevice->PortOffset, 0x88, 0x08);
1047 bySIFS = C_SIFS_BG;
1048 if(VNTWIFIbIsShortSlotTime(wCapInfo)) {
1049 bySlot = C_SLOT_SHORT;
1050 byDIFS = C_SIFS_BG + 2*C_SLOT_SHORT;
1051 } else {
1052 bySlot = C_SLOT_LONG;
1053 byDIFS = C_SIFS_BG + 2*C_SLOT_LONG;
1054 }
1055 if (VNTWIFIbyGetMaxSupportRate(pSupportRates, pExtSupportRates) > RATE_11M) {
1056 byCWMaxMin = 0xA4;
1057 } else {
1058 byCWMaxMin = 0xA5;
1059 }
1060 if (pDevice->bProtectMode != VNTWIFIbIsProtectMode(byERPField)) {
1061 pDevice->bProtectMode = VNTWIFIbIsProtectMode(byERPField);
1062 if (pDevice->bProtectMode) {
1063 MACvEnableProtectMD(pDevice->PortOffset);
1064 } else {
1065 MACvDisableProtectMD(pDevice->PortOffset);
1066 }
1067 }
1068 if (pDevice->bBarkerPreambleMd != VNTWIFIbIsBarkerMode(byERPField)) {
1069 pDevice->bBarkerPreambleMd = VNTWIFIbIsBarkerMode(byERPField);
1070 if (pDevice->bBarkerPreambleMd) {
1071 MACvEnableBarkerPreambleMd(pDevice->PortOffset);
1072 } else {
1073 MACvDisableBarkerPreambleMd(pDevice->PortOffset);
1074 }
1075 }
1076 }
1077
1078 if (pDevice->byRFType == RF_RFMD2959) {
1079 // bcs TX_PE will reserve 3 us
1080 // hardware's processing time here is 2 us.
1081 bySIFS -= 3;
1082 byDIFS -= 3;
1083 //{{ RobertYu: 20041202
1084 //// TX_PE will reserve 3 us for MAX2829 A mode only, it is for better TX throughput
1085 //// MAC will need 2 us to process, so the SIFS, DIFS can be shorter by 2 us.
1086 }
1087
1088 if (pDevice->bySIFS != bySIFS) {
1089 pDevice->bySIFS = bySIFS;
1090 VNSvOutPortB(pDevice->PortOffset + MAC_REG_SIFS, pDevice->bySIFS);
1091 }
1092 if (pDevice->byDIFS != byDIFS) {
1093 pDevice->byDIFS = byDIFS;
1094 VNSvOutPortB(pDevice->PortOffset + MAC_REG_DIFS, pDevice->byDIFS);
1095 }
1096 if (pDevice->byEIFS != C_EIFS) {
1097 pDevice->byEIFS = C_EIFS;
1098 VNSvOutPortB(pDevice->PortOffset + MAC_REG_EIFS, pDevice->byEIFS);
1099 }
1100 if (pDevice->bySlot != bySlot) {
1101 pDevice->bySlot = bySlot;
1102 VNSvOutPortB(pDevice->PortOffset + MAC_REG_SLOT, pDevice->bySlot);
1103 if (pDevice->bySlot == C_SLOT_SHORT) {
1104 pDevice->bShortSlotTime = TRUE;
1105 } else {
1106 pDevice->bShortSlotTime = FALSE;
1107 }
1108 BBvSetShortSlotTime(pDevice);
1109 }
1110 if (pDevice->byCWMaxMin != byCWMaxMin) {
1111 pDevice->byCWMaxMin = byCWMaxMin;
1112 VNSvOutPortB(pDevice->PortOffset + MAC_REG_CWMAXMIN0, pDevice->byCWMaxMin);
1113 }
1114 if (VNTWIFIbIsShortPreamble(wCapInfo)) {
1115 pDevice->byPreambleType = pDevice->byShortPreamble;
1116 } else {
1117 pDevice->byPreambleType = 0;
1118 }
1119 s_vSetRSPINF(pDevice, ePHYType, pSupportRates, pExtSupportRates);
1120 pDevice->eCurrentPHYType = ePHYType;
1121 // set for NDIS OID_802_11SUPPORTED_RATES
1122 return (TRUE);
1123}
1124
1125/*
1126 * Description: Sync. TSF counter to BSS
1127 * Get TSF offset and write to HW
1128 *
1129 * Parameters:
1130 * In:
1131 * pDevice - The adapter to be sync.
1132 * byRxRate - data rate of receive beacon
1133 * qwBSSTimestamp - Rx BCN's TSF
1134 * qwLocalTSF - Local TSF
1135 * Out:
1136 * none
1137 *
1138 * Return Value: none
1139 *
1140 */
1141BOOL CARDbUpdateTSF (PVOID pDeviceHandler, BYTE byRxRate, QWORD qwBSSTimestamp, QWORD qwLocalTSF)
1142{
1143 PSDevice pDevice = (PSDevice) pDeviceHandler;
1144 QWORD qwTSFOffset;
1145
1146 HIDWORD(qwTSFOffset) = 0;
1147 LODWORD(qwTSFOffset) = 0;
1148
1149 if ((HIDWORD(qwBSSTimestamp) != HIDWORD(qwLocalTSF)) ||
1150 (LODWORD(qwBSSTimestamp) != LODWORD(qwLocalTSF))) {
1151 qwTSFOffset = CARDqGetTSFOffset(byRxRate, qwBSSTimestamp, qwLocalTSF);
1152 // adjust TSF
1153 // HW's TSF add TSF Offset reg
1154 VNSvOutPortD(pDevice->PortOffset + MAC_REG_TSFOFST, LODWORD(qwTSFOffset));
1155 VNSvOutPortD(pDevice->PortOffset + MAC_REG_TSFOFST + 4, HIDWORD(qwTSFOffset));
1156 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_TFTCTL, TFTCTL_TSFSYNCEN);
1157 }
1158 return(TRUE);
1159}
1160
1161
1162/*
1163 * Description: Set NIC TSF counter for first Beacon time
1164 * Get NEXTTBTT from adjusted TSF and Beacon Interval
1165 *
1166 * Parameters:
1167 * In:
1168 * pDevice - The adapter to be set.
1169 * wBeaconInterval - Beacon Interval
1170 * Out:
1171 * none
1172 *
1173 * Return Value: TRUE if succeed; otherwise FALSE
1174 *
1175 */
1176BOOL CARDbSetBeaconPeriod (PVOID pDeviceHandler, WORD wBeaconInterval)
1177{
1178 PSDevice pDevice = (PSDevice) pDeviceHandler;
1179 UINT uBeaconInterval = 0;
1180 UINT uLowNextTBTT = 0;
1181 UINT uHighRemain = 0;
1182 UINT uLowRemain = 0;
1183 QWORD qwNextTBTT;
1184
1185 HIDWORD(qwNextTBTT) = 0;
1186 LODWORD(qwNextTBTT) = 0;
1187 CARDbGetCurrentTSF(pDevice->PortOffset, &qwNextTBTT); //Get Local TSF counter
1188 uBeaconInterval = wBeaconInterval * 1024;
1189 // Next TBTT = ((local_current_TSF / beacon_interval) + 1 ) * beacon_interval
1190 uLowNextTBTT = (LODWORD(qwNextTBTT) >> 10) << 10;
1191 uLowRemain = (uLowNextTBTT) % uBeaconInterval;
1192 // high dword (mod) bcn
1193 uHighRemain = (((0xffffffff % uBeaconInterval) + 1) * HIDWORD(qwNextTBTT))
1194 % uBeaconInterval;
1195 uLowRemain = (uHighRemain + uLowRemain) % uBeaconInterval;
1196 uLowRemain = uBeaconInterval - uLowRemain;
1197
1198 // check if carry when add one beacon interval
1199 if ((~uLowNextTBTT) < uLowRemain) {
1200 HIDWORD(qwNextTBTT) ++ ;
1201 }
1202 LODWORD(qwNextTBTT) = uLowNextTBTT + uLowRemain;
1203
1204 // set HW beacon interval
1205 VNSvOutPortW(pDevice->PortOffset + MAC_REG_BI, wBeaconInterval);
1206 pDevice->wBeaconInterval = wBeaconInterval;
1207 // Set NextTBTT
1208 VNSvOutPortD(pDevice->PortOffset + MAC_REG_NEXTTBTT, LODWORD(qwNextTBTT));
1209 VNSvOutPortD(pDevice->PortOffset + MAC_REG_NEXTTBTT + 4, HIDWORD(qwNextTBTT));
1210 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_TFTCTL, TFTCTL_TBTTSYNCEN);
1211
1212 return(TRUE);
1213}
1214
1215
1216
1217/*
1218 * Description: Card Stop Hardware Tx
1219 *
1220 * Parameters:
1221 * In:
1222 * pDeviceHandler - The adapter to be set
1223 * ePktType - Packet type to stop
1224 * Out:
1225 * none
1226 *
1227 * Return Value: TRUE if all data packet complete; otherwise FALSE.
1228 *
1229 */
1230BOOL CARDbStopTxPacket (PVOID pDeviceHandler, CARD_PKT_TYPE ePktType)
1231{
1232 PSDevice pDevice = (PSDevice) pDeviceHandler;
1233
1234
1235 if (ePktType == PKT_TYPE_802_11_ALL) {
1236 pDevice->bStopBeacon = TRUE;
1237 pDevice->bStopTx0Pkt = TRUE;
1238 pDevice->bStopDataPkt = TRUE;
1239 } else if (ePktType == PKT_TYPE_802_11_BCN) {
1240 pDevice->bStopBeacon = TRUE;
1241 } else if (ePktType == PKT_TYPE_802_11_MNG) {
1242 pDevice->bStopTx0Pkt = TRUE;
1243 } else if (ePktType == PKT_TYPE_802_11_DATA) {
1244 pDevice->bStopDataPkt = TRUE;
1245 }
1246
1247 if (pDevice->bStopBeacon == TRUE) {
1248 if (pDevice->bIsBeaconBufReadySet == TRUE) {
1249 if (pDevice->cbBeaconBufReadySetCnt < WAIT_BEACON_TX_DOWN_TMO) {
1250 pDevice->cbBeaconBufReadySetCnt ++;
1251 return(FALSE);
1252 }
1253 }
1254 pDevice->bIsBeaconBufReadySet = FALSE;
1255 pDevice->cbBeaconBufReadySetCnt = 0;
1256 MACvRegBitsOff(pDevice->PortOffset, MAC_REG_TCR, TCR_AUTOBCNTX);
1257 }
1258 // wait all TD0 complete
1259 if (pDevice->bStopTx0Pkt == TRUE) {
1260 if (pDevice->iTDUsed[TYPE_TXDMA0] != 0){
1261 return(FALSE);
1262 }
1263 }
1264 // wait all Data TD complete
1265 if (pDevice->bStopDataPkt == TRUE) {
1266 if (pDevice->iTDUsed[TYPE_AC0DMA] != 0){
1267 return(FALSE);
1268 }
1269 }
1270
1271 return(TRUE);
1272}
1273
1274
1275/*
1276 * Description: Card Start Hardware Tx
1277 *
1278 * Parameters:
1279 * In:
1280 * pDeviceHandler - The adapter to be set
1281 * ePktType - Packet type to start
1282 * Out:
1283 * none
1284 *
1285 * Return Value: TRUE if success; FALSE if failed.
1286 *
1287 */
1288BOOL CARDbStartTxPacket (PVOID pDeviceHandler, CARD_PKT_TYPE ePktType)
1289{
1290 PSDevice pDevice = (PSDevice) pDeviceHandler;
1291
1292
1293 if (ePktType == PKT_TYPE_802_11_ALL) {
1294 pDevice->bStopBeacon = FALSE;
1295 pDevice->bStopTx0Pkt = FALSE;
1296 pDevice->bStopDataPkt = FALSE;
1297 } else if (ePktType == PKT_TYPE_802_11_BCN) {
1298 pDevice->bStopBeacon = FALSE;
1299 } else if (ePktType == PKT_TYPE_802_11_MNG) {
1300 pDevice->bStopTx0Pkt = FALSE;
1301 } else if (ePktType == PKT_TYPE_802_11_DATA) {
1302 pDevice->bStopDataPkt = FALSE;
1303 }
1304
1305 if ((pDevice->bStopBeacon == FALSE) &&
1306 (pDevice->bBeaconBufReady == TRUE) &&
1307 (pDevice->eOPMode == OP_MODE_ADHOC)) {
1308 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_TCR, TCR_AUTOBCNTX);
1309 }
1310
1311 return(TRUE);
1312}
1313
1314
1315
1316/*
1317 * Description: Card Set BSSID value
1318 *
1319 * Parameters:
1320 * In:
1321 * pDeviceHandler - The adapter to be set
1322 * pbyBSSID - pointer to BSSID field
1323 * bAdhoc - flag to indicate IBSS
1324 * Out:
1325 * none
1326 *
1327 * Return Value: TRUE if success; FALSE if failed.
1328 *
1329 */
1330BOOL CARDbSetBSSID(PVOID pDeviceHandler, PBYTE pbyBSSID, CARD_OP_MODE eOPMode)
1331{
1332 PSDevice pDevice = (PSDevice) pDeviceHandler;
1333
1334 MACvWriteBSSIDAddress(pDevice->PortOffset, pbyBSSID);
1335 MEMvCopy(pDevice->abyBSSID, pbyBSSID, WLAN_BSSID_LEN);
1336 if (eOPMode == OP_MODE_ADHOC) {
1337 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_HOSTCR, HOSTCR_ADHOC);
1338 } else {
1339 MACvRegBitsOff(pDevice->PortOffset, MAC_REG_HOSTCR, HOSTCR_ADHOC);
1340 }
1341 if (eOPMode == OP_MODE_AP) {
1342 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_HOSTCR, HOSTCR_AP);
1343 } else {
1344 MACvRegBitsOff(pDevice->PortOffset, MAC_REG_HOSTCR, HOSTCR_AP);
1345 }
1346 if (eOPMode == OP_MODE_UNKNOWN) {
1347 MACvRegBitsOff(pDevice->PortOffset, MAC_REG_RCR, RCR_BSSID);
1348 pDevice->bBSSIDFilter = FALSE;
1349 pDevice->byRxMode &= ~RCR_BSSID;
1350 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "wcmd: rx_mode = %x\n", pDevice->byRxMode );
1351 } else {
1352 if (IS_NULL_ADDRESS(pDevice->abyBSSID) == FALSE) {
1353 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_RCR, RCR_BSSID);
1354 pDevice->bBSSIDFilter = TRUE;
1355 pDevice->byRxMode |= RCR_BSSID;
1356 }
1357 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "wmgr: rx_mode = %x\n", pDevice->byRxMode );
1358 }
1359 // Adopt BSS state in Adapter Device Object
1360 pDevice->eOPMode = eOPMode;
1361 return(TRUE);
1362}
1363
1364
1365/*
1366 * Description: Card indicate status
1367 *
1368 * Parameters:
1369 * In:
1370 * pDeviceHandler - The adapter to be set
1371 * eStatus - Status
1372 * Out:
1373 * none
1374 *
1375 * Return Value: TRUE if success; FALSE if failed.
1376 *
1377 */
1378
1379
1380
1381
1382/*
1383 * Description: Save Assoc info. contain in assoc. response frame
1384 *
1385 * Parameters:
1386 * In:
1387 * pDevice - The adapter to be set
1388 * wCapabilityInfo - Capability information
1389 * wStatus - Status code
1390 * wAID - Assoc. ID
1391 * uLen - Length of IEs
1392 * pbyIEs - pointer to IEs
1393 * Out:
1394 * none
1395 *
1396 * Return Value: TRUE if succeed; otherwise FALSE
1397 *
1398 */
1399BOOL CARDbSetTxDataRate(
1400 PVOID pDeviceHandler,
1401 WORD wDataRate
1402 )
1403{
1404 PSDevice pDevice = (PSDevice) pDeviceHandler;
1405
1406 pDevice->wCurrentRate = wDataRate;
1407 return(TRUE);
1408}
1409
1410/*+
1411 *
1412 * Routine Description:
1413 * Consider to power down when no more packets to tx or rx.
1414 *
1415 * Parameters:
1416 * In:
1417 * pDevice - The adapter to be set
1418 * Out:
1419 * none
1420 *
1421 * Return Value: TRUE if power down success; otherwise FALSE
1422 *
1423-*/
1424BOOL
1425CARDbPowerDown(
1426 PVOID pDeviceHandler
1427 )
1428{
1429 PSDevice pDevice = (PSDevice)pDeviceHandler;
1430 UINT uIdx;
1431
1432 // check if already in Doze mode
1433 if (MACbIsRegBitsOn(pDevice->PortOffset, MAC_REG_PSCTL, PSCTL_PS))
1434 return TRUE;
1435
1436 // Froce PSEN on
1437 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_PSCTL, PSCTL_PSEN);
1438
1439 // check if all TD are empty,
1440
1441 for (uIdx = 0; uIdx < TYPE_MAXTD; uIdx ++) {
1442 if (pDevice->iTDUsed[uIdx] != 0)
1443 return FALSE;
1444 }
1445
1446 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_PSCTL, PSCTL_GO2DOZE);
1447 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Go to Doze ZZZZZZZZZZZZZZZ\n");
1448 return TRUE;
1449}
1450
1451/*
1452 * Description: Turn off Radio power
1453 *
1454 * Parameters:
1455 * In:
1456 * pDevice - The adapter to be turned off
1457 * Out:
1458 * none
1459 *
1460 * Return Value: TRUE if success; otherwise FALSE
1461 *
1462 */
1463BOOL CARDbRadioPowerOff (PVOID pDeviceHandler)
1464{
1465 PSDevice pDevice = (PSDevice) pDeviceHandler;
1466 BOOL bResult = TRUE;
1467
1468 if (pDevice->bRadioOff == TRUE)
1469 return TRUE;
1470
1471
1472 switch (pDevice->byRFType) {
1473
1474 case RF_RFMD2959:
1475 MACvWordRegBitsOff(pDevice->PortOffset, MAC_REG_SOFTPWRCTL, SOFTPWRCTL_TXPEINV);
1476 MACvWordRegBitsOn(pDevice->PortOffset, MAC_REG_SOFTPWRCTL, SOFTPWRCTL_SWPE1);
1477 break;
1478
1479 case RF_AIROHA:
1480 case RF_AL2230S:
1481 case RF_AIROHA7230: //RobertYu:20050104
1482 MACvWordRegBitsOff(pDevice->PortOffset, MAC_REG_SOFTPWRCTL, SOFTPWRCTL_SWPE2);
1483 MACvWordRegBitsOff(pDevice->PortOffset, MAC_REG_SOFTPWRCTL, SOFTPWRCTL_SWPE3);
1484 break;
1485
1486 }
1487
1488 MACvRegBitsOff(pDevice->PortOffset, MAC_REG_HOSTCR, HOSTCR_RXON);
1489
1490 BBvSetDeepSleep(pDevice->PortOffset, pDevice->byLocalID);
1491
1492 pDevice->bRadioOff = TRUE;
1493 //2007-0409-03,<Add> by chester
1494printk("chester power off\n");
1495MACvRegBitsOn(pDevice->PortOffset, MAC_REG_GPIOCTL0, LED_ACTSET); //LED issue
1496 return bResult;
1497}
1498
1499
1500/*
1501 * Description: Turn on Radio power
1502 *
1503 * Parameters:
1504 * In:
1505 * pDevice - The adapter to be turned on
1506 * Out:
1507 * none
1508 *
1509 * Return Value: TRUE if success; otherwise FALSE
1510 *
1511 */
1512BOOL CARDbRadioPowerOn (PVOID pDeviceHandler)
1513{
1514 PSDevice pDevice = (PSDevice) pDeviceHandler;
1515 BOOL bResult = TRUE;
1516printk("chester power on\n");
1517 if (pDevice->bRadioControlOff == TRUE){
1518if (pDevice->bHWRadioOff == TRUE) printk("chester bHWRadioOff\n");
1519if (pDevice->bRadioControlOff == TRUE) printk("chester bRadioControlOff\n");
1520 return FALSE;}
1521
1522 if (pDevice->bRadioOff == FALSE)
1523 {
1524printk("chester pbRadioOff\n");
1525return TRUE;}
1526
1527 BBvExitDeepSleep(pDevice->PortOffset, pDevice->byLocalID);
1528
1529 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_HOSTCR, HOSTCR_RXON);
1530
1531 switch (pDevice->byRFType) {
1532
1533 case RF_RFMD2959:
1534 MACvWordRegBitsOn(pDevice->PortOffset, MAC_REG_SOFTPWRCTL, SOFTPWRCTL_TXPEINV);
1535 MACvWordRegBitsOff(pDevice->PortOffset, MAC_REG_SOFTPWRCTL, SOFTPWRCTL_SWPE1);
1536 break;
1537
1538 case RF_AIROHA:
1539 case RF_AL2230S:
1540 case RF_AIROHA7230: //RobertYu:20050104
1541 MACvWordRegBitsOn(pDevice->PortOffset, MAC_REG_SOFTPWRCTL, (SOFTPWRCTL_SWPE2 |
1542 SOFTPWRCTL_SWPE3));
1543 break;
1544
1545 }
1546
1547 pDevice->bRadioOff = FALSE;
1548// 2007-0409-03,<Add> by chester
1549printk("chester power on\n");
1550MACvRegBitsOff(pDevice->PortOffset, MAC_REG_GPIOCTL0, LED_ACTSET); //LED issue
1551 return bResult;
1552}
1553
1554
1555
1556BOOL CARDbRemoveKey (PVOID pDeviceHandler, PBYTE pbyBSSID)
1557{
1558 PSDevice pDevice = (PSDevice) pDeviceHandler;
1559
1560 KeybRemoveAllKey(&(pDevice->sKey), pbyBSSID, pDevice->PortOffset);
1561 return (TRUE);
1562}
1563
1564
1565/*
1566 *
1567 * Description:
1568 * Add BSSID in PMKID Candidate list.
1569 *
1570 * Parameters:
1571 * In:
1572 * hDeviceContext - device structure point
1573 * pbyBSSID - BSSID address for adding
1574 * wRSNCap - BSS's RSN capability
1575 * Out:
1576 * none
1577 *
1578 * Return Value: none.
1579 *
1580-*/
1581BOOL
1582CARDbAdd_PMKID_Candidate (
1583 IN PVOID pDeviceHandler,
1584 IN PBYTE pbyBSSID,
1585 IN BOOL bRSNCapExist,
1586 IN WORD wRSNCap
1587 )
1588{
1589 PSDevice pDevice = (PSDevice) pDeviceHandler;
1590 PPMKID_CANDIDATE pCandidateList;
1591 UINT ii = 0;
1592
1593 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"bAdd_PMKID_Candidate START: (%d)\n", (int)pDevice->gsPMKIDCandidate.NumCandidates);
1594
1595 if (pDevice->gsPMKIDCandidate.NumCandidates >= MAX_PMKIDLIST) {
1596 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"vFlush_PMKID_Candidate: 3\n");
1597 ZERO_MEMORY(&pDevice->gsPMKIDCandidate, sizeof(SPMKIDCandidateEvent));
1598 }
1599
1600 for (ii = 0; ii < 6; ii++) {
1601 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"%02X ", *(pbyBSSID + ii));
1602 }
1603 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"\n");
1604
1605
1606 // Update Old Candidate
1607 for (ii = 0; ii < pDevice->gsPMKIDCandidate.NumCandidates; ii++) {
1608 pCandidateList = &pDevice->gsPMKIDCandidate.CandidateList[ii];
1609 if (MEMEqualMemory(pCandidateList->BSSID, pbyBSSID, U_ETHER_ADDR_LEN)) {
1610 if ((bRSNCapExist == TRUE) && (wRSNCap & BIT0)) {
1611 pCandidateList->Flags |= NDIS_802_11_PMKID_CANDIDATE_PREAUTH_ENABLED;
1612 } else {
1613 pCandidateList->Flags &= ~(NDIS_802_11_PMKID_CANDIDATE_PREAUTH_ENABLED);
1614 }
1615 return TRUE;
1616 }
1617 }
1618
1619 // New Candidate
1620 pCandidateList = &pDevice->gsPMKIDCandidate.CandidateList[pDevice->gsPMKIDCandidate.NumCandidates];
1621 if ((bRSNCapExist == TRUE) && (wRSNCap & BIT0)) {
1622 pCandidateList->Flags |= NDIS_802_11_PMKID_CANDIDATE_PREAUTH_ENABLED;
1623 } else {
1624 pCandidateList->Flags &= ~(NDIS_802_11_PMKID_CANDIDATE_PREAUTH_ENABLED);
1625 }
1626 MEMvCopy(pCandidateList->BSSID, pbyBSSID, U_ETHER_ADDR_LEN);
1627 pDevice->gsPMKIDCandidate.NumCandidates++;
1628 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"NumCandidates:%d\n", (int)pDevice->gsPMKIDCandidate.NumCandidates);
1629 return TRUE;
1630}
1631
1632PVOID
1633CARDpGetCurrentAddress (
1634 IN PVOID pDeviceHandler
1635 )
1636{
1637 PSDevice pDevice = (PSDevice) pDeviceHandler;
1638
1639 return (pDevice->abyCurrentNetAddr);
1640}
1641
1642
1643
1644VOID CARDvInitChannelTable (PVOID pDeviceHandler)
1645{
1646 PSDevice pDevice = (PSDevice) pDeviceHandler;
1647 BOOL bMultiBand = FALSE;
1648 UINT ii;
1649
1650 for(ii=1;ii<=CARD_MAX_CHANNEL_TBL;ii++) {
1651 sChannelTbl[ii].bValid = FALSE;
1652 }
1653
1654 switch (pDevice->byRFType) {
1655 case RF_RFMD2959 :
1656 case RF_AIROHA :
1657 case RF_AL2230S:
1658 case RF_UW2451 :
1659 case RF_VT3226 :
1660 // printk("chester-false\n");
1661 bMultiBand = FALSE;
1662 break;
1663 case RF_AIROHA7230 :
1664 case RF_UW2452 :
1665 case RF_NOTHING :
1666 default :
1667 bMultiBand = TRUE;
1668 break;
1669 }
1670
1671 if ((pDevice->dwDiagRefCount != 0) ||
1672 (pDevice->b11hEnable == TRUE)) {
1673 if (bMultiBand == TRUE) {
1674 for(ii=0;ii<CARD_MAX_CHANNEL_TBL;ii++) {
1675 sChannelTbl[ii+1].bValid = TRUE;
1676 pDevice->abyRegPwr[ii+1] = pDevice->abyOFDMDefaultPwr[ii+1];
1677 pDevice->abyLocalPwr[ii+1] = pDevice->abyOFDMDefaultPwr[ii+1];
1678 }
1679 for(ii=0;ii<CHANNEL_MAX_24G;ii++) {
1680 pDevice->abyRegPwr[ii+1] = pDevice->abyCCKDefaultPwr[ii+1];
1681 pDevice->abyLocalPwr[ii+1] = pDevice->abyCCKDefaultPwr[ii+1];
1682 }
1683 } else {
1684 for(ii=0;ii<CHANNEL_MAX_24G;ii++) {
1685//2008-8-4 <add> by chester
1686 if (ChannelRuleTab[pDevice->byZoneType].bChannelIdxList[ii] != 0) {
1687 sChannelTbl[ii+1].bValid = TRUE;
1688 pDevice->abyRegPwr[ii+1] = pDevice->abyCCKDefaultPwr[ii+1];
1689 pDevice->abyLocalPwr[ii+1] = pDevice->abyCCKDefaultPwr[ii+1];
1690 }
1691 }
1692 }
1693 } else if (pDevice->byZoneType <= CCODE_MAX) {
1694 if (bMultiBand == TRUE) {
1695 for(ii=0;ii<CARD_MAX_CHANNEL_TBL;ii++) {
1696 if (ChannelRuleTab[pDevice->byZoneType].bChannelIdxList[ii] != 0) {
1697 sChannelTbl[ii+1].bValid = TRUE;
1698 pDevice->abyRegPwr[ii+1] = ChannelRuleTab[pDevice->byZoneType].byPower[ii];
1699 pDevice->abyLocalPwr[ii+1] = ChannelRuleTab[pDevice->byZoneType].byPower[ii];
1700 }
1701 }
1702 } else {
1703 for(ii=0;ii<CHANNEL_MAX_24G;ii++) {
1704 if (ChannelRuleTab[pDevice->byZoneType].bChannelIdxList[ii] != 0) {
1705 sChannelTbl[ii+1].bValid = TRUE;
1706 pDevice->abyRegPwr[ii+1] = ChannelRuleTab[pDevice->byZoneType].byPower[ii];
1707 pDevice->abyLocalPwr[ii+1] = ChannelRuleTab[pDevice->byZoneType].byPower[ii];
1708 }
1709 }
1710 }
1711 }
1712 DEVICE_PRT(MSG_LEVEL_NOTICE, KERN_INFO"Zone=[%d][%c][%c]!!\n",pDevice->byZoneType,ChannelRuleTab[pDevice->byZoneType].chCountryCode[0],ChannelRuleTab[pDevice->byZoneType].chCountryCode[1]);
1713 for(ii=0;ii<CARD_MAX_CHANNEL_TBL;ii++) {
1714 if (pDevice->abyRegPwr[ii+1] == 0) {
1715 pDevice->abyRegPwr[ii+1] = pDevice->abyOFDMDefaultPwr[ii+1];
1716 }
1717 if (pDevice->abyLocalPwr[ii+1] == 0) {
1718 pDevice->abyLocalPwr[ii+1] = pDevice->abyOFDMDefaultPwr[ii+1];
1719 }
1720 }
1721}
1722
1723
1724
1725/*
1726 *
1727 * Description:
1728 * Start Spectrum Measure defined in 802.11h
1729 *
1730 * Parameters:
1731 * In:
1732 * hDeviceContext - device structure point
1733 * Out:
1734 * none
1735 *
1736 * Return Value: none.
1737 *
1738-*/
1739BOOL
1740CARDbStartMeasure (
1741 IN PVOID pDeviceHandler,
1742 IN PVOID pvMeasureEIDs,
1743 IN UINT uNumOfMeasureEIDs
1744 )
1745{
1746 PSDevice pDevice = (PSDevice) pDeviceHandler;
1747 PWLAN_IE_MEASURE_REQ pEID = (PWLAN_IE_MEASURE_REQ) pvMeasureEIDs;
1748 QWORD qwCurrTSF;
1749 QWORD qwStartTSF;
1750 BOOL bExpired = TRUE;
1751 WORD wDuration = 0;
1752
1753 if ((pEID == NULL) ||
1754 (uNumOfMeasureEIDs == 0)) {
1755 return (TRUE);
1756 }
1757 CARDbGetCurrentTSF(pDevice->PortOffset, &qwCurrTSF);
1758 if (pDevice->bMeasureInProgress == TRUE) {
1759 pDevice->bMeasureInProgress = FALSE;
1760 VNSvOutPortB(pDevice->PortOffset + MAC_REG_RCR, pDevice->byOrgRCR);
1761 MACvSelectPage1(pDevice->PortOffset);
1762 VNSvOutPortD(pDevice->PortOffset + MAC_REG_MAR0, pDevice->dwOrgMAR0);
1763 VNSvOutPortD(pDevice->PortOffset + MAC_REG_MAR4, pDevice->dwOrgMAR4);
1764 // clear measure control
1765 MACvRegBitsOff(pDevice->PortOffset, MAC_REG_MSRCTL, MSRCTL_EN);
1766 MACvSelectPage0(pDevice->PortOffset);
1767 CARDbSetChannel(pDevice, pDevice->byOrgChannel);
1768 MACvSelectPage1(pDevice->PortOffset);
1769 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_MSRCTL+1, MSRCTL1_TXPAUSE);
1770 MACvSelectPage0(pDevice->PortOffset);
1771 }
1772 pDevice->uNumOfMeasureEIDs = uNumOfMeasureEIDs;
1773
1774 do {
1775 pDevice->pCurrMeasureEID = pEID;
1776 pEID++;
1777 pDevice->uNumOfMeasureEIDs--;
1778
1779 if (pDevice->byLocalID > REV_ID_VT3253_B1) {
1780 HIDWORD(qwStartTSF) = HIDWORD(*((PQWORD) (pDevice->pCurrMeasureEID->sReq.abyStartTime)));
1781 LODWORD(qwStartTSF) = LODWORD(*((PQWORD) (pDevice->pCurrMeasureEID->sReq.abyStartTime)));
1782 wDuration = *((PWORD) (pDevice->pCurrMeasureEID->sReq.abyDuration));
1783 wDuration += 1; // 1 TU for channel switching
1784
1785 if ((LODWORD(qwStartTSF) == 0) && (HIDWORD(qwStartTSF) == 0)) {
1786 // start imediately by setting start TSF == current TSF + 2 TU
1787 LODWORD(qwStartTSF) = LODWORD(qwCurrTSF) + 2048;
1788 HIDWORD(qwStartTSF) = HIDWORD(qwCurrTSF);
1789 if (LODWORD(qwCurrTSF) > LODWORD(qwStartTSF)) {
1790 HIDWORD(qwStartTSF)++;
1791 }
1792 bExpired = FALSE;
1793 break;
1794 } else {
1795 // start at setting start TSF - 1TU(for channel switching)
1796 if (LODWORD(qwStartTSF) < 1024) {
1797 HIDWORD(qwStartTSF)--;
1798 }
1799 LODWORD(qwStartTSF) -= 1024;
1800 }
1801
1802 if ((HIDWORD(qwCurrTSF) < HIDWORD(qwStartTSF)) ||
1803 ((HIDWORD(qwCurrTSF) == HIDWORD(qwStartTSF)) &&
1804 (LODWORD(qwCurrTSF) < LODWORD(qwStartTSF)))
1805 ) {
1806 bExpired = FALSE;
1807 break;
1808 }
1809 VNTWIFIbMeasureReport( pDevice->pMgmt,
1810 FALSE,
1811 pDevice->pCurrMeasureEID,
1812 MEASURE_MODE_LATE,
1813 pDevice->byBasicMap,
1814 pDevice->byCCAFraction,
1815 pDevice->abyRPIs
1816 );
1817 } else {
1818 // hardware do not support measure
1819 VNTWIFIbMeasureReport( pDevice->pMgmt,
1820 FALSE,
1821 pDevice->pCurrMeasureEID,
1822 MEASURE_MODE_INCAPABLE,
1823 pDevice->byBasicMap,
1824 pDevice->byCCAFraction,
1825 pDevice->abyRPIs
1826 );
1827 }
1828 } while (pDevice->uNumOfMeasureEIDs != 0);
1829
1830 if (bExpired == FALSE) {
1831 MACvSelectPage1(pDevice->PortOffset);
1832 VNSvOutPortD(pDevice->PortOffset + MAC_REG_MSRSTART, LODWORD(qwStartTSF));
1833 VNSvOutPortD(pDevice->PortOffset + MAC_REG_MSRSTART + 4, HIDWORD(qwStartTSF));
1834 VNSvOutPortW(pDevice->PortOffset + MAC_REG_MSRDURATION, wDuration);
1835 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_MSRCTL, MSRCTL_EN);
1836 MACvSelectPage0(pDevice->PortOffset);
1837 } else {
1838 // all measure start time expired we should complete action
1839 VNTWIFIbMeasureReport( pDevice->pMgmt,
1840 TRUE,
1841 NULL,
1842 0,
1843 pDevice->byBasicMap,
1844 pDevice->byCCAFraction,
1845 pDevice->abyRPIs
1846 );
1847 }
1848 return (TRUE);
1849}
1850
1851
1852/*
1853 *
1854 * Description:
1855 * Do Channel Switch defined in 802.11h
1856 *
1857 * Parameters:
1858 * In:
1859 * hDeviceContext - device structure point
1860 * Out:
1861 * none
1862 *
1863 * Return Value: none.
1864 *
1865-*/
1866BOOL
1867CARDbChannelSwitch (
1868 IN PVOID pDeviceHandler,
1869 IN BYTE byMode,
1870 IN BYTE byNewChannel,
1871 IN BYTE byCount
1872 )
1873{
1874 PSDevice pDevice = (PSDevice) pDeviceHandler;
1875 BOOL bResult = TRUE;
1876
1877 if (byCount == 0) {
1878 bResult = CARDbSetChannel(pDevice, byNewChannel);
1879 VNTWIFIbChannelSwitch(pDevice->pMgmt, byNewChannel);
1880 MACvSelectPage1(pDevice->PortOffset);
1881 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_MSRCTL+1, MSRCTL1_TXPAUSE);
1882 MACvSelectPage0(pDevice->PortOffset);
1883 return(bResult);
1884 }
1885 pDevice->byChannelSwitchCount = byCount;
1886 pDevice->byNewChannel = byNewChannel;
1887 pDevice->bChannelSwitch = TRUE;
1888 if (byMode == 1) {
1889 bResult=CARDbStopTxPacket(pDevice, PKT_TYPE_802_11_ALL);
1890 }
1891 return (bResult);
1892}
1893
1894
1895/*
1896 *
1897 * Description:
1898 * Handle Quiet EID defined in 802.11h
1899 *
1900 * Parameters:
1901 * In:
1902 * hDeviceContext - device structure point
1903 * Out:
1904 * none
1905 *
1906 * Return Value: none.
1907 *
1908-*/
1909BOOL
1910CARDbSetQuiet (
1911 IN PVOID pDeviceHandler,
1912 IN BOOL bResetQuiet,
1913 IN BYTE byQuietCount,
1914 IN BYTE byQuietPeriod,
1915 IN WORD wQuietDuration,
1916 IN WORD wQuietOffset
1917 )
1918{
1919 PSDevice pDevice = (PSDevice) pDeviceHandler;
1920 UINT ii = 0;
1921
1922 if (bResetQuiet == TRUE) {
1923 MACvRegBitsOff(pDevice->PortOffset, MAC_REG_MSRCTL, (MSRCTL_QUIETTXCHK | MSRCTL_QUIETEN));
1924 for(ii=0;ii<MAX_QUIET_COUNT;ii++) {
1925 pDevice->sQuiet[ii].bEnable = FALSE;
1926 }
1927 pDevice->uQuietEnqueue = 0;
1928 pDevice->bEnableFirstQuiet = FALSE;
1929 pDevice->bQuietEnable = FALSE;
1930 pDevice->byQuietStartCount = byQuietCount;
1931 }
1932 if (pDevice->sQuiet[pDevice->uQuietEnqueue].bEnable == FALSE) {
1933 pDevice->sQuiet[pDevice->uQuietEnqueue].bEnable = TRUE;
1934 pDevice->sQuiet[pDevice->uQuietEnqueue].byPeriod = byQuietPeriod;
1935 pDevice->sQuiet[pDevice->uQuietEnqueue].wDuration = wQuietDuration;
1936 pDevice->sQuiet[pDevice->uQuietEnqueue].dwStartTime = (DWORD) byQuietCount;
1937 pDevice->sQuiet[pDevice->uQuietEnqueue].dwStartTime *= pDevice->wBeaconInterval;
1938 pDevice->sQuiet[pDevice->uQuietEnqueue].dwStartTime += wQuietOffset;
1939 pDevice->uQuietEnqueue++;
1940 pDevice->uQuietEnqueue %= MAX_QUIET_COUNT;
1941 if (pDevice->byQuietStartCount < byQuietCount) {
1942 pDevice->byQuietStartCount = byQuietCount;
1943 }
1944 } else {
1945 // we can not handle Quiet EID more
1946 }
1947 return (TRUE);
1948}
1949
1950
1951/*
1952 *
1953 * Description:
1954 * Do Quiet, It will called by either ISR (after start) or VNTWIFI (before start) so do not need SPINLOCK
1955 *
1956 * Parameters:
1957 * In:
1958 * hDeviceContext - device structure point
1959 * Out:
1960 * none
1961 *
1962 * Return Value: none.
1963 *
1964-*/
1965BOOL
1966CARDbStartQuiet (
1967 IN PVOID pDeviceHandler
1968 )
1969{
1970 PSDevice pDevice = (PSDevice) pDeviceHandler;
1971 UINT ii = 0;
1972 DWORD dwStartTime = 0xFFFFFFFF;
1973 UINT uCurrentQuietIndex = 0;
1974 DWORD dwNextTime = 0;
1975 DWORD dwGap = 0;
1976 DWORD dwDuration = 0;
1977
1978 for(ii=0;ii<MAX_QUIET_COUNT;ii++) {
1979 if ((pDevice->sQuiet[ii].bEnable == TRUE) &&
1980 (dwStartTime > pDevice->sQuiet[ii].dwStartTime)) {
1981 dwStartTime = pDevice->sQuiet[ii].dwStartTime;
1982 uCurrentQuietIndex = ii;
1983 }
1984 }
1985 if (dwStartTime == 0xFFFFFFFF) {
1986 // no more quiet
1987 pDevice->bQuietEnable = FALSE;
1988 MACvRegBitsOff(pDevice->PortOffset, MAC_REG_MSRCTL, (MSRCTL_QUIETTXCHK | MSRCTL_QUIETEN));
1989 } else {
1990 if (pDevice->bQuietEnable == FALSE) {
1991 // first quiet
1992 pDevice->byQuietStartCount--;
1993 dwNextTime = pDevice->sQuiet[uCurrentQuietIndex].dwStartTime;
1994 dwNextTime %= pDevice->wBeaconInterval;
1995 MACvSelectPage1(pDevice->PortOffset);
1996 VNSvOutPortW(pDevice->PortOffset + MAC_REG_QUIETINIT, (WORD) dwNextTime);
1997 VNSvOutPortW(pDevice->PortOffset + MAC_REG_QUIETDUR, (WORD) pDevice->sQuiet[uCurrentQuietIndex].wDuration);
1998 if (pDevice->byQuietStartCount == 0) {
1999 pDevice->bEnableFirstQuiet = FALSE;
2000 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_MSRCTL, (MSRCTL_QUIETTXCHK | MSRCTL_QUIETEN));
2001 } else {
2002 pDevice->bEnableFirstQuiet = TRUE;
2003 }
2004 MACvSelectPage0(pDevice->PortOffset);
2005 } else {
2006 if (pDevice->dwCurrentQuietEndTime > pDevice->sQuiet[uCurrentQuietIndex].dwStartTime) {
2007 // overlap with previous Quiet
2008 dwGap = pDevice->dwCurrentQuietEndTime - pDevice->sQuiet[uCurrentQuietIndex].dwStartTime;
2009 if (dwGap >= pDevice->sQuiet[uCurrentQuietIndex].wDuration) {
2010 // return FALSE to indicate next quiet expired, should call this function again
2011 return (FALSE);
2012 }
2013 dwDuration = pDevice->sQuiet[uCurrentQuietIndex].wDuration - dwGap;
2014 dwGap = 0;
2015 } else {
2016 dwGap = pDevice->sQuiet[uCurrentQuietIndex].dwStartTime - pDevice->dwCurrentQuietEndTime;
2017 dwDuration = pDevice->sQuiet[uCurrentQuietIndex].wDuration;
2018 }
2019 // set GAP and Next duration
2020 MACvSelectPage1(pDevice->PortOffset);
2021 VNSvOutPortW(pDevice->PortOffset + MAC_REG_QUIETGAP, (WORD) dwGap);
2022 VNSvOutPortW(pDevice->PortOffset + MAC_REG_QUIETDUR, (WORD) dwDuration);
2023 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_MSRCTL, MSRCTL_QUIETRPT);
2024 MACvSelectPage0(pDevice->PortOffset);
2025 }
2026 pDevice->bQuietEnable = TRUE;
2027 pDevice->dwCurrentQuietEndTime = pDevice->sQuiet[uCurrentQuietIndex].dwStartTime;
2028 pDevice->dwCurrentQuietEndTime += pDevice->sQuiet[uCurrentQuietIndex].wDuration;
2029 if (pDevice->sQuiet[uCurrentQuietIndex].byPeriod == 0) {
2030 // not period disable current quiet element
2031 pDevice->sQuiet[uCurrentQuietIndex].bEnable = FALSE;
2032 } else {
2033 // set next period start time
2034 dwNextTime = (DWORD) pDevice->sQuiet[uCurrentQuietIndex].byPeriod;
2035 dwNextTime *= pDevice->wBeaconInterval;
2036 pDevice->sQuiet[uCurrentQuietIndex].dwStartTime = dwNextTime;
2037 }
2038 if (pDevice->dwCurrentQuietEndTime > 0x80010000) {
2039 // decreament all time to avoid wrap around
2040 for(ii=0;ii<MAX_QUIET_COUNT;ii++) {
2041 if (pDevice->sQuiet[ii].bEnable == TRUE) {
2042 pDevice->sQuiet[ii].dwStartTime -= 0x80000000;
2043 }
2044 }
2045 pDevice->dwCurrentQuietEndTime -= 0x80000000;
2046 }
2047 }
2048 return (TRUE);
2049}
2050
2051
2052/*
2053 *
2054 * Description:
2055 * Set Channel Info of Country
2056 *
2057 * Parameters:
2058 * In:
2059 * hDeviceContext - device structure point
2060 * Out:
2061 * none
2062 *
2063 * Return Value: none.
2064 *
2065-*/
2066VOID
2067CARDvSetCountryInfo (
2068 IN PVOID pDeviceHandler,
2069 IN CARD_PHY_TYPE ePHYType,
2070 IN PVOID pIE
2071 )
2072{
2073 PSDevice pDevice = (PSDevice) pDeviceHandler;
2074 UINT ii = 0;
2075 UINT uu = 0;
2076 UINT step = 0;
2077 UINT uNumOfCountryInfo = 0;
2078 BYTE byCh = 0;
2079 PWLAN_IE_COUNTRY pIE_Country = (PWLAN_IE_COUNTRY) pIE;
2080
2081
2082 uNumOfCountryInfo = (pIE_Country->len - 3);
2083 uNumOfCountryInfo /= 3;
2084
2085 if (ePHYType == PHY_TYPE_11A) {
2086 pDevice->bCountryInfo5G = TRUE;
2087 for(ii=CB_MAX_CHANNEL_24G+1;ii<=CARD_MAX_CHANNEL_TBL;ii++) {
2088 sChannelTbl[ii].bValid = FALSE;
2089 }
2090 step = 4;
2091 } else {
2092 pDevice->bCountryInfo24G = TRUE;
2093 for(ii=1;ii<=CB_MAX_CHANNEL_24G;ii++) {
2094 sChannelTbl[ii].bValid = FALSE;
2095 }
2096 step = 1;
2097 }
2098 pDevice->abyCountryCode[0] = pIE_Country->abyCountryString[0];
2099 pDevice->abyCountryCode[1] = pIE_Country->abyCountryString[1];
2100 pDevice->abyCountryCode[2] = pIE_Country->abyCountryString[2];
2101
2102 for(ii=0;ii<uNumOfCountryInfo;ii++) {
2103 for(uu=0;uu<pIE_Country->abyCountryInfo[ii*3+1];uu++) {
2104 byCh = CARDbyGetChannelMapping(pDevice, (BYTE)(pIE_Country->abyCountryInfo[ii*3]+step*uu), ePHYType);
2105 sChannelTbl[byCh].bValid = TRUE;
2106 pDevice->abyRegPwr[byCh] = pIE_Country->abyCountryInfo[ii*3+2];
2107 }
2108 }
2109}
2110
2111/*
2112 *
2113 * Description:
2114 * Set Local Power Constraint
2115 *
2116 * Parameters:
2117 * In:
2118 * hDeviceContext - device structure point
2119 * Out:
2120 * none
2121 *
2122 * Return Value: none.
2123 *
2124-*/
2125VOID
2126CARDvSetPowerConstraint (
2127 IN PVOID pDeviceHandler,
2128 IN BYTE byChannel,
2129 IN I8 byPower
2130 )
2131{
2132 PSDevice pDevice = (PSDevice) pDeviceHandler;
2133
2134 if (byChannel > CB_MAX_CHANNEL_24G) {
2135 if (pDevice->bCountryInfo5G == TRUE) {
2136 pDevice->abyLocalPwr[byChannel] = pDevice->abyRegPwr[byChannel] - byPower;
2137 }
2138 } else {
2139 if (pDevice->bCountryInfo24G == TRUE) {
2140 pDevice->abyLocalPwr[byChannel] = pDevice->abyRegPwr[byChannel] - byPower;
2141 }
2142 }
2143}
2144
2145
2146/*
2147 *
2148 * Description:
2149 * Set Local Power Constraint
2150 *
2151 * Parameters:
2152 * In:
2153 * hDeviceContext - device structure point
2154 * Out:
2155 * none
2156 *
2157 * Return Value: none.
2158 *
2159-*/
2160VOID
2161CARDvGetPowerCapability (
2162 IN PVOID pDeviceHandler,
2163 OUT PBYTE pbyMinPower,
2164 OUT PBYTE pbyMaxPower
2165 )
2166{
2167 PSDevice pDevice = (PSDevice) pDeviceHandler;
2168 BYTE byDec = 0;
2169
2170 *pbyMaxPower = pDevice->abyOFDMDefaultPwr[pDevice->byCurrentCh];
2171 byDec = pDevice->abyOFDMPwrTbl[pDevice->byCurrentCh];
2172 if (pDevice->byRFType == RF_UW2452) {
2173 byDec *= 3;
2174 byDec >>= 1;
2175 } else {
2176 byDec <<= 1;
2177 }
2178 *pbyMinPower = pDevice->abyOFDMDefaultPwr[pDevice->byCurrentCh] - byDec;
2179}
2180
2181
2182/*
2183 *
2184 * Description:
2185 * Set Support Channels IE defined in 802.11h
2186 *
2187 * Parameters:
2188 * In:
2189 * hDeviceContext - device structure point
2190 * Out:
2191 * none
2192 *
2193 * Return Value: none.
2194 *
2195-*/
2196BYTE
2197CARDbySetSupportChannels (
2198 IN PVOID pDeviceHandler,
2199 IN OUT PBYTE pbyIEs
2200 )
2201{
2202 PSDevice pDevice = (PSDevice) pDeviceHandler;
2203 UINT ii;
2204 BYTE byCount;
2205 PWLAN_IE_SUPP_CH pIE = (PWLAN_IE_SUPP_CH) pbyIEs;
2206 PBYTE pbyChTupple;
2207 BYTE byLen = 0;
2208
2209
2210 pIE->byElementID = WLAN_EID_SUPP_CH;
2211 pIE->len = 0;
2212 pbyChTupple = pIE->abyChannelTuple;
2213 byLen = 2;
2214 // lower band
2215 byCount = 0;
2216 if (ChannelRuleTab[pDevice->byZoneType].bChannelIdxList[28] == TRUE) {
2217 for (ii=28;ii<36;ii+=2) {
2218 if (ChannelRuleTab[pDevice->byZoneType].bChannelIdxList[ii] == TRUE) {
2219 byCount++;
2220 }
2221 }
2222 *pbyChTupple++ = 34;
2223 *pbyChTupple++ = byCount;
2224 byLen += 2;
2225 } else if (ChannelRuleTab[pDevice->byZoneType].bChannelIdxList[29] == TRUE) {
2226 for (ii=29;ii<36;ii+=2) {
2227 if (ChannelRuleTab[pDevice->byZoneType].bChannelIdxList[ii] == TRUE) {
2228 byCount++;
2229 }
2230 }
2231 *pbyChTupple++ = 36;
2232 *pbyChTupple++ = byCount;
2233 byLen += 2;
2234 }
2235 // middle band
2236 byCount = 0;
2237 if (ChannelRuleTab[pDevice->byZoneType].bChannelIdxList[36] == TRUE) {
2238 for (ii=36;ii<40;ii++) {
2239 if (ChannelRuleTab[pDevice->byZoneType].bChannelIdxList[ii] == TRUE) {
2240 byCount++;
2241 }
2242 }
2243 *pbyChTupple++ = 52;
2244 *pbyChTupple++ = byCount;
2245 byLen += 2;
2246 }
2247 // higher band
2248 byCount = 0;
2249 if (ChannelRuleTab[pDevice->byZoneType].bChannelIdxList[40] == TRUE) {
2250 for (ii=40;ii<51;ii++) {
2251 if (ChannelRuleTab[pDevice->byZoneType].bChannelIdxList[ii] == TRUE) {
2252 byCount++;
2253 }
2254 }
2255 *pbyChTupple++ = 100;
2256 *pbyChTupple++ = byCount;
2257 byLen += 2;
2258 } else if (ChannelRuleTab[pDevice->byZoneType].bChannelIdxList[51] == TRUE) {
2259 for (ii=51;ii<56;ii++) {
2260 if (ChannelRuleTab[pDevice->byZoneType].bChannelIdxList[ii] == TRUE) {
2261 byCount++;
2262 }
2263 }
2264 *pbyChTupple++ = 149;
2265 *pbyChTupple++ = byCount;
2266 byLen += 2;
2267 }
2268 pIE->len += (byLen - 2);
2269 return (byLen);
2270}
2271
2272
2273/*
2274 *
2275 * Description:
2276 * Get Current Tx Power
2277 *
2278 * Parameters:
2279 * In:
2280 * hDeviceContext - device structure point
2281 * Out:
2282 * none
2283 *
2284 * Return Value: none.
2285 *
2286-*/
2287I8
2288CARDbyGetTransmitPower (
2289 IN PVOID pDeviceHandler
2290 )
2291{
2292 PSDevice pDevice = (PSDevice) pDeviceHandler;
2293
2294 return (pDevice->byCurPwrdBm);
2295}
2296
2297
2298BOOL
2299CARDbChannelGetList (
2300 IN UINT uCountryCodeIdx,
2301 OUT PBYTE pbyChannelTable
2302 )
2303{
2304 if (uCountryCodeIdx >= CCODE_MAX) {
2305 return (FALSE);
2306 }
2307 MEMvCopy(pbyChannelTable, ChannelRuleTab[uCountryCodeIdx].bChannelIdxList, CB_MAX_CHANNEL);
2308 return (TRUE);
2309}
2310
2311
2312VOID
2313CARDvSetCountryIE(
2314 IN PVOID pDeviceHandler,
2315 IN PVOID pIE
2316 )
2317{
2318 PSDevice pDevice = (PSDevice) pDeviceHandler;
2319 UINT ii;
2320 PWLAN_IE_COUNTRY pIECountry = (PWLAN_IE_COUNTRY) pIE;
2321
2322 pIECountry->byElementID = WLAN_EID_COUNTRY;
2323 pIECountry->len = 0;
2324 pIECountry->abyCountryString[0] = ChannelRuleTab[pDevice->byZoneType].chCountryCode[0];
2325 pIECountry->abyCountryString[1] = ChannelRuleTab[pDevice->byZoneType].chCountryCode[1];
2326 pIECountry->abyCountryString[2] = ' ';
2327 for (ii = CB_MAX_CHANNEL_24G; ii < CB_MAX_CHANNEL; ii++ ) {
2328 if (ChannelRuleTab[pDevice->byZoneType].bChannelIdxList[ii] != 0) {
2329 pIECountry->abyCountryInfo[pIECountry->len++] = sChannelTbl[ii+1].byChannelNumber;
2330 pIECountry->abyCountryInfo[pIECountry->len++] = 1;
2331 pIECountry->abyCountryInfo[pIECountry->len++] = ChannelRuleTab[pDevice->byZoneType].byPower[ii];
2332 }
2333 }
2334 pIECountry->len += 3;
2335}
2336
2337
2338BOOL
2339CARDbGetChannelMapInfo(
2340 IN PVOID pDeviceHandler,
2341 IN UINT uChannelIndex,
2342 OUT PBYTE pbyChannelNumber,
2343 OUT PBYTE pbyMap
2344 )
2345{
2346// PSDevice pDevice = (PSDevice) pDeviceHandler;
2347
2348 if (uChannelIndex > CB_MAX_CHANNEL) {
2349 return FALSE;
2350 }
2351 *pbyChannelNumber = sChannelTbl[uChannelIndex].byChannelNumber;
2352 *pbyMap = sChannelTbl[uChannelIndex].byMAP;
2353 return sChannelTbl[uChannelIndex].bValid;
2354}
2355
2356
2357VOID
2358CARDvSetChannelMapInfo(
2359 IN PVOID pDeviceHandler,
2360 IN UINT uChannelIndex,
2361 IN BYTE byMap
2362 )
2363{
2364// PSDevice pDevice = (PSDevice) pDeviceHandler;
2365
2366 if (uChannelIndex > CB_MAX_CHANNEL) {
2367 return;
2368 }
2369 sChannelTbl[uChannelIndex].byMAP |= byMap;
2370}
2371
2372
2373VOID
2374CARDvClearChannelMapInfo(
2375 IN PVOID pDeviceHandler
2376 )
2377{
2378// PSDevice pDevice = (PSDevice) pDeviceHandler;
2379 UINT ii = 0;
2380
2381 for (ii = 1; ii <= CB_MAX_CHANNEL; ii++) {
2382 sChannelTbl[ii].byMAP = 0;
2383 }
2384}
2385
2386
2387BYTE
2388CARDbyAutoChannelSelect(
2389 IN PVOID pDeviceHandler,
2390 CARD_PHY_TYPE ePHYType
2391 )
2392{
2393// PSDevice pDevice = (PSDevice) pDeviceHandler;
2394 UINT ii = 0;
2395 BYTE byOptionChannel = 0;
2396 INT aiWeight[CB_MAX_CHANNEL_24G+1] = {-1000,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
2397
2398 if (ePHYType == PHY_TYPE_11A) {
2399 for(ii=CB_MAX_CHANNEL_24G+1;ii<=CB_MAX_CHANNEL;ii++) {
2400 if (sChannelTbl[ii].bValid == TRUE) {
2401 if (byOptionChannel == 0) {
2402 byOptionChannel = (BYTE) ii;
2403 }
2404 if (sChannelTbl[ii].byMAP == 0) {
2405 return ((BYTE) ii);
2406 } else if (BITbIsBitOff(sChannelTbl[ii].byMAP, 0x08)) {
2407 byOptionChannel = (BYTE) ii;
2408 }
2409 }
2410 }
2411 } else {
2412 byOptionChannel = 0;
2413 for(ii=1;ii<=CB_MAX_CHANNEL_24G;ii++) {
2414 if (sChannelTbl[ii].bValid == TRUE) {
2415 if (sChannelTbl[ii].byMAP == 0) {
2416 aiWeight[ii] += 100;
2417 } else if (BITbIsBitOn(sChannelTbl[ii].byMAP, 0x01)) {
2418 if (ii > 3) {
2419 aiWeight[ii-3] -= 10;
2420 }
2421 if (ii > 2) {
2422 aiWeight[ii-2] -= 20;
2423 }
2424 if (ii > 1) {
2425 aiWeight[ii-1] -= 40;
2426 }
2427 aiWeight[ii] -= 80;
2428 if (ii < CB_MAX_CHANNEL_24G) {
2429 aiWeight[ii+1] -= 40;
2430 }
2431 if (ii < (CB_MAX_CHANNEL_24G - 1)) {
2432 aiWeight[ii+2] -= 20;
2433 }
2434 if (ii < (CB_MAX_CHANNEL_24G - 2)) {
2435 aiWeight[ii+3] -= 10;
2436 }
2437 }
2438 }
2439 }
2440 for(ii=1;ii<=CB_MAX_CHANNEL_24G;ii++) {
2441 if ((sChannelTbl[ii].bValid == TRUE) &&
2442 (aiWeight[ii] > aiWeight[byOptionChannel])) {
2443 byOptionChannel = (BYTE) ii;
2444 }
2445 }
2446 }
2447 return (byOptionChannel);
2448}
2449
2450
2451
2452//xxx
2453VOID
2454CARDvSafeResetTx (
2455 IN PVOID pDeviceHandler
2456 )
2457{
2458 PSDevice pDevice = (PSDevice) pDeviceHandler;
2459 UINT uu;
2460 PSTxDesc pCurrTD;
2461
2462 // initialize TD index
2463 pDevice->apTailTD[0] = pDevice->apCurrTD[0] = &(pDevice->apTD0Rings[0]);
2464 pDevice->apTailTD[1] = pDevice->apCurrTD[1] = &(pDevice->apTD1Rings[0]);
2465
2466 for (uu = 0; uu < TYPE_MAXTD; uu ++)
2467 pDevice->iTDUsed[uu] = 0;
2468
2469 for (uu = 0; uu < pDevice->sOpts.nTxDescs[0]; uu++) {
2470 pCurrTD = &(pDevice->apTD0Rings[uu]);
2471 pCurrTD->m_td0TD0.f1Owner = OWNED_BY_HOST;
2472 // init all Tx Packet pointer to NULL
2473 }
2474 for (uu = 0; uu < pDevice->sOpts.nTxDescs[1]; uu++) {
2475 pCurrTD = &(pDevice->apTD1Rings[uu]);
2476 pCurrTD->m_td0TD0.f1Owner = OWNED_BY_HOST;
2477 // init all Tx Packet pointer to NULL
2478 }
2479
2480 // set MAC TD pointer
2481 MACvSetCurrTXDescAddr(TYPE_TXDMA0, pDevice->PortOffset,
2482 (pDevice->td0_pool_dma));
2483
2484 MACvSetCurrTXDescAddr(TYPE_AC0DMA, pDevice->PortOffset,
2485 (pDevice->td1_pool_dma));
2486
2487 // set MAC Beacon TX pointer
2488 MACvSetCurrBCNTxDescAddr(pDevice->PortOffset,
2489 (pDevice->tx_beacon_dma));
2490
2491}
2492
2493
2494
2495/*+
2496 *
2497 * Description:
2498 * Reset Rx
2499 *
2500 * Parameters:
2501 * In:
2502 * pDevice - Pointer to the adapter
2503 * Out:
2504 * none
2505 *
2506 * Return Value: none
2507 *
2508-*/
2509VOID
2510CARDvSafeResetRx (
2511 IN PVOID pDeviceHandler
2512 )
2513{
2514 PSDevice pDevice = (PSDevice) pDeviceHandler;
2515 UINT uu;
2516 PSRxDesc pDesc;
2517
2518
2519
2520 // initialize RD index
2521 pDevice->pCurrRD[0]=&(pDevice->aRD0Ring[0]);
2522 pDevice->pCurrRD[1]=&(pDevice->aRD1Ring[0]);
2523
2524 // init state, all RD is chip's
2525 for (uu = 0; uu < pDevice->sOpts.nRxDescs0; uu++) {
2526 pDesc =&(pDevice->aRD0Ring[uu]);
2527 pDesc->m_rd0RD0.wResCount = (WORD)(pDevice->rx_buf_sz);
2528 pDesc->m_rd0RD0.f1Owner=OWNED_BY_NIC;
2529 pDesc->m_rd1RD1.wReqCount = (WORD)(pDevice->rx_buf_sz);
2530 }
2531
2532 // init state, all RD is chip's
2533 for (uu = 0; uu < pDevice->sOpts.nRxDescs1; uu++) {
2534 pDesc =&(pDevice->aRD1Ring[uu]);
2535 pDesc->m_rd0RD0.wResCount = (WORD)(pDevice->rx_buf_sz);
2536 pDesc->m_rd0RD0.f1Owner=OWNED_BY_NIC;
2537 pDesc->m_rd1RD1.wReqCount = (WORD)(pDevice->rx_buf_sz);
2538 }
2539
2540 pDevice->cbDFCB = CB_MAX_RX_FRAG;
2541 pDevice->cbFreeDFCB = pDevice->cbDFCB;
2542
2543 // set perPkt mode
2544 MACvRx0PerPktMode(pDevice->PortOffset);
2545 MACvRx1PerPktMode(pDevice->PortOffset);
2546 // set MAC RD pointer
2547 MACvSetCurrRx0DescAddr(pDevice->PortOffset,
2548 pDevice->rd0_pool_dma);
2549
2550 MACvSetCurrRx1DescAddr(pDevice->PortOffset,
2551 pDevice->rd1_pool_dma);
2552}
2553
2554
2555
2556
2557/*
2558 * Description: Get response Control frame rate in CCK mode
2559 *
2560 * Parameters:
2561 * In:
2562 * pDevice - The adapter to be set
2563 * wRateIdx - Receiving data rate
2564 * Out:
2565 * none
2566 *
2567 * Return Value: response Control frame rate
2568 *
2569 */
2570WORD CARDwGetCCKControlRate(PVOID pDeviceHandler, WORD wRateIdx)
2571{
2572 PSDevice pDevice = (PSDevice) pDeviceHandler;
2573 UINT ui = (UINT)wRateIdx;
2574
2575 while (ui > RATE_1M) {
2576 if (pDevice->wBasicRate & ((WORD)1 << ui)) {
2577 return (WORD)ui;
2578 }
2579 ui --;
2580 }
2581 return (WORD)RATE_1M;
2582}
2583
2584/*
2585 * Description: Get response Control frame rate in OFDM mode
2586 *
2587 * Parameters:
2588 * In:
2589 * pDevice - The adapter to be set
2590 * wRateIdx - Receiving data rate
2591 * Out:
2592 * none
2593 *
2594 * Return Value: response Control frame rate
2595 *
2596 */
2597WORD CARDwGetOFDMControlRate (PVOID pDeviceHandler, WORD wRateIdx)
2598{
2599 PSDevice pDevice = (PSDevice) pDeviceHandler;
2600 UINT ui = (UINT)wRateIdx;
2601
2602 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"BASIC RATE: %X\n", pDevice->wBasicRate);
2603
2604 if (!CARDbIsOFDMinBasicRate((PVOID)pDevice)) {
2605 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"CARDwGetOFDMControlRate:(NO OFDM) %d\n", wRateIdx);
2606 if (wRateIdx > RATE_24M)
2607 wRateIdx = RATE_24M;
2608 return wRateIdx;
2609 }
2610 while (ui > RATE_11M) {
2611 if (pDevice->wBasicRate & ((WORD)1 << ui)) {
2612 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"CARDwGetOFDMControlRate : %d\n", ui);
2613 return (WORD)ui;
2614 }
2615 ui --;
2616 }
2617 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"CARDwGetOFDMControlRate: 6M\n");
2618 return (WORD)RATE_24M;
2619}
2620
2621
2622/*
2623 * Description: Set RSPINF
2624 *
2625 * Parameters:
2626 * In:
2627 * pDevice - The adapter to be set
2628 * Out:
2629 * none
2630 *
2631 * Return Value: None.
2632 *
2633 */
2634void CARDvSetRSPINF (PVOID pDeviceHandler, CARD_PHY_TYPE ePHYType)
2635{
2636 PSDevice pDevice = (PSDevice) pDeviceHandler;
2637 BYTE byServ = 0x00, bySignal = 0x00; //For CCK
2638 WORD wLen = 0x0000;
2639 BYTE byTxRate, byRsvTime; //For OFDM
2640
2641 //Set to Page1
2642 MACvSelectPage1(pDevice->PortOffset);
2643
2644 //RSPINF_b_1
2645 BBvCaculateParameter(pDevice,
2646 14,
2647 CARDwGetCCKControlRate((PVOID)pDevice, RATE_1M),
2648 PK_TYPE_11B,
2649 &wLen,
2650 &byServ,
2651 &bySignal
2652 );
2653
2654 VNSvOutPortD(pDevice->PortOffset + MAC_REG_RSPINF_B_1, MAKEDWORD(wLen,MAKEWORD(bySignal,byServ)));
2655 ///RSPINF_b_2
2656 BBvCaculateParameter(pDevice,
2657 14,
2658 CARDwGetCCKControlRate((PVOID)pDevice, RATE_2M),
2659 PK_TYPE_11B,
2660 &wLen,
2661 &byServ,
2662 &bySignal
2663 );
2664
2665 VNSvOutPortD(pDevice->PortOffset + MAC_REG_RSPINF_B_2, MAKEDWORD(wLen,MAKEWORD(bySignal,byServ)));
2666 //RSPINF_b_5
2667 BBvCaculateParameter(pDevice,
2668 14,
2669 CARDwGetCCKControlRate((PVOID)pDevice, RATE_5M),
2670 PK_TYPE_11B,
2671 &wLen,
2672 &byServ,
2673 &bySignal
2674 );
2675
2676 VNSvOutPortD(pDevice->PortOffset + MAC_REG_RSPINF_B_5, MAKEDWORD(wLen,MAKEWORD(bySignal,byServ)));
2677 //RSPINF_b_11
2678 BBvCaculateParameter(pDevice,
2679 14,
2680 CARDwGetCCKControlRate((PVOID)pDevice, RATE_11M),
2681 PK_TYPE_11B,
2682 &wLen,
2683 &byServ,
2684 &bySignal
2685 );
2686
2687 VNSvOutPortD(pDevice->PortOffset + MAC_REG_RSPINF_B_11, MAKEDWORD(wLen,MAKEWORD(bySignal,byServ)));
2688 //RSPINF_a_6
2689 s_vCaculateOFDMRParameter(RATE_6M,
2690 ePHYType,
2691 &byTxRate,
2692 &byRsvTime);
2693 VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_6, MAKEWORD(byTxRate,byRsvTime));
2694 //RSPINF_a_9
2695 s_vCaculateOFDMRParameter(RATE_9M,
2696 ePHYType,
2697 &byTxRate,
2698 &byRsvTime);
2699 VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_9, MAKEWORD(byTxRate,byRsvTime));
2700 //RSPINF_a_12
2701 s_vCaculateOFDMRParameter(RATE_12M,
2702 ePHYType,
2703 &byTxRate,
2704 &byRsvTime);
2705 VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_12, MAKEWORD(byTxRate,byRsvTime));
2706 //RSPINF_a_18
2707 s_vCaculateOFDMRParameter(RATE_18M,
2708 ePHYType,
2709 &byTxRate,
2710 &byRsvTime);
2711 VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_18, MAKEWORD(byTxRate,byRsvTime));
2712 //RSPINF_a_24
2713 s_vCaculateOFDMRParameter(RATE_24M,
2714 ePHYType,
2715 &byTxRate,
2716 &byRsvTime);
2717 VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_24, MAKEWORD(byTxRate,byRsvTime));
2718 //RSPINF_a_36
2719 s_vCaculateOFDMRParameter(CARDwGetOFDMControlRate((PVOID)pDevice, RATE_36M),
2720 ePHYType,
2721 &byTxRate,
2722 &byRsvTime);
2723 VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_36, MAKEWORD(byTxRate,byRsvTime));
2724 //RSPINF_a_48
2725 s_vCaculateOFDMRParameter(CARDwGetOFDMControlRate((PVOID)pDevice, RATE_48M),
2726 ePHYType,
2727 &byTxRate,
2728 &byRsvTime);
2729 VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_48, MAKEWORD(byTxRate,byRsvTime));
2730 //RSPINF_a_54
2731 s_vCaculateOFDMRParameter(CARDwGetOFDMControlRate((PVOID)pDevice, RATE_54M),
2732 ePHYType,
2733 &byTxRate,
2734 &byRsvTime);
2735 VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_54, MAKEWORD(byTxRate,byRsvTime));
2736
2737 //RSPINF_a_72
2738 s_vCaculateOFDMRParameter(CARDwGetOFDMControlRate((PVOID)pDevice, RATE_54M),
2739 ePHYType,
2740 &byTxRate,
2741 &byRsvTime);
2742 VNSvOutPortW(pDevice->PortOffset + MAC_REG_RSPINF_A_72, MAKEWORD(byTxRate,byRsvTime));
2743 //Set to Page0
2744 MACvSelectPage0(pDevice->PortOffset);
2745}
2746
2747/*
2748 * Description: Update IFS
2749 *
2750 * Parameters:
2751 * In:
2752 * pDevice - The adapter to be set
2753 * Out:
2754 * none
2755 *
2756 * Return Value: None.
2757 *
2758 */
2759void vUpdateIFS (PVOID pDeviceHandler)
2760{
2761 //Set SIFS, DIFS, EIFS, SlotTime, CwMin
2762 PSDevice pDevice = (PSDevice) pDeviceHandler;
2763
2764 BYTE byMaxMin = 0;
2765 if (pDevice->byPacketType==PK_TYPE_11A) {//0000 0000 0000 0000,11a
2766 pDevice->uSlot = C_SLOT_SHORT;
2767 pDevice->uSIFS = C_SIFS_A;
2768 pDevice->uDIFS = C_SIFS_A + 2*C_SLOT_SHORT;
2769 pDevice->uCwMin = C_CWMIN_A;
2770 byMaxMin = 4;
2771 }
2772 else if (pDevice->byPacketType==PK_TYPE_11B) {//0000 0001 0000 0000,11b
2773 pDevice->uSlot = C_SLOT_LONG;
2774 pDevice->uSIFS = C_SIFS_BG;
2775 pDevice->uDIFS = C_SIFS_BG + 2*C_SLOT_LONG;
2776 pDevice->uCwMin = C_CWMIN_B;
2777 byMaxMin = 5;
2778 }
2779 else { // PK_TYPE_11GA & PK_TYPE_11GB
2780 pDevice->uSIFS = C_SIFS_BG;
2781 if (pDevice->bShortSlotTime) {
2782 pDevice->uSlot = C_SLOT_SHORT;
2783 } else {
2784 pDevice->uSlot = C_SLOT_LONG;
2785 }
2786 pDevice->uDIFS = C_SIFS_BG + 2*pDevice->uSlot;
2787 if (pDevice->wBasicRate & 0x0150) { //0000 0001 0101 0000,24M,12M,6M
2788 pDevice->uCwMin = C_CWMIN_A;
2789 byMaxMin = 4;
2790 }
2791 else {
2792 pDevice->uCwMin = C_CWMIN_B;
2793 byMaxMin = 5;
2794 }
2795 }
2796
2797 pDevice->uCwMax = C_CWMAX;
2798 pDevice->uEIFS = C_EIFS;
2799 if (pDevice->byRFType == RF_RFMD2959) {
2800 // bcs TX_PE will reserve 3 us
2801 VNSvOutPortB(pDevice->PortOffset + MAC_REG_SIFS, (BYTE)(pDevice->uSIFS - 3));
2802 VNSvOutPortB(pDevice->PortOffset + MAC_REG_DIFS, (BYTE)(pDevice->uDIFS - 3));
2803 } else {
2804 VNSvOutPortB(pDevice->PortOffset + MAC_REG_SIFS, (BYTE)pDevice->uSIFS);
2805 VNSvOutPortB(pDevice->PortOffset + MAC_REG_DIFS, (BYTE)pDevice->uDIFS);
2806 }
2807 VNSvOutPortB(pDevice->PortOffset + MAC_REG_EIFS, (BYTE)pDevice->uEIFS);
2808 VNSvOutPortB(pDevice->PortOffset + MAC_REG_SLOT, (BYTE)pDevice->uSlot);
2809 byMaxMin |= 0xA0;//1010 1111,C_CWMAX = 1023
2810 VNSvOutPortB(pDevice->PortOffset + MAC_REG_CWMAXMIN0, (BYTE)byMaxMin);
2811}
2812
2813void CARDvUpdateBasicTopRate (PVOID pDeviceHandler)
2814{
2815 PSDevice pDevice = (PSDevice) pDeviceHandler;
2816 BYTE byTopOFDM = RATE_24M, byTopCCK = RATE_1M;
2817 BYTE ii;
2818
2819 //Determines the highest basic rate.
2820 for (ii = RATE_54M; ii >= RATE_6M; ii --) {
2821 if ( (pDevice->wBasicRate) & ((WORD)(1<<ii)) )
2822 byTopOFDM = ii;
2823 break;
2824 }
2825 pDevice->byTopOFDMBasicRate = byTopOFDM;
2826
2827 for (ii = RATE_11M;; ii --) {
2828 if ( (pDevice->wBasicRate) & ((WORD)(1<<ii)) )
2829 byTopCCK = ii;
2830 break;
2831 if (ii == RATE_1M)
2832 break;
2833 }
2834 pDevice->byTopCCKBasicRate = byTopCCK;
2835}
2836
2837
2838/*
2839 * Description: Set NIC Tx Basic Rate
2840 *
2841 * Parameters:
2842 * In:
2843 * pDevice - The adapter to be set
2844 * wBasicRate - Basic Rate to be set
2845 * Out:
2846 * none
2847 *
2848 * Return Value: TRUE if succeeded; FALSE if failed.
2849 *
2850 */
2851BOOL CARDbAddBasicRate (PVOID pDeviceHandler, WORD wRateIdx)
2852{
2853 PSDevice pDevice = (PSDevice) pDeviceHandler;
2854 WORD wRate = (WORD)(1<<wRateIdx);
2855
2856 pDevice->wBasicRate |= wRate;
2857
2858 //Determines the highest basic rate.
2859 CARDvUpdateBasicTopRate((PVOID)pDevice);
2860
2861 return(TRUE);
2862}
2863
2864BOOL CARDbIsOFDMinBasicRate (PVOID pDeviceHandler)
2865{
2866 PSDevice pDevice = (PSDevice) pDeviceHandler;
2867 int ii;
2868
2869 for (ii = RATE_54M; ii >= RATE_6M; ii --) {
2870 if ((pDevice->wBasicRate) & ((WORD)(1<<ii)))
2871 return TRUE;
2872 }
2873 return FALSE;
2874}
2875
2876BYTE CARDbyGetPktType (PVOID pDeviceHandler)
2877{
2878 PSDevice pDevice = (PSDevice) pDeviceHandler;
2879
2880 if (pDevice->byBBType == BB_TYPE_11A || pDevice->byBBType == BB_TYPE_11B) {
2881 return (BYTE)pDevice->byBBType;
2882 }
2883 else if (CARDbIsOFDMinBasicRate((PVOID)pDevice)) {
2884 return PK_TYPE_11GA;
2885 }
2886 else {
2887 return PK_TYPE_11GB;
2888 }
2889}
2890
2891/*
2892 * Description: Set NIC Loopback mode
2893 *
2894 * Parameters:
2895 * In:
2896 * pDevice - The adapter to be set
2897 * wLoopbackMode - Loopback mode to be set
2898 * Out:
2899 * none
2900 *
2901 * Return Value: none
2902 *
2903 */
2904void CARDvSetLoopbackMode (DWORD_PTR dwIoBase, WORD wLoopbackMode)
2905{
2906 switch(wLoopbackMode) {
2907 case CARD_LB_NONE:
2908 case CARD_LB_MAC:
2909 case CARD_LB_PHY:
2910 break;
2911 default:
2912 ASSERT(FALSE);
2913 break;
2914 }
2915 // set MAC loopback
2916 MACvSetLoopbackMode(dwIoBase, LOBYTE(wLoopbackMode));
2917 // set Baseband loopback
2918}
2919
2920
2921/*
2922 * Description: Software Reset NIC
2923 *
2924 * Parameters:
2925 * In:
2926 * pDevice - The adapter to be reset
2927 * Out:
2928 * none
2929 *
2930 * Return Value: none
2931 *
2932 */
2933BOOL CARDbSoftwareReset (PVOID pDeviceHandler)
2934{
2935 PSDevice pDevice = (PSDevice) pDeviceHandler;
2936
2937 // reset MAC
2938 if (!MACbSafeSoftwareReset(pDevice->PortOffset))
2939 return FALSE;
2940
2941 return TRUE;
2942}
2943
2944
2945/*
2946 * Description: Caculate TSF offset of two TSF input
2947 * Get TSF Offset from RxBCN's TSF and local TSF
2948 *
2949 * Parameters:
2950 * In:
2951 * pDevice - The adapter to be sync.
2952 * qwTSF1 - Rx BCN's TSF
2953 * qwTSF2 - Local TSF
2954 * Out:
2955 * none
2956 *
2957 * Return Value: TSF Offset value
2958 *
2959 */
2960QWORD CARDqGetTSFOffset (BYTE byRxRate, QWORD qwTSF1, QWORD qwTSF2)
2961{
2962 QWORD qwTSFOffset;
2963 WORD wRxBcnTSFOffst= 0;;
2964
2965 HIDWORD(qwTSFOffset) = 0;
2966 LODWORD(qwTSFOffset) = 0;
2967 wRxBcnTSFOffst = cwRXBCNTSFOff[byRxRate%MAX_RATE];
2968 (qwTSF2).u.dwLowDword += (DWORD)(wRxBcnTSFOffst);
2969 if ((qwTSF2).u.dwLowDword < (DWORD)(wRxBcnTSFOffst)) {
2970 (qwTSF2).u.dwHighDword++;
2971 }
2972 LODWORD(qwTSFOffset) = LODWORD(qwTSF1) - LODWORD(qwTSF2);
2973 if (LODWORD(qwTSF1) < LODWORD(qwTSF2)) {
2974 // if borrow needed
2975 HIDWORD(qwTSFOffset) = HIDWORD(qwTSF1) - HIDWORD(qwTSF2) - 1 ;
2976 }
2977 else {
2978 HIDWORD(qwTSFOffset) = HIDWORD(qwTSF1) - HIDWORD(qwTSF2);
2979 };
2980 return (qwTSFOffset);
2981}
2982
2983
2984/*
2985 * Description: Read NIC TSF counter
2986 * Get local TSF counter
2987 *
2988 * Parameters:
2989 * In:
2990 * pDevice - The adapter to be read
2991 * Out:
2992 * qwCurrTSF - Current TSF counter
2993 *
2994 * Return Value: TRUE if success; otherwise FALSE
2995 *
2996 */
2997BOOL CARDbGetCurrentTSF (DWORD_PTR dwIoBase, PQWORD pqwCurrTSF)
2998{
2999 WORD ww;
3000 BYTE byData;
3001
3002 MACvRegBitsOn(dwIoBase, MAC_REG_TFTCTL, TFTCTL_TSFCNTRRD);
3003 for (ww = 0; ww < W_MAX_TIMEOUT; ww++) {
3004 VNSvInPortB(dwIoBase + MAC_REG_TFTCTL, &byData);
3005 if (BITbIsBitOff(byData, TFTCTL_TSFCNTRRD))
3006 break;
3007 }
3008 if (ww == W_MAX_TIMEOUT)
3009 return(FALSE);
3010 VNSvInPortD(dwIoBase + MAC_REG_TSFCNTR, &LODWORD(*pqwCurrTSF));
3011 VNSvInPortD(dwIoBase + MAC_REG_TSFCNTR + 4, &HIDWORD(*pqwCurrTSF));
3012
3013 return(TRUE);
3014}
3015
3016
3017/*
3018 * Description: Read NIC TSF counter
3019 * Get NEXTTBTT from adjusted TSF and Beacon Interval
3020 *
3021 * Parameters:
3022 * In:
3023 * qwTSF - Current TSF counter
3024 * wbeaconInterval - Beacon Interval
3025 * Out:
3026 * qwCurrTSF - Current TSF counter
3027 *
3028 * Return Value: TSF value of next Beacon
3029 *
3030 */
3031QWORD CARDqGetNextTBTT (QWORD qwTSF, WORD wBeaconInterval)
3032{
3033
3034 UINT uLowNextTBTT;
3035 UINT uHighRemain, uLowRemain;
3036 UINT uBeaconInterval;
3037
3038 uBeaconInterval = wBeaconInterval * 1024;
3039 // Next TBTT = ((local_current_TSF / beacon_interval) + 1 ) * beacon_interval
3040 uLowNextTBTT = (LODWORD(qwTSF) >> 10) << 10;
3041 // low dword (mod) bcn
3042 uLowRemain = (uLowNextTBTT) % uBeaconInterval;
3043// uHighRemain = ((0x80000000 % uBeaconInterval)* 2 * HIDWORD(qwTSF))
3044// % uBeaconInterval;
3045 // high dword (mod) bcn
3046 uHighRemain = (((0xffffffff % uBeaconInterval) + 1) * HIDWORD(qwTSF))
3047 % uBeaconInterval;
3048 uLowRemain = (uHighRemain + uLowRemain) % uBeaconInterval;
3049 uLowRemain = uBeaconInterval - uLowRemain;
3050
3051 // check if carry when add one beacon interval
3052 if ((~uLowNextTBTT) < uLowRemain)
3053 HIDWORD(qwTSF) ++ ;
3054
3055 LODWORD(qwTSF) = uLowNextTBTT + uLowRemain;
3056
3057 return (qwTSF);
3058}
3059
3060
3061/*
3062 * Description: Set NIC TSF counter for first Beacon time
3063 * Get NEXTTBTT from adjusted TSF and Beacon Interval
3064 *
3065 * Parameters:
3066 * In:
3067 * dwIoBase - IO Base
3068 * wBeaconInterval - Beacon Interval
3069 * Out:
3070 * none
3071 *
3072 * Return Value: none
3073 *
3074 */
3075void CARDvSetFirstNextTBTT (DWORD_PTR dwIoBase, WORD wBeaconInterval)
3076{
3077
3078 QWORD qwNextTBTT;
3079
3080 HIDWORD(qwNextTBTT) = 0;
3081 LODWORD(qwNextTBTT) = 0;
3082 CARDbGetCurrentTSF(dwIoBase, &qwNextTBTT); //Get Local TSF counter
3083 qwNextTBTT = CARDqGetNextTBTT(qwNextTBTT, wBeaconInterval);
3084 // Set NextTBTT
3085 VNSvOutPortD(dwIoBase + MAC_REG_NEXTTBTT, LODWORD(qwNextTBTT));
3086 VNSvOutPortD(dwIoBase + MAC_REG_NEXTTBTT + 4, HIDWORD(qwNextTBTT));
3087 MACvRegBitsOn(dwIoBase, MAC_REG_TFTCTL, TFTCTL_TBTTSYNCEN);
3088 //DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Card:First Next TBTT[%8xh:%8xh] \n", HIDWORD(qwNextTBTT), LODWORD(qwNextTBTT));
3089 return;
3090}
3091
3092
3093/*
3094 * Description: Sync NIC TSF counter for Beacon time
3095 * Get NEXTTBTT and write to HW
3096 *
3097 * Parameters:
3098 * In:
3099 * pDevice - The adapter to be set
3100 * qwTSF - Current TSF counter
3101 * wBeaconInterval - Beacon Interval
3102 * Out:
3103 * none
3104 *
3105 * Return Value: none
3106 *
3107 */
3108void CARDvUpdateNextTBTT (DWORD_PTR dwIoBase, QWORD qwTSF, WORD wBeaconInterval)
3109{
3110
3111 qwTSF = CARDqGetNextTBTT(qwTSF, wBeaconInterval);
3112 // Set NextTBTT
3113 VNSvOutPortD(dwIoBase + MAC_REG_NEXTTBTT, LODWORD(qwTSF));
3114 VNSvOutPortD(dwIoBase + MAC_REG_NEXTTBTT + 4, HIDWORD(qwTSF));
3115 MACvRegBitsOn(dwIoBase, MAC_REG_TFTCTL, TFTCTL_TBTTSYNCEN);
3116 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Card:Update Next TBTT[%8xh:%8xh] \n",(UINT)HIDWORD(qwTSF), (UINT)LODWORD(qwTSF));
3117
3118 return;
3119}
3120
3121
3122
3123
3124
3125
3126
diff --git a/drivers/staging/vt6655/card.h b/drivers/staging/vt6655/card.h
new file mode 100644
index 000000000000..bb292e14b0b3
--- /dev/null
+++ b/drivers/staging/vt6655/card.h
@@ -0,0 +1,273 @@
1/*
2 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
3 * All rights reserved.
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * File: card.h
20 *
21 * Purpose: Provide functions to setup NIC operation mode
22 *
23 * Author: Tevin Chen
24 *
25 * Date: May 21, 1996
26 *
27 */
28
29
30#ifndef __CARD_H__
31#define __CARD_H__
32
33//#if !defined(__DEVICE_H__)
34//#include "device.h"
35//#endif
36#if !defined(__TTYPE_H__)
37#include "ttype.h"
38#endif
39
40
41
42
43/*--------------------- Export Definitions -------------------------*/
44//
45// Loopback mode
46//
47// LOBYTE is MAC LB mode, HIBYTE is MII LB mode
48#define CARD_LB_NONE MAKEWORD(MAC_LB_NONE, 0)
49#define CARD_LB_MAC MAKEWORD(MAC_LB_INTERNAL, 0) // PHY must ISO, avoid MAC loopback packet go out
50#define CARD_LB_PHY MAKEWORD(MAC_LB_EXT, 0)
51
52
53#define DEFAULT_MSDU_LIFETIME 512 // ms
54#define DEFAULT_MSDU_LIFETIME_RES_64us 8000 // 64us
55
56#define DEFAULT_MGN_LIFETIME 8 // ms
57#define DEFAULT_MGN_LIFETIME_RES_64us 125 // 64us
58
59#define CB_MAX_CHANNEL_24G 14
60#define CB_MAX_CHANNEL_5G 42 //[20050104] add channel9(5045MHz), 41==>42
61#define CB_MAX_CHANNEL (CB_MAX_CHANNEL_24G+CB_MAX_CHANNEL_5G)
62
63typedef enum _CARD_PHY_TYPE {
64 PHY_TYPE_AUTO,
65 PHY_TYPE_11B,
66 PHY_TYPE_11G,
67 PHY_TYPE_11A
68} CARD_PHY_TYPE, *PCARD_PHY_TYPE;
69
70typedef enum _CARD_PKT_TYPE {
71 PKT_TYPE_802_11_BCN,
72 PKT_TYPE_802_11_MNG,
73 PKT_TYPE_802_11_DATA,
74 PKT_TYPE_802_11_ALL
75} CARD_PKT_TYPE, *PCARD_PKT_TYPE;
76
77typedef enum _CARD_STATUS_TYPE {
78 CARD_STATUS_MEDIA_CONNECT,
79 CARD_STATUS_MEDIA_DISCONNECT,
80 CARD_STATUS_PMKID
81} CARD_STATUS_TYPE, *PCARD_STATUS_TYPE;
82
83typedef enum _CARD_OP_MODE {
84 OP_MODE_INFRASTRUCTURE,
85 OP_MODE_ADHOC,
86 OP_MODE_AP,
87 OP_MODE_UNKNOWN
88} CARD_OP_MODE, *PCARD_OP_MODE;
89
90
91
92/*--------------------- Export Classes ----------------------------*/
93
94/*--------------------- Export Variables --------------------------*/
95
96/*--------------------- Export Functions --------------------------*/
97#ifdef __cplusplus
98extern "C" { /* Assume C declarations for C++ */
99#endif /* __cplusplus */
100
101BOOL ChannelValid(UINT CountryCode, UINT ChannelIndex);
102void CARDvSetRSPINF(PVOID pDeviceHandler, CARD_PHY_TYPE ePHYType);
103void vUpdateIFS(PVOID pDeviceHandler);
104void CARDvUpdateBasicTopRate(PVOID pDeviceHandler);
105BOOL CARDbAddBasicRate(PVOID pDeviceHandler, WORD wRateIdx);
106BOOL CARDbIsOFDMinBasicRate(PVOID pDeviceHandler);
107void CARDvSetLoopbackMode(DWORD_PTR dwIoBase, WORD wLoopbackMode);
108BOOL CARDbSoftwareReset(PVOID pDeviceHandler);
109void CARDvSetFirstNextTBTT(DWORD_PTR dwIoBase, WORD wBeaconInterval);
110void CARDvUpdateNextTBTT(DWORD_PTR dwIoBase, QWORD qwTSF, WORD wBeaconInterval);
111BOOL CARDbGetCurrentTSF(DWORD_PTR dwIoBase, PQWORD pqwCurrTSF);
112QWORD CARDqGetNextTBTT(QWORD qwTSF, WORD wBeaconInterval);
113QWORD CARDqGetTSFOffset(BYTE byRxRate, QWORD qwTSF1, QWORD qwTSF2);
114BOOL CARDbSetTxPower(PVOID pDeviceHandler, ULONG ulTxPower);
115BYTE CARDbyGetPktType(PVOID pDeviceHandler);
116VOID CARDvSafeResetTx(PVOID pDeviceHandler);
117VOID CARDvSafeResetRx(PVOID pDeviceHandler);
118
119//xxx
120BOOL CARDbRadioPowerOff(PVOID pDeviceHandler);
121BOOL CARDbRadioPowerOn(PVOID pDeviceHandler);
122BOOL CARDbSetChannel(PVOID pDeviceHandler, UINT uConnectionChannel);
123//BOOL CARDbSendPacket(PVOID pDeviceHandler, PVOID pPacket, CARD_PKT_TYPE ePktType, UINT uLength);
124BOOL CARDbIsShortPreamble(PVOID pDeviceHandler);
125BOOL CARDbIsShorSlotTime(PVOID pDeviceHandler);
126BOOL CARDbSetPhyParameter(PVOID pDeviceHandler, CARD_PHY_TYPE ePHYType, WORD wCapInfo, BYTE byERPField, PVOID pvSupportRateIEs, PVOID pvExtSupportRateIEs);
127BOOL CARDbUpdateTSF(PVOID pDeviceHandler, BYTE byRxRate, QWORD qwBSSTimestamp, QWORD qwLocalTSF);
128BOOL CARDbStopTxPacket(PVOID pDeviceHandler, CARD_PKT_TYPE ePktType);
129BOOL CARDbStartTxPacket(PVOID pDeviceHandler, CARD_PKT_TYPE ePktType);
130BOOL CARDbSetBeaconPeriod(PVOID pDeviceHandler, WORD wBeaconInterval);
131BOOL CARDbSetBSSID(PVOID pDeviceHandler, PBYTE pbyBSSID, CARD_OP_MODE eOPMode);
132
133BOOL
134CARDbPowerDown(
135 PVOID pDeviceHandler
136 );
137
138BOOL CARDbSetTxDataRate(
139 PVOID pDeviceHandler,
140 WORD wDataRate
141 );
142
143
144BOOL CARDbRemoveKey (PVOID pDeviceHandler, PBYTE pbyBSSID);
145
146BOOL
147CARDbAdd_PMKID_Candidate (
148 IN PVOID pDeviceHandler,
149 IN PBYTE pbyBSSID,
150 IN BOOL bRSNCapExist,
151 IN WORD wRSNCap
152 );
153
154PVOID
155CARDpGetCurrentAddress (
156 IN PVOID pDeviceHandler
157 );
158
159
160VOID CARDvInitChannelTable(PVOID pDeviceHandler);
161BYTE CARDbyGetChannelMapping(PVOID pDeviceHandler, BYTE byChannelNumber, CARD_PHY_TYPE ePhyType);
162
163BOOL
164CARDbStartMeasure (
165 IN PVOID pDeviceHandler,
166 IN PVOID pvMeasureEIDs,
167 IN UINT uNumOfMeasureEIDs
168 );
169
170BOOL
171CARDbChannelSwitch (
172 IN PVOID pDeviceHandler,
173 IN BYTE byMode,
174 IN BYTE byNewChannel,
175 IN BYTE byCount
176 );
177
178BOOL
179CARDbSetQuiet (
180 IN PVOID pDeviceHandler,
181 IN BOOL bResetQuiet,
182 IN BYTE byQuietCount,
183 IN BYTE byQuietPeriod,
184 IN WORD wQuietDuration,
185 IN WORD wQuietOffset
186 );
187
188BOOL
189CARDbStartQuiet (
190 IN PVOID pDeviceHandler
191 );
192
193VOID
194CARDvSetCountryInfo (
195 IN PVOID pDeviceHandler,
196 IN CARD_PHY_TYPE ePHYType,
197 IN PVOID pIE
198 );
199
200VOID
201CARDvSetPowerConstraint (
202 IN PVOID pDeviceHandler,
203 IN BYTE byChannel,
204 IN I8 byPower
205 );
206
207VOID
208CARDvGetPowerCapability (
209 IN PVOID pDeviceHandler,
210 OUT PBYTE pbyMinPower,
211 OUT PBYTE pbyMaxPower
212 );
213
214BYTE
215CARDbySetSupportChannels (
216 IN PVOID pDeviceHandler,
217 IN OUT PBYTE pbyIEs
218 );
219
220I8
221CARDbyGetTransmitPower (
222 IN PVOID pDeviceHandler
223 );
224
225BOOL
226CARDbChannelGetList (
227 IN UINT uCountryCodeIdx,
228 OUT PBYTE pbyChannelTable
229 );
230
231VOID
232CARDvSetCountryIE(
233 IN PVOID pDeviceHandler,
234 IN PVOID pIE
235 );
236
237BOOL
238CARDbGetChannelMapInfo(
239 IN PVOID pDeviceHandler,
240 IN UINT uChannelIndex,
241 OUT PBYTE pbyChannelNumber,
242 OUT PBYTE pbyMap
243 );
244
245VOID
246CARDvSetChannelMapInfo(
247 IN PVOID pDeviceHandler,
248 IN UINT uChannelIndex,
249 IN BYTE byMap
250 );
251
252VOID
253CARDvClearChannelMapInfo(
254 IN PVOID pDeviceHandler
255 );
256
257BYTE
258CARDbyAutoChannelSelect(
259 IN PVOID pDeviceHandler,
260 CARD_PHY_TYPE ePHYType
261 );
262
263BYTE CARDbyGetChannelNumber(PVOID pDeviceHandler, BYTE byChannelIndex);
264
265#ifdef __cplusplus
266} /* End of extern "C" { */
267#endif /* __cplusplus */
268
269
270#endif // __CARD_H__
271
272
273
diff --git a/drivers/staging/vt6655/country.h b/drivers/staging/vt6655/country.h
new file mode 100644
index 000000000000..65d1e52916ce
--- /dev/null
+++ b/drivers/staging/vt6655/country.h
@@ -0,0 +1,192 @@
1/*
2 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
3 * All rights reserved.
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 *
20 * File: country.h
21 *
22 * Purpose: Country Code information
23 *
24 * Author: Lucas Lin
25 *
26 * Date: Dec 23, 2004
27 *
28 */
29
30#ifndef __COUNTRY_H__
31#define __COUNTRY_H__
32
33#if !defined(__TTYPE_H__)
34#include "ttype.h"
35#endif
36
37
38/*--------------------- Export Definitions -------------------------*/
39/************************************************************************
40 * The definition here should be complied with the INF country order
41 * Please check with VNWL.inf/VNWL64.inf/VNWL*.inf
42 ************************************************************************/
43typedef enum _COUNTRY_CODE {
44 CCODE_FCC = 0,
45 CCODE_TELEC,
46 CCODE_ETSI,
47 CCODE_RESV3,
48 CCODE_RESV4,
49 CCODE_RESV5,
50 CCODE_RESV6,
51 CCODE_RESV7,
52 CCODE_RESV8,
53 CCODE_RESV9,
54 CCODE_RESVa,
55 CCODE_RESVb,
56 CCODE_RESVc,
57 CCODE_RESVd,
58 CCODE_RESVe,
59 CCODE_ALLBAND,
60 CCODE_ALBANIA,
61 CCODE_ALGERIA,
62 CCODE_ARGENTINA,
63 CCODE_ARMENIA,
64 CCODE_AUSTRALIA,
65 CCODE_AUSTRIA,
66 CCODE_AZERBAIJAN,
67 CCODE_BAHRAIN,
68 CCODE_BELARUS,
69 CCODE_BELGIUM,
70 CCODE_BELIZE,
71 CCODE_BOLIVIA,
72 CCODE_BRAZIL,
73 CCODE_BRUNEI_DARUSSALAM,
74 CCODE_BULGARIA,
75 CCODE_CANADA,
76 CCODE_CHILE,
77 CCODE_CHINA,
78 CCODE_COLOMBIA,
79 CCODE_COSTA_RICA,
80 CCODE_CROATIA,
81 CCODE_CYPRUS,
82 CCODE_CZECH,
83 CCODE_DENMARK,
84 CCODE_DOMINICAN_REPUBLIC,
85 CCODE_ECUADOR,
86 CCODE_EGYPT,
87 CCODE_EL_SALVADOR,
88 CCODE_ESTONIA,
89 CCODE_FINLAND,
90 CCODE_FRANCE,
91 CCODE_GERMANY,
92 CCODE_GREECE,
93 CCODE_GEORGIA,
94 CCODE_GUATEMALA,
95 CCODE_HONDURAS,
96 CCODE_HONG_KONG,
97 CCODE_HUNGARY,
98 CCODE_ICELAND,
99 CCODE_INDIA,
100 CCODE_INDONESIA,
101 CCODE_IRAN,
102 CCODE_IRELAND,
103 CCODE_ITALY,
104 CCODE_ISRAEL,
105 CCODE_JAPAN,
106 CCODE_JORDAN,
107 CCODE_KAZAKHSTAN,
108 CCODE_KUWAIT,
109 CCODE_LATVIA,
110 CCODE_LEBANON,
111 CCODE_LEICHTENSTEIN,
112 CCODE_LITHUANIA,
113 CCODE_LUXEMBURG,
114 CCODE_MACAU,
115 CCODE_MACEDONIA,
116 CCODE_MALTA,
117 CCODE_MALAYSIA,
118 CCODE_MEXICO,
119 CCODE_MONACO,
120 CCODE_MOROCCO,
121 CCODE_NETHERLANDS,
122 CCODE_NEW_ZEALAND,
123 CCODE_NORTH_KOREA,
124 CCODE_NORWAY,
125 CCODE_OMAN,
126 CCODE_PAKISTAN,
127 CCODE_PANAMA,
128 CCODE_PERU,
129 CCODE_PHILIPPINES,
130 CCODE_POLAND,
131 CCODE_PORTUGAL,
132 CCODE_PUERTO_RICO,
133 CCODE_QATAR,
134 CCODE_ROMANIA,
135 CCODE_RUSSIA,
136 CCODE_SAUDI_ARABIA,
137 CCODE_SINGAPORE,
138 CCODE_SLOVAKIA,
139 CCODE_SLOVENIA,
140 CCODE_SOUTH_AFRICA,
141 CCODE_SOUTH_KOREA,
142 CCODE_SPAIN,
143 CCODE_SWEDEN,
144 CCODE_SWITZERLAND,
145 CCODE_SYRIA,
146 CCODE_TAIWAN,
147 CCODE_THAILAND,
148 CCODE_TRINIDAD_TOBAGO,
149 CCODE_TUNISIA,
150 CCODE_TURKEY,
151 CCODE_UK,
152 CCODE_UKRAINE,
153 CCODE_UNITED_ARAB_EMIRATES,
154 CCODE_UNITED_STATES,
155 CCODE_URUGUAY,
156 CCODE_UZBEKISTAN,
157 CCODE_VENEZUELA,
158 CCODE_VIETNAM,
159 CCODE_YEMEN,
160 CCODE_ZIMBABWE,
161 CCODE_JAPAN_W52_W53,
162 CCODE_MAX
163} COUNTRY_CODE;
164
165typedef struct tagSCountryTable
166{
167 BYTE byChannelCountryCode; /* The country code */
168 CHAR chCountryCode[2];
169 BYTE bChannelIdxList[CB_MAX_CHANNEL]; /* Available channels Index */
170 BYTE byPower[CB_MAX_CHANNEL];
171} SCountryTable, DEF* PSCountryTable;
172
173/*--------------------- Export Classes ----------------------------*/
174
175/*--------------------- Export Variables --------------------------*/
176extern SCountryTable ChannelRuleTab[CCODE_MAX+1];
177
178/*--------------------- Export Functions --------------------------*/
179#ifdef __cplusplus
180extern "C" { /* Assume C declarations for C++ */
181#endif /* __cplusplus */
182
183
184#ifdef __cplusplus
185} /* End of extern "C" { */
186#endif /* __cplusplus */
187
188
189/************************************************************************
190 * Function prototype
191 ************************************************************************/
192#endif /* __COUNTRY_H__ */
diff --git a/drivers/staging/vt6655/datarate.c b/drivers/staging/vt6655/datarate.c
new file mode 100644
index 000000000000..f58f9636be2d
--- /dev/null
+++ b/drivers/staging/vt6655/datarate.c
@@ -0,0 +1,455 @@
1/*
2 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
3 * All rights reserved.
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * File: datarate.c
20 *
21 * Purpose: Handles the auto fallback & data rates functions
22 *
23 * Author: Lyndon Chen
24 *
25 * Date: July 17, 2002
26 *
27 * Functions:
28 * RATEvParseMaxRate - Parsing the highest basic & support rate in rate field of frame
29 * RATEvTxRateFallBack - Rate fallback Algorithm Implementaion
30 * RATEuSetIE- Set rate IE field.
31 *
32 * Revision History:
33 *
34 */
35
36#if !defined(__TTYPE_H__)
37#include "ttype.h"
38#endif
39#if !defined(__TMACRO_H__)
40#include "tmacro.h"
41#endif
42#if !defined(__MAC_H__)
43#include "mac.h"
44#endif
45#if !defined(__80211MGR_H__)
46#include "80211mgr.h"
47#endif
48#if !defined(__BSSDB_H__)
49#include "bssdb.h"
50#endif
51#if !defined(__DATARATE_H__)
52#include "datarate.h"
53#endif
54#if !defined(__CARD_H__)
55#include "card.h"
56#endif
57#if !defined(__BASEBAND_H__)
58#include "baseband.h"
59#endif
60#if !defined(__SROM_H__)
61#include "srom.h"
62#endif
63
64/*--------------------- Static Definitions -------------------------*/
65
66
67
68
69/*--------------------- Static Classes ----------------------------*/
70
71
72 extern WORD TxRate_iwconfig; //2008-5-8 <add> by chester
73/*--------------------- Static Variables --------------------------*/
74//static int msglevel =MSG_LEVEL_DEBUG;
75static int msglevel =MSG_LEVEL_INFO;
76const BYTE acbyIERate[MAX_RATE] =
77{0x02, 0x04, 0x0B, 0x16, 0x0C, 0x12, 0x18, 0x24, 0x30, 0x48, 0x60, 0x6C};
78
79#define AUTORATE_TXOK_CNT 0x0400
80#define AUTORATE_TXFAIL_CNT 0x0064
81#define AUTORATE_TIMEOUT 10
82
83/*--------------------- Static Functions --------------------------*/
84
85VOID s_vResetCounter (
86 IN PKnownNodeDB psNodeDBTable
87 );
88
89
90
91VOID
92s_vResetCounter (
93 IN PKnownNodeDB psNodeDBTable
94 )
95{
96 BYTE ii;
97
98 // clear statistic counter for auto_rate
99 for(ii=0;ii<=MAX_RATE;ii++) {
100 psNodeDBTable->uTxOk[ii] = 0;
101 psNodeDBTable->uTxFail[ii] = 0;
102 }
103}
104
105/*--------------------- Export Variables --------------------------*/
106
107
108/*--------------------- Export Functions --------------------------*/
109
110
111/*+
112 *
113 * Description:
114 * Get RateIdx from the value in SuppRates IE or ExtSuppRates IE
115 *
116 * Parameters:
117 * In:
118 * BYTE - Rate value in SuppRates IE or ExtSuppRates IE
119 * Out:
120 * none
121 *
122 * Return Value: RateIdx
123 *
124-*/
125BYTE
126DATARATEbyGetRateIdx (
127 IN BYTE byRate
128 )
129{
130 BYTE ii;
131
132 //Erase basicRate flag.
133 byRate = byRate & 0x7F;//0111 1111
134
135 for (ii = 0; ii < MAX_RATE; ii ++) {
136 if (acbyIERate[ii] == byRate)
137 return ii;
138 }
139 return 0;
140}
141
142
143
144/*+
145 *
146 * Routine Description:
147 * Rate fallback Algorithm Implementaion
148 *
149 * Parameters:
150 * In:
151 * pDevice - Pointer to the adapter
152 * psNodeDBTable - Pointer to Node Data Base
153 * Out:
154 * none
155 *
156 * Return Value: none
157 *
158-*/
159#define AUTORATE_TXCNT_THRESHOLD 20
160#define AUTORATE_INC_THRESHOLD 30
161
162
163
164
165/*+
166 *
167 * Description:
168 * Get RateIdx from the value in SuppRates IE or ExtSuppRates IE
169 *
170 * Parameters:
171 * In:
172 * BYTE - Rate value in SuppRates IE or ExtSuppRates IE
173 * Out:
174 * none
175 *
176 * Return Value: RateIdx
177 *
178-*/
179WORD
180wGetRateIdx(
181 IN BYTE byRate
182 )
183{
184 WORD ii;
185
186 //Erase basicRate flag.
187 byRate = byRate & 0x7F;//0111 1111
188
189 for (ii = 0; ii < MAX_RATE; ii ++) {
190 if (acbyIERate[ii] == byRate)
191 return ii;
192 }
193 return 0;
194}
195
196/*+
197 *
198 * Description:
199 * Parsing the highest basic & support rate in rate field of frame.
200 *
201 * Parameters:
202 * In:
203 * pDevice - Pointer to the adapter
204 * pItemRates - Pointer to Rate field defined in 802.11 spec.
205 * pItemExtRates - Pointer to Extended Rate field defined in 802.11 spec.
206 * Out:
207 * pwMaxBasicRate - Maximum Basic Rate
208 * pwMaxSuppRate - Maximum Supported Rate
209 * pbyTopCCKRate - Maximum Basic Rate in CCK mode
210 * pbyTopOFDMRate - Maximum Basic Rate in OFDM mode
211 *
212 * Return Value: none
213 *
214-*/
215VOID
216RATEvParseMaxRate (
217 IN PVOID pDeviceHandler,
218 IN PWLAN_IE_SUPP_RATES pItemRates,
219 IN PWLAN_IE_SUPP_RATES pItemExtRates,
220 IN BOOL bUpdateBasicRate,
221 OUT PWORD pwMaxBasicRate,
222 OUT PWORD pwMaxSuppRate,
223 OUT PWORD pwSuppRate,
224 OUT PBYTE pbyTopCCKRate,
225 OUT PBYTE pbyTopOFDMRate
226 )
227{
228PSDevice pDevice = (PSDevice) pDeviceHandler;
229UINT ii;
230BYTE byHighSuppRate = 0;
231BYTE byRate = 0;
232WORD wOldBasicRate = pDevice->wBasicRate;
233UINT uRateLen;
234
235
236 if (pItemRates == NULL)
237 return;
238
239 *pwSuppRate = 0;
240 uRateLen = pItemRates->len;
241
242 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"ParseMaxRate Len: %d\n", uRateLen);
243 if (pDevice->eCurrentPHYType != PHY_TYPE_11B) {
244 if (uRateLen > WLAN_RATES_MAXLEN)
245 uRateLen = WLAN_RATES_MAXLEN;
246 } else {
247 if (uRateLen > WLAN_RATES_MAXLEN_11B)
248 uRateLen = WLAN_RATES_MAXLEN_11B;
249 }
250
251 for (ii = 0; ii < uRateLen; ii++) {
252 byRate = (BYTE)(pItemRates->abyRates[ii]);
253 if (WLAN_MGMT_IS_BASICRATE(byRate) &&
254 (bUpdateBasicRate == TRUE)) {
255 // Add to basic rate set, update pDevice->byTopCCKBasicRate and pDevice->byTopOFDMBasicRate
256 CARDbAddBasicRate((PVOID)pDevice, wGetRateIdx(byRate));
257 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"ParseMaxRate AddBasicRate: %d\n", wGetRateIdx(byRate));
258 }
259 byRate = (BYTE)(pItemRates->abyRates[ii]&0x7F);
260 if (byHighSuppRate == 0)
261 byHighSuppRate = byRate;
262 if (byRate > byHighSuppRate)
263 byHighSuppRate = byRate;
264 *pwSuppRate |= (1<<wGetRateIdx(byRate));
265 }
266 if ((pItemExtRates != NULL) && (pItemExtRates->byElementID == WLAN_EID_EXTSUPP_RATES) &&
267 (pDevice->eCurrentPHYType != PHY_TYPE_11B)) {
268
269 UINT uExtRateLen = pItemExtRates->len;
270
271 if (uExtRateLen > WLAN_RATES_MAXLEN)
272 uExtRateLen = WLAN_RATES_MAXLEN;
273
274 for (ii = 0; ii < uExtRateLen ; ii++) {
275 byRate = (BYTE)(pItemExtRates->abyRates[ii]);
276 // select highest basic rate
277 if (WLAN_MGMT_IS_BASICRATE(pItemExtRates->abyRates[ii])) {
278 // Add to basic rate set, update pDevice->byTopCCKBasicRate and pDevice->byTopOFDMBasicRate
279 CARDbAddBasicRate((PVOID)pDevice, wGetRateIdx(byRate));
280 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"ParseMaxRate AddBasicRate: %d\n", wGetRateIdx(byRate));
281 }
282 byRate = (BYTE)(pItemExtRates->abyRates[ii]&0x7F);
283 if (byHighSuppRate == 0)
284 byHighSuppRate = byRate;
285 if (byRate > byHighSuppRate)
286 byHighSuppRate = byRate;
287 *pwSuppRate |= (1<<wGetRateIdx(byRate));
288 //DBG_PRN_GRP09(("ParseMaxRate : HighSuppRate: %d, %X\n", wGetRateIdx(byRate), byRate));
289 }
290 } //if(pItemExtRates != NULL)
291
292 if ((pDevice->byPacketType == PK_TYPE_11GB) && CARDbIsOFDMinBasicRate((PVOID)pDevice)) {
293 pDevice->byPacketType = PK_TYPE_11GA;
294 }
295
296 *pbyTopCCKRate = pDevice->byTopCCKBasicRate;
297 *pbyTopOFDMRate = pDevice->byTopOFDMBasicRate;
298 *pwMaxSuppRate = wGetRateIdx(byHighSuppRate);
299 if ((pDevice->byPacketType==PK_TYPE_11B) || (pDevice->byPacketType==PK_TYPE_11GB))
300 *pwMaxBasicRate = pDevice->byTopCCKBasicRate;
301 else
302 *pwMaxBasicRate = pDevice->byTopOFDMBasicRate;
303 if (wOldBasicRate != pDevice->wBasicRate)
304 CARDvSetRSPINF((PVOID)pDevice, pDevice->eCurrentPHYType);
305
306 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Exit ParseMaxRate\n");
307}
308
309
310/*+
311 *
312 * Routine Description:
313 * Rate fallback Algorithm Implementaion
314 *
315 * Parameters:
316 * In:
317 * pDevice - Pointer to the adapter
318 * psNodeDBTable - Pointer to Node Data Base
319 * Out:
320 * none
321 *
322 * Return Value: none
323 *
324-*/
325#define AUTORATE_TXCNT_THRESHOLD 20
326#define AUTORATE_INC_THRESHOLD 30
327
328VOID
329RATEvTxRateFallBack (
330 IN PVOID pDeviceHandler,
331 IN PKnownNodeDB psNodeDBTable
332 )
333{
334PSDevice pDevice = (PSDevice) pDeviceHandler;
335WORD wIdxDownRate = 0;
336UINT ii;
337//DWORD dwRateTable[MAX_RATE] = {1, 2, 5, 11, 6, 9, 12, 18, 24, 36, 48, 54};
338BOOL bAutoRate[MAX_RATE] = {TRUE,TRUE,TRUE,TRUE,FALSE,FALSE,TRUE,TRUE,TRUE,TRUE,TRUE,TRUE};
339DWORD dwThroughputTbl[MAX_RATE] = {10, 20, 55, 110, 60, 90, 120, 180, 240, 360, 480, 540};
340DWORD dwThroughput = 0;
341WORD wIdxUpRate = 0;
342DWORD dwTxDiff = 0;
343
344 if (pDevice->pMgmt->eScanState != WMAC_NO_SCANNING) {
345 // Don't do Fallback when scanning Channel
346 return;
347 }
348
349 psNodeDBTable->uTimeCount ++;
350
351 if (psNodeDBTable->uTxFail[MAX_RATE] > psNodeDBTable->uTxOk[MAX_RATE])
352 dwTxDiff = psNodeDBTable->uTxFail[MAX_RATE] - psNodeDBTable->uTxOk[MAX_RATE];
353
354 if ((psNodeDBTable->uTxOk[MAX_RATE] < AUTORATE_TXOK_CNT) &&
355 (dwTxDiff < AUTORATE_TXFAIL_CNT) &&
356 (psNodeDBTable->uTimeCount < AUTORATE_TIMEOUT)) {
357 return;
358 }
359
360 if (psNodeDBTable->uTimeCount >= AUTORATE_TIMEOUT) {
361 psNodeDBTable->uTimeCount = 0;
362 }
363
364
365 for(ii=0;ii<MAX_RATE;ii++) {
366 if (psNodeDBTable->wSuppRate & (0x0001<<ii)) {
367 if (bAutoRate[ii] == TRUE) {
368 wIdxUpRate = (WORD) ii;
369 }
370 } else {
371 bAutoRate[ii] = FALSE;
372 }
373 }
374
375 for(ii=0;ii<=psNodeDBTable->wTxDataRate;ii++) {
376 if ( (psNodeDBTable->uTxOk[ii] != 0) ||
377 (psNodeDBTable->uTxFail[ii] != 0) ) {
378 dwThroughputTbl[ii] *= psNodeDBTable->uTxOk[ii];
379 if (ii < RATE_11M) {
380 psNodeDBTable->uTxFail[ii] *= 4;
381 }
382 dwThroughputTbl[ii] /= (psNodeDBTable->uTxOk[ii] + psNodeDBTable->uTxFail[ii]);
383 }
384// DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Rate %d,Ok: %d, Fail:%d, Throughput:%d\n",
385// ii, psNodeDBTable->uTxOk[ii], psNodeDBTable->uTxFail[ii], dwThroughputTbl[ii]);
386 }
387 dwThroughput = dwThroughputTbl[psNodeDBTable->wTxDataRate];
388
389 wIdxDownRate = psNodeDBTable->wTxDataRate;
390 for(ii = psNodeDBTable->wTxDataRate; ii > 0;) {
391 ii--;
392 if ( (dwThroughputTbl[ii] > dwThroughput) &&
393 (bAutoRate[ii]==TRUE) ) {
394 dwThroughput = dwThroughputTbl[ii];
395 wIdxDownRate = (WORD) ii;
396 }
397 }
398 psNodeDBTable->wTxDataRate = wIdxDownRate;
399 if (psNodeDBTable->uTxOk[MAX_RATE]) {
400 if (psNodeDBTable->uTxOk[MAX_RATE] >
401 (psNodeDBTable->uTxFail[MAX_RATE] * 4) ) {
402 psNodeDBTable->wTxDataRate = wIdxUpRate;
403 }
404 }else { // adhoc, if uTxOk =0 & uTxFail = 0
405 if (psNodeDBTable->uTxFail[MAX_RATE] == 0)
406 psNodeDBTable->wTxDataRate = wIdxUpRate;
407 }
408//2008-5-8 <add> by chester
409TxRate_iwconfig=psNodeDBTable->wTxDataRate;
410 s_vResetCounter(psNodeDBTable);
411// DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Rate: %d, U:%d, D:%d\n", psNodeDBTable->wTxDataRate, wIdxUpRate, wIdxDownRate);
412
413 return;
414
415}
416
417/*+
418 *
419 * Description:
420 * This routine is used to assemble available Rate IE.
421 *
422 * Parameters:
423 * In:
424 * pDevice
425 * Out:
426 *
427 * Return Value: None
428 *
429-*/
430BYTE
431RATEuSetIE (
432 IN PWLAN_IE_SUPP_RATES pSrcRates,
433 IN PWLAN_IE_SUPP_RATES pDstRates,
434 IN UINT uRateLen
435 )
436{
437 UINT ii, uu, uRateCnt = 0;
438
439 if ((pSrcRates == NULL) || (pDstRates == NULL))
440 return 0;
441
442 if (pSrcRates->len == 0)
443 return 0;
444
445 for (ii = 0; ii < uRateLen; ii++) {
446 for (uu = 0; uu < pSrcRates->len; uu++) {
447 if ((pSrcRates->abyRates[uu] & 0x7F) == acbyIERate[ii]) {
448 pDstRates->abyRates[uRateCnt ++] = pSrcRates->abyRates[uu];
449 break;
450 }
451 }
452 }
453 return (BYTE)uRateCnt;
454}
455
diff --git a/drivers/staging/vt6655/datarate.h b/drivers/staging/vt6655/datarate.h
new file mode 100644
index 000000000000..5096f3df4993
--- /dev/null
+++ b/drivers/staging/vt6655/datarate.h
@@ -0,0 +1,95 @@
1/*
2 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
3 * All rights reserved.
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 *
20 * File: datarate.h
21 *
22 * Purpose: Handles the auto fallback & data rates functions
23 *
24 * Author: Lyndon Chen
25 *
26 * Date: July 16, 2002
27 *
28 */
29#ifndef __DATARATE_H__
30#define __DATARATE_H__
31
32/*--------------------- Export Definitions -------------------------*/
33
34#define FALLBACK_PKT_COLLECT_TR_H 50 // pkts
35#define FALLBACK_PKT_COLLECT_TR_L 10 // pkts
36#define FALLBACK_POLL_SECOND 5 // 5 sec
37#define FALLBACK_RECOVER_SECOND 30 // 30 sec
38#define FALLBACK_THRESHOLD 15 // percent
39#define UPGRADE_THRESHOLD 5 // percent
40#define UPGRADE_CNT_THRD 3 // times
41#define RETRY_TIMES_THRD_H 2 // times
42#define RETRY_TIMES_THRD_L 1 // times
43
44
45/*--------------------- Export Classes ----------------------------*/
46
47/*--------------------- Export Variables --------------------------*/
48
49
50/*--------------------- Export Types ------------------------------*/
51
52
53/*--------------------- Export Functions --------------------------*/
54
55
56
57VOID
58RATEvParseMaxRate(
59 IN PVOID pDeviceHandler,
60 IN PWLAN_IE_SUPP_RATES pItemRates,
61 IN PWLAN_IE_SUPP_RATES pItemExtRates,
62 IN BOOL bUpdateBasicRate,
63 OUT PWORD pwMaxBasicRate,
64 OUT PWORD pwMaxSuppRate,
65 OUT PWORD pwSuppRate,
66 OUT PBYTE pbyTopCCKRate,
67 OUT PBYTE pbyTopOFDMRate
68 );
69
70VOID
71RATEvTxRateFallBack(
72 IN PVOID pDeviceHandler,
73 IN PKnownNodeDB psNodeDBTable
74 );
75
76BYTE
77RATEuSetIE(
78 IN PWLAN_IE_SUPP_RATES pSrcRates,
79 IN PWLAN_IE_SUPP_RATES pDstRates,
80 IN UINT uRateLen
81 );
82
83WORD
84wGetRateIdx(
85 IN BYTE byRate
86 );
87
88
89BYTE
90DATARATEbyGetRateIdx(
91 IN BYTE byRate
92 );
93
94
95#endif //__DATARATE_H__
diff --git a/drivers/staging/vt6655/desc.h b/drivers/staging/vt6655/desc.h
new file mode 100644
index 000000000000..c0fc1d3b0a2e
--- /dev/null
+++ b/drivers/staging/vt6655/desc.h
@@ -0,0 +1,697 @@
1/*
2 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
3 * All rights reserved.
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * File: desc.h
20 *
21 * Purpose:The header file of descriptor
22 *
23 * Revision History:
24 *
25 * Author: Tevin Chen
26 *
27 * Date: May 21, 1996
28 *
29 */
30
31
32#ifndef __DESC_H__
33#define __DESC_H__
34
35#include <linux/types.h>
36#include <linux/mm.h>
37
38#if !defined(__TTYPE_H__)
39#include "ttype.h"
40#endif
41#if !defined(__TETHER_H__)
42#include "tether.h"
43#endif
44// #ifdef PRIVATE_OBJ
45//#if !defined(__DEVICE_MODULE_H)
46//#include "device_module.h"
47//#endif
48
49
50
51
52/*--------------------- Export Definitions -------------------------*/
53
54#define B_OWNED_BY_CHIP 1 //
55#define B_OWNED_BY_HOST 0 //
56
57//
58// Bits in the RSR register
59//
60#define RSR_ADDRBROAD 0x80 // 1000 0000
61#define RSR_ADDRMULTI 0x40 // 0100 0000
62#define RSR_ADDRUNI 0x00 // 0000 0000
63#define RSR_IVLDTYP 0x20 // 0010 0000 , invalid packet type
64#define RSR_IVLDLEN 0x10 // 0001 0000 , invalid len (> 2312 byte)
65#define RSR_BSSIDOK 0x08 // 0000 1000
66#define RSR_CRCOK 0x04 // 0000 0100
67#define RSR_BCNSSIDOK 0x02 // 0000 0010
68#define RSR_ADDROK 0x01 // 0000 0001
69
70//
71// Bits in the new RSR register
72//
73#define NEWRSR_DECRYPTOK 0x10 // 0001 0000
74#define NEWRSR_CFPIND 0x08 // 0000 1000
75#define NEWRSR_HWUTSF 0x04 // 0000 0100
76#define NEWRSR_BCNHITAID 0x02 // 0000 0010
77#define NEWRSR_BCNHITAID0 0x01 // 0000 0001
78
79//
80// Bits in the TSR0 register
81//
82#define TSR0_PWRSTS1_2 0xC0 // 1100 0000
83#define TSR0_PWRSTS7 0x20 // 0010 0000
84#define TSR0_NCR 0x1F // 0001 1111
85
86//
87// Bits in the TSR1 register
88//
89#define TSR1_TERR 0x80 // 1000 0000
90#define TSR1_PWRSTS4_6 0x70 // 0111 0000
91#define TSR1_RETRYTMO 0x08 // 0000 1000
92#define TSR1_TMO 0x04 // 0000 0100
93#define TSR1_PWRSTS3 0x02 // 0000 0010
94#define ACK_DATA 0x01 // 0000 0000
95
96//
97// Bits in the TCR register
98//
99#define EDMSDU 0x04 // 0000 0100 end of sdu
100#define TCR_EDP 0x02 // 0000 0010 end of packet
101#define TCR_STP 0x01 // 0000 0001 start of packet
102
103// max transmit or receive buffer size
104#define CB_MAX_BUF_SIZE 2900U // max buffer size
105 // NOTE: must be multiple of 4
106#define CB_MAX_TX_BUF_SIZE CB_MAX_BUF_SIZE // max Tx buffer size
107#define CB_MAX_RX_BUF_SIZE_NORMAL CB_MAX_BUF_SIZE // max Rx buffer size when not use Multi-RD
108
109#define CB_BEACON_BUF_SIZE 512U // default beacon buffer size
110
111#define CB_MAX_RX_DESC 128 // max # of descriptor
112#define CB_MIN_RX_DESC 16 // min # of rx descriptor
113#define CB_MAX_TX_DESC 64 // max # of descriptor
114#define CB_MIN_TX_DESC 16 // min # of tx descriptor
115
116#define CB_MAX_RECEIVED_PACKETS 16 // max # of received packets at one time
117 // limit our receive routine to indicating
118 // this many at a time for 2 reasons:
119 // 1. driver flow control to protocol layer
120 // 2. limit the time used in ISR routine
121
122#define CB_EXTRA_RD_NUM 32 // default # of Extra RD
123#define CB_RD_NUM 32 // default # of RD
124#define CB_TD_NUM 32 // default # of TD
125
126
127// max number of physical segments
128// in a single NDIS packet. Above this threshold, the packet
129// is copied into a single physically contiguous buffer
130#define CB_MAX_SEGMENT 4
131
132#define CB_MIN_MAP_REG_NUM 4
133#define CB_MAX_MAP_REG_NUM CB_MAX_TX_DESC
134
135#define CB_PROTOCOL_RESERVED_SECTION 16
136
137
138// if retrys excess 15 times , tx will abort, and
139// if tx fifo underflow, tx will fail
140// we should try to resend it
141#define CB_MAX_TX_ABORT_RETRY 3
142
143#ifdef __BIG_ENDIAN
144
145// WMAC definition FIFO Control
146#define FIFOCTL_AUTO_FB_1 0x0010 // 0001 0000 0000 0000
147#define FIFOCTL_AUTO_FB_0 0x0008 // 0000 1000 0000 0000
148#define FIFOCTL_GRPACK 0x0004 // 0000 0100 0000 0000
149#define FIFOCTL_11GA 0x0003 // 0000 0011 0000 0000
150#define FIFOCTL_11GB 0x0002 // 0000 0010 0000 0000
151#define FIFOCTL_11B 0x0001 // 0000 0001 0000 0000
152#define FIFOCTL_11A 0x0000 // 0000 0000 0000 0000
153#define FIFOCTL_RTS 0x8000 // 0000 0000 1000 0000
154#define FIFOCTL_ISDMA0 0x4000 // 0000 0000 0100 0000
155#define FIFOCTL_GENINT 0x2000 // 0000 0000 0010 0000
156#define FIFOCTL_TMOEN 0x1000 // 0000 0000 0001 0000
157#define FIFOCTL_LRETRY 0x0800 // 0000 0000 0000 1000
158#define FIFOCTL_CRCDIS 0x0400 // 0000 0000 0000 0100
159#define FIFOCTL_NEEDACK 0x0200 // 0000 0000 0000 0010
160#define FIFOCTL_LHEAD 0x0100 // 0000 0000 0000 0001
161
162//WMAC definition Frag Control
163#define FRAGCTL_AES 0x0003 // 0000 0011 0000 0000
164#define FRAGCTL_TKIP 0x0002 // 0000 0010 0000 0000
165#define FRAGCTL_LEGACY 0x0001 // 0000 0001 0000 0000
166#define FRAGCTL_NONENCRYPT 0x0000 // 0000 0000 0000 0000
167//#define FRAGCTL_AC3 0x0C00 // 0000 0000 0000 1100
168//#define FRAGCTL_AC2 0x0800 // 0000 0000 0000 1000
169//#define FRAGCTL_AC1 0x0400 // 0000 0000 0000 0100
170//#define FRAGCTL_AC0 0x0000 // 0000 0000 0000 0000
171#define FRAGCTL_ENDFRAG 0x0300 // 0000 0000 0000 0011
172#define FRAGCTL_MIDFRAG 0x0200 // 0000 0000 0000 0010
173#define FRAGCTL_STAFRAG 0x0100 // 0000 0000 0000 0001
174#define FRAGCTL_NONFRAG 0x0000 // 0000 0000 0000 0000
175
176#else
177
178#define FIFOCTL_AUTO_FB_1 0x1000 // 0001 0000 0000 0000
179#define FIFOCTL_AUTO_FB_0 0x0800 // 0000 1000 0000 0000
180#define FIFOCTL_GRPACK 0x0400 // 0000 0100 0000 0000
181#define FIFOCTL_11GA 0x0300 // 0000 0011 0000 0000
182#define FIFOCTL_11GB 0x0200 // 0000 0010 0000 0000
183#define FIFOCTL_11B 0x0100 // 0000 0001 0000 0000
184#define FIFOCTL_11A 0x0000 // 0000 0000 0000 0000
185#define FIFOCTL_RTS 0x0080 // 0000 0000 1000 0000
186#define FIFOCTL_ISDMA0 0x0040 // 0000 0000 0100 0000
187#define FIFOCTL_GENINT 0x0020 // 0000 0000 0010 0000
188#define FIFOCTL_TMOEN 0x0010 // 0000 0000 0001 0000
189#define FIFOCTL_LRETRY 0x0008 // 0000 0000 0000 1000
190#define FIFOCTL_CRCDIS 0x0004 // 0000 0000 0000 0100
191#define FIFOCTL_NEEDACK 0x0002 // 0000 0000 0000 0010
192#define FIFOCTL_LHEAD 0x0001 // 0000 0000 0000 0001
193
194//WMAC definition Frag Control
195#define FRAGCTL_AES 0x0300 // 0000 0011 0000 0000
196#define FRAGCTL_TKIP 0x0200 // 0000 0010 0000 0000
197#define FRAGCTL_LEGACY 0x0100 // 0000 0001 0000 0000
198#define FRAGCTL_NONENCRYPT 0x0000 // 0000 0000 0000 0000
199//#define FRAGCTL_AC3 0x000C // 0000 0000 0000 1100
200//#define FRAGCTL_AC2 0x0008 // 0000 0000 0000 1000
201//#define FRAGCTL_AC1 0x0004 // 0000 0000 0000 0100
202//#define FRAGCTL_AC0 0x0000 // 0000 0000 0000 0000
203#define FRAGCTL_ENDFRAG 0x0003 // 0000 0000 0000 0011
204#define FRAGCTL_MIDFRAG 0x0002 // 0000 0000 0000 0010
205#define FRAGCTL_STAFRAG 0x0001 // 0000 0000 0000 0001
206#define FRAGCTL_NONFRAG 0x0000 // 0000 0000 0000 0000
207
208#endif // #ifdef __BIG_ENDIAN
209
210//#define TYPE_AC0DMA 0
211//#define TYPE_TXDMA0 1
212#define TYPE_TXDMA0 0
213#define TYPE_AC0DMA 1
214#define TYPE_ATIMDMA 2
215#define TYPE_SYNCDMA 3
216#define TYPE_MAXTD 2
217
218#define TYPE_BEACONDMA 4
219
220#define TYPE_RXDMA0 0
221#define TYPE_RXDMA1 1
222#define TYPE_MAXRD 2
223
224
225
226// TD_INFO flags control bit
227#define TD_FLAGS_NETIF_SKB 0x01 // check if need release skb
228#define TD_FLAGS_PRIV_SKB 0x02 // check if called from private skb(hostap)
229#define TD_FLAGS_PS_RETRY 0x04 // check if PS STA frame re-transmit
230//#define TD_FLAGS_NETIF_SKB 0x04
231
232/*--------------------- Export Types ------------------------------*/
233
234// ref_sk_buff is used for mapping the skb structure between pre-built driver-obj & running kernel.
235// Since different kernel version (2.4x) may change skb structure, i.e. pre-built driver-obj
236// may link to older skb that leads error.
237
238typedef struct tagDEVICE_RD_INFO {
239 struct sk_buff* skb;
240#ifdef PRIVATE_OBJ
241 ref_sk_buff ref_skb;
242#endif
243 dma_addr_t skb_dma;
244 dma_addr_t curr_desc;
245} DEVICE_RD_INFO, *PDEVICE_RD_INFO;
246
247/*
248static inline PDEVICE_RD_INFO alloc_rd_info(void) {
249 PDEVICE_RD_INFO ptr;
250 if ((ptr = kmalloc(sizeof(DEVICE_RD_INFO), GFP_ATOMIC)) == NULL)
251 return NULL;
252 else {
253 memset(ptr,0,sizeof(DEVICE_RD_INFO));
254 return ptr;
255 }
256}
257*/
258
259/*
260typedef struct tagRDES0 {
261 WORD wResCount;
262 WORD wf1Owner ;
263// WORD f15Reserved : 15;
264// WORD f1Owner : 1;
265} __attribute__ ((__packed__))
266SRDES0;
267*/
268
269#ifdef __BIG_ENDIAN
270
271typedef struct tagRDES0 {
272 volatile WORD wResCount;
273 union {
274 volatile U16 f15Reserved;
275 struct {
276 volatile U8 f8Reserved1;
277 volatile U8 f1Owner:1;
278 volatile U8 f7Reserved:7;
279 } __attribute__ ((__packed__));
280 } __attribute__ ((__packed__));
281} __attribute__ ((__packed__))
282SRDES0, *PSRDES0;
283
284#else
285
286typedef struct tagRDES0 {
287 WORD wResCount;
288 WORD f15Reserved : 15;
289 WORD f1Owner : 1;
290} __attribute__ ((__packed__))
291SRDES0;
292
293
294#endif
295
296typedef struct tagRDES1 {
297 WORD wReqCount;
298 WORD wReserved;
299} __attribute__ ((__packed__))
300SRDES1;
301
302//
303// Rx descriptor
304//
305typedef struct tagSRxDesc {
306 volatile SRDES0 m_rd0RD0;
307 volatile SRDES1 m_rd1RD1;
308 volatile U32 buff_addr;
309 volatile U32 next_desc;
310 struct tagSRxDesc *next;//4 bytes
311 volatile PDEVICE_RD_INFO pRDInfo;//4 bytes
312 volatile U32 Reserved[2];//8 bytes
313} __attribute__ ((__packed__))
314SRxDesc, DEF* PSRxDesc;
315typedef const SRxDesc DEF* PCSRxDesc;
316
317#ifdef __BIG_ENDIAN
318
319/*
320typedef struct tagTDES0 {
321 volatile BYTE byTSR0;
322 volatile BYTE byTSR1;
323 volatile WORD wOwner_Txtime;
324// volatile WORD f15Txtime : 15;
325// volatile WORD f1Owner:1;
326} __attribute__ ((__packed__))
327STDES0;
328*/
329
330typedef struct tagTDES0 {
331 volatile BYTE byTSR0;
332 volatile BYTE byTSR1;
333 union {
334 volatile U16 f15Txtime;
335 struct {
336 volatile U8 f8Reserved1;
337 volatile U8 f1Owner:1;
338 volatile U8 f7Reserved:7;
339 } __attribute__ ((__packed__));
340 } __attribute__ ((__packed__));
341} __attribute__ ((__packed__))
342STDES0, PSTDES0;
343
344#else
345
346typedef struct tagTDES0 {
347 volatile BYTE byTSR0;
348 volatile BYTE byTSR1;
349 volatile WORD f15Txtime : 15;
350 volatile WORD f1Owner:1;
351} __attribute__ ((__packed__))
352STDES0;
353
354#endif
355
356
357typedef struct tagTDES1 {
358 volatile WORD wReqCount;
359 volatile BYTE byTCR;
360 volatile BYTE byReserved;
361} __attribute__ ((__packed__))
362STDES1;
363
364
365typedef struct tagDEVICE_TD_INFO{
366 struct sk_buff* skb;
367 PBYTE buf;
368 dma_addr_t skb_dma;
369 dma_addr_t buf_dma;
370 dma_addr_t curr_desc;
371 DWORD dwReqCount;
372 DWORD dwHeaderLength;
373 BYTE byFlags;
374} DEVICE_TD_INFO, *PDEVICE_TD_INFO;
375
376/*
377static inline PDEVICE_TD_INFO alloc_td_info(void) {
378 PDEVICE_TD_INFO ptr;
379 if ((ptr = kmalloc(sizeof(DEVICE_TD_INFO),GFP_ATOMIC))==NULL)
380 return NULL;
381 else {
382 memset(ptr,0,sizeof(DEVICE_TD_INFO));
383 return ptr;
384 }
385}
386*/
387
388//
389// transmit descriptor
390//
391typedef struct tagSTxDesc {
392 volatile STDES0 m_td0TD0;
393 volatile STDES1 m_td1TD1;
394 volatile U32 buff_addr;
395 volatile U32 next_desc;
396 struct tagSTxDesc* next; //4 bytes
397 volatile PDEVICE_TD_INFO pTDInfo;//4 bytes
398 volatile U32 Reserved[2];//8 bytes
399} __attribute__ ((__packed__))
400STxDesc, DEF* PSTxDesc;
401typedef const STxDesc DEF* PCSTxDesc;
402
403
404typedef struct tagSTxSyncDesc {
405 volatile STDES0 m_td0TD0;
406 volatile STDES1 m_td1TD1;
407 volatile DWORD buff_addr; // pointer to logical buffer
408 volatile DWORD next_desc; // pointer to next logical descriptor
409 volatile WORD m_wFIFOCtl;
410 volatile WORD m_wTimeStamp;
411 struct tagSTxSyncDesc* next; //4 bytes
412 volatile PDEVICE_TD_INFO pTDInfo;//4 bytes
413 volatile DWORD m_dwReserved2;
414} __attribute__ ((__packed__))
415STxSyncDesc, DEF* PSTxSyncDesc;
416typedef const STxSyncDesc DEF* PCSTxSyncDesc;
417
418
419//
420// RsvTime buffer header
421//
422typedef struct tagSRrvTime_gRTS {
423 WORD wRTSTxRrvTime_ba;
424 WORD wRTSTxRrvTime_aa;
425 WORD wRTSTxRrvTime_bb;
426 WORD wReserved;
427 WORD wTxRrvTime_b;
428 WORD wTxRrvTime_a;
429}__attribute__ ((__packed__))
430SRrvTime_gRTS, DEF* PSRrvTime_gRTS;
431typedef const SRrvTime_gRTS DEF* PCSRrvTime_gRTS;
432
433typedef struct tagSRrvTime_gCTS {
434 WORD wCTSTxRrvTime_ba;
435 WORD wReserved;
436 WORD wTxRrvTime_b;
437 WORD wTxRrvTime_a;
438}__attribute__ ((__packed__))
439SRrvTime_gCTS, DEF* PSRrvTime_gCTS;
440typedef const SRrvTime_gCTS DEF* PCSRrvTime_gCTS;
441
442typedef struct tagSRrvTime_ab {
443 WORD wRTSTxRrvTime;
444 WORD wTxRrvTime;
445}__attribute__ ((__packed__))
446SRrvTime_ab, DEF* PSRrvTime_ab;
447typedef const SRrvTime_ab DEF* PCSRrvTime_ab;
448
449typedef struct tagSRrvTime_atim {
450 WORD wCTSTxRrvTime_ba;
451 WORD wTxRrvTime_a;
452}__attribute__ ((__packed__))
453SRrvTime_atim, DEF* PSRrvTime_atim;
454typedef const SRrvTime_atim DEF* PCSRrvTime_atim;
455
456//
457// RTS buffer header
458//
459typedef struct tagSRTSData {
460 WORD wFrameControl;
461 WORD wDurationID;
462 BYTE abyRA[U_ETHER_ADDR_LEN];
463 BYTE abyTA[U_ETHER_ADDR_LEN];
464}__attribute__ ((__packed__))
465SRTSData, DEF* PSRTSData;
466typedef const SRTSData DEF* PCSRTSData;
467
468typedef struct tagSRTS_g {
469 BYTE bySignalField_b;
470 BYTE byServiceField_b;
471 WORD wTransmitLength_b;
472 BYTE bySignalField_a;
473 BYTE byServiceField_a;
474 WORD wTransmitLength_a;
475 WORD wDuration_ba;
476 WORD wDuration_aa;
477 WORD wDuration_bb;
478 WORD wReserved;
479 SRTSData Data;
480}__attribute__ ((__packed__))
481SRTS_g, DEF* PSRTS_g;
482typedef const SRTS_g DEF* PCSRTS_g;
483
484
485typedef struct tagSRTS_g_FB {
486 BYTE bySignalField_b;
487 BYTE byServiceField_b;
488 WORD wTransmitLength_b;
489 BYTE bySignalField_a;
490 BYTE byServiceField_a;
491 WORD wTransmitLength_a;
492 WORD wDuration_ba;
493 WORD wDuration_aa;
494 WORD wDuration_bb;
495 WORD wReserved;
496 WORD wRTSDuration_ba_f0;
497 WORD wRTSDuration_aa_f0;
498 WORD wRTSDuration_ba_f1;
499 WORD wRTSDuration_aa_f1;
500 SRTSData Data;
501}__attribute__ ((__packed__))
502SRTS_g_FB, DEF* PSRTS_g_FB;
503typedef const SRTS_g_FB DEF* PCSRTS_g_FB;
504
505
506typedef struct tagSRTS_ab {
507 BYTE bySignalField;
508 BYTE byServiceField;
509 WORD wTransmitLength;
510 WORD wDuration;
511 WORD wReserved;
512 SRTSData Data;
513}__attribute__ ((__packed__))
514SRTS_ab, DEF* PSRTS_ab;
515typedef const SRTS_ab DEF* PCSRTS_ab;
516
517
518typedef struct tagSRTS_a_FB {
519 BYTE bySignalField;
520 BYTE byServiceField;
521 WORD wTransmitLength;
522 WORD wDuration;
523 WORD wReserved;
524 WORD wRTSDuration_f0;
525 WORD wRTSDuration_f1;
526 SRTSData Data;
527}__attribute__ ((__packed__))
528SRTS_a_FB, DEF* PSRTS_a_FB;
529typedef const SRTS_a_FB DEF* PCSRTS_a_FB;
530
531
532//
533// CTS buffer header
534//
535typedef struct tagSCTSData {
536 WORD wFrameControl;
537 WORD wDurationID;
538 BYTE abyRA[U_ETHER_ADDR_LEN];
539 WORD wReserved;
540}__attribute__ ((__packed__))
541SCTSData, DEF* PSCTSData;
542
543typedef struct tagSCTS {
544 BYTE bySignalField_b;
545 BYTE byServiceField_b;
546 WORD wTransmitLength_b;
547 WORD wDuration_ba;
548 WORD wReserved;
549 SCTSData Data;
550}__attribute__ ((__packed__))
551SCTS, DEF* PSCTS;
552typedef const SCTS DEF* PCSCTS;
553
554typedef struct tagSCTS_FB {
555 BYTE bySignalField_b;
556 BYTE byServiceField_b;
557 WORD wTransmitLength_b;
558 WORD wDuration_ba;
559 WORD wReserved;
560 WORD wCTSDuration_ba_f0;
561 WORD wCTSDuration_ba_f1;
562 SCTSData Data;
563}__attribute__ ((__packed__))
564SCTS_FB, DEF* PSCTS_FB;
565typedef const SCTS_FB DEF* PCSCTS_FB;
566
567
568//
569// Tx FIFO header
570//
571typedef struct tagSTxBufHead {
572 DWORD adwTxKey[4];
573 WORD wFIFOCtl;
574 WORD wTimeStamp;
575 WORD wFragCtl;
576 BYTE byTxPower;
577 BYTE wReserved;
578}__attribute__ ((__packed__))
579STxBufHead, DEF* PSTxBufHead;
580typedef const STxBufHead DEF* PCSTxBufHead;
581
582typedef struct tagSTxShortBufHead {
583 WORD wFIFOCtl;
584 WORD wTimeStamp;
585}__attribute__ ((__packed__))
586STxShortBufHead, DEF* PSTxShortBufHead;
587typedef const STxShortBufHead DEF* PCSTxShortBufHead;
588
589//
590// Tx data header
591//
592typedef struct tagSTxDataHead_g {
593 BYTE bySignalField_b;
594 BYTE byServiceField_b;
595 WORD wTransmitLength_b;
596 BYTE bySignalField_a;
597 BYTE byServiceField_a;
598 WORD wTransmitLength_a;
599 WORD wDuration_b;
600 WORD wDuration_a;
601 WORD wTimeStampOff_b;
602 WORD wTimeStampOff_a;
603}__attribute__ ((__packed__))
604STxDataHead_g, DEF* PSTxDataHead_g;
605typedef const STxDataHead_g DEF* PCSTxDataHead_g;
606
607typedef struct tagSTxDataHead_g_FB {
608 BYTE bySignalField_b;
609 BYTE byServiceField_b;
610 WORD wTransmitLength_b;
611 BYTE bySignalField_a;
612 BYTE byServiceField_a;
613 WORD wTransmitLength_a;
614 WORD wDuration_b;
615 WORD wDuration_a;
616 WORD wDuration_a_f0;
617 WORD wDuration_a_f1;
618 WORD wTimeStampOff_b;
619 WORD wTimeStampOff_a;
620}__attribute__ ((__packed__))
621STxDataHead_g_FB, DEF* PSTxDataHead_g_FB;
622typedef const STxDataHead_g_FB DEF* PCSTxDataHead_g_FB;
623
624
625typedef struct tagSTxDataHead_ab {
626 BYTE bySignalField;
627 BYTE byServiceField;
628 WORD wTransmitLength;
629 WORD wDuration;
630 WORD wTimeStampOff;
631}__attribute__ ((__packed__))
632STxDataHead_ab, DEF* PSTxDataHead_ab;
633typedef const STxDataHead_ab DEF* PCSTxDataHead_ab;
634
635
636typedef struct tagSTxDataHead_a_FB {
637 BYTE bySignalField;
638 BYTE byServiceField;
639 WORD wTransmitLength;
640 WORD wDuration;
641 WORD wTimeStampOff;
642 WORD wDuration_f0;
643 WORD wDuration_f1;
644}__attribute__ ((__packed__))
645STxDataHead_a_FB, DEF* PSTxDataHead_a_FB;
646typedef const STxDataHead_a_FB DEF* PCSTxDataHead_a_FB;
647
648//
649// MICHDR data header
650//
651typedef struct tagSMICHDRHead {
652 DWORD adwHDR0[4];
653 DWORD adwHDR1[4];
654 DWORD adwHDR2[4];
655}__attribute__ ((__packed__))
656SMICHDRHead, DEF* PSMICHDRHead;
657typedef const SMICHDRHead DEF* PCSMICHDRHead;
658
659typedef struct tagSBEACONCtl {
660 DWORD BufReady : 1;
661 DWORD TSF : 15;
662 DWORD BufLen : 11;
663 DWORD Reserved : 5;
664}__attribute__ ((__packed__))
665SBEACONCtl;
666
667
668typedef struct tagSSecretKey {
669 DWORD dwLowDword;
670 BYTE byHighByte;
671}__attribute__ ((__packed__))
672SSecretKey;
673
674typedef struct tagSKeyEntry {
675 BYTE abyAddrHi[2];
676 WORD wKCTL;
677 BYTE abyAddrLo[4];
678 DWORD dwKey0[4];
679 DWORD dwKey1[4];
680 DWORD dwKey2[4];
681 DWORD dwKey3[4];
682 DWORD dwKey4[4];
683}__attribute__ ((__packed__))
684SKeyEntry;
685/*--------------------- Export Macros ------------------------------*/
686
687/*--------------------- Export Classes ----------------------------*/
688
689/*--------------------- Export Variables --------------------------*/
690
691/*--------------------- Export Functions --------------------------*/
692
693
694
695
696#endif // __DESC_H__
697
diff --git a/drivers/staging/vt6655/device.h b/drivers/staging/vt6655/device.h
new file mode 100644
index 000000000000..264d1bb2ff79
--- /dev/null
+++ b/drivers/staging/vt6655/device.h
@@ -0,0 +1,1063 @@
1/*
2 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
3 * All rights reserved.
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * File: device.h
20 *
21 * Purpose: MAC Data structure
22 *
23 * Author: Tevin Chen
24 *
25 * Date: Mar 17, 1997
26 *
27 */
28
29#ifndef __DEVICE_H__
30#define __DEVICE_H__
31
32#ifdef MODULE
33#ifdef MODVERSIONS
34#include <linux/modversions.h>
35#endif /* MODVERSIONS */
36#include <linux/module.h>
37#endif /* MODULE */
38
39#include <linux/types.h>
40#include <linux/init.h>
41#include <linux/mm.h>
42#include <linux/errno.h>
43#include <linux/ioport.h>
44#include <linux/pci.h>
45#include <linux/kernel.h>
46#include <linux/netdevice.h>
47#include <linux/etherdevice.h>
48#include <linux/skbuff.h>
49#include <linux/delay.h>
50#include <linux/timer.h>
51#include <linux/slab.h>
52#include <linux/interrupt.h>
53#include <linux/version.h>
54#include <linux/string.h>
55#include <linux/wait.h>
56#include <linux/if_arp.h>
57#include <linux/sched.h>
58#include <asm/io.h>
59#include <linux/if.h>
60//#include <linux/config.h>
61#include <asm/uaccess.h>
62#include <linux/proc_fs.h>
63#include <linux/inetdevice.h>
64#include <linux/reboot.h>
65#ifdef SIOCETHTOOL
66#define DEVICE_ETHTOOL_IOCTL_SUPPORT
67#include <linux/ethtool.h>
68#else
69#undef DEVICE_ETHTOOL_IOCTL_SUPPORT
70#endif
71/* Include Wireless Extension definition and check version - Jean II */
72#include <linux/wireless.h>
73#if WIRELESS_EXT > 12
74#include <net/iw_handler.h> // New driver API
75#endif /* WIRELESS_EXT > 12 */
76
77//2008-0409-07, <Add> by Einsn Liu
78#if WIRELESS_EXT > 17
79#ifndef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
80#define WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
81#endif
82#endif
83//2008-4-14<add> by chester for led issue
84//#define FOR_LED_ON_NOTEBOOK
85//
86
87
88
89// device specific
90//
91#if !defined(_KCOMPAT_H)
92#include "kcompat.h"
93#endif
94
95#if !defined(__DEVICE_CONFIG_H)
96#include "device_cfg.h"
97#endif
98
99#if !defined(__TTYPE_H__)
100#include "ttype.h"
101#endif
102#if !defined(__80211HDR_H__)
103#include "80211hdr.h"
104#endif
105#if !defined(__TETHER_H__)
106#include "tether.h"
107#endif
108#if !defined(__WMGR_H__)
109#include "wmgr.h"
110#endif
111#if !defined(__WCMD_H__)
112#include "wcmd.h"
113#endif
114#if !defined(__MIB_H__)
115#include "mib.h"
116#endif
117#if !defined(__SROM_H__)
118#include "srom.h"
119#endif
120#if !defined(__RC4_H__)
121#include "rc4.h"
122#endif
123#if !defined(__TPCI_H__)
124#include "tpci.h"
125#endif
126#if !defined(__DESC_H__)
127#include "desc.h"
128#endif
129
130#if !defined(__KEY_H__)
131#include "key.h"
132#endif
133
134#if !defined(__MAC_H__)
135#include "mac.h"
136#endif
137
138//PLICE_DEBUG->
139//#define THREAD
140
141//#define TASK_LET
142//PLICE_DEBUG<-
143
144// #ifdef PRIVATE_OBJ
145//#if !defined(__DEVICE_MODULE_H)
146//#include "device_module.h"
147//#endif
148
149
150/*--------------------- Export Definitions -------------------------*/
151
152#define MAC_MAX_CONTEXT_REG (256+128)
153
154#define MAX_MULTICAST_ADDRESS_NUM 32
155#define MULTICAST_ADDRESS_LIST_SIZE (MAX_MULTICAST_ADDRESS_NUM * U_ETHER_ADDR_LEN)
156
157
158//#define OP_MODE_INFRASTRUCTURE 0
159//#define OP_MODE_ADHOC 1
160//#define OP_MODE_AP 2
161
162#define DUPLICATE_RX_CACHE_LENGTH 5
163
164#define NUM_KEY_ENTRY 11
165
166#define TX_WEP_NONE 0
167#define TX_WEP_OTF 1
168#define TX_WEP_SW 2
169#define TX_WEP_SWOTP 3
170#define TX_WEP_OTPSW 4
171#define TX_WEP_SW232 5
172
173#define KEYSEL_WEP40 0
174#define KEYSEL_WEP104 1
175#define KEYSEL_TKIP 2
176#define KEYSEL_CCMP 3
177
178
179
180#define AUTO_FB_NONE 0
181#define AUTO_FB_0 1
182#define AUTO_FB_1 2
183
184#define FB_RATE0 0
185#define FB_RATE1 1
186
187// Antenna Mode
188#define ANT_A 0
189#define ANT_B 1
190#define ANT_DIVERSITY 2
191#define ANT_RXD_TXA 3
192#define ANT_RXD_TXB 4
193#define ANT_UNKNOWN 0xFF
194
195#define MAXCHECKHANGCNT 4
196
197#define BB_VGA_LEVEL 4
198#define BB_VGA_CHANGE_THRESHOLD 16
199
200
201#ifndef RUN_AT
202#define RUN_AT(x) (jiffies+(x))
203#endif
204
205// DMA related
206#define RESERV_AC0DMA 4
207
208
209// BUILD OBJ mode
210#ifdef PRIVATE_OBJ
211
212#undef dev_kfree_skb
213#undef dev_kfree_skb_irq
214#undef dev_alloc_skb
215#undef kfree
216#undef del_timer
217#undef init_timer
218#undef add_timer
219#undef kmalloc
220#undef netif_stop_queue
221#undef netif_start_queue
222#undef netif_wake_queue
223#undef netif_queue_stopped
224#undef netif_rx
225#undef netif_running
226#undef udelay
227#undef mdelay
228#undef eth_type_trans
229#undef skb_put
230#undef HZ
231#undef RUN_AT
232#undef pci_alloc_consistent
233#undef pci_free_consistent
234#undef register_netdevice
235#undef register_netdev
236#undef unregister_netdevice
237#undef unregister_netdev
238#undef skb_queue_head_init
239#undef skb_queue_tail
240#undef skb_queue_empty
241#undef free_irq
242#undef copy_from_user
243#undef copy_to_user
244#undef spin_lock_init
245#undef pci_map_single
246#undef pci_unmap_single
247
248// redefine kernel dependent fucntion
249#define dev_kfree_skb ref_dev_kfree_skb
250#define dev_kfree_skb_irq ref_dev_kfree_skb_irq
251#define dev_alloc_skb ref_dev_alloc_skb
252#define kfree ref_kfree
253#define del_timer ref_del_timer
254#define init_timer ref_init_timer
255#define add_timer ref_add_timer
256#define kmalloc ref_kmalloc
257#define netif_stop_queue ref_netif_stop_queue
258#define netif_start_queue ref_netif_start_queue
259#define netif_wake_queue ref_netif_wake_queue
260#define netif_queue_stopped ref_netif_queue_stopped
261#define netif_rx ref_netif_rx
262#define netif_running ref_netif_running
263#define udelay ref_udelay
264#define mdelay ref_mdelay
265#define get_jiffies() ref_get_jiffies()
266#define RUN_AT(x) (get_jiffies()+(x))
267#define HZ ref_HZ_tick()
268#define eth_type_trans ref_eth_type_trans
269#define skb_put ref_skb_put
270#define skb_queue_head_init ref_skb_queue_head_init
271#define skb_queue_tail ref_skb_queue_tail
272#define skb_queue_empty ref_skb_queue_empty
273
274#define pci_alloc_consistent ref_pci_alloc_consistent
275#define pci_free_consistent ref_pci_free_consistent
276#define register_netdevice ref_register_netdevice
277#define register_netdev ref_register_netdev
278#define unregister_netdevice ref_unregister_netdevice
279#define unregister_netdev ref_unregister_netdev
280
281#define free_irq ref_free_irq
282#define copy_from_user ref_copy_from_user
283#define copy_to_user ref_copy_to_user
284#define spin_lock_init ref_spin_lock_init
285#define pci_map_single ref_pci_map_single
286#define pci_unmap_single ref_pci_unmap_single
287#endif
288
289
290#ifdef PRIVATE_OBJ
291#undef printk
292#define DEVICE_PRT(l, p, args...) {if (l<=msglevel) do {} while (0);}
293//#define DEVICE_PRT(l, p, args...) {if (l<=msglevel) printk( p ,##args);}
294#else
295#define DEVICE_PRT(l, p, args...) {if (l<=msglevel) printk( p ,##args);}
296#endif
297
298
299#define AVAIL_TD(p,q) ((p)->sOpts.nTxDescs[(q)]-((p)->iTDUsed[(q)]))
300
301//PLICE_DEBUG ->
302#define NUM 64
303//PLICE_DEUBG <-
304
305
306
307/*--------------------- Export Types ------------------------------*/
308
309
310//0:11A 1:11B 2:11G
311typedef enum _VIA_BB_TYPE
312{
313 BB_TYPE_11A=0,
314 BB_TYPE_11B,
315 BB_TYPE_11G
316} VIA_BB_TYPE, *PVIA_BB_TYPE;
317
318//0:11a,1:11b,2:11gb(only CCK in BasicRate),3:11ga(OFDM in Basic Rate)
319typedef enum _VIA_PKT_TYPE
320{
321 PK_TYPE_11A=0,
322 PK_TYPE_11B,
323 PK_TYPE_11GB,
324 PK_TYPE_11GA
325} VIA_PKT_TYPE, *PVIA_PKT_TYPE;
326
327
328typedef enum __device_msg_level {
329 MSG_LEVEL_ERR=0, //Errors that will cause abnormal operation.
330 MSG_LEVEL_NOTICE=1, //Some errors need users to be notified.
331 MSG_LEVEL_INFO=2, //Normal message.
332 MSG_LEVEL_VERBOSE=3, //Will report all trival errors.
333 MSG_LEVEL_DEBUG=4 //Only for debug purpose.
334} DEVICE_MSG_LEVEL, *PDEVICE_MSG_LEVEL;
335
336typedef enum __device_init_type {
337 DEVICE_INIT_COLD=0, // cold init
338 DEVICE_INIT_RESET, // reset init or Dx to D0 power remain init
339 DEVICE_INIT_DXPL // Dx to D0 power lost init
340} DEVICE_INIT_TYPE, *PDEVICE_INIT_TYPE;
341
342
343//++ NDIS related
344
345#define MAX_BSSIDINFO_4_PMKID 16
346#define MAX_PMKIDLIST 5
347//Flags for PMKID Candidate list structure
348#define NDIS_802_11_PMKID_CANDIDATE_PREAUTH_ENABLED 0x01
349
350// PMKID Structures
351typedef UCHAR NDIS_802_11_PMKID_VALUE[16];
352
353
354typedef enum _NDIS_802_11_WEP_STATUS
355{
356 Ndis802_11WEPEnabled,
357 Ndis802_11Encryption1Enabled = Ndis802_11WEPEnabled,
358 Ndis802_11WEPDisabled,
359 Ndis802_11EncryptionDisabled = Ndis802_11WEPDisabled,
360 Ndis802_11WEPKeyAbsent,
361 Ndis802_11Encryption1KeyAbsent = Ndis802_11WEPKeyAbsent,
362 Ndis802_11WEPNotSupported,
363 Ndis802_11EncryptionNotSupported = Ndis802_11WEPNotSupported,
364 Ndis802_11Encryption2Enabled,
365 Ndis802_11Encryption2KeyAbsent,
366 Ndis802_11Encryption3Enabled,
367 Ndis802_11Encryption3KeyAbsent
368} NDIS_802_11_WEP_STATUS, *PNDIS_802_11_WEP_STATUS,
369 NDIS_802_11_ENCRYPTION_STATUS, *PNDIS_802_11_ENCRYPTION_STATUS;
370
371
372typedef enum _NDIS_802_11_STATUS_TYPE
373{
374 Ndis802_11StatusType_Authentication,
375 Ndis802_11StatusType_MediaStreamMode,
376 Ndis802_11StatusType_PMKID_CandidateList,
377 Ndis802_11StatusTypeMax // not a real type, defined as an upper bound
378} NDIS_802_11_STATUS_TYPE, *PNDIS_802_11_STATUS_TYPE;
379
380//Added new types for PMKID Candidate lists.
381typedef struct _PMKID_CANDIDATE {
382 NDIS_802_11_MAC_ADDRESS BSSID;
383 ULONG Flags;
384} PMKID_CANDIDATE, *PPMKID_CANDIDATE;
385
386
387typedef struct _BSSID_INFO
388{
389 NDIS_802_11_MAC_ADDRESS BSSID;
390 NDIS_802_11_PMKID_VALUE PMKID;
391} BSSID_INFO, *PBSSID_INFO;
392
393typedef struct tagSPMKID {
394 ULONG Length;
395 ULONG BSSIDInfoCount;
396 BSSID_INFO BSSIDInfo[MAX_BSSIDINFO_4_PMKID];
397} SPMKID, *PSPMKID;
398
399typedef struct tagSPMKIDCandidateEvent {
400 NDIS_802_11_STATUS_TYPE StatusType;
401 ULONG Version; // Version of the structure
402 ULONG NumCandidates; // No. of pmkid candidates
403 PMKID_CANDIDATE CandidateList[MAX_PMKIDLIST];
404} SPMKIDCandidateEvent, DEF* PSPMKIDCandidateEvent;
405
406
407//--
408
409//++ 802.11h related
410#define MAX_QUIET_COUNT 8
411
412typedef struct tagSQuietControl {
413 BOOL bEnable;
414 DWORD dwStartTime;
415 BYTE byPeriod;
416 WORD wDuration;
417} SQuietControl, DEF* PSQuietControl;
418
419//--
420typedef struct __chip_info_tbl{
421 CHIP_TYPE chip_id;
422 char* name;
423 int io_size;
424 int nTxQueue;
425 U32 flags;
426} CHIP_INFO, *PCHIP_INFO;
427
428
429typedef enum {
430 OWNED_BY_HOST=0,
431 OWNED_BY_NIC=1
432} DEVICE_OWNER_TYPE, *PDEVICE_OWNER_TYPE;
433
434
435// The receive duplicate detection cache entry
436typedef struct tagSCacheEntry{
437 WORD wFmSequence;
438 BYTE abyAddr2[U_ETHER_ADDR_LEN];
439} SCacheEntry, *PSCacheEntry;
440
441
442typedef struct tagSCache{
443/* The receive cache is updated circularly. The next entry to be written is
444 * indexed by the "InPtr".
445*/
446 UINT uInPtr; // Place to use next
447 SCacheEntry asCacheEntry[DUPLICATE_RX_CACHE_LENGTH];
448} SCache, *PSCache;
449
450#define CB_MAX_RX_FRAG 64
451// DeFragment Control Block, used for collecting fragments prior to reassembly
452typedef struct tagSDeFragControlBlock
453{
454 WORD wSequence;
455 WORD wFragNum;
456 BYTE abyAddr2[U_ETHER_ADDR_LEN];
457 UINT uLifetime;
458 struct sk_buff* skb;
459#ifdef PRIVATE_OBJ
460 ref_sk_buff ref_skb;
461#endif
462 PBYTE pbyRxBuffer;
463 UINT cbFrameLength;
464 BOOL bInUse;
465} SDeFragControlBlock, DEF* PSDeFragControlBlock;
466
467
468
469
470//flags for options
471#define DEVICE_FLAGS_IP_ALIGN 0x00000001UL
472#define DEVICE_FLAGS_PREAMBLE_TYPE 0x00000002UL
473#define DEVICE_FLAGS_OP_MODE 0x00000004UL
474#define DEVICE_FLAGS_PS_MODE 0x00000008UL
475#define DEVICE_FLAGS_80211h_MODE 0x00000010UL
476#define DEVICE_FLAGS_DiversityANT 0x00000020UL
477
478//flags for driver status
479#define DEVICE_FLAGS_OPENED 0x00010000UL
480#define DEVICE_FLAGS_WOL_ENABLED 0x00080000UL
481//flags for capbilities
482#define DEVICE_FLAGS_TX_ALIGN 0x01000000UL
483#define DEVICE_FLAGS_HAVE_CAM 0x02000000UL
484#define DEVICE_FLAGS_FLOW_CTRL 0x04000000UL
485
486//flags for MII status
487#define DEVICE_LINK_FAIL 0x00000001UL
488#define DEVICE_SPEED_10 0x00000002UL
489#define DEVICE_SPEED_100 0x00000004UL
490#define DEVICE_SPEED_1000 0x00000008UL
491#define DEVICE_DUPLEX_FULL 0x00000010UL
492#define DEVICE_AUTONEG_ENABLE 0x00000020UL
493#define DEVICE_FORCED_BY_EEPROM 0x00000040UL
494//for device_set_media_duplex
495#define DEVICE_LINK_CHANGE 0x00000001UL
496
497
498//PLICE_DEBUG->
499
500
501typedef struct _RxManagementQueue
502{
503 int packet_num;
504 int head,tail;
505 PSRxMgmtPacket Q[NUM];
506} RxManagementQueue,*PSRxManagementQueue;
507
508
509
510//PLICE_DEBUG<-
511
512
513typedef struct __device_opt {
514 int nRxDescs0; //Number of RX descriptors0
515 int nRxDescs1; //Number of RX descriptors1
516 int nTxDescs[2]; //Number of TX descriptors 0, 1
517 int int_works; //interrupt limits
518 int rts_thresh; //rts threshold
519 int frag_thresh;
520 int data_rate;
521 int channel_num;
522 int short_retry;
523 int long_retry;
524 int bbp_type;
525 U32 flags;
526} OPTIONS, *POPTIONS;
527
528
529typedef struct __device_info {
530 struct __device_info* next;
531 struct __device_info* prev;
532
533 struct pci_dev* pcid;
534
535#if CONFIG_PM
536 u32 pci_state[16];
537#endif
538
539// netdev
540 struct net_device* dev;
541 struct net_device* next_module;
542 struct net_device_stats stats;
543
544//dma addr, rx/tx pool
545 dma_addr_t pool_dma;
546 dma_addr_t rd0_pool_dma;
547 dma_addr_t rd1_pool_dma;
548
549 dma_addr_t td0_pool_dma;
550 dma_addr_t td1_pool_dma;
551
552 dma_addr_t tx_bufs_dma0;
553 dma_addr_t tx_bufs_dma1;
554 dma_addr_t tx_beacon_dma;
555
556 PBYTE tx0_bufs;
557 PBYTE tx1_bufs;
558 PBYTE tx_beacon_bufs;
559
560 CHIP_TYPE chip_id;
561
562 U32 PortOffset;
563 DWORD dwIsr;
564 U32 memaddr;
565 U32 ioaddr;
566 U32 io_size;
567
568 BYTE byRevId;
569 WORD SubSystemID;
570 WORD SubVendorID;
571
572 int nTxQueues;
573 volatile int iTDUsed[TYPE_MAXTD];
574
575 volatile PSTxDesc apCurrTD[TYPE_MAXTD];
576 volatile PSTxDesc apTailTD[TYPE_MAXTD];
577
578 volatile PSTxDesc apTD0Rings;
579 volatile PSTxDesc apTD1Rings;
580
581 volatile PSRxDesc aRD0Ring;
582 volatile PSRxDesc aRD1Ring;
583 volatile PSRxDesc pCurrRD[TYPE_MAXRD];
584 SCache sDupRxCache;
585
586 SDeFragControlBlock sRxDFCB[CB_MAX_RX_FRAG];
587 UINT cbDFCB;
588 UINT cbFreeDFCB;
589 UINT uCurrentDFCBIdx;
590
591 OPTIONS sOpts;
592
593 U32 flags;
594
595 U32 rx_buf_sz;
596 int multicast_limit;
597 BYTE byRxMode;
598
599 spinlock_t lock;
600//PLICE_DEBUG->
601 struct tasklet_struct RxMngWorkItem;
602 RxManagementQueue rxManeQueue;
603//PLICE_DEBUG<-
604//PLICE_DEBUG ->
605 pid_t MLMEThr_pid;
606 struct completion notify;
607 struct semaphore mlme_semaphore;
608//PLICE_DEBUG <-
609
610
611 U32 rx_bytes;
612
613 // Version control
614 BYTE byLocalID;
615 BYTE byRFType;
616
617 BYTE byMaxPwrLevel;
618 BYTE byZoneType;
619 BOOL bZoneRegExist;
620 BYTE byOriginalZonetype;
621 BYTE abyMacContext[MAC_MAX_CONTEXT_REG];
622 BOOL bLinkPass; // link status: OK or fail
623 BYTE abyCurrentNetAddr[U_ETHER_ADDR_LEN];
624
625 // Adapter statistics
626 SStatCounter scStatistic;
627 // 802.11 counter
628 SDot11Counters s802_11Counter;
629
630
631 // 802.11 management
632 PSMgmtObject pMgmt;
633 SMgmtObject sMgmtObj;
634
635 // 802.11 MAC specific
636 UINT uCurrRSSI;
637 BYTE byCurrSQ;
638
639 DWORD dwTxAntennaSel;
640 DWORD dwRxAntennaSel;
641 BYTE byAntennaCount;
642 BYTE byRxAntennaMode;
643 BYTE byTxAntennaMode;
644 BOOL bTxRxAntInv;
645
646 PBYTE pbyTmpBuff;
647 UINT uSIFS; //Current SIFS
648 UINT uDIFS; //Current DIFS
649 UINT uEIFS; //Current EIFS
650 UINT uSlot; //Current SlotTime
651 UINT uCwMin; //Current CwMin
652 UINT uCwMax; //CwMax is fixed on 1023.
653 // PHY parameter
654 BYTE bySIFS;
655 BYTE byDIFS;
656 BYTE byEIFS;
657 BYTE bySlot;
658 BYTE byCWMaxMin;
659 CARD_PHY_TYPE eCurrentPHYType;
660
661
662 VIA_BB_TYPE byBBType; //0: 11A, 1:11B, 2:11G
663 VIA_PKT_TYPE byPacketType; //0:11a,1:11b,2:11gb(only CCK in BasicRate),3:11ga(OFDM in Basic Rate)
664 WORD wBasicRate;
665 BYTE byACKRate;
666 BYTE byTopOFDMBasicRate;
667 BYTE byTopCCKBasicRate;
668
669 BYTE byMinChannel;
670 BYTE byMaxChannel;
671 UINT uConnectionRate;
672
673 BYTE byPreambleType;
674 BYTE byShortPreamble;
675
676 WORD wCurrentRate;
677 WORD wRTSThreshold;
678 WORD wFragmentationThreshold;
679 BYTE byShortRetryLimit;
680 BYTE byLongRetryLimit;
681 CARD_OP_MODE eOPMode;
682 BYTE byOpMode;
683 BOOL bBSSIDFilter;
684 WORD wMaxTransmitMSDULifetime;
685 BYTE abyBSSID[U_ETHER_ADDR_LEN];
686 BYTE abyDesireBSSID[U_ETHER_ADDR_LEN];
687 WORD wCTSDuration; // update while speed change
688 WORD wACKDuration; // update while speed change
689 WORD wRTSTransmitLen; // update while speed change
690 BYTE byRTSServiceField; // update while speed change
691 BYTE byRTSSignalField; // update while speed change
692
693 DWORD dwMaxReceiveLifetime; // dot11MaxReceiveLifetime
694
695 BOOL bCCK;
696 BOOL bEncryptionEnable;
697 BOOL bLongHeader;
698 BOOL bShortSlotTime;
699 BOOL bProtectMode;
700 BOOL bNonERPPresent;
701 BOOL bBarkerPreambleMd;
702
703 BYTE byERPFlag;
704 WORD wUseProtectCntDown;
705
706 BOOL bRadioControlOff;
707 BOOL bRadioOff;
708 BOOL bEnablePSMode;
709 WORD wListenInterval;
710 BOOL bPWBitOn;
711 WMAC_POWER_MODE ePSMode;
712
713
714 // GPIO Radio Control
715 BYTE byRadioCtl;
716 BYTE byGPIO;
717 BOOL bHWRadioOff;
718 BOOL bPrvActive4RadioOFF;
719 BOOL bGPIOBlockRead;
720
721 // Beacon releated
722 WORD wSeqCounter;
723 WORD wBCNBufLen;
724 BOOL bBeaconBufReady;
725 BOOL bBeaconSent;
726 BOOL bIsBeaconBufReadySet;
727 UINT cbBeaconBufReadySetCnt;
728 BOOL bFixRate;
729 BYTE byCurrentCh;
730 UINT uScanTime;
731
732 CMD_STATE eCommandState;
733
734 CMD_CODE eCommand;
735 BOOL bBeaconTx;
736
737 BOOL bStopBeacon;
738 BOOL bStopDataPkt;
739 BOOL bStopTx0Pkt;
740 UINT uAutoReConnectTime;
741
742 // 802.11 counter
743
744 CMD_ITEM eCmdQueue[CMD_Q_SIZE];
745 UINT uCmdDequeueIdx;
746 UINT uCmdEnqueueIdx;
747 UINT cbFreeCmdQueue;
748 BOOL bCmdRunning;
749 BOOL bCmdClear;
750
751
752
753 BOOL bRoaming;
754 //WOW
755 BYTE abyIPAddr[4];
756
757 ULONG ulTxPower;
758 NDIS_802_11_WEP_STATUS eEncryptionStatus;
759 BOOL bTransmitKey;
760//2007-0925-01<Add>by MikeLiu
761//mike add :save old Encryption
762 NDIS_802_11_WEP_STATUS eOldEncryptionStatus;
763 SKeyManagement sKey;
764 DWORD dwIVCounter;
765
766 QWORD qwPacketNumber; //For CCMP and TKIP as TSC(6 bytes)
767 UINT uCurrentWEPMode;
768
769 RC4Ext SBox;
770 BYTE abyPRNG[WLAN_WEPMAX_KEYLEN+3];
771
772 BYTE byKeyIndex;
773 UINT uKeyLength;
774 BYTE abyKey[WLAN_WEP232_KEYLEN];
775
776 BOOL bAES;
777 BYTE byCntMeasure;
778
779 // for AP mode
780 UINT uAssocCount;
781 BOOL bMoreData;
782
783 // QoS
784 BOOL bGrpAckPolicy;
785
786 // for OID_802_11_ASSOCIATION_INFORMATION
787 BOOL bAssocInfoSet;
788
789
790 BYTE byAutoFBCtrl;
791
792 BOOL bTxMICFail;
793 BOOL bRxMICFail;
794
795
796 UINT uRATEIdx;
797
798
799 // For Update BaseBand VGA Gain Offset
800 BOOL bUpdateBBVGA;
801 UINT uBBVGADiffCount;
802 BYTE byBBVGANew;
803 BYTE byBBVGACurrent;
804 BYTE abyBBVGA[BB_VGA_LEVEL];
805 LONG ldBmThreshold[BB_VGA_LEVEL];
806
807 BYTE byBBPreEDRSSI;
808 BYTE byBBPreEDIndex;
809
810 BOOL bRadioCmd;
811 DWORD dwDiagRefCount;
812
813 // For FOE Tuning
814 BYTE byFOETuning;
815
816 // For Auto Power Tunning
817
818 BYTE byAutoPwrTunning;
819 SHORT sPSetPointCCK;
820 SHORT sPSetPointOFDMG;
821 SHORT sPSetPointOFDMA;
822 LONG lPFormulaOffset;
823 SHORT sPThreshold;
824 CHAR cAdjustStep;
825 CHAR cMinTxAGC;
826
827 // For RF Power table
828 BYTE byCCKPwr;
829 BYTE byOFDMPwrG;
830 BYTE byCurPwr;
831 I8 byCurPwrdBm;
832 BYTE abyCCKPwrTbl[CB_MAX_CHANNEL_24G+1];
833 BYTE abyOFDMPwrTbl[CB_MAX_CHANNEL+1];
834 I8 abyCCKDefaultPwr[CB_MAX_CHANNEL_24G+1];
835 I8 abyOFDMDefaultPwr[CB_MAX_CHANNEL+1];
836 I8 abyRegPwr[CB_MAX_CHANNEL+1];
837 I8 abyLocalPwr[CB_MAX_CHANNEL+1];
838
839
840 // BaseBand Loopback Use
841 BYTE byBBCR4d;
842 BYTE byBBCRc9;
843 BYTE byBBCR88;
844 BYTE byBBCR09;
845
846 // command timer
847 struct timer_list sTimerCommand;
848#ifdef TxInSleep
849 struct timer_list sTimerTxData;
850 ULONG nTxDataTimeCout;
851 BOOL fTxDataInSleep;
852 BOOL IsTxDataTrigger;
853#endif
854
855#ifdef WPA_SM_Transtatus
856 BOOL fWPA_Authened; //is WPA/WPA-PSK or WPA2/WPA2-PSK authen??
857#endif
858 BYTE byReAssocCount; //mike add:re-association retry times!
859 BYTE byLinkWaitCount;
860
861
862 BYTE abyNodeName[17];
863
864 BOOL bDiversityRegCtlON;
865 BOOL bDiversityEnable;
866 ULONG ulDiversityNValue;
867 ULONG ulDiversityMValue;
868 BYTE byTMax;
869 BYTE byTMax2;
870 BYTE byTMax3;
871 ULONG ulSQ3TH;
872
873// ANT diversity
874 ULONG uDiversityCnt;
875 BYTE byAntennaState;
876 ULONG ulRatio_State0;
877 ULONG ulRatio_State1;
878
879 //SQ3 functions for antenna diversity
880 struct timer_list TimerSQ3Tmax1;
881 struct timer_list TimerSQ3Tmax2;
882 struct timer_list TimerSQ3Tmax3;
883
884
885 ULONG uNumSQ3[MAX_RATE];
886 WORD wAntDiversityMaxRate;
887
888
889 SEthernetHeader sTxEthHeader;
890 SEthernetHeader sRxEthHeader;
891 BYTE abyBroadcastAddr[U_ETHER_ADDR_LEN];
892 BYTE abySNAP_RFC1042[U_ETHER_ADDR_LEN];
893 BYTE abySNAP_Bridgetunnel[U_ETHER_ADDR_LEN];
894 BYTE abyEEPROM[EEP_MAX_CONTEXT_SIZE]; //DWORD alignment
895 // Pre-Authentication & PMK cache
896 SPMKID gsPMKID;
897 SPMKIDCandidateEvent gsPMKIDCandidate;
898
899
900 // for 802.11h
901 BOOL b11hEnable;
902 BYTE abyCountryCode[3];
903 // for 802.11h DFS
904 UINT uNumOfMeasureEIDs;
905 PWLAN_IE_MEASURE_REQ pCurrMeasureEID;
906 BOOL bMeasureInProgress;
907 BYTE byOrgChannel;
908 BYTE byOrgRCR;
909 DWORD dwOrgMAR0;
910 DWORD dwOrgMAR4;
911 BYTE byBasicMap;
912 BYTE byCCAFraction;
913 BYTE abyRPIs[8];
914 DWORD dwRPIs[8];
915 BOOL bChannelSwitch;
916 BYTE byNewChannel;
917 BYTE byChannelSwitchCount;
918 BOOL bQuietEnable;
919 BOOL bEnableFirstQuiet;
920 BYTE byQuietStartCount;
921 UINT uQuietEnqueue;
922 DWORD dwCurrentQuietEndTime;
923 SQuietControl sQuiet[MAX_QUIET_COUNT];
924 // for 802.11h TPC
925 BOOL bCountryInfo5G;
926 BOOL bCountryInfo24G;
927
928 WORD wBeaconInterval;
929
930 //WPA supplicant deamon
931 struct net_device *wpadev;
932 BOOL bWPADEVUp;
933 struct sk_buff *skb;
934#ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
935/*
936 BOOL bwextstep0;
937 BOOL bwextstep1;
938 BOOL bwextstep2;
939 BOOL bwextstep3;
940 */
941 UINT bwextcount;
942 BOOL bWPASuppWextEnabled;
943#endif
944
945 //--
946#ifdef HOSTAP
947 // user space daemon: hostapd, is used for HOSTAP
948 BOOL bEnableHostapd;
949 BOOL bEnable8021x;
950 BOOL bEnableHostWEP;
951 struct net_device *apdev;
952 int (*tx_80211)(struct sk_buff *skb, struct net_device *dev);
953#endif
954 UINT uChannel;
955 BOOL bMACSuspend;
956
957#ifdef WIRELESS_EXT
958 struct iw_statistics wstats; // wireless stats
959#endif /* WIRELESS_EXT */
960 BOOL bCommit;
961
962} DEVICE_INFO, *PSDevice;
963
964
965//PLICE_DEBUG->
966
967
968 inline static VOID EnQueue (PSDevice pDevice,PSRxMgmtPacket pRxMgmtPacket)
969{
970 //printk("Enter EnQueue:tail is %d\n",pDevice->rxManeQueue.tail);
971 if ((pDevice->rxManeQueue.tail+1) % NUM == pDevice->rxManeQueue.head)
972 {
973 //printk("Queue is Full,tail is %d\n",pDevice->rxManeQueue.tail);
974 return ;
975 }
976 else
977 {
978 pDevice->rxManeQueue.tail = (pDevice->rxManeQueue.tail+1)% NUM;
979 pDevice->rxManeQueue.Q[pDevice->rxManeQueue.tail] = pRxMgmtPacket;
980 pDevice->rxManeQueue.packet_num++;
981 //printk("packet num is %d\n",pDevice->rxManeQueue.packet_num);
982 }
983}
984
985
986
987
988 inline static PSRxMgmtPacket DeQueue (PSDevice pDevice)
989{
990 PSRxMgmtPacket pRxMgmtPacket;
991 if (pDevice->rxManeQueue.tail == pDevice->rxManeQueue.head)
992 {
993 printk("Queue is Empty\n");
994 return NULL;
995 }
996 else
997 {
998 int x;
999 //x=pDevice->rxManeQueue.head = (pDevice->rxManeQueue.head+1)%NUM;
1000 pDevice->rxManeQueue.head = (pDevice->rxManeQueue.head+1)%NUM;
1001 x = pDevice->rxManeQueue.head;
1002 //printk("Enter DeQueue:head is %d\n",x);
1003 pRxMgmtPacket = pDevice->rxManeQueue.Q[x];
1004 pDevice->rxManeQueue.packet_num--;
1005 return pRxMgmtPacket;
1006 }
1007}
1008
1009VOID InitRxManagementQueue(PSDevice pDevice);
1010
1011
1012
1013//PLICE_DEBUG<-
1014
1015
1016
1017
1018
1019
1020inline static BOOL device_get_ip(PSDevice pInfo) {
1021 struct in_device* in_dev=(struct in_device*) pInfo->dev->ip_ptr;
1022 struct in_ifaddr* ifa;
1023
1024 if (in_dev!=NULL) {
1025 ifa=(struct in_ifaddr*) in_dev->ifa_list;
1026 if (ifa!=NULL) {
1027 memcpy(pInfo->abyIPAddr,&ifa->ifa_address,4);
1028 return TRUE;
1029 }
1030 }
1031 return FALSE;
1032}
1033
1034
1035
1036static inline PDEVICE_RD_INFO alloc_rd_info(void) {
1037 PDEVICE_RD_INFO ptr;
1038 if ((ptr = (PDEVICE_RD_INFO)kmalloc((int)sizeof(DEVICE_RD_INFO), (int)GFP_ATOMIC)) == NULL)
1039 return NULL;
1040 else {
1041 memset(ptr,0,sizeof(DEVICE_RD_INFO));
1042 return ptr;
1043 }
1044}
1045
1046static inline PDEVICE_TD_INFO alloc_td_info(void) {
1047 PDEVICE_TD_INFO ptr;
1048 if ((ptr = (PDEVICE_TD_INFO)kmalloc((int)sizeof(DEVICE_TD_INFO), (int)GFP_ATOMIC))==NULL)
1049 return NULL;
1050 else {
1051 memset(ptr,0,sizeof(DEVICE_TD_INFO));
1052 return ptr;
1053 }
1054}
1055
1056/*--------------------- Export Functions --------------------------*/
1057
1058BOOL device_dma0_xmit(PSDevice pDevice, struct sk_buff *skb, UINT uNodeIndex);
1059BOOL device_alloc_frag_buf(PSDevice pDevice, PSDeFragControlBlock pDeF);
1060int Config_FileOperation(PSDevice pDevice,BOOL fwrite,unsigned char *Parameter);
1061#endif
1062
1063
diff --git a/drivers/staging/vt6655/device_main.c b/drivers/staging/vt6655/device_main.c
new file mode 100644
index 000000000000..bade552ba737
--- /dev/null
+++ b/drivers/staging/vt6655/device_main.c
@@ -0,0 +1,4153 @@
1/*
2 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
3 * All rights reserved.
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * File: device_main.c
20 *
21 * Purpose: driver entry for initial, open, close, tx and rx.
22 *
23 * Author: Lyndon Chen
24 *
25 * Date: Jan 8, 2003
26 *
27 * Functions:
28 *
29 * device_found1 - module initial (insmod) driver entry
30 * device_remove1 - module remove entry
31 * device_init_info - device structure resource allocation function
32 * device_free_info - device structure resource free function
33 * device_get_pci_info - get allocated pci io/mem resource
34 * device_print_info - print out resource
35 * device_open - allocate dma/descripter resource & initial mac/bbp function
36 * device_xmit - asynchrous data tx function
37 * device_intr - interrupt handle function
38 * device_set_multi - set mac filter
39 * device_ioctl - ioctl entry
40 * device_close - shutdown mac/bbp & free dma/descripter resource
41 * device_rx_srv - rx service function
42 * device_receive_frame - rx data function
43 * device_alloc_rx_buf - rx buffer pre-allocated function
44 * device_alloc_frag_buf - rx fragement pre-allocated function
45 * device_free_tx_buf - free tx buffer function
46 * device_free_frag_buf- free de-fragement buffer
47 * device_dma0_tx_80211- tx 802.11 frame via dma0
48 * device_dma0_xmit- tx PS bufferred frame via dma0
49 * device_init_rd0_ring- initial rd dma0 ring
50 * device_init_rd1_ring- initial rd dma1 ring
51 * device_init_td0_ring- initial tx dma0 ring buffer
52 * device_init_td1_ring- initial tx dma1 ring buffer
53 * device_init_registers- initial MAC & BBP & RF internal registers.
54 * device_init_rings- initial tx/rx ring buffer
55 * device_init_defrag_cb- initial & allocate de-fragement buffer.
56 * device_free_rings- free all allocated ring buffer
57 * device_tx_srv- tx interrupt service function
58 *
59 * Revision History:
60 */
61#undef __NO_VERSION__
62
63#if !defined(__DEVICE_H__)
64#include "device.h"
65#endif
66#if !defined(__CARD_H__)
67#include "card.h"
68#endif
69#if !defined(__TBIT_H__)
70#include "tbit.h"
71#endif
72#if !defined(__BASEBAND_H__)
73#include "baseband.h"
74#endif
75#if !defined(__MAC_H__)
76#include "mac.h"
77#endif
78#if !defined(__TETHER_H__)
79#include "tether.h"
80#endif
81#if !defined(__WMGR_H__)
82#include "wmgr.h"
83#endif
84#if !defined(__WCTL_H__)
85#include "wctl.h"
86#endif
87#if !defined(__POWER_H__)
88#include "power.h"
89#endif
90#if !defined(__WCMD_H__)
91#include "wcmd.h"
92#endif
93#if !defined(__IOCMD_H__)
94#include "iocmd.h"
95#endif
96#if !defined(__TCRC_H__)
97#include "tcrc.h"
98#endif
99#if !defined(__RXTX_H__)
100#include "rxtx.h"
101#endif
102#if !defined(__WROUTE_H__)
103#include "wroute.h"
104#endif
105#if !defined(__BSSDB_H__)
106#include "bssdb.h"
107#endif
108#if !defined(__HOSTAP_H__)
109#include "hostap.h"
110#endif
111#if !defined(__WPACTL_H__)
112#include "wpactl.h"
113#endif
114#if !defined(__IOCTL_H__)
115#include "ioctl.h"
116#endif
117#if !defined(__IWCTL_H__)
118#include "iwctl.h"
119#endif
120#if !defined(__DPC_H__)
121#include "dpc.h"
122#endif
123#if !defined(__DATARATE_H__)
124#include "datarate.h"
125#endif
126#if !defined(__RF_H__)
127#include "rf.h"
128#endif
129#if !defined(__IOWPA_H__)
130#include "iowpa.h"
131#endif
132
133#include <linux/delay.h>
134#include <linux/kthread.h>
135// #ifdef PRIVATE_OBJ
136//#if !defined(__DEVICE_EXP_H)
137//#include "device_exp.h"
138//#endif
139//#if !defined(__DEVICE_MODULE_H)
140//#include "device_module.h"
141//#endif
142
143
144// #endif
145//#define DEBUG
146/*--------------------- Static Definitions -------------------------*/
147//static int msglevel =MSG_LEVEL_DEBUG;
148static int msglevel = MSG_LEVEL_INFO;
149
150//#define PLICE_DEBUG
151//
152// Define module options
153//
154#ifndef PRIVATE_OBJ
155MODULE_AUTHOR("VIA Networking Technologies, Inc., <lyndonchen@vntek.com.tw>");
156MODULE_LICENSE("GPL");
157MODULE_DESCRIPTION("VIA Networking Solomon-A/B/G Wireless LAN Adapter Driver");
158#endif
159
160//PLICE_DEBUG ->
161 static int mlme_kill;
162 //static struct task_struct * mlme_task;
163//PLICE_DEBUG <-
164
165#define DEVICE_PARAM(N,D)
166/*
167 static const int N[MAX_UINTS]=OPTION_DEFAULT;\
168 MODULE_PARM(N, "1-" __MODULE_STRING(MAX_UINTS) "i");\
169 MODULE_PARM_DESC(N, D);
170*/
171
172#define RX_DESC_MIN0 16
173#define RX_DESC_MAX0 128
174#define RX_DESC_DEF0 32
175DEVICE_PARAM(RxDescriptors0,"Number of receive descriptors0");
176
177#define RX_DESC_MIN1 16
178#define RX_DESC_MAX1 128
179#define RX_DESC_DEF1 32
180DEVICE_PARAM(RxDescriptors1,"Number of receive descriptors1");
181
182#define TX_DESC_MIN0 16
183#define TX_DESC_MAX0 128
184#define TX_DESC_DEF0 32
185DEVICE_PARAM(TxDescriptors0,"Number of transmit descriptors0");
186
187#define TX_DESC_MIN1 16
188#define TX_DESC_MAX1 128
189#define TX_DESC_DEF1 64
190DEVICE_PARAM(TxDescriptors1,"Number of transmit descriptors1");
191
192
193#define IP_ALIG_DEF 0
194/* IP_byte_align[] is used for IP header DWORD byte aligned
195 0: indicate the IP header won't be DWORD byte aligned.(Default) .
196 1: indicate the IP header will be DWORD byte aligned.
197 In some enviroment, the IP header should be DWORD byte aligned,
198 or the packet will be droped when we receive it. (eg: IPVS)
199*/
200DEVICE_PARAM(IP_byte_align,"Enable IP header dword aligned");
201
202
203#define INT_WORKS_DEF 20
204#define INT_WORKS_MIN 10
205#define INT_WORKS_MAX 64
206
207DEVICE_PARAM(int_works,"Number of packets per interrupt services");
208
209#define CHANNEL_MIN 1
210#define CHANNEL_MAX 14
211#define CHANNEL_DEF 6
212
213DEVICE_PARAM(Channel, "Channel number");
214
215
216/* PreambleType[] is the preamble length used for transmit.
217 0: indicate allows long preamble type
218 1: indicate allows short preamble type
219*/
220
221#define PREAMBLE_TYPE_DEF 1
222
223DEVICE_PARAM(PreambleType, "Preamble Type");
224
225
226#define RTS_THRESH_MIN 512
227#define RTS_THRESH_MAX 2347
228#define RTS_THRESH_DEF 2347
229
230DEVICE_PARAM(RTSThreshold, "RTS threshold");
231
232
233#define FRAG_THRESH_MIN 256
234#define FRAG_THRESH_MAX 2346
235#define FRAG_THRESH_DEF 2346
236
237DEVICE_PARAM(FragThreshold, "Fragmentation threshold");
238
239
240#define DATA_RATE_MIN 0
241#define DATA_RATE_MAX 13
242#define DATA_RATE_DEF 13
243/* datarate[] index
244 0: indicate 1 Mbps 0x02
245 1: indicate 2 Mbps 0x04
246 2: indicate 5.5 Mbps 0x0B
247 3: indicate 11 Mbps 0x16
248 4: indicate 6 Mbps 0x0c
249 5: indicate 9 Mbps 0x12
250 6: indicate 12 Mbps 0x18
251 7: indicate 18 Mbps 0x24
252 8: indicate 24 Mbps 0x30
253 9: indicate 36 Mbps 0x48
254 10: indicate 48 Mbps 0x60
255 11: indicate 54 Mbps 0x6c
256 12: indicate 72 Mbps 0x90
257 13: indicate auto rate
258*/
259
260DEVICE_PARAM(ConnectionRate, "Connection data rate");
261
262#define OP_MODE_DEF 0
263
264DEVICE_PARAM(OPMode, "Infrastruct, adhoc, AP mode ");
265
266/* OpMode[] is used for transmit.
267 0: indicate infrastruct mode used
268 1: indicate adhoc mode used
269 2: indicate AP mode used
270*/
271
272
273/* PSMode[]
274 0: indicate disable power saving mode
275 1: indicate enable power saving mode
276*/
277
278#define PS_MODE_DEF 0
279
280DEVICE_PARAM(PSMode, "Power saving mode");
281
282
283#define SHORT_RETRY_MIN 0
284#define SHORT_RETRY_MAX 31
285#define SHORT_RETRY_DEF 8
286
287
288DEVICE_PARAM(ShortRetryLimit, "Short frame retry limits");
289
290#define LONG_RETRY_MIN 0
291#define LONG_RETRY_MAX 15
292#define LONG_RETRY_DEF 4
293
294
295DEVICE_PARAM(LongRetryLimit, "long frame retry limits");
296
297
298/* BasebandType[] baseband type selected
299 0: indicate 802.11a type
300 1: indicate 802.11b type
301 2: indicate 802.11g type
302*/
303#define BBP_TYPE_MIN 0
304#define BBP_TYPE_MAX 2
305#define BBP_TYPE_DEF 2
306
307DEVICE_PARAM(BasebandType, "baseband type");
308
309
310
311/* 80211hEnable[]
312 0: indicate disable 802.11h
313 1: indicate enable 802.11h
314*/
315
316#define X80211h_MODE_DEF 0
317
318DEVICE_PARAM(b80211hEnable, "802.11h mode");
319
320/* 80211hEnable[]
321 0: indicate disable 802.11h
322 1: indicate enable 802.11h
323*/
324
325#define DIVERSITY_ANT_DEF 0
326
327DEVICE_PARAM(bDiversityANTEnable, "ANT diversity mode");
328
329
330//
331// Static vars definitions
332//
333
334
335#ifndef PRIVATE_OBJ
336static int device_nics =0;
337static PSDevice pDevice_Infos =NULL;
338static struct net_device *root_device_dev = NULL;
339
340static CHIP_INFO chip_info_table[]= {
341 { VT3253, "VIA Networking Solomon-A/B/G Wireless LAN Adapter ",
342 256, 1, DEVICE_FLAGS_IP_ALIGN|DEVICE_FLAGS_TX_ALIGN },
343 {0,NULL}
344};
345
346static struct pci_device_id device_id_table[] __devinitdata = {
347{ 0x1106, 0x3253, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (int)&chip_info_table[0]},
348{ 0, }
349};
350#endif
351
352/*--------------------- Static Functions --------------------------*/
353
354#ifndef PRIVATE_OBJ
355
356static int device_found1(struct pci_dev *pcid, const struct pci_device_id *ent);
357static BOOL device_init_info(struct pci_dev* pcid, PSDevice* ppDevice, PCHIP_INFO);
358static void device_free_info(PSDevice pDevice);
359static BOOL device_get_pci_info(PSDevice, struct pci_dev* pcid);
360static void device_print_info(PSDevice pDevice);
361static struct net_device_stats *device_get_stats(struct net_device *dev);
362static void device_init_diversity_timer(PSDevice pDevice);
363static int device_open(struct net_device *dev);
364static int device_xmit(struct sk_buff *skb, struct net_device *dev);
365static irqreturn_t device_intr(int irq, void*dev_instance);
366static void device_set_multi(struct net_device *dev);
367static int device_close(struct net_device *dev);
368static int device_ioctl(struct net_device *dev, struct ifreq *rq, int cmd);
369
370#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,9)
371#ifdef CONFIG_PM
372static int device_notify_reboot(struct notifier_block *, unsigned long event, void *ptr);
373static int viawget_suspend(struct pci_dev *pcid, u32 state);
374static int viawget_resume(struct pci_dev *pcid);
375struct notifier_block device_notifier = {
376 notifier_call: device_notify_reboot,
377 next: NULL,
378 priority: 0
379};
380#endif
381#endif
382
383#endif // #ifndef PRIVATE_OBJ
384
385static void device_init_rd0_ring(PSDevice pDevice);
386static void device_init_rd1_ring(PSDevice pDevice);
387static void device_init_defrag_cb(PSDevice pDevice);
388static void device_init_td0_ring(PSDevice pDevice);
389static void device_init_td1_ring(PSDevice pDevice);
390
391#ifndef PRIVATE_OBJ
392static int device_dma0_tx_80211(struct sk_buff *skb, struct net_device *dev);
393#endif
394//2008-0714<Add>by Mike Liu
395static BOOL device_release_WPADEV(PSDevice pDevice);
396
397static int ethtool_ioctl(struct net_device *dev, void *useraddr);
398static int device_rx_srv(PSDevice pDevice, UINT uIdx);
399static int device_tx_srv(PSDevice pDevice, UINT uIdx);
400static BOOL device_alloc_rx_buf(PSDevice pDevice, PSRxDesc pDesc);
401static void device_init_registers(PSDevice pDevice, DEVICE_INIT_TYPE InitType);
402static void device_free_tx_buf(PSDevice pDevice, PSTxDesc pDesc);
403static void device_free_td0_ring(PSDevice pDevice);
404static void device_free_td1_ring(PSDevice pDevice);
405static void device_free_rd0_ring(PSDevice pDevice);
406static void device_free_rd1_ring(PSDevice pDevice);
407static void device_free_rings(PSDevice pDevice);
408static void device_free_frag_buf(PSDevice pDevice);
409static int Config_FileGetParameter(UCHAR *string, UCHAR *dest,UCHAR *source);
410
411
412/*--------------------- Export Variables --------------------------*/
413
414/*--------------------- Export Functions --------------------------*/
415
416
417#ifndef PRIVATE_OBJ
418
419static char* get_chip_name(int chip_id) {
420 int i;
421 for (i=0;chip_info_table[i].name!=NULL;i++)
422 if (chip_info_table[i].chip_id==chip_id)
423 break;
424 return chip_info_table[i].name;
425}
426
427static void __devexit device_remove1(struct pci_dev *pcid)
428{
429 PSDevice pDevice=pci_get_drvdata(pcid);
430
431 if (pDevice==NULL)
432 return;
433 device_free_info(pDevice);
434
435}
436
437#endif
438/*
439static void
440device_set_int_opt(int *opt, int val, int min, int max, int def,char* name,char* devname) {
441 if (val==-1)
442 *opt=def;
443 else if (val<min || val>max) {
444 DEVICE_PRT(MSG_LEVEL_INFO, KERN_NOTICE "%s: the value of parameter %s is invalid, the valid range is (%d-%d)\n" ,
445 devname,name, min,max);
446 *opt=def;
447 } else {
448 DEVICE_PRT(MSG_LEVEL_INFO, KERN_INFO "%s: set value of parameter %s to %d\n",
449 devname, name, val);
450 *opt=val;
451 }
452}
453
454static void
455device_set_bool_opt(PU32 opt, int val,BOOL def,U32 flag, char* name,char* devname) {
456 (*opt)&=(~flag);
457 if (val==-1)
458 *opt|=(def ? flag : 0);
459 else if (val<0 || val>1) {
460 DEVICE_PRT(MSG_LEVEL_INFO, KERN_NOTICE
461 "%s: the value of parameter %s is invalid, the valid range is (0-1)\n",devname,name);
462 *opt|=(def ? flag : 0);
463 } else {
464 DEVICE_PRT(MSG_LEVEL_INFO, KERN_NOTICE "%s: set parameter %s to %s\n",
465 devname,name , val ? "TRUE" : "FALSE");
466 *opt|=(val ? flag : 0);
467 }
468}
469*/
470static void
471device_get_options(PSDevice pDevice, int index, char* devname) {
472
473 POPTIONS pOpts = &(pDevice->sOpts);
474 pOpts->nRxDescs0=RX_DESC_DEF0;
475 pOpts->nRxDescs1=RX_DESC_DEF1;
476 pOpts->nTxDescs[0]=TX_DESC_DEF0;
477 pOpts->nTxDescs[1]=TX_DESC_DEF1;
478pOpts->flags|=DEVICE_FLAGS_IP_ALIGN;
479 pOpts->int_works=INT_WORKS_DEF;
480 pOpts->rts_thresh=RTS_THRESH_DEF;
481 pOpts->frag_thresh=FRAG_THRESH_DEF;
482 pOpts->data_rate=DATA_RATE_DEF;
483 pOpts->channel_num=CHANNEL_DEF;
484
485pOpts->flags|=DEVICE_FLAGS_PREAMBLE_TYPE;
486pOpts->flags|=DEVICE_FLAGS_OP_MODE;
487//pOpts->flags|=DEVICE_FLAGS_PS_MODE;
488 pOpts->short_retry=SHORT_RETRY_DEF;
489 pOpts->long_retry=LONG_RETRY_DEF;
490 pOpts->bbp_type=BBP_TYPE_DEF;
491pOpts->flags|=DEVICE_FLAGS_80211h_MODE;
492pOpts->flags|=DEVICE_FLAGS_DiversityANT;
493
494
495}
496
497static void
498device_set_options(PSDevice pDevice) {
499
500 BYTE abyBroadcastAddr[U_ETHER_ADDR_LEN] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
501 BYTE abySNAP_RFC1042[U_ETHER_ADDR_LEN] = {0xAA, 0xAA, 0x03, 0x00, 0x00, 0x00};
502 BYTE abySNAP_Bridgetunnel[U_ETHER_ADDR_LEN] = {0xAA, 0xAA, 0x03, 0x00, 0x00, 0xF8};
503
504
505 memcpy(pDevice->abyBroadcastAddr, abyBroadcastAddr, U_ETHER_ADDR_LEN);
506 memcpy(pDevice->abySNAP_RFC1042, abySNAP_RFC1042, U_ETHER_ADDR_LEN);
507 memcpy(pDevice->abySNAP_Bridgetunnel, abySNAP_Bridgetunnel, U_ETHER_ADDR_LEN);
508
509 pDevice->uChannel = pDevice->sOpts.channel_num;
510 pDevice->wRTSThreshold = pDevice->sOpts.rts_thresh;
511 pDevice->wFragmentationThreshold = pDevice->sOpts.frag_thresh;
512 pDevice->byShortRetryLimit = pDevice->sOpts.short_retry;
513 pDevice->byLongRetryLimit = pDevice->sOpts.long_retry;
514 pDevice->wMaxTransmitMSDULifetime = DEFAULT_MSDU_LIFETIME;
515 pDevice->byShortPreamble = (pDevice->sOpts.flags & DEVICE_FLAGS_PREAMBLE_TYPE) ? 1 : 0;
516 pDevice->byOpMode = (pDevice->sOpts.flags & DEVICE_FLAGS_OP_MODE) ? 1 : 0;
517 pDevice->ePSMode = (pDevice->sOpts.flags & DEVICE_FLAGS_PS_MODE) ? 1 : 0;
518 pDevice->b11hEnable = (pDevice->sOpts.flags & DEVICE_FLAGS_80211h_MODE) ? 1 : 0;
519 pDevice->bDiversityRegCtlON = (pDevice->sOpts.flags & DEVICE_FLAGS_DiversityANT) ? 1 : 0;
520 pDevice->uConnectionRate = pDevice->sOpts.data_rate;
521 if (pDevice->uConnectionRate < RATE_AUTO) pDevice->bFixRate = TRUE;
522 pDevice->byBBType = pDevice->sOpts.bbp_type;
523 pDevice->byPacketType = pDevice->byBBType;
524
525//PLICE_DEBUG->
526 pDevice->byAutoFBCtrl = AUTO_FB_0;
527 //pDevice->byAutoFBCtrl = AUTO_FB_1;
528//PLICE_DEBUG<-
529pDevice->bUpdateBBVGA = TRUE;
530 pDevice->byFOETuning = 0;
531 pDevice->wCTSDuration = 0;
532 pDevice->byPreambleType = 0;
533
534
535 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO" uChannel= %d\n",(INT)pDevice->uChannel);
536 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO" byOpMode= %d\n",(INT)pDevice->byOpMode);
537 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO" ePSMode= %d\n",(INT)pDevice->ePSMode);
538 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO" wRTSThreshold= %d\n",(INT)pDevice->wRTSThreshold);
539 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO" byShortRetryLimit= %d\n",(INT)pDevice->byShortRetryLimit);
540 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO" byLongRetryLimit= %d\n",(INT)pDevice->byLongRetryLimit);
541 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO" byPreambleType= %d\n",(INT)pDevice->byPreambleType);
542 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO" byShortPreamble= %d\n",(INT)pDevice->byShortPreamble);
543 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO" uConnectionRate= %d\n",(INT)pDevice->uConnectionRate);
544 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO" byBBType= %d\n",(INT)pDevice->byBBType);
545 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO" pDevice->b11hEnable= %d\n",(INT)pDevice->b11hEnable);
546 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO" pDevice->bDiversityRegCtlON= %d\n",(INT)pDevice->bDiversityRegCtlON);
547}
548
549static VOID s_vCompleteCurrentMeasure (IN PSDevice pDevice, IN BYTE byResult)
550{
551 UINT ii;
552 DWORD dwDuration = 0;
553 BYTE byRPI0 = 0;
554
555 for(ii=1;ii<8;ii++) {
556 pDevice->dwRPIs[ii] *= 255;
557 dwDuration |= *((PWORD) (pDevice->pCurrMeasureEID->sReq.abyDuration));
558 dwDuration <<= 10;
559 pDevice->dwRPIs[ii] /= dwDuration;
560 pDevice->abyRPIs[ii] = (BYTE) pDevice->dwRPIs[ii];
561 byRPI0 += pDevice->abyRPIs[ii];
562 }
563 pDevice->abyRPIs[0] = (0xFF - byRPI0);
564
565 if (pDevice->uNumOfMeasureEIDs == 0) {
566 VNTWIFIbMeasureReport( pDevice->pMgmt,
567 TRUE,
568 pDevice->pCurrMeasureEID,
569 byResult,
570 pDevice->byBasicMap,
571 pDevice->byCCAFraction,
572 pDevice->abyRPIs
573 );
574 } else {
575 VNTWIFIbMeasureReport( pDevice->pMgmt,
576 FALSE,
577 pDevice->pCurrMeasureEID,
578 byResult,
579 pDevice->byBasicMap,
580 pDevice->byCCAFraction,
581 pDevice->abyRPIs
582 );
583 CARDbStartMeasure (pDevice, pDevice->pCurrMeasureEID++, pDevice->uNumOfMeasureEIDs);
584 }
585
586}
587
588
589
590//
591// Initialiation of MAC & BBP registers
592//
593
594static void device_init_registers(PSDevice pDevice, DEVICE_INIT_TYPE InitType)
595{
596 UINT ii;
597 BYTE byValue;
598 BYTE byValue1;
599 BYTE byCCKPwrdBm = 0;
600 BYTE byOFDMPwrdBm = 0;
601 INT zonetype=0;
602 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
603 MACbShutdown(pDevice->PortOffset);
604 BBvSoftwareReset(pDevice->PortOffset);
605
606 if ((InitType == DEVICE_INIT_COLD) ||
607 (InitType == DEVICE_INIT_DXPL)) {
608 // Do MACbSoftwareReset in MACvInitialize
609 MACbSoftwareReset(pDevice->PortOffset);
610 // force CCK
611 pDevice->bCCK = TRUE;
612 pDevice->bAES = FALSE;
613 pDevice->bProtectMode = FALSE; //Only used in 11g type, sync with ERP IE
614 pDevice->bNonERPPresent = FALSE;
615 pDevice->bBarkerPreambleMd = FALSE;
616 pDevice->wCurrentRate = RATE_1M;
617 pDevice->byTopOFDMBasicRate = RATE_24M;
618 pDevice->byTopCCKBasicRate = RATE_1M;
619
620 pDevice->byRevId = 0; //Target to IF pin while programming to RF chip.
621
622 // init MAC
623 MACvInitialize(pDevice->PortOffset);
624
625 // Get Local ID
626 VNSvInPortB(pDevice->PortOffset + MAC_REG_LOCALID, &(pDevice->byLocalID));
627
628 spin_lock_irq(&pDevice->lock);
629 SROMvReadAllContents(pDevice->PortOffset,pDevice->abyEEPROM);
630
631 spin_unlock_irq(&pDevice->lock);
632
633 // Get Channel range
634
635 pDevice->byMinChannel = 1;
636 pDevice->byMaxChannel = CB_MAX_CHANNEL;
637
638 // Get Antena
639 byValue = SROMbyReadEmbedded(pDevice->PortOffset, EEP_OFS_ANTENNA);
640 if (byValue & EEP_ANTINV)
641 pDevice->bTxRxAntInv = TRUE;
642 else
643 pDevice->bTxRxAntInv = FALSE;
644#ifdef PLICE_DEBUG
645 //printk("init_register:TxRxAntInv is %d,byValue is %d\n",pDevice->bTxRxAntInv,byValue);
646#endif
647
648 byValue &= (EEP_ANTENNA_AUX | EEP_ANTENNA_MAIN);
649 if (byValue == 0) // if not set default is All
650 byValue = (EEP_ANTENNA_AUX | EEP_ANTENNA_MAIN);
651#ifdef PLICE_DEBUG
652 //printk("init_register:byValue is %d\n",byValue);
653#endif
654 pDevice->ulDiversityNValue = 100*260;//100*SROMbyReadEmbedded(pDevice->PortOffset, 0x51);
655 pDevice->ulDiversityMValue = 100*16;//SROMbyReadEmbedded(pDevice->PortOffset, 0x52);
656 pDevice->byTMax = 1;//SROMbyReadEmbedded(pDevice->PortOffset, 0x53);
657 pDevice->byTMax2 = 4;//SROMbyReadEmbedded(pDevice->PortOffset, 0x54);
658 pDevice->ulSQ3TH = 0;//(ULONG) SROMbyReadEmbedded(pDevice->PortOffset, 0x55);
659 pDevice->byTMax3 = 64;//SROMbyReadEmbedded(pDevice->PortOffset, 0x56);
660
661 if (byValue == (EEP_ANTENNA_AUX | EEP_ANTENNA_MAIN)) {
662 pDevice->byAntennaCount = 2;
663 pDevice->byTxAntennaMode = ANT_B;
664 pDevice->dwTxAntennaSel = 1;
665 pDevice->dwRxAntennaSel = 1;
666 if (pDevice->bTxRxAntInv == TRUE)
667 pDevice->byRxAntennaMode = ANT_A;
668 else
669 pDevice->byRxAntennaMode = ANT_B;
670 // chester for antenna
671byValue1 = SROMbyReadEmbedded(pDevice->PortOffset, EEP_OFS_ANTENNA);
672 // if (pDevice->bDiversityRegCtlON)
673 if((byValue1&0x08)==0)
674 pDevice->bDiversityEnable = FALSE;//SROMbyReadEmbedded(pDevice->PortOffset, 0x50);
675 else
676 pDevice->bDiversityEnable = TRUE;
677#ifdef PLICE_DEBUG
678 //printk("aux |main antenna: RxAntennaMode is %d\n",pDevice->byRxAntennaMode);
679#endif
680 } else {
681 pDevice->bDiversityEnable = FALSE;
682 pDevice->byAntennaCount = 1;
683 pDevice->dwTxAntennaSel = 0;
684 pDevice->dwRxAntennaSel = 0;
685 if (byValue & EEP_ANTENNA_AUX) {
686 pDevice->byTxAntennaMode = ANT_A;
687 if (pDevice->bTxRxAntInv == TRUE)
688 pDevice->byRxAntennaMode = ANT_B;
689 else
690 pDevice->byRxAntennaMode = ANT_A;
691 } else {
692 pDevice->byTxAntennaMode = ANT_B;
693 if (pDevice->bTxRxAntInv == TRUE)
694 pDevice->byRxAntennaMode = ANT_A;
695 else
696 pDevice->byRxAntennaMode = ANT_B;
697 }
698 }
699#ifdef PLICE_DEBUG
700 //printk("init registers: TxAntennaMode is %d\n",pDevice->byTxAntennaMode);
701#endif
702 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "bDiversityEnable=[%d],NValue=[%d],MValue=[%d],TMax=[%d],TMax2=[%d]\n",
703 pDevice->bDiversityEnable,(int)pDevice->ulDiversityNValue,(int)pDevice->ulDiversityMValue,pDevice->byTMax,pDevice->byTMax2);
704
705//#ifdef ZoneType_DefaultSetting
706//2008-8-4 <add> by chester
707//zonetype initial
708 pDevice->byOriginalZonetype = pDevice->abyEEPROM[EEP_OFS_ZONETYPE];
709 if((zonetype=Config_FileOperation(pDevice,FALSE,NULL)) >= 0) { //read zonetype file ok!
710 if ((zonetype == 0)&&
711 (pDevice->abyEEPROM[EEP_OFS_ZONETYPE] !=0x00)){ //for USA
712 pDevice->abyEEPROM[EEP_OFS_ZONETYPE] = 0;
713 pDevice->abyEEPROM[EEP_OFS_MAXCHANNEL] = 0x0B;
714 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Init Zone Type :USA\n");
715 }
716 else if((zonetype == 1)&&
717 (pDevice->abyEEPROM[EEP_OFS_ZONETYPE]!=0x01)){ //for Japan
718 pDevice->abyEEPROM[EEP_OFS_ZONETYPE] = 0x01;
719 pDevice->abyEEPROM[EEP_OFS_MAXCHANNEL] = 0x0D;
720 }
721 else if((zonetype == 2)&&
722 (pDevice->abyEEPROM[EEP_OFS_ZONETYPE]!=0x02)){ //for Europe
723 pDevice->abyEEPROM[EEP_OFS_ZONETYPE] = 0x02;
724 pDevice->abyEEPROM[EEP_OFS_MAXCHANNEL] = 0x0D;
725 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Init Zone Type :Europe\n");
726 }
727
728else
729{
730 if(zonetype!=pDevice->abyEEPROM[EEP_OFS_ZONETYPE])
731 printk("zonetype in file[%02x] mismatch with in EEPROM[%02x]\n",zonetype,pDevice->abyEEPROM[EEP_OFS_ZONETYPE]);
732 else
733 printk("Read Zonetype file sucess,use default zonetype setting[%02x]\n",zonetype);
734 }
735 }
736 else
737 printk("Read Zonetype file fail,use default zonetype setting[%02x]\n",SROMbyReadEmbedded(pDevice->PortOffset, EEP_OFS_ZONETYPE));
738
739 // Get RFType
740 pDevice->byRFType = SROMbyReadEmbedded(pDevice->PortOffset, EEP_OFS_RFTYPE);
741
742 if ((pDevice->byRFType & RF_EMU) != 0) {
743 // force change RevID for VT3253 emu
744 pDevice->byRevId = 0x80;
745 }
746
747 pDevice->byRFType &= RF_MASK;
748 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "pDevice->byRFType = %x\n", pDevice->byRFType);
749
750 if (pDevice->bZoneRegExist == FALSE) {
751 pDevice->byZoneType = pDevice->abyEEPROM[EEP_OFS_ZONETYPE];
752 }
753 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "pDevice->byZoneType = %x\n", pDevice->byZoneType);
754
755 //Init RF module
756 RFbInit(pDevice);
757
758 //Get Desire Power Value
759 pDevice->byCurPwr = 0xFF;
760 pDevice->byCCKPwr = SROMbyReadEmbedded(pDevice->PortOffset, EEP_OFS_PWR_CCK);
761 pDevice->byOFDMPwrG = SROMbyReadEmbedded(pDevice->PortOffset, EEP_OFS_PWR_OFDMG);
762 //byCCKPwrdBm = SROMbyReadEmbedded(pDevice->PortOffset, EEP_OFS_CCK_PWR_dBm);
763
764 //byOFDMPwrdBm = SROMbyReadEmbedded(pDevice->PortOffset, EEP_OFS_OFDM_PWR_dBm);
765//printk("CCKPwrdBm is 0x%x,byOFDMPwrdBm is 0x%x\n",byCCKPwrdBm,byOFDMPwrdBm);
766 // Load power Table
767
768
769 for (ii=0;ii<CB_MAX_CHANNEL_24G;ii++) {
770 pDevice->abyCCKPwrTbl[ii+1] = SROMbyReadEmbedded(pDevice->PortOffset, (BYTE)(ii + EEP_OFS_CCK_PWR_TBL));
771 if (pDevice->abyCCKPwrTbl[ii+1] == 0) {
772 pDevice->abyCCKPwrTbl[ii+1] = pDevice->byCCKPwr;
773 }
774 pDevice->abyOFDMPwrTbl[ii+1] = SROMbyReadEmbedded(pDevice->PortOffset, (BYTE)(ii + EEP_OFS_OFDM_PWR_TBL));
775 if (pDevice->abyOFDMPwrTbl[ii+1] == 0) {
776 pDevice->abyOFDMPwrTbl[ii+1] = pDevice->byOFDMPwrG;
777 }
778 pDevice->abyCCKDefaultPwr[ii+1] = byCCKPwrdBm;
779 pDevice->abyOFDMDefaultPwr[ii+1] = byOFDMPwrdBm;
780 }
781 //2008-8-4 <add> by chester
782 //recover 12,13 ,14channel for EUROPE by 11 channel
783 if(((pDevice->abyEEPROM[EEP_OFS_ZONETYPE] == ZoneType_Japan) ||
784 (pDevice->abyEEPROM[EEP_OFS_ZONETYPE] == ZoneType_Europe))&&
785 (pDevice->byOriginalZonetype == ZoneType_USA)) {
786 for(ii=11;ii<14;ii++) {
787 pDevice->abyCCKPwrTbl[ii] = pDevice->abyCCKPwrTbl[10];
788 pDevice->abyOFDMPwrTbl[ii] = pDevice->abyOFDMPwrTbl[10];
789
790 }
791 }
792
793
794 // Load OFDM A Power Table
795 for (ii=0;ii<CB_MAX_CHANNEL_5G;ii++) { //RobertYu:20041224, bug using CB_MAX_CHANNEL
796 pDevice->abyOFDMPwrTbl[ii+CB_MAX_CHANNEL_24G+1] = SROMbyReadEmbedded(pDevice->PortOffset, (BYTE)(ii + EEP_OFS_OFDMA_PWR_TBL));
797 pDevice->abyOFDMDefaultPwr[ii+CB_MAX_CHANNEL_24G+1] = SROMbyReadEmbedded(pDevice->PortOffset, (BYTE)(ii + EEP_OFS_OFDMA_PWR_dBm));
798 }
799 CARDvInitChannelTable((PVOID)pDevice);
800
801
802 if (pDevice->byLocalID > REV_ID_VT3253_B1) {
803 MACvSelectPage1(pDevice->PortOffset);
804 VNSvOutPortB(pDevice->PortOffset + MAC_REG_MSRCTL + 1, (MSRCTL1_TXPWR | MSRCTL1_CSAPAREN));
805 MACvSelectPage0(pDevice->PortOffset);
806 }
807
808
809 // use relative tx timeout and 802.11i D4
810 MACvWordRegBitsOn(pDevice->PortOffset, MAC_REG_CFG, (CFG_TKIPOPT | CFG_NOTXTIMEOUT));
811
812 // set performance parameter by registry
813 MACvSetShortRetryLimit(pDevice->PortOffset, pDevice->byShortRetryLimit);
814 MACvSetLongRetryLimit(pDevice->PortOffset, pDevice->byLongRetryLimit);
815
816 // reset TSF counter
817 VNSvOutPortB(pDevice->PortOffset + MAC_REG_TFTCTL, TFTCTL_TSFCNTRST);
818 // enable TSF counter
819 VNSvOutPortB(pDevice->PortOffset + MAC_REG_TFTCTL, TFTCTL_TSFCNTREN);
820
821 // initialize BBP registers
822 BBbVT3253Init(pDevice);
823
824 if (pDevice->bUpdateBBVGA) {
825 pDevice->byBBVGACurrent = pDevice->abyBBVGA[0];
826 pDevice->byBBVGANew = pDevice->byBBVGACurrent;
827 BBvSetVGAGainOffset(pDevice, pDevice->abyBBVGA[0]);
828 }
829#ifdef PLICE_DEBUG
830 //printk("init registers:RxAntennaMode is %x,TxAntennaMode is %x\n",pDevice->byRxAntennaMode,pDevice->byTxAntennaMode);
831#endif
832 BBvSetRxAntennaMode(pDevice->PortOffset, pDevice->byRxAntennaMode);
833 BBvSetTxAntennaMode(pDevice->PortOffset, pDevice->byTxAntennaMode);
834
835 pDevice->byCurrentCh = 0;
836
837 //pDevice->NetworkType = Ndis802_11Automode;
838 // Set BB and packet type at the same time.
839 // Set Short Slot Time, xIFS, and RSPINF.
840 if (pDevice->uConnectionRate == RATE_AUTO) {
841 pDevice->wCurrentRate = RATE_54M;
842 } else {
843 pDevice->wCurrentRate = (WORD)pDevice->uConnectionRate;
844 }
845
846 // default G Mode
847 VNTWIFIbConfigPhyMode(pDevice->pMgmt, PHY_TYPE_11G);
848 VNTWIFIbConfigPhyMode(pDevice->pMgmt, PHY_TYPE_AUTO);
849
850 pDevice->bRadioOff = FALSE;
851
852 pDevice->byRadioCtl = SROMbyReadEmbedded(pDevice->PortOffset, EEP_OFS_RADIOCTL);
853 pDevice->bHWRadioOff = FALSE;
854
855 if (pDevice->byRadioCtl & EEP_RADIOCTL_ENABLE) {
856 // Get GPIO
857 MACvGPIOIn(pDevice->PortOffset, &pDevice->byGPIO);
858//2008-4-14 <add> by chester for led issue
859 #ifdef FOR_LED_ON_NOTEBOOK
860if (BITbIsBitOn(pDevice->byGPIO,GPIO0_DATA)){pDevice->bHWRadioOff = TRUE;}
861if (BITbIsBitOff(pDevice->byGPIO,GPIO0_DATA)){pDevice->bHWRadioOff = FALSE;}
862
863 }
864 if ( (pDevice->bRadioControlOff == TRUE)) {
865 CARDbRadioPowerOff(pDevice);
866 }
867else CARDbRadioPowerOn(pDevice);
868#else
869 if ((BITbIsBitOn(pDevice->byGPIO,GPIO0_DATA) && BITbIsBitOff(pDevice->byRadioCtl, EEP_RADIOCTL_INV)) ||
870 (BITbIsBitOff(pDevice->byGPIO,GPIO0_DATA) && BITbIsBitOn(pDevice->byRadioCtl, EEP_RADIOCTL_INV))) {
871 pDevice->bHWRadioOff = TRUE;
872 }
873 }
874 if ((pDevice->bHWRadioOff == TRUE) || (pDevice->bRadioControlOff == TRUE)) {
875 CARDbRadioPowerOff(pDevice);
876 }
877
878#endif
879 }
880 pMgmt->eScanType = WMAC_SCAN_PASSIVE;
881 // get Permanent network address
882 SROMvReadEtherAddress(pDevice->PortOffset, pDevice->abyCurrentNetAddr);
883 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Network address = %02x-%02x-%02x=%02x-%02x-%02x\n",
884 pDevice->abyCurrentNetAddr[0],
885 pDevice->abyCurrentNetAddr[1],
886 pDevice->abyCurrentNetAddr[2],
887 pDevice->abyCurrentNetAddr[3],
888 pDevice->abyCurrentNetAddr[4],
889 pDevice->abyCurrentNetAddr[5]);
890
891
892 // reset Tx pointer
893 CARDvSafeResetRx(pDevice);
894 // reset Rx pointer
895 CARDvSafeResetTx(pDevice);
896
897 if (pDevice->byLocalID <= REV_ID_VT3253_A1) {
898 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_RCR, RCR_WPAERR);
899 }
900
901 pDevice->eEncryptionStatus = Ndis802_11EncryptionDisabled;
902
903 // Turn On Rx DMA
904 MACvReceive0(pDevice->PortOffset);
905 MACvReceive1(pDevice->PortOffset);
906
907 // start the adapter
908 MACvStart(pDevice->PortOffset);
909
910 netif_stop_queue(pDevice->dev);
911
912
913}
914
915
916
917static VOID device_init_diversity_timer(PSDevice pDevice) {
918
919 init_timer(&pDevice->TimerSQ3Tmax1);
920 pDevice->TimerSQ3Tmax1.data = (ULONG)pDevice;
921 pDevice->TimerSQ3Tmax1.function = (TimerFunction)TimerSQ3CallBack;
922 pDevice->TimerSQ3Tmax1.expires = RUN_AT(HZ);
923
924 init_timer(&pDevice->TimerSQ3Tmax2);
925 pDevice->TimerSQ3Tmax2.data = (ULONG)pDevice;
926 pDevice->TimerSQ3Tmax2.function = (TimerFunction)TimerSQ3CallBack;
927 pDevice->TimerSQ3Tmax2.expires = RUN_AT(HZ);
928
929 init_timer(&pDevice->TimerSQ3Tmax3);
930 pDevice->TimerSQ3Tmax3.data = (ULONG)pDevice;
931 pDevice->TimerSQ3Tmax3.function = (TimerFunction)TimerState1CallBack;
932 pDevice->TimerSQ3Tmax3.expires = RUN_AT(HZ);
933
934 return;
935}
936
937
938static BOOL device_release_WPADEV(PSDevice pDevice)
939{
940 viawget_wpa_header *wpahdr;
941 int ii=0;
942 // wait_queue_head_t Set_wait;
943 //send device close to wpa_supplicnat layer
944 if (pDevice->bWPADEVUp==TRUE) {
945 wpahdr = (viawget_wpa_header *)pDevice->skb->data;
946 wpahdr->type = VIAWGET_DEVICECLOSE_MSG;
947 wpahdr->resp_ie_len = 0;
948 wpahdr->req_ie_len = 0;
949 skb_put(pDevice->skb, sizeof(viawget_wpa_header));
950 pDevice->skb->dev = pDevice->wpadev;
951//2008-4-3 modify by Chester for wpa
952#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,22)
953 pDevice->skb->mac_header = pDevice->skb->data;
954#else
955 pDevice->skb->mac.raw = pDevice->skb->data;
956#endif
957 pDevice->skb->pkt_type = PACKET_HOST;
958 pDevice->skb->protocol = htons(ETH_P_802_2);
959 memset(pDevice->skb->cb, 0, sizeof(pDevice->skb->cb));
960 netif_rx(pDevice->skb);
961 pDevice->skb = dev_alloc_skb((int)pDevice->rx_buf_sz);
962
963 //wait release WPADEV
964 // init_waitqueue_head(&Set_wait);
965 // wait_event_timeout(Set_wait, ((pDevice->wpadev==NULL)&&(pDevice->skb == NULL)),5*HZ); //1s wait
966 while((pDevice->bWPADEVUp==TRUE)) {
967 set_current_state(TASK_UNINTERRUPTIBLE);
968 schedule_timeout (HZ/20); //wait 50ms
969 ii++;
970 if(ii>20)
971 break;
972 }
973 };
974 return TRUE;
975}
976
977
978#ifndef PRIVATE_OBJ
979
980static int
981device_found1(struct pci_dev *pcid, const struct pci_device_id *ent)
982{
983 static BOOL bFirst = TRUE;
984 struct net_device* dev = NULL;
985 PCHIP_INFO pChip_info = (PCHIP_INFO)ent->driver_data;
986 PSDevice pDevice;
987#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
988 int rc;
989#endif
990//#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,23)
991 // BYTE fake_mac[U_ETHER_ADDR_LEN] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x01};//fake MAC address
992//#endif
993 if (device_nics ++>= MAX_UINTS) {
994 printk(KERN_NOTICE DEVICE_NAME ": already found %d NICs\n", device_nics);
995 return -ENODEV;
996 }
997
998
999#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
1000 dev = alloc_etherdev(0);
1001#else
1002 dev = init_etherdev(dev, 0);
1003#endif
1004
1005 if (dev == NULL) {
1006 printk(KERN_ERR DEVICE_NAME ": allocate net device failed \n");
1007 return -ENODEV;
1008 }
1009
1010#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
1011 // Chain it all together
1012 // SET_MODULE_OWNER(dev);
1013 SET_NETDEV_DEV(dev, &pcid->dev);
1014#endif
1015
1016 if (bFirst) {
1017 printk(KERN_NOTICE "%s Ver. %s\n",DEVICE_FULL_DRV_NAM, DEVICE_VERSION);
1018 printk(KERN_NOTICE "Copyright (c) 2003 VIA Networking Technologies, Inc.\n");
1019 bFirst=FALSE;
1020 }
1021
1022 if (!device_init_info(pcid, &pDevice, pChip_info)) {
1023 return -ENOMEM;
1024 }
1025 pDevice->dev = dev;
1026 pDevice->next_module = root_device_dev;
1027 root_device_dev = dev;
1028 dev->priv = pDevice;
1029 dev->irq = pcid->irq;
1030
1031 if (pci_enable_device(pcid)) {
1032 device_free_info(pDevice);
1033 return -ENODEV;
1034 }
1035#ifdef DEBUG
1036 printk("Before get pci_info memaddr is %x\n",pDevice->memaddr);
1037#endif
1038 if (device_get_pci_info(pDevice,pcid) == FALSE) {
1039 printk(KERN_ERR DEVICE_NAME ": Failed to find PCI device.\n");
1040 device_free_info(pDevice);
1041 return -ENODEV;
1042 }
1043
1044#if 1
1045
1046#ifdef DEBUG
1047
1048 //pci_read_config_byte(pcid, PCI_BASE_ADDRESS_0, &pDevice->byRevId);
1049 printk("after get pci_info memaddr is %x, io addr is %x,io_size is %d\n",pDevice->memaddr,pDevice->ioaddr,pDevice->io_size);
1050 {
1051 int i;
1052 U32 bar,len;
1053 u32 address[] = {
1054 PCI_BASE_ADDRESS_0,
1055 PCI_BASE_ADDRESS_1,
1056 PCI_BASE_ADDRESS_2,
1057 PCI_BASE_ADDRESS_3,
1058 PCI_BASE_ADDRESS_4,
1059 PCI_BASE_ADDRESS_5,
1060 0};
1061 for (i=0;address[i];i++)
1062 {
1063 //pci_write_config_dword(pcid,address[i], 0xFFFFFFFF);
1064 pci_read_config_dword(pcid, address[i], &bar);
1065 printk("bar %d is %x\n",i,bar);
1066 if (!bar)
1067 {
1068 printk("bar %d not implemented\n",i);
1069 continue;
1070 }
1071 if (bar & PCI_BASE_ADDRESS_SPACE_IO) {
1072 /* This is IO */
1073
1074 len = bar & (PCI_BASE_ADDRESS_IO_MASK & 0xFFFF);
1075 len = len & ~(len - 1);
1076
1077 printk("IO space: len in IO %x, BAR %d\n", len, i);
1078 }
1079 else
1080 {
1081 len = bar & 0xFFFFFFF0;
1082 len = ~len + 1;
1083
1084 printk("len in MEM %x, BAR %d\n", len, i);
1085 }
1086 }
1087 }
1088#endif
1089
1090
1091#endif
1092
1093#ifdef DEBUG
1094 //return 0 ;
1095#endif
1096 pDevice->PortOffset = (DWORD)ioremap(pDevice->memaddr & PCI_BASE_ADDRESS_MEM_MASK, pDevice->io_size);
1097 //pDevice->PortOffset = (DWORD)ioremap(pDevice->ioaddr & PCI_BASE_ADDRESS_IO_MASK, pDevice->io_size);
1098
1099 if(pDevice->PortOffset == 0) {
1100 printk(KERN_ERR DEVICE_NAME ": Failed to IO remapping ..\n");
1101 device_free_info(pDevice);
1102 return -ENODEV;
1103 }
1104
1105
1106
1107
1108#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
1109 rc = pci_request_regions(pcid, DEVICE_NAME);
1110 if (rc) {
1111 printk(KERN_ERR DEVICE_NAME ": Failed to find PCI device\n");
1112 device_free_info(pDevice);
1113 return -ENODEV;
1114 }
1115#else
1116 if (check_region(pDevice->ioaddr, pDevice->io_size)) {
1117 printk(KERN_ERR DEVICE_NAME ": Failed to find PCI device\n");
1118 device_free_info(pDevice);
1119 return -ENODEV;
1120 }
1121 request_region(pDevice->ioaddr, pDevice->io_size, DEVICE_NAME);
1122#endif
1123
1124 dev->base_addr = pDevice->ioaddr;
1125#ifdef PLICE_DEBUG
1126 BYTE value;
1127
1128 VNSvInPortB(pDevice->PortOffset+0x4F, &value);
1129 printk("Before write: value is %x\n",value);
1130 //VNSvInPortB(pDevice->PortOffset+0x3F, 0x00);
1131 VNSvOutPortB(pDevice->PortOffset,value);
1132 VNSvInPortB(pDevice->PortOffset+0x4F, &value);
1133 printk("After write: value is %x\n",value);
1134#endif
1135
1136
1137
1138#ifdef IO_MAP
1139 pDevice->PortOffset = pDevice->ioaddr;
1140#endif
1141 // do reset
1142 if (!MACbSoftwareReset(pDevice->PortOffset)) {
1143 printk(KERN_ERR DEVICE_NAME ": Failed to access MAC hardware..\n");
1144 device_free_info(pDevice);
1145 return -ENODEV;
1146 }
1147 // initial to reload eeprom
1148 MACvInitialize(pDevice->PortOffset);
1149 MACvReadEtherAddress(pDevice->PortOffset, dev->dev_addr);
1150
1151 device_get_options(pDevice, device_nics-1, dev->name);
1152 device_set_options(pDevice);
1153 //Mask out the options cannot be set to the chip
1154 pDevice->sOpts.flags &= pChip_info->flags;
1155
1156 //Enable the chip specified capbilities
1157 pDevice->flags = pDevice->sOpts.flags | (pChip_info->flags & 0xFF000000UL);
1158 pDevice->tx_80211 = device_dma0_tx_80211;
1159 pDevice->sMgmtObj.pAdapter = (PVOID)pDevice;
1160 pDevice->pMgmt = &(pDevice->sMgmtObj);
1161
1162 dev->irq = pcid->irq;
1163 dev->open = device_open;
1164 dev->hard_start_xmit = device_xmit;
1165 dev->stop = device_close;
1166 dev->get_stats = device_get_stats;
1167 dev->set_multicast_list = device_set_multi;
1168 dev->do_ioctl = device_ioctl;
1169
1170#ifdef WIRELESS_EXT
1171//Einsn Modify for ubuntu-7.04
1172// dev->wireless_handlers->get_wireless_stats = iwctl_get_wireless_stats;
1173#if WIRELESS_EXT > 12
1174 dev->wireless_handlers = (struct iw_handler_def *)&iwctl_handler_def;
1175// netdev->wireless_handlers = NULL;
1176#endif /* WIRELESS_EXT > 12 */
1177#endif /* WIRELESS_EXT */
1178
1179 // #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,23)
1180 // memcpy(pDevice->dev->dev_addr, fake_mac, U_ETHER_ADDR_LEN); //use fake mac address
1181 // #endif
1182#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
1183 rc = register_netdev(dev);
1184 if (rc)
1185 {
1186 printk(KERN_ERR DEVICE_NAME " Failed to register netdev\n");
1187 device_free_info(pDevice);
1188 return -ENODEV;
1189 }
1190#endif
1191//2008-07-21-01<Add>by MikeLiu
1192//register wpadev
1193 if(wpa_set_wpadev(pDevice, 1)!=0) {
1194 printk("Fail to Register WPADEV?\n");
1195 unregister_netdev(pDevice->dev);
1196 free_netdev(dev);
1197 kfree(pDevice);
1198 }
1199 device_print_info(pDevice);
1200 pci_set_drvdata(pcid, pDevice);
1201 return 0;
1202
1203}
1204
1205static void device_print_info(PSDevice pDevice)
1206{
1207 struct net_device* dev=pDevice->dev;
1208
1209 DEVICE_PRT(MSG_LEVEL_INFO, KERN_INFO "%s: %s\n",dev->name, get_chip_name(pDevice->chip_id));
1210 DEVICE_PRT(MSG_LEVEL_INFO, KERN_INFO "%s: MAC=%2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X",
1211 dev->name,
1212 dev->dev_addr[0],dev->dev_addr[1],dev->dev_addr[2],
1213 dev->dev_addr[3],dev->dev_addr[4],dev->dev_addr[5]);
1214#ifdef IO_MAP
1215 DEVICE_PRT(MSG_LEVEL_INFO, KERN_INFO" IO=0x%lx ",(ULONG) pDevice->ioaddr);
1216 DEVICE_PRT(MSG_LEVEL_INFO, KERN_INFO" IRQ=%d \n", pDevice->dev->irq);
1217#else
1218 DEVICE_PRT(MSG_LEVEL_INFO, KERN_INFO" IO=0x%lx Mem=0x%lx ",(ULONG) pDevice->ioaddr,(ULONG) pDevice->PortOffset);
1219 DEVICE_PRT(MSG_LEVEL_INFO, KERN_INFO" IRQ=%d \n", pDevice->dev->irq);
1220#endif
1221
1222}
1223
1224static BOOL device_init_info(struct pci_dev* pcid, PSDevice* ppDevice,
1225 PCHIP_INFO pChip_info) {
1226
1227 PSDevice p;
1228
1229 *ppDevice = kmalloc(sizeof(DEVICE_INFO),GFP_ATOMIC);
1230
1231 if (*ppDevice == NULL)
1232 return FALSE;
1233
1234 memset(*ppDevice,0,sizeof(DEVICE_INFO));
1235
1236 if (pDevice_Infos == NULL) {
1237 pDevice_Infos =*ppDevice;
1238 }
1239 else {
1240 for (p=pDevice_Infos;p->next!=NULL;p=p->next)
1241 do {} while (0);
1242 p->next = *ppDevice;
1243 (*ppDevice)->prev = p;
1244 }
1245
1246 (*ppDevice)->pcid = pcid;
1247 (*ppDevice)->chip_id = pChip_info->chip_id;
1248 (*ppDevice)->io_size = pChip_info->io_size;
1249 (*ppDevice)->nTxQueues = pChip_info->nTxQueue;
1250 (*ppDevice)->multicast_limit =32;
1251
1252 spin_lock_init(&((*ppDevice)->lock));
1253
1254 return TRUE;
1255}
1256
1257static BOOL device_get_pci_info(PSDevice pDevice, struct pci_dev* pcid) {
1258
1259 U16 pci_cmd;
1260 U8 b;
1261 UINT cis_addr;
1262#ifdef PLICE_DEBUG
1263 BYTE pci_config[256];
1264 BYTE value =0x00;
1265 int ii,j;
1266 U16 max_lat=0x0000;
1267 memset(pci_config,0x00,256);
1268#endif
1269
1270 pci_read_config_byte(pcid, PCI_REVISION_ID, &pDevice->byRevId);
1271 pci_read_config_word(pcid, PCI_SUBSYSTEM_ID,&pDevice->SubSystemID);
1272 pci_read_config_word(pcid, PCI_SUBSYSTEM_VENDOR_ID, &pDevice->SubVendorID);
1273 pci_read_config_word(pcid, PCI_COMMAND, (u16 *) & (pci_cmd));
1274
1275 pci_set_master(pcid);
1276
1277 pDevice->memaddr = pci_resource_start(pcid,0);
1278 pDevice->ioaddr = pci_resource_start(pcid,1);
1279
1280#ifdef DEBUG
1281// pDevice->ioaddr = pci_resource_start(pcid, 0);
1282// pDevice->memaddr = pci_resource_start(pcid,1);
1283#endif
1284
1285 cis_addr = pci_resource_start(pcid,2);
1286
1287 pDevice->pcid = pcid;
1288
1289 pci_read_config_byte(pcid, PCI_REG_COMMAND, &b);
1290 pci_write_config_byte(pcid, PCI_REG_COMMAND, (b|COMMAND_BUSM));
1291
1292#ifdef PLICE_DEBUG
1293 //pci_read_config_word(pcid,PCI_REG_MAX_LAT,&max_lat);
1294 //printk("max lat is %x,SubSystemID is %x\n",max_lat,pDevice->SubSystemID);
1295 //for (ii=0;ii<0xFF;ii++)
1296 //pci_read_config_word(pcid,PCI_REG_MAX_LAT,&max_lat);
1297 //max_lat = 0x20;
1298 //pci_write_config_word(pcid,PCI_REG_MAX_LAT,max_lat);
1299 //pci_read_config_word(pcid,PCI_REG_MAX_LAT,&max_lat);
1300 //printk("max lat is %x\n",max_lat);
1301
1302 for (ii=0;ii<0xFF;ii++)
1303 {
1304 pci_read_config_byte(pcid,ii,&value);
1305 pci_config[ii] = value;
1306 }
1307 for (ii=0,j=1;ii<0x100;ii++,j++)
1308 {
1309 if (j %16 == 0)
1310 {
1311 printk("%x:",pci_config[ii]);
1312 printk("\n");
1313 }
1314 else
1315 {
1316 printk("%x:",pci_config[ii]);
1317 }
1318 }
1319#endif
1320 return TRUE;
1321}
1322
1323static void device_free_info(PSDevice pDevice) {
1324 PSDevice ptr;
1325 struct net_device* dev=pDevice->dev;
1326
1327 ASSERT(pDevice);
1328//2008-0714-01<Add>by chester
1329device_release_WPADEV(pDevice);
1330
1331//2008-07-21-01<Add>by MikeLiu
1332//unregister wpadev
1333 if(wpa_set_wpadev(pDevice, 0)!=0)
1334 printk("unregister wpadev fail?\n");
1335
1336 if (pDevice_Infos==NULL)
1337 return;
1338
1339 for (ptr=pDevice_Infos;ptr && (ptr!=pDevice);ptr=ptr->next)
1340 do {} while (0);
1341
1342 if (ptr==pDevice) {
1343 if (ptr==pDevice_Infos)
1344 pDevice_Infos=ptr->next;
1345 else
1346 ptr->prev->next=ptr->next;
1347 }
1348 else {
1349 DEVICE_PRT(MSG_LEVEL_ERR, KERN_ERR "info struct not found\n");
1350 return;
1351 }
1352#ifdef HOSTAP
1353 if (dev)
1354 hostap_set_hostapd(pDevice, 0, 0);
1355#endif
1356 if (dev)
1357 unregister_netdev(dev);
1358
1359 if (pDevice->PortOffset)
1360 iounmap((PVOID)pDevice->PortOffset);
1361
1362#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
1363 if (pDevice->pcid)
1364 pci_release_regions(pDevice->pcid);
1365 if (dev)
1366 free_netdev(dev);
1367#else
1368 if (pDevice->ioaddr)
1369 release_region(pDevice->ioaddr,pDevice->io_size);
1370 if (dev)
1371 kfree(dev);
1372#endif
1373
1374 if (pDevice->pcid) {
1375 pci_set_drvdata(pDevice->pcid,NULL);
1376 }
1377 kfree(pDevice);
1378
1379}
1380#endif// ifndef PRIVATE_OBJ
1381
1382static BOOL device_init_rings(PSDevice pDevice) {
1383 void* vir_pool;
1384
1385
1386 /*allocate all RD/TD rings a single pool*/
1387 vir_pool = pci_alloc_consistent(pDevice->pcid,
1388 pDevice->sOpts.nRxDescs0 * sizeof(SRxDesc) +
1389 pDevice->sOpts.nRxDescs1 * sizeof(SRxDesc) +
1390 pDevice->sOpts.nTxDescs[0] * sizeof(STxDesc) +
1391 pDevice->sOpts.nTxDescs[1] * sizeof(STxDesc),
1392 &pDevice->pool_dma);
1393
1394 if (vir_pool == NULL) {
1395 DEVICE_PRT(MSG_LEVEL_ERR,KERN_ERR "%s : allocate desc dma memory failed\n", pDevice->dev->name);
1396 return FALSE;
1397 }
1398
1399 memset(vir_pool, 0,
1400 pDevice->sOpts.nRxDescs0 * sizeof(SRxDesc) +
1401 pDevice->sOpts.nRxDescs1 * sizeof(SRxDesc) +
1402 pDevice->sOpts.nTxDescs[0] * sizeof(STxDesc) +
1403 pDevice->sOpts.nTxDescs[1] * sizeof(STxDesc)
1404 );
1405
1406 pDevice->aRD0Ring = vir_pool;
1407 pDevice->aRD1Ring = vir_pool +
1408 pDevice->sOpts.nRxDescs0 * sizeof(SRxDesc);
1409
1410
1411 pDevice->rd0_pool_dma = pDevice->pool_dma;
1412 pDevice->rd1_pool_dma = pDevice->rd0_pool_dma +
1413 pDevice->sOpts.nRxDescs0 * sizeof(SRxDesc);
1414
1415 pDevice->tx0_bufs = pci_alloc_consistent(pDevice->pcid,
1416 pDevice->sOpts.nTxDescs[0] * PKT_BUF_SZ +
1417 pDevice->sOpts.nTxDescs[1] * PKT_BUF_SZ +
1418 CB_BEACON_BUF_SIZE +
1419 CB_MAX_BUF_SIZE,
1420 &pDevice->tx_bufs_dma0);
1421
1422 if (pDevice->tx0_bufs == NULL) {
1423 DEVICE_PRT(MSG_LEVEL_ERR,KERN_ERR "%s: allocate buf dma memory failed\n", pDevice->dev->name);
1424 pci_free_consistent(pDevice->pcid,
1425 pDevice->sOpts.nRxDescs0 * sizeof(SRxDesc) +
1426 pDevice->sOpts.nRxDescs1 * sizeof(SRxDesc) +
1427 pDevice->sOpts.nTxDescs[0] * sizeof(STxDesc) +
1428 pDevice->sOpts.nTxDescs[1] * sizeof(STxDesc),
1429 vir_pool, pDevice->pool_dma
1430 );
1431 return FALSE;
1432 }
1433
1434 memset(pDevice->tx0_bufs, 0,
1435 pDevice->sOpts.nTxDescs[0] * PKT_BUF_SZ +
1436 pDevice->sOpts.nTxDescs[1] * PKT_BUF_SZ +
1437 CB_BEACON_BUF_SIZE +
1438 CB_MAX_BUF_SIZE
1439 );
1440
1441 pDevice->td0_pool_dma = pDevice->rd1_pool_dma +
1442 pDevice->sOpts.nRxDescs1 * sizeof(SRxDesc);
1443
1444 pDevice->td1_pool_dma = pDevice->td0_pool_dma +
1445 pDevice->sOpts.nTxDescs[0] * sizeof(STxDesc);
1446
1447
1448 // vir_pool: pvoid type
1449 pDevice->apTD0Rings = vir_pool
1450 + pDevice->sOpts.nRxDescs0 * sizeof(SRxDesc)
1451 + pDevice->sOpts.nRxDescs1 * sizeof(SRxDesc);
1452
1453 pDevice->apTD1Rings = vir_pool
1454 + pDevice->sOpts.nRxDescs0 * sizeof(SRxDesc)
1455 + pDevice->sOpts.nRxDescs1 * sizeof(SRxDesc)
1456 + pDevice->sOpts.nTxDescs[0] * sizeof(STxDesc);
1457
1458
1459 pDevice->tx1_bufs = pDevice->tx0_bufs +
1460 pDevice->sOpts.nTxDescs[0] * PKT_BUF_SZ;
1461
1462
1463 pDevice->tx_beacon_bufs = pDevice->tx1_bufs +
1464 pDevice->sOpts.nTxDescs[1] * PKT_BUF_SZ;
1465
1466 pDevice->pbyTmpBuff = pDevice->tx_beacon_bufs +
1467 CB_BEACON_BUF_SIZE;
1468
1469 pDevice->tx_bufs_dma1 = pDevice->tx_bufs_dma0 +
1470 pDevice->sOpts.nTxDescs[0] * PKT_BUF_SZ;
1471
1472
1473 pDevice->tx_beacon_dma = pDevice->tx_bufs_dma1 +
1474 pDevice->sOpts.nTxDescs[1] * PKT_BUF_SZ;
1475
1476
1477 return TRUE;
1478}
1479
1480static void device_free_rings(PSDevice pDevice) {
1481
1482 pci_free_consistent(pDevice->pcid,
1483 pDevice->sOpts.nRxDescs0 * sizeof(SRxDesc) +
1484 pDevice->sOpts.nRxDescs1 * sizeof(SRxDesc) +
1485 pDevice->sOpts.nTxDescs[0] * sizeof(STxDesc) +
1486 pDevice->sOpts.nTxDescs[1] * sizeof(STxDesc)
1487 ,
1488 pDevice->aRD0Ring, pDevice->pool_dma
1489 );
1490
1491 if (pDevice->tx0_bufs)
1492 pci_free_consistent(pDevice->pcid,
1493 pDevice->sOpts.nTxDescs[0] * PKT_BUF_SZ +
1494 pDevice->sOpts.nTxDescs[1] * PKT_BUF_SZ +
1495 CB_BEACON_BUF_SIZE +
1496 CB_MAX_BUF_SIZE,
1497 pDevice->tx0_bufs, pDevice->tx_bufs_dma0
1498 );
1499}
1500
1501static void device_init_rd0_ring(PSDevice pDevice) {
1502 int i;
1503 dma_addr_t curr = pDevice->rd0_pool_dma;
1504 PSRxDesc pDesc;
1505
1506 /* Init the RD0 ring entries */
1507 for (i = 0; i < pDevice->sOpts.nRxDescs0; i ++, curr += sizeof(SRxDesc)) {
1508 pDesc = &(pDevice->aRD0Ring[i]);
1509 pDesc->pRDInfo = alloc_rd_info();
1510 ASSERT(pDesc->pRDInfo);
1511 if (!device_alloc_rx_buf(pDevice, pDesc)) {
1512 DEVICE_PRT(MSG_LEVEL_ERR,KERN_ERR "%s: can not alloc rx bufs\n",
1513 pDevice->dev->name);
1514 }
1515 pDesc->next = &(pDevice->aRD0Ring[(i+1) % pDevice->sOpts.nRxDescs0]);
1516 pDesc->pRDInfo->curr_desc = cpu_to_le32(curr);
1517 pDesc->next_desc = cpu_to_le32(curr + sizeof(SRxDesc));
1518 }
1519
1520 pDevice->aRD0Ring[i-1].next_desc = cpu_to_le32(pDevice->rd0_pool_dma);
1521 pDevice->pCurrRD[0] = &(pDevice->aRD0Ring[0]);
1522}
1523
1524
1525static void device_init_rd1_ring(PSDevice pDevice) {
1526 int i;
1527 dma_addr_t curr = pDevice->rd1_pool_dma;
1528 PSRxDesc pDesc;
1529
1530 /* Init the RD1 ring entries */
1531 for (i = 0; i < pDevice->sOpts.nRxDescs1; i ++, curr += sizeof(SRxDesc)) {
1532 pDesc = &(pDevice->aRD1Ring[i]);
1533 pDesc->pRDInfo = alloc_rd_info();
1534 ASSERT(pDesc->pRDInfo);
1535 if (!device_alloc_rx_buf(pDevice, pDesc)) {
1536 DEVICE_PRT(MSG_LEVEL_ERR,KERN_ERR "%s: can not alloc rx bufs\n",
1537 pDevice->dev->name);
1538 }
1539 pDesc->next = &(pDevice->aRD1Ring[(i+1) % pDevice->sOpts.nRxDescs1]);
1540 pDesc->pRDInfo->curr_desc = cpu_to_le32(curr);
1541 pDesc->next_desc = cpu_to_le32(curr + sizeof(SRxDesc));
1542 }
1543
1544 pDevice->aRD1Ring[i-1].next_desc = cpu_to_le32(pDevice->rd1_pool_dma);
1545 pDevice->pCurrRD[1] = &(pDevice->aRD1Ring[0]);
1546}
1547
1548
1549static void device_init_defrag_cb(PSDevice pDevice) {
1550 int i;
1551 PSDeFragControlBlock pDeF;
1552
1553 /* Init the fragment ctl entries */
1554 for (i = 0; i < CB_MAX_RX_FRAG; i++) {
1555 pDeF = &(pDevice->sRxDFCB[i]);
1556 if (!device_alloc_frag_buf(pDevice, pDeF)) {
1557 DEVICE_PRT(MSG_LEVEL_ERR,KERN_ERR "%s: can not alloc frag bufs\n",
1558 pDevice->dev->name);
1559 };
1560 }
1561 pDevice->cbDFCB = CB_MAX_RX_FRAG;
1562 pDevice->cbFreeDFCB = pDevice->cbDFCB;
1563}
1564
1565
1566
1567
1568static void device_free_rd0_ring(PSDevice pDevice) {
1569 int i;
1570
1571 for (i = 0; i < pDevice->sOpts.nRxDescs0; i++) {
1572 PSRxDesc pDesc =&(pDevice->aRD0Ring[i]);
1573 PDEVICE_RD_INFO pRDInfo =pDesc->pRDInfo;
1574
1575 pci_unmap_single(pDevice->pcid,pRDInfo->skb_dma,
1576 pDevice->rx_buf_sz, PCI_DMA_FROMDEVICE);
1577
1578 dev_kfree_skb(pRDInfo->skb);
1579
1580 kfree((PVOID)pDesc->pRDInfo);
1581 }
1582
1583}
1584
1585static void device_free_rd1_ring(PSDevice pDevice) {
1586 int i;
1587
1588
1589 for (i = 0; i < pDevice->sOpts.nRxDescs1; i++) {
1590 PSRxDesc pDesc=&(pDevice->aRD1Ring[i]);
1591 PDEVICE_RD_INFO pRDInfo=pDesc->pRDInfo;
1592
1593 pci_unmap_single(pDevice->pcid,pRDInfo->skb_dma,
1594 pDevice->rx_buf_sz, PCI_DMA_FROMDEVICE);
1595
1596 dev_kfree_skb(pRDInfo->skb);
1597
1598 kfree((PVOID)pDesc->pRDInfo);
1599 }
1600
1601}
1602
1603static void device_free_frag_buf(PSDevice pDevice) {
1604 PSDeFragControlBlock pDeF;
1605 int i;
1606
1607 for (i = 0; i < CB_MAX_RX_FRAG; i++) {
1608
1609 pDeF = &(pDevice->sRxDFCB[i]);
1610
1611 if (pDeF->skb)
1612 dev_kfree_skb(pDeF->skb);
1613
1614 }
1615
1616}
1617
1618static void device_init_td0_ring(PSDevice pDevice) {
1619 int i;
1620 dma_addr_t curr;
1621 PSTxDesc pDesc;
1622
1623 curr = pDevice->td0_pool_dma;
1624 for (i = 0; i < pDevice->sOpts.nTxDescs[0]; i++, curr += sizeof(STxDesc)) {
1625 pDesc = &(pDevice->apTD0Rings[i]);
1626 pDesc->pTDInfo = alloc_td_info();
1627 ASSERT(pDesc->pTDInfo);
1628 if (pDevice->flags & DEVICE_FLAGS_TX_ALIGN) {
1629 pDesc->pTDInfo->buf = pDevice->tx0_bufs + (i)*PKT_BUF_SZ;
1630 pDesc->pTDInfo->buf_dma = pDevice->tx_bufs_dma0 + (i)*PKT_BUF_SZ;
1631 }
1632 pDesc->next =&(pDevice->apTD0Rings[(i+1) % pDevice->sOpts.nTxDescs[0]]);
1633 pDesc->pTDInfo->curr_desc = cpu_to_le32(curr);
1634 pDesc->next_desc = cpu_to_le32(curr+sizeof(STxDesc));
1635 }
1636
1637 pDevice->apTD0Rings[i-1].next_desc = cpu_to_le32(pDevice->td0_pool_dma);
1638 pDevice->apTailTD[0] = pDevice->apCurrTD[0] =&(pDevice->apTD0Rings[0]);
1639
1640}
1641
1642static void device_init_td1_ring(PSDevice pDevice) {
1643 int i;
1644 dma_addr_t curr;
1645 PSTxDesc pDesc;
1646
1647 /* Init the TD ring entries */
1648 curr=pDevice->td1_pool_dma;
1649 for (i = 0; i < pDevice->sOpts.nTxDescs[1]; i++, curr+=sizeof(STxDesc)) {
1650 pDesc=&(pDevice->apTD1Rings[i]);
1651 pDesc->pTDInfo = alloc_td_info();
1652 ASSERT(pDesc->pTDInfo);
1653 if (pDevice->flags & DEVICE_FLAGS_TX_ALIGN) {
1654 pDesc->pTDInfo->buf=pDevice->tx1_bufs+(i)*PKT_BUF_SZ;
1655 pDesc->pTDInfo->buf_dma=pDevice->tx_bufs_dma1+(i)*PKT_BUF_SZ;
1656 }
1657 pDesc->next=&(pDevice->apTD1Rings[(i+1) % pDevice->sOpts.nTxDescs[1]]);
1658 pDesc->pTDInfo->curr_desc = cpu_to_le32(curr);
1659 pDesc->next_desc = cpu_to_le32(curr+sizeof(STxDesc));
1660 }
1661
1662 pDevice->apTD1Rings[i-1].next_desc = cpu_to_le32(pDevice->td1_pool_dma);
1663 pDevice->apTailTD[1] = pDevice->apCurrTD[1] = &(pDevice->apTD1Rings[0]);
1664}
1665
1666
1667
1668static void device_free_td0_ring(PSDevice pDevice) {
1669 int i;
1670 for (i = 0; i < pDevice->sOpts.nTxDescs[0]; i++) {
1671 PSTxDesc pDesc=&(pDevice->apTD0Rings[i]);
1672 PDEVICE_TD_INFO pTDInfo=pDesc->pTDInfo;
1673
1674 if (pTDInfo->skb_dma && (pTDInfo->skb_dma != pTDInfo->buf_dma))
1675 pci_unmap_single(pDevice->pcid,pTDInfo->skb_dma,
1676 pTDInfo->skb->len, PCI_DMA_TODEVICE);
1677
1678 if (pTDInfo->skb)
1679 dev_kfree_skb(pTDInfo->skb);
1680
1681 kfree((PVOID)pDesc->pTDInfo);
1682 }
1683}
1684
1685static void device_free_td1_ring(PSDevice pDevice) {
1686 int i;
1687
1688 for (i = 0; i < pDevice->sOpts.nTxDescs[1]; i++) {
1689 PSTxDesc pDesc=&(pDevice->apTD1Rings[i]);
1690 PDEVICE_TD_INFO pTDInfo=pDesc->pTDInfo;
1691
1692 if (pTDInfo->skb_dma && (pTDInfo->skb_dma != pTDInfo->buf_dma))
1693 pci_unmap_single(pDevice->pcid, pTDInfo->skb_dma,
1694 pTDInfo->skb->len, PCI_DMA_TODEVICE);
1695
1696 if (pTDInfo->skb)
1697 dev_kfree_skb(pTDInfo->skb);
1698
1699 kfree((PVOID)pDesc->pTDInfo);
1700 }
1701
1702}
1703
1704
1705
1706/*-----------------------------------------------------------------*/
1707
1708static int device_rx_srv(PSDevice pDevice, UINT uIdx) {
1709 PSRxDesc pRD;
1710 int works = 0;
1711
1712
1713 for (pRD = pDevice->pCurrRD[uIdx];
1714 pRD->m_rd0RD0.f1Owner == OWNED_BY_HOST;
1715 pRD = pRD->next) {
1716// DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "pDevice->pCurrRD = %x, works = %d\n", pRD, works);
1717 if (works++>15)
1718 break;
1719 if (device_receive_frame(pDevice, pRD)) {
1720 if (!device_alloc_rx_buf(pDevice,pRD)) {
1721 DEVICE_PRT(MSG_LEVEL_ERR, KERN_ERR
1722 "%s: can not allocate rx buf\n", pDevice->dev->name);
1723 break;
1724 }
1725 }
1726 pRD->m_rd0RD0.f1Owner = OWNED_BY_NIC;
1727#ifdef PRIVATE_OBJ
1728 ref_set_rx_jiffies(pDevice->dev);
1729#else
1730 pDevice->dev->last_rx = jiffies;
1731#endif
1732 }
1733
1734 pDevice->pCurrRD[uIdx]=pRD;
1735
1736 return works;
1737}
1738
1739
1740static BOOL device_alloc_rx_buf(PSDevice pDevice, PSRxDesc pRD) {
1741
1742 PDEVICE_RD_INFO pRDInfo=pRD->pRDInfo;
1743
1744#ifdef PRIVATE_OBJ
1745
1746 pRDInfo->skb=dev_alloc_skb(pDevice->rx_buf_sz);
1747 if (pRDInfo->skb==NULL)
1748 return FALSE;
1749 ref_skb_remap(pDevice->dev, &(pRDInfo->ref_skb), pRDInfo->skb);
1750 pRDInfo->skb_dma = pci_map_single(pDevice->pcid, pRDInfo->ref_skb.tail, pDevice->rx_buf_sz,
1751 PCI_DMA_FROMDEVICE);
1752#else
1753
1754 pRDInfo->skb = dev_alloc_skb((int)pDevice->rx_buf_sz);
1755#ifdef PLICE_DEBUG
1756 //printk("device_alloc_rx_buf:skb is %x\n",pRDInfo->skb);
1757#endif
1758 if (pRDInfo->skb==NULL)
1759 return FALSE;
1760 ASSERT(pRDInfo->skb);
1761 pRDInfo->skb->dev = pDevice->dev;
1762 pRDInfo->skb_dma = pci_map_single(pDevice->pcid, pRDInfo->skb->tail, pDevice->rx_buf_sz,
1763 PCI_DMA_FROMDEVICE);
1764#endif
1765 *((PU32) &(pRD->m_rd0RD0)) = 0;
1766
1767 pRD->m_rd0RD0.wResCount = cpu_to_le16(pDevice->rx_buf_sz);
1768 pRD->m_rd0RD0.f1Owner = OWNED_BY_NIC;
1769 pRD->m_rd1RD1.wReqCount = cpu_to_le16(pDevice->rx_buf_sz);
1770 pRD->buff_addr = cpu_to_le32(pRDInfo->skb_dma);
1771
1772 return TRUE;
1773}
1774
1775
1776
1777BOOL device_alloc_frag_buf(PSDevice pDevice, PSDeFragControlBlock pDeF) {
1778
1779#ifdef PRIVATE_OBJ
1780
1781 pDeF->skb=dev_alloc_skb(pDevice->rx_buf_sz);
1782 if (pDeF->skb==NULL)
1783 return FALSE;
1784 ref_skb_remap(pDevice->dev, &(pDeF->ref_skb), pDeF->skb);
1785
1786#else
1787 pDeF->skb = dev_alloc_skb((int)pDevice->rx_buf_sz);
1788 if (pDeF->skb == NULL)
1789 return FALSE;
1790 ASSERT(pDeF->skb);
1791 pDeF->skb->dev = pDevice->dev;
1792#endif
1793
1794 return TRUE;
1795}
1796
1797
1798
1799static int device_tx_srv(PSDevice pDevice, UINT uIdx) {
1800 PSTxDesc pTD;
1801 BOOL bFull=FALSE;
1802 int works = 0;
1803 BYTE byTsr0;
1804 BYTE byTsr1;
1805 UINT uFrameSize, uFIFOHeaderSize;
1806 PSTxBufHead pTxBufHead;
1807 struct net_device_stats* pStats = &pDevice->stats;
1808 struct sk_buff* skb;
1809 UINT uNodeIndex;
1810 PSMgmtObject pMgmt = pDevice->pMgmt;
1811#ifdef PRIVATE_OBJ
1812 ref_sk_buff ref_skb;
1813#endif
1814
1815
1816 for (pTD = pDevice->apTailTD[uIdx]; pDevice->iTDUsed[uIdx] >0; pTD = pTD->next) {
1817
1818 if (pTD->m_td0TD0.f1Owner == OWNED_BY_NIC)
1819 break;
1820 if (works++>15)
1821 break;
1822
1823 byTsr0 = pTD->m_td0TD0.byTSR0;
1824 byTsr1 = pTD->m_td0TD0.byTSR1;
1825
1826 //Only the status of first TD in the chain is correct
1827 if (pTD->m_td1TD1.byTCR & TCR_STP) {
1828
1829 if ((pTD->pTDInfo->byFlags & TD_FLAGS_NETIF_SKB) != 0) {
1830 uFIFOHeaderSize = pTD->pTDInfo->dwHeaderLength;
1831 uFrameSize = pTD->pTDInfo->dwReqCount - uFIFOHeaderSize;
1832 pTxBufHead = (PSTxBufHead) (pTD->pTDInfo->buf);
1833#ifdef PRIVATE_OBJ
1834 ref_skb_remap(pDevice->dev, &ref_skb, pTD->pTDInfo->skb);
1835#endif
1836 // Update the statistics based on the Transmit status
1837 // now, we DO'NT check TSR0_CDH
1838
1839 STAvUpdateTDStatCounter(&pDevice->scStatistic,
1840 byTsr0, byTsr1,
1841 (PBYTE)(pTD->pTDInfo->buf + uFIFOHeaderSize),
1842 uFrameSize, uIdx);
1843
1844
1845 BSSvUpdateNodeTxCounter(pDevice,
1846 byTsr0, byTsr1,
1847 (PBYTE)(pTD->pTDInfo->buf),
1848 uFIFOHeaderSize
1849 );
1850
1851 if (BITbIsBitOff(byTsr1, TSR1_TERR)) {
1852 if (byTsr0 != 0) {
1853 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO" Tx[%d] OK but has error. tsr1[%02X] tsr0[%02X].\n",
1854 (INT)uIdx, byTsr1, byTsr0);
1855 }
1856 if ((pTxBufHead->wFragCtl & FRAGCTL_ENDFRAG) != FRAGCTL_NONFRAG) {
1857 pDevice->s802_11Counter.TransmittedFragmentCount ++;
1858 }
1859 pStats->tx_packets++;
1860#ifdef PRIVATE_OBJ
1861 pStats->tx_bytes += *(ref_skb.len);
1862#else
1863 pStats->tx_bytes += pTD->pTDInfo->skb->len;
1864#endif
1865 }
1866 else {
1867 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO" Tx[%d] dropped & tsr1[%02X] tsr0[%02X].\n",
1868 (INT)uIdx, byTsr1, byTsr0);
1869 pStats->tx_errors++;
1870 pStats->tx_dropped++;
1871 }
1872 }
1873
1874 if ((pTD->pTDInfo->byFlags & TD_FLAGS_PRIV_SKB) != 0) {
1875 if (pDevice->bEnableHostapd) {
1876 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "tx call back netif.. \n");
1877#ifdef PRIVATE_OBJ
1878 ref_skb_remap(pDevice->apdev, &(ref_skb), pTD->pTDInfo->skb);
1879 ref_skb.mac.raw = ref_skb.data;
1880 *(ref_skb.pkt_type) = PACKET_OTHERHOST;
1881 //*(ref_skb.protocol) = htons(ETH_P_802_2);
1882 memset(ref_skb.cb, 0, sizeof(ref_skb.cb));
1883 netif_rx(ref_skb.skb);
1884#else
1885 skb = pTD->pTDInfo->skb;
1886 skb->dev = pDevice->apdev;
1887#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,22)
1888 skb->mac_header = skb->data;
1889#else
1890 skb->mac.raw = skb->data;
1891#endif
1892 skb->pkt_type = PACKET_OTHERHOST;
1893 //skb->protocol = htons(ETH_P_802_2);
1894 memset(skb->cb, 0, sizeof(skb->cb));
1895 netif_rx(skb);
1896#endif
1897 }
1898 }
1899
1900 if (BITbIsBitOn(byTsr1, TSR1_TERR)) {
1901 if ((pTD->pTDInfo->byFlags & TD_FLAGS_PRIV_SKB) != 0) {
1902 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO" Tx[%d] fail has error. tsr1[%02X] tsr0[%02X].\n",
1903 (INT)uIdx, byTsr1, byTsr0);
1904 }
1905
1906// DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO" Tx[%d] fail has error. tsr1[%02X] tsr0[%02X].\n",
1907// (INT)uIdx, byTsr1, byTsr0);
1908
1909 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_AP) &&
1910 (pTD->pTDInfo->byFlags & TD_FLAGS_NETIF_SKB)) {
1911 WORD wAID;
1912 BYTE byMask[8] = {1, 2, 4, 8, 0x10, 0x20, 0x40, 0x80};
1913
1914 skb = pTD->pTDInfo->skb;
1915 if (BSSDBbIsSTAInNodeDB(pMgmt, (PBYTE)(skb->data), &uNodeIndex)) {
1916 if (pMgmt->sNodeDBTable[uNodeIndex].bPSEnable) {
1917 skb_queue_tail(&pMgmt->sNodeDBTable[uNodeIndex].sTxPSQueue, skb);
1918 pMgmt->sNodeDBTable[uNodeIndex].wEnQueueCnt++;
1919 // set tx map
1920 wAID = pMgmt->sNodeDBTable[uNodeIndex].wAID;
1921 pMgmt->abyPSTxMap[wAID >> 3] |= byMask[wAID & 7];
1922 pTD->pTDInfo->byFlags &= ~(TD_FLAGS_NETIF_SKB);
1923 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "tx_srv:tx fail re-queue sta index= %d, QueCnt= %d\n"
1924 ,(INT)uNodeIndex, pMgmt->sNodeDBTable[uNodeIndex].wEnQueueCnt);
1925 pStats->tx_errors--;
1926 pStats->tx_dropped--;
1927 }
1928 }
1929 }
1930 }
1931 device_free_tx_buf(pDevice,pTD);
1932 pDevice->iTDUsed[uIdx]--;
1933 }
1934 }
1935
1936
1937 if (uIdx == TYPE_AC0DMA) {
1938 // RESERV_AC0DMA reserved for relay
1939
1940 if (AVAIL_TD(pDevice, uIdx) < RESERV_AC0DMA) {
1941 bFull = TRUE;
1942 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO " AC0DMA is Full = %d\n", pDevice->iTDUsed[uIdx]);
1943 }
1944 if (netif_queue_stopped(pDevice->dev) && (bFull==FALSE)){
1945 netif_wake_queue(pDevice->dev);
1946 }
1947 }
1948
1949
1950 pDevice->apTailTD[uIdx] = pTD;
1951
1952 return works;
1953}
1954
1955
1956static void device_error(PSDevice pDevice, WORD status) {
1957
1958 if (status & ISR_FETALERR) {
1959 DEVICE_PRT(MSG_LEVEL_ERR, KERN_ERR
1960 "%s: Hardware fatal error.\n",
1961 pDevice->dev->name);
1962 netif_stop_queue(pDevice->dev);
1963 del_timer(&pDevice->sTimerCommand);
1964 del_timer(&(pDevice->pMgmt->sTimerSecondCallback));
1965 pDevice->bCmdRunning = FALSE;
1966 MACbShutdown(pDevice->PortOffset);
1967 return;
1968 }
1969
1970}
1971
1972static void device_free_tx_buf(PSDevice pDevice, PSTxDesc pDesc) {
1973 PDEVICE_TD_INFO pTDInfo=pDesc->pTDInfo;
1974 struct sk_buff* skb=pTDInfo->skb;
1975
1976 // pre-allocated buf_dma can't be unmapped.
1977 if (pTDInfo->skb_dma && (pTDInfo->skb_dma != pTDInfo->buf_dma)) {
1978 pci_unmap_single(pDevice->pcid,pTDInfo->skb_dma,skb->len,
1979 PCI_DMA_TODEVICE);
1980 }
1981
1982 if ((pTDInfo->byFlags & TD_FLAGS_NETIF_SKB) != 0)
1983 dev_kfree_skb_irq(skb);
1984
1985 pTDInfo->skb_dma = 0;
1986 pTDInfo->skb = 0;
1987 pTDInfo->byFlags = 0;
1988}
1989
1990
1991
1992//PLICE_DEBUG ->
1993VOID InitRxManagementQueue(PSDevice pDevice)
1994{
1995 pDevice->rxManeQueue.packet_num = 0;
1996 pDevice->rxManeQueue.head = pDevice->rxManeQueue.tail = 0;
1997}
1998//PLICE_DEBUG<-
1999
2000
2001
2002
2003
2004//PLICE_DEBUG ->
2005INT MlmeThread(
2006 void * Context)
2007{
2008 PSDevice pDevice = (PSDevice) Context;
2009 PSRxMgmtPacket pRxMgmtPacket;
2010 // int i ;
2011 //complete(&pDevice->notify);
2012//printk("Enter MngWorkItem,Queue packet num is %d\n",pDevice->rxManeQueue.packet_num);
2013
2014 //printk("Enter MlmeThread,packet _num is %d\n",pDevice->rxManeQueue.packet_num);
2015 //i = 0;
2016#if 1
2017 while (1)
2018 {
2019
2020 //printk("DDDD\n");
2021 //down(&pDevice->mlme_semaphore);
2022 // pRxMgmtPacket = DeQueue(pDevice);
2023#if 1
2024 spin_lock_irq(&pDevice->lock);
2025 while(pDevice->rxManeQueue.packet_num != 0)
2026 {
2027 pRxMgmtPacket = DeQueue(pDevice);
2028 //pDevice;
2029 //DequeueManageObject(pDevice->FirstRecvMngList, pDevice->LastRecvMngList);
2030 vMgrRxManagePacket(pDevice, pDevice->pMgmt, pRxMgmtPacket);
2031 //printk("packet_num is %d\n",pDevice->rxManeQueue.packet_num);
2032
2033 }
2034 spin_unlock_irq(&pDevice->lock);
2035 if (mlme_kill == 0)
2036 break;
2037 //udelay(200);
2038#endif
2039 //printk("Before schedule thread jiffies is %x\n",jiffies);
2040 schedule();
2041 //printk("after schedule thread jiffies is %x\n",jiffies);
2042 if (mlme_kill == 0)
2043 break;
2044 //printk("i is %d\n",i);
2045 }
2046
2047#endif
2048 return 0;
2049
2050}
2051
2052
2053#ifdef PRIVATE_OBJ
2054
2055int __device_open(HANDLE pExDevice) {
2056 PSDevice_info pDevice_info = (PSDevice_info)pExDevice;
2057 PSDevice pDevice = (PSDevice)(pDevice_info->pWDevice);
2058
2059#else
2060
2061static int device_open(struct net_device *dev) {
2062 PSDevice pDevice=(PSDevice) dev->priv;
2063 int i;
2064#endif
2065 pDevice->rx_buf_sz = PKT_BUF_SZ;
2066 if (!device_init_rings(pDevice)) {
2067 return -ENOMEM;
2068 }
2069//2008-5-13 <add> by chester
2070#ifndef PRIVATE_OBJ
2071#if LINUX_VERSION_CODE > KERNEL_VERSION(2,6,16)
2072 i=request_irq(pDevice->pcid->irq, &device_intr, IRQF_SHARED, dev->name, dev);
2073#else
2074 i=request_irq(pDevice->pcid->irq, &device_intr, (unsigned long)SA_SHIRQ, dev->name, dev);
2075#endif
2076 if (i)
2077 return i;
2078#endif
2079 //printk("DEBUG1\n");
2080#ifdef WPA_SM_Transtatus
2081 extern SWPAResult wpa_Result;
2082 memset(wpa_Result.ifname,0,sizeof(wpa_Result.ifname));
2083 wpa_Result.proto = 0;
2084 wpa_Result.key_mgmt = 0;
2085 wpa_Result.eap_type = 0;
2086 wpa_Result.authenticated = FALSE;
2087 pDevice->fWPA_Authened = FALSE;
2088#endif
2089DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "call device init rd0 ring\n");
2090device_init_rd0_ring(pDevice);
2091 device_init_rd1_ring(pDevice);
2092 device_init_defrag_cb(pDevice);
2093 device_init_td0_ring(pDevice);
2094 device_init_td1_ring(pDevice);
2095// VNTWIFIvSet11h(pDevice->pMgmt, pDevice->b11hEnable);
2096
2097
2098 if (pDevice->bDiversityRegCtlON) {
2099 device_init_diversity_timer(pDevice);
2100 }
2101 vMgrObjectInit(pDevice);
2102 vMgrTimerInit(pDevice);
2103
2104//PLICE_DEBUG->
2105#ifdef TASK_LET
2106 tasklet_init (&pDevice->RxMngWorkItem,(void *)MngWorkItem,(unsigned long )pDevice);
2107#endif
2108#ifdef THREAD
2109 InitRxManagementQueue(pDevice);
2110 mlme_kill = 0;
2111 mlme_task = kthread_run(MlmeThread,(void *) pDevice, "MLME");
2112 if (IS_ERR(mlme_task)) {
2113 printk("thread create fail\n");
2114 return -1;
2115 }
2116
2117 mlme_kill = 1;
2118#endif
2119
2120
2121
2122#if 0
2123 pDevice->MLMEThr_pid = kernel_thread(MlmeThread, pDevice, CLONE_VM);
2124 if (pDevice->MLMEThr_pid <0 )
2125 {
2126 printk("unable start thread MlmeThread\n");
2127 return -1;
2128 }
2129#endif
2130
2131 //printk("thread id is %d\n",pDevice->MLMEThr_pid);
2132 //printk("Create thread time is %x\n",jiffies);
2133 //wait_for_completion(&pDevice->notify);
2134
2135
2136
2137
2138 // if (( SROMbyReadEmbedded(pDevice->PortOffset, EEP_OFS_RADIOCTL)&0x06)==0x04)
2139 // return -ENOMEM;
2140DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "call device_init_registers\n");
2141 device_init_registers(pDevice, DEVICE_INIT_COLD);
2142 MACvReadEtherAddress(pDevice->PortOffset, pDevice->abyCurrentNetAddr);
2143 memcpy(pDevice->pMgmt->abyMACAddr, pDevice->abyCurrentNetAddr, U_ETHER_ADDR_LEN);
2144#ifdef PRIVATE_OBJ
2145 __device_set_multi(pExDevice);
2146#else
2147 device_set_multi(pDevice->dev);
2148#endif
2149
2150 // Init for Key Management
2151 KeyvInitTable(&pDevice->sKey, pDevice->PortOffset);
2152 add_timer(&(pDevice->pMgmt->sTimerSecondCallback));
2153
2154 #ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
2155 /*
2156 pDevice->bwextstep0 = FALSE;
2157 pDevice->bwextstep1 = FALSE;
2158 pDevice->bwextstep2 = FALSE;
2159 pDevice->bwextstep3 = FALSE;
2160 */
2161 pDevice->bwextcount=0;
2162 pDevice->bWPASuppWextEnabled = FALSE;
2163#endif
2164 pDevice->byReAssocCount = 0;
2165 pDevice->bWPADEVUp = FALSE;
2166 // Patch: if WEP key already set by iwconfig but device not yet open
2167 if ((pDevice->bEncryptionEnable == TRUE) && (pDevice->bTransmitKey == TRUE)) {
2168 KeybSetDefaultKey(&(pDevice->sKey),
2169 (DWORD)(pDevice->byKeyIndex | (1 << 31)),
2170 pDevice->uKeyLength,
2171 NULL,
2172 pDevice->abyKey,
2173 KEY_CTL_WEP,
2174 pDevice->PortOffset,
2175 pDevice->byLocalID
2176 );
2177 pDevice->eEncryptionStatus = Ndis802_11Encryption1Enabled;
2178 }
2179
2180//printk("DEBUG2\n");
2181
2182
2183DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "call MACvIntEnable\n");
2184 MACvIntEnable(pDevice->PortOffset, IMR_MASK_VALUE);
2185
2186 if (pDevice->pMgmt->eConfigMode == WMAC_CONFIG_AP) {
2187 bScheduleCommand((HANDLE)pDevice, WLAN_CMD_RUN_AP, NULL);
2188 }
2189 else {
2190 bScheduleCommand((HANDLE)pDevice, WLAN_CMD_BSSID_SCAN, NULL);
2191 bScheduleCommand((HANDLE)pDevice, WLAN_CMD_SSID, NULL);
2192 }
2193 pDevice->flags |=DEVICE_FLAGS_OPENED;
2194
2195#ifndef PRIVATE_OBJ
2196#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
2197 MOD_INC_USE_COUNT;
2198#endif
2199#endif
2200
2201 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "device_open success.. \n");
2202 return 0;
2203}
2204
2205
2206#ifdef PRIVATE_OBJ
2207
2208int __device_close(HANDLE pExDevice) {
2209 PSDevice_info pDevice_info = (PSDevice_info)pExDevice;
2210 struct net_device *dev = pDevice_info->dev;
2211 PSDevice pDevice = (PSDevice)(pDevice_info->pWDevice);
2212
2213#else
2214static int device_close(struct net_device *dev) {
2215 PSDevice pDevice=(PSDevice) dev->priv;
2216#endif
2217 PSMgmtObject pMgmt = pDevice->pMgmt;
2218 //PLICE_DEBUG->
2219#ifdef THREAD
2220 mlme_kill = 0;
2221#endif
2222//PLICE_DEBUG<-
2223//2007-1121-02<Add>by EinsnLiu
2224 if (pDevice->bLinkPass) {
2225 bScheduleCommand((HANDLE)pDevice, WLAN_CMD_DISASSOCIATE, NULL);
2226 mdelay(30);
2227 }
2228#ifdef TxInSleep
2229 del_timer(&pDevice->sTimerTxData);
2230#endif
2231 del_timer(&pDevice->sTimerCommand);
2232 del_timer(&pMgmt->sTimerSecondCallback);
2233 if (pDevice->bDiversityRegCtlON) {
2234 del_timer(&pDevice->TimerSQ3Tmax1);
2235 del_timer(&pDevice->TimerSQ3Tmax2);
2236 del_timer(&pDevice->TimerSQ3Tmax3);
2237 }
2238
2239#ifdef TASK_LET
2240 tasklet_kill(&pDevice->RxMngWorkItem);
2241#endif
2242 netif_stop_queue(dev);
2243 pDevice->bCmdRunning = FALSE;
2244 MACbShutdown(pDevice->PortOffset);
2245 MACbSoftwareReset(pDevice->PortOffset);
2246 CARDbRadioPowerOff(pDevice);
2247
2248 pDevice->bLinkPass = FALSE;
2249 memset(pMgmt->abyCurrBSSID, 0, 6);
2250 pMgmt->eCurrState = WMAC_STATE_IDLE;
2251 device_free_td0_ring(pDevice);
2252 device_free_td1_ring(pDevice);
2253 device_free_rd0_ring(pDevice);
2254 device_free_rd1_ring(pDevice);
2255 device_free_frag_buf(pDevice);
2256 device_free_rings(pDevice);
2257 BSSvClearNodeDBTable(pDevice, 0);
2258 free_irq(dev->irq, dev);
2259 pDevice->flags &=(~DEVICE_FLAGS_OPENED);
2260 //2008-0714-01<Add>by chester
2261device_release_WPADEV(pDevice);
2262//PLICE_DEBUG->
2263 //tasklet_kill(&pDevice->RxMngWorkItem);
2264//PLICE_DEBUG<-
2265#ifndef PRIVATE_OBJ
2266#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
2267 MOD_DEC_USE_COUNT;
2268#endif
2269#endif
2270 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "device_close.. \n");
2271 return 0;
2272}
2273
2274#ifdef PRIVATE_OBJ
2275
2276int __device_dma0_tx_80211(HANDLE pExDevice, struct sk_buff *skb) {
2277 PSDevice_info pDevice_info = (PSDevice_info)pExDevice;
2278 PSDevice pDevice = (PSDevice)(pDevice_info->pWDevice);
2279 ref_sk_buff ref_skb;
2280
2281#else
2282
2283
2284static int device_dma0_tx_80211(struct sk_buff *skb, struct net_device *dev) {
2285 PSDevice pDevice=dev->priv;
2286#endif
2287 PBYTE pbMPDU;
2288 UINT cbMPDULen = 0;
2289
2290
2291 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "device_dma0_tx_80211\n");
2292 spin_lock_irq(&pDevice->lock);
2293
2294 if (AVAIL_TD(pDevice, TYPE_TXDMA0) <= 0) {
2295 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "device_dma0_tx_80211, td0 <=0\n");
2296 dev_kfree_skb_irq(skb);
2297 spin_unlock_irq(&pDevice->lock);
2298 return 0;
2299 }
2300
2301 if (pDevice->bStopTx0Pkt == TRUE) {
2302 dev_kfree_skb_irq(skb);
2303 spin_unlock_irq(&pDevice->lock);
2304 return 0;
2305 };
2306
2307#ifdef PRIVATE_OBJ
2308 ref_skb_remap(pDevice->dev, &ref_skb, skb);
2309 cbMPDULen = *(ref_skb.len);
2310 pbMPDU = ref_skb.data;
2311#else
2312 cbMPDULen = skb->len;
2313 pbMPDU = skb->data;
2314#endif
2315
2316 vDMA0_tx_80211(pDevice, skb, pbMPDU, cbMPDULen);
2317
2318 spin_unlock_irq(&pDevice->lock);
2319
2320 return 0;
2321
2322}
2323
2324
2325
2326BOOL device_dma0_xmit(PSDevice pDevice, struct sk_buff *skb, UINT uNodeIndex) {
2327 PSMgmtObject pMgmt = pDevice->pMgmt;
2328 PSTxDesc pHeadTD, pLastTD;
2329 UINT cbFrameBodySize;
2330 UINT uMACfragNum;
2331 BYTE byPktTyp;
2332 BOOL bNeedEncryption = FALSE;
2333 PSKeyItem pTransmitKey = NULL;
2334 UINT cbHeaderSize;
2335 UINT ii;
2336 SKeyItem STempKey;
2337// BYTE byKeyIndex = 0;
2338#ifdef PRIVATE_OBJ
2339 ref_sk_buff ref_skb;
2340#endif
2341
2342
2343 if (pDevice->bStopTx0Pkt == TRUE) {
2344 dev_kfree_skb_irq(skb);
2345 return FALSE;
2346 };
2347
2348 if (AVAIL_TD(pDevice, TYPE_TXDMA0) <= 0) {
2349 dev_kfree_skb_irq(skb);
2350 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "device_dma0_xmit, td0 <=0\n");
2351 return FALSE;
2352 }
2353
2354 if (pMgmt->eCurrMode == WMAC_MODE_ESS_AP) {
2355 if (pDevice->uAssocCount == 0) {
2356 dev_kfree_skb_irq(skb);
2357 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "device_dma0_xmit, assocCount = 0\n");
2358 return FALSE;
2359 }
2360 }
2361
2362#ifdef PRIVATE_OBJ
2363 ref_skb_remap(pDevice->dev, &(ref_skb), skb);
2364#endif
2365 pHeadTD = pDevice->apCurrTD[TYPE_TXDMA0];
2366
2367 pHeadTD->m_td1TD1.byTCR = (TCR_EDP|TCR_STP);
2368
2369#ifdef PRIVATE_OBJ
2370 memcpy(pDevice->sTxEthHeader.abyDstAddr, (PBYTE)(ref_skb.data), U_HEADER_LEN);
2371 cbFrameBodySize = *(ref_skb.len) - U_HEADER_LEN;
2372
2373#else
2374 memcpy(pDevice->sTxEthHeader.abyDstAddr, (PBYTE)(skb->data), U_HEADER_LEN);
2375 cbFrameBodySize = skb->len - U_HEADER_LEN;
2376#endif
2377
2378 // 802.1H
2379 if (ntohs(pDevice->sTxEthHeader.wType) > MAX_DATA_LEN) {
2380 cbFrameBodySize += 8;
2381 }
2382 uMACfragNum = cbGetFragCount(pDevice, pTransmitKey, cbFrameBodySize, &pDevice->sTxEthHeader);
2383
2384 if ( uMACfragNum > AVAIL_TD(pDevice, TYPE_TXDMA0)) {
2385 dev_kfree_skb_irq(skb);
2386 return FALSE;
2387 }
2388 byPktTyp = (BYTE)pDevice->byPacketType;
2389
2390
2391 if (pDevice->bFixRate) {
2392 if (pDevice->eCurrentPHYType == PHY_TYPE_11B) {
2393 if (pDevice->uConnectionRate >= RATE_11M) {
2394 pDevice->wCurrentRate = RATE_11M;
2395 } else {
2396 pDevice->wCurrentRate = (WORD)pDevice->uConnectionRate;
2397 }
2398 } else {
2399 if (pDevice->uConnectionRate >= RATE_54M)
2400 pDevice->wCurrentRate = RATE_54M;
2401 else
2402 pDevice->wCurrentRate = (WORD)pDevice->uConnectionRate;
2403 }
2404 }
2405 else {
2406 pDevice->wCurrentRate = pDevice->pMgmt->sNodeDBTable[uNodeIndex].wTxDataRate;
2407 }
2408
2409 //preamble type
2410 if (pMgmt->sNodeDBTable[uNodeIndex].bShortPreamble) {
2411 pDevice->byPreambleType = pDevice->byShortPreamble;
2412 }
2413 else {
2414 pDevice->byPreambleType = PREAMBLE_LONG;
2415 }
2416
2417 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "dma0: pDevice->wCurrentRate = %d \n", pDevice->wCurrentRate);
2418
2419
2420 if (pDevice->wCurrentRate <= RATE_11M) {
2421 byPktTyp = PK_TYPE_11B;
2422 } else if (pDevice->eCurrentPHYType == PHY_TYPE_11A) {
2423 byPktTyp = PK_TYPE_11A;
2424 } else {
2425 if (pDevice->bProtectMode == TRUE) {
2426 byPktTyp = PK_TYPE_11GB;
2427 } else {
2428 byPktTyp = PK_TYPE_11GA;
2429 }
2430 }
2431
2432 if (pDevice->bEncryptionEnable == TRUE)
2433 bNeedEncryption = TRUE;
2434
2435 if (pDevice->bEnableHostWEP) {
2436 pTransmitKey = &STempKey;
2437 pTransmitKey->byCipherSuite = pMgmt->sNodeDBTable[uNodeIndex].byCipherSuite;
2438 pTransmitKey->dwKeyIndex = pMgmt->sNodeDBTable[uNodeIndex].dwKeyIndex;
2439 pTransmitKey->uKeyLength = pMgmt->sNodeDBTable[uNodeIndex].uWepKeyLength;
2440 pTransmitKey->dwTSC47_16 = pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16;
2441 pTransmitKey->wTSC15_0 = pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0;
2442 memcpy(pTransmitKey->abyKey,
2443 &pMgmt->sNodeDBTable[uNodeIndex].abyWepKey[0],
2444 pTransmitKey->uKeyLength
2445 );
2446 }
2447 vGenerateFIFOHeader(pDevice, byPktTyp, pDevice->pbyTmpBuff, bNeedEncryption,
2448 cbFrameBodySize, TYPE_TXDMA0, pHeadTD,
2449 &pDevice->sTxEthHeader, (PBYTE)skb->data, pTransmitKey, uNodeIndex,
2450 &uMACfragNum,
2451 &cbHeaderSize
2452 );
2453
2454 if (MACbIsRegBitsOn(pDevice->PortOffset, MAC_REG_PSCTL, PSCTL_PS)) {
2455 // Disable PS
2456 MACbPSWakeup(pDevice->PortOffset);
2457 }
2458
2459 pDevice->bPWBitOn = FALSE;
2460
2461 pLastTD = pHeadTD;
2462 for (ii = 0; ii < uMACfragNum; ii++) {
2463 // Poll Transmit the adapter
2464 wmb();
2465 pHeadTD->m_td0TD0.f1Owner=OWNED_BY_NIC;
2466 wmb();
2467 if (ii == (uMACfragNum - 1))
2468 pLastTD = pHeadTD;
2469 pHeadTD = pHeadTD->next;
2470 }
2471
2472 // Save the information needed by the tx interrupt handler
2473 // to complete the Send request
2474 pLastTD->pTDInfo->skb = skb;
2475 pLastTD->pTDInfo->byFlags = 0;
2476 pLastTD->pTDInfo->byFlags |= TD_FLAGS_NETIF_SKB;
2477
2478 pDevice->apCurrTD[TYPE_TXDMA0] = pHeadTD;
2479
2480 MACvTransmit0(pDevice->PortOffset);
2481
2482
2483 return TRUE;
2484}
2485
2486//TYPE_AC0DMA data tx
2487#ifdef PRIVATE_OBJ
2488
2489int __device_xmit(HANDLE pExDevice, struct sk_buff *skb) {
2490 PSDevice_info pDevice_info = (PSDevice_info)pExDevice;
2491 PSDevice pDevice = (PSDevice)(pDevice_info->pWDevice);
2492 struct net_device *dev = pDevice_info->dev;
2493 ref_sk_buff ref_skb;
2494
2495#else
2496static int device_xmit(struct sk_buff *skb, struct net_device *dev) {
2497 PSDevice pDevice=dev->priv;
2498
2499#endif
2500 PSMgmtObject pMgmt = pDevice->pMgmt;
2501 PSTxDesc pHeadTD, pLastTD;
2502 UINT uNodeIndex = 0;
2503 BYTE byMask[8] = {1, 2, 4, 8, 0x10, 0x20, 0x40, 0x80};
2504 WORD wAID;
2505 UINT uMACfragNum = 1;
2506 UINT cbFrameBodySize;
2507 BYTE byPktTyp;
2508 UINT cbHeaderSize;
2509 BOOL bNeedEncryption = FALSE;
2510 PSKeyItem pTransmitKey = NULL;
2511 SKeyItem STempKey;
2512 UINT ii;
2513 BOOL bTKIP_UseGTK = FALSE;
2514 BOOL bNeedDeAuth = FALSE;
2515 PBYTE pbyBSSID;
2516 BOOL bNodeExist = FALSE;
2517
2518
2519
2520 spin_lock_irq(&pDevice->lock);
2521 if (pDevice->bLinkPass == FALSE) {
2522 dev_kfree_skb_irq(skb);
2523 spin_unlock_irq(&pDevice->lock);
2524 return 0;
2525 }
2526
2527 if (pDevice->bStopDataPkt) {
2528 dev_kfree_skb_irq(skb);
2529 spin_unlock_irq(&pDevice->lock);
2530 return 0;
2531 }
2532
2533#ifdef PRIVATE_OBJ
2534 ref_skb_remap(pDevice->dev, &ref_skb, skb);
2535#endif
2536
2537 if (pMgmt->eCurrMode == WMAC_MODE_ESS_AP) {
2538 if (pDevice->uAssocCount == 0) {
2539 dev_kfree_skb_irq(skb);
2540 spin_unlock_irq(&pDevice->lock);
2541 return 0;
2542 }
2543#ifdef PRIVATE_OBJ
2544 if (IS_MULTICAST_ADDRESS((PBYTE)(ref_skb.data))) {
2545#else
2546 if (IS_MULTICAST_ADDRESS((PBYTE)(skb->data))) {
2547#endif
2548 uNodeIndex = 0;
2549 bNodeExist = TRUE;
2550 if (pMgmt->sNodeDBTable[0].bPSEnable) {
2551#ifdef PRIVATE_OBJ
2552 skb_queue_tail(&(pMgmt->sNodeDBTable[0].sTxPSQueue), ref_skb.skb);
2553#else
2554 skb_queue_tail(&(pMgmt->sNodeDBTable[0].sTxPSQueue), skb);
2555#endif
2556 pMgmt->sNodeDBTable[0].wEnQueueCnt++;
2557 // set tx map
2558 pMgmt->abyPSTxMap[0] |= byMask[0];
2559 spin_unlock_irq(&pDevice->lock);
2560 return 0;
2561 }
2562}else {
2563#ifdef PRIVATE_OBJ
2564 if (BSSDBbIsSTAInNodeDB(pMgmt, (PBYTE)(ref_skb.data), &uNodeIndex)) {
2565#else
2566 if (BSSDBbIsSTAInNodeDB(pMgmt, (PBYTE)(skb->data), &uNodeIndex)) {
2567#endif
2568 if (pMgmt->sNodeDBTable[uNodeIndex].bPSEnable) {
2569#ifdef PRIVATE_OBJ
2570 skb_queue_tail(&pMgmt->sNodeDBTable[uNodeIndex].sTxPSQueue, ref_skb.skb);
2571#else
2572 skb_queue_tail(&pMgmt->sNodeDBTable[uNodeIndex].sTxPSQueue, skb);
2573#endif
2574 pMgmt->sNodeDBTable[uNodeIndex].wEnQueueCnt++;
2575 // set tx map
2576 wAID = pMgmt->sNodeDBTable[uNodeIndex].wAID;
2577 pMgmt->abyPSTxMap[wAID >> 3] |= byMask[wAID & 7];
2578 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Set:pMgmt->abyPSTxMap[%d]= %d\n",
2579 (wAID >> 3), pMgmt->abyPSTxMap[wAID >> 3]);
2580 spin_unlock_irq(&pDevice->lock);
2581 return 0;
2582 }
2583
2584 if (pMgmt->sNodeDBTable[uNodeIndex].bShortPreamble) {
2585 pDevice->byPreambleType = pDevice->byShortPreamble;
2586
2587 }else {
2588 pDevice->byPreambleType = PREAMBLE_LONG;
2589 }
2590 bNodeExist = TRUE;
2591
2592 }
2593 }
2594
2595 if (bNodeExist == FALSE) {
2596 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"Unknown STA not found in node DB \n");
2597 dev_kfree_skb_irq(skb);
2598 spin_unlock_irq(&pDevice->lock);
2599 return 0;
2600 }
2601 }
2602
2603 pHeadTD = pDevice->apCurrTD[TYPE_AC0DMA];
2604
2605 pHeadTD->m_td1TD1.byTCR = (TCR_EDP|TCR_STP);
2606
2607
2608#ifdef PRIVATE_OBJ
2609 memcpy(pDevice->sTxEthHeader.abyDstAddr, (PBYTE)(ref_skb.data), U_HEADER_LEN);
2610 cbFrameBodySize = *(ref_skb.len) - U_HEADER_LEN;
2611#else
2612 memcpy(pDevice->sTxEthHeader.abyDstAddr, (PBYTE)(skb->data), U_HEADER_LEN);
2613 cbFrameBodySize = skb->len - U_HEADER_LEN;
2614#endif
2615 // 802.1H
2616 if (ntohs(pDevice->sTxEthHeader.wType) > MAX_DATA_LEN) {
2617 cbFrameBodySize += 8;
2618 }
2619
2620
2621 if (pDevice->bEncryptionEnable == TRUE) {
2622 bNeedEncryption = TRUE;
2623 // get Transmit key
2624 do {
2625 if ((pDevice->pMgmt->eCurrMode == WMAC_MODE_ESS_STA) &&
2626 (pDevice->pMgmt->eCurrState == WMAC_STATE_ASSOC)) {
2627 pbyBSSID = pDevice->abyBSSID;
2628 // get pairwise key
2629 if (KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, PAIRWISE_KEY, &pTransmitKey) == FALSE) {
2630 // get group key
2631 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == TRUE) {
2632 bTKIP_UseGTK = TRUE;
2633 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"Get GTK.\n");
2634 break;
2635 }
2636 } else {
2637 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"Get PTK.\n");
2638 break;
2639 }
2640 }else if (pDevice->pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) {
2641
2642 pbyBSSID = pDevice->sTxEthHeader.abyDstAddr; //TO_DS = 0 and FROM_DS = 0 --> 802.11 MAC Address1
2643 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"IBSS Serach Key: \n");
2644 for (ii = 0; ii< 6; ii++)
2645 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"%x \n", *(pbyBSSID+ii));
2646 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"\n");
2647
2648 // get pairwise key
2649 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, PAIRWISE_KEY, &pTransmitKey) == TRUE)
2650 break;
2651 }
2652 // get group key
2653 pbyBSSID = pDevice->abyBroadcastAddr;
2654 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == FALSE) {
2655 pTransmitKey = NULL;
2656 if (pDevice->pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) {
2657 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"IBSS and KEY is NULL. [%d]\n", pDevice->pMgmt->eCurrMode);
2658 }
2659 else
2660 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"NOT IBSS and KEY is NULL. [%d]\n", pDevice->pMgmt->eCurrMode);
2661 } else {
2662 bTKIP_UseGTK = TRUE;
2663 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"Get GTK.\n");
2664 }
2665 } while(FALSE);
2666 }
2667
2668 if (pDevice->bEnableHostWEP) {
2669 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"acdma0: STA index %d\n", uNodeIndex);
2670 if (pDevice->bEncryptionEnable == TRUE) {
2671 pTransmitKey = &STempKey;
2672 pTransmitKey->byCipherSuite = pMgmt->sNodeDBTable[uNodeIndex].byCipherSuite;
2673 pTransmitKey->dwKeyIndex = pMgmt->sNodeDBTable[uNodeIndex].dwKeyIndex;
2674 pTransmitKey->uKeyLength = pMgmt->sNodeDBTable[uNodeIndex].uWepKeyLength;
2675 pTransmitKey->dwTSC47_16 = pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16;
2676 pTransmitKey->wTSC15_0 = pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0;
2677 memcpy(pTransmitKey->abyKey,
2678 &pMgmt->sNodeDBTable[uNodeIndex].abyWepKey[0],
2679 pTransmitKey->uKeyLength
2680 );
2681 }
2682 }
2683
2684 uMACfragNum = cbGetFragCount(pDevice, pTransmitKey, cbFrameBodySize, &pDevice->sTxEthHeader);
2685
2686 if (uMACfragNum > AVAIL_TD(pDevice, TYPE_AC0DMA)) {
2687 DEVICE_PRT(MSG_LEVEL_ERR, KERN_DEBUG "uMACfragNum > AVAIL_TD(TYPE_AC0DMA) = %d\n", uMACfragNum);
2688 dev_kfree_skb_irq(skb);
2689 spin_unlock_irq(&pDevice->lock);
2690 return 0;
2691 }
2692
2693 if (pTransmitKey != NULL) {
2694 if ((pTransmitKey->byCipherSuite == KEY_CTL_WEP) &&
2695 (pTransmitKey->uKeyLength == WLAN_WEP232_KEYLEN)) {
2696 uMACfragNum = 1; //WEP256 doesn't support fragment
2697 }
2698 }
2699
2700 byPktTyp = (BYTE)pDevice->byPacketType;
2701
2702 if (pDevice->bFixRate) {
2703#ifdef PLICE_DEBUG
2704 printk("Fix Rate: PhyType is %d,ConnectionRate is %d\n",pDevice->eCurrentPHYType,pDevice->uConnectionRate);
2705#endif
2706
2707 if (pDevice->eCurrentPHYType == PHY_TYPE_11B) {
2708 if (pDevice->uConnectionRate >= RATE_11M) {
2709 pDevice->wCurrentRate = RATE_11M;
2710 } else {
2711 pDevice->wCurrentRate = (WORD)pDevice->uConnectionRate;
2712 }
2713 } else {
2714 if ((pDevice->eCurrentPHYType == PHY_TYPE_11A) &&
2715 (pDevice->uConnectionRate <= RATE_6M)) {
2716 pDevice->wCurrentRate = RATE_6M;
2717 } else {
2718 if (pDevice->uConnectionRate >= RATE_54M)
2719 pDevice->wCurrentRate = RATE_54M;
2720 else
2721 pDevice->wCurrentRate = (WORD)pDevice->uConnectionRate;
2722
2723 }
2724 }
2725 pDevice->byACKRate = (BYTE) pDevice->wCurrentRate;
2726 pDevice->byTopCCKBasicRate = RATE_1M;
2727 pDevice->byTopOFDMBasicRate = RATE_6M;
2728 }
2729 else {
2730 //auto rate
2731 if (pDevice->sTxEthHeader.wType == TYPE_PKT_802_1x) {
2732 if (pDevice->eCurrentPHYType != PHY_TYPE_11A) {
2733 pDevice->wCurrentRate = RATE_1M;
2734 pDevice->byACKRate = RATE_1M;
2735 pDevice->byTopCCKBasicRate = RATE_1M;
2736 pDevice->byTopOFDMBasicRate = RATE_6M;
2737 } else {
2738 pDevice->wCurrentRate = RATE_6M;
2739 pDevice->byACKRate = RATE_6M;
2740 pDevice->byTopCCKBasicRate = RATE_1M;
2741 pDevice->byTopOFDMBasicRate = RATE_6M;
2742 }
2743 }
2744 else {
2745 VNTWIFIvGetTxRate( pDevice->pMgmt,
2746 pDevice->sTxEthHeader.abyDstAddr,
2747 &(pDevice->wCurrentRate),
2748 &(pDevice->byACKRate),
2749 &(pDevice->byTopCCKBasicRate),
2750 &(pDevice->byTopOFDMBasicRate));
2751
2752#if 0
2753printk("auto rate:Rate : %d,AckRate:%d,TopCCKRate:%d,TopOFDMRate:%d\n",
2754pDevice->wCurrentRate,pDevice->byACKRate,
2755pDevice->byTopCCKBasicRate,pDevice->byTopOFDMBasicRate);
2756
2757#endif
2758
2759#if 0
2760
2761 pDevice->wCurrentRate = 11;
2762 pDevice->byACKRate = 8;
2763 pDevice->byTopCCKBasicRate = 3;
2764 pDevice->byTopOFDMBasicRate = 8;
2765#endif
2766
2767
2768 }
2769 }
2770
2771// DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "acdma0: pDevice->wCurrentRate = %d \n", pDevice->wCurrentRate);
2772
2773 if (pDevice->wCurrentRate <= RATE_11M) {
2774 byPktTyp = PK_TYPE_11B;
2775 } else if (pDevice->eCurrentPHYType == PHY_TYPE_11A) {
2776 byPktTyp = PK_TYPE_11A;
2777 } else {
2778 if (pDevice->bProtectMode == TRUE) {
2779 byPktTyp = PK_TYPE_11GB;
2780 } else {
2781 byPktTyp = PK_TYPE_11GA;
2782 }
2783 }
2784
2785//#ifdef PLICE_DEBUG
2786// printk("FIX RATE:CurrentRate is %d");
2787//#endif
2788
2789 if (bNeedEncryption == TRUE) {
2790 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"ntohs Pkt Type=%04x\n", ntohs(pDevice->sTxEthHeader.wType));
2791 if ((pDevice->sTxEthHeader.wType) == TYPE_PKT_802_1x) {
2792 bNeedEncryption = FALSE;
2793 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Pkt Type=%04x\n", (pDevice->sTxEthHeader.wType));
2794 if ((pDevice->pMgmt->eCurrMode == WMAC_MODE_ESS_STA) && (pDevice->pMgmt->eCurrState == WMAC_STATE_ASSOC)) {
2795 if (pTransmitKey == NULL) {
2796 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Don't Find TX KEY\n");
2797 }
2798 else {
2799 if (bTKIP_UseGTK == TRUE) {
2800 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"error: KEY is GTK!!~~\n");
2801 }
2802 else {
2803 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Find PTK [%lX]\n", pTransmitKey->dwKeyIndex);
2804 bNeedEncryption = TRUE;
2805 }
2806 }
2807 }
2808
2809 if (pDevice->byCntMeasure == 2) {
2810 bNeedDeAuth = TRUE;
2811 pDevice->s802_11Counter.TKIPCounterMeasuresInvoked++;
2812 }
2813
2814 if (pDevice->bEnableHostWEP) {
2815 if ((uNodeIndex != 0) &&
2816 (pMgmt->sNodeDBTable[uNodeIndex].dwKeyIndex & PAIRWISE_KEY)) {
2817 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Find PTK [%lX]\n", pTransmitKey->dwKeyIndex);
2818 bNeedEncryption = TRUE;
2819 }
2820 }
2821 }
2822 else {
2823 if (pTransmitKey == NULL) {
2824 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"return no tx key\n");
2825 dev_kfree_skb_irq(skb);
2826 spin_unlock_irq(&pDevice->lock);
2827 return 0;
2828 }
2829 }
2830 }
2831
2832
2833#ifdef PRIVATE_OBJ
2834 vGenerateFIFOHeader(pDevice, byPktTyp, pDevice->pbyTmpBuff, bNeedEncryption,
2835 cbFrameBodySize, TYPE_AC0DMA, pHeadTD,
2836 &pDevice->sTxEthHeader, (PBYTE)ref_skb.data, pTransmitKey, uNodeIndex,
2837 &uMACfragNum,
2838 &cbHeaderSize
2839 );
2840#else
2841#ifdef PLICE_DEBUG
2842 //if (skb->len == 98)
2843 //{
2844 // printk("ping:len is %d\n");
2845 //}
2846#endif
2847 vGenerateFIFOHeader(pDevice, byPktTyp, pDevice->pbyTmpBuff, bNeedEncryption,
2848 cbFrameBodySize, TYPE_AC0DMA, pHeadTD,
2849 &pDevice->sTxEthHeader, (PBYTE)skb->data, pTransmitKey, uNodeIndex,
2850 &uMACfragNum,
2851 &cbHeaderSize
2852 );
2853#endif
2854
2855 if (MACbIsRegBitsOn(pDevice->PortOffset, MAC_REG_PSCTL, PSCTL_PS)) {
2856 // Disable PS
2857 MACbPSWakeup(pDevice->PortOffset);
2858 }
2859 pDevice->bPWBitOn = FALSE;
2860
2861 pLastTD = pHeadTD;
2862 for (ii = 0; ii < uMACfragNum; ii++) {
2863 // Poll Transmit the adapter
2864 wmb();
2865 pHeadTD->m_td0TD0.f1Owner=OWNED_BY_NIC;
2866 wmb();
2867 if (ii == uMACfragNum - 1)
2868 pLastTD = pHeadTD;
2869 pHeadTD = pHeadTD->next;
2870 }
2871
2872 // Save the information needed by the tx interrupt handler
2873 // to complete the Send request
2874#ifdef PRIVATE_OBJ
2875 pLastTD->pTDInfo->skb = ref_skb.skb;
2876#else
2877 pLastTD->pTDInfo->skb = skb;
2878#endif
2879 pLastTD->pTDInfo->byFlags = 0;
2880 pLastTD->pTDInfo->byFlags |= TD_FLAGS_NETIF_SKB;
2881#ifdef TxInSleep
2882 pDevice->nTxDataTimeCout=0; //2008-8-21 chester <add> for send null packet
2883 #endif
2884 if (AVAIL_TD(pDevice, TYPE_AC0DMA) <= 1) {
2885 netif_stop_queue(dev);
2886 }
2887
2888 pDevice->apCurrTD[TYPE_AC0DMA] = pHeadTD;
2889//#ifdef PLICE_DEBUG
2890 if (pDevice->bFixRate)
2891 {
2892 printk("FixRate:Rate is %d,TxPower is %d\n",pDevice->wCurrentRate,pDevice->byCurPwr);
2893 }
2894 else
2895 {
2896 //printk("Auto Rate:Rate is %d,TxPower is %d\n",pDevice->wCurrentRate,pDevice->byCurPwr);
2897 }
2898//#endif
2899
2900{
2901 BYTE Protocol_Version; //802.1x Authentication
2902 BYTE Packet_Type; //802.1x Authentication
2903 BYTE Descriptor_type;
2904 WORD Key_info;
2905BOOL bTxeapol_key = FALSE;
2906 Protocol_Version = skb->data[U_HEADER_LEN];
2907 Packet_Type = skb->data[U_HEADER_LEN+1];
2908 Descriptor_type = skb->data[U_HEADER_LEN+1+1+2];
2909 Key_info = (skb->data[U_HEADER_LEN+1+1+2+1] << 8)|(skb->data[U_HEADER_LEN+1+1+2+2]);
2910 if (pDevice->sTxEthHeader.wType == TYPE_PKT_802_1x) {
2911 if(((Protocol_Version==1) ||(Protocol_Version==2)) &&
2912 (Packet_Type==3)) { //802.1x OR eapol-key challenge frame transfer
2913 bTxeapol_key = TRUE;
2914 if((Descriptor_type==254)||(Descriptor_type==2)) { //WPA or RSN
2915 if(!(Key_info & BIT3) && //group-key challenge
2916 (Key_info & BIT8) && (Key_info & BIT9)) { //send 2/2 key
2917 pDevice->fWPA_Authened = TRUE;
2918 if(Descriptor_type==254)
2919 printk("WPA ");
2920 else
2921 printk("WPA2 ");
2922 printk("Authentication completed!!\n");
2923 }
2924 }
2925 }
2926 }
2927}
2928
2929 MACvTransmitAC0(pDevice->PortOffset);
2930// DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "acdma0:pDevice->apCurrTD= %p\n", pHeadTD);
2931
2932#ifdef PRIVATE_OBJ
2933 ref_set_tx_jiffies(pDevice->dev);
2934#else
2935 dev->trans_start = jiffies;
2936#endif
2937
2938 spin_unlock_irq(&pDevice->lock);
2939 return 0;
2940
2941}
2942
2943#ifdef PRIVATE_OBJ
2944
2945int __device_intr(int irq, HANDLE pExDevice, struct pt_regs *regs) {
2946 PSDevice_info pDevice_info = (PSDevice_info)pExDevice;
2947 PSDevice pDevice = (PSDevice)(pDevice_info->pWDevice);
2948
2949
2950#else
2951static irqreturn_t device_intr(int irq, void *dev_instance) {
2952 struct net_device* dev=dev_instance;
2953 PSDevice pDevice=(PSDevice) dev->priv;
2954#endif
2955
2956 int max_count=0;
2957 DWORD dwMIBCounter=0;
2958 PSMgmtObject pMgmt = pDevice->pMgmt;
2959 BYTE byOrgPageSel=0;
2960 int handled = 0;
2961 BYTE byData = 0;
2962 int ii= 0;
2963// BYTE byRSSI;
2964
2965
2966 MACvReadISR(pDevice->PortOffset, &pDevice->dwIsr);
2967
2968 if (pDevice->dwIsr == 0)
2969 return IRQ_RETVAL(handled);
2970
2971 if (pDevice->dwIsr == 0xffffffff) {
2972 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "dwIsr = 0xffff\n");
2973 return IRQ_RETVAL(handled);
2974 }
2975 /*
2976 // 2008-05-21 <mark> by Richardtai, we can't read RSSI here, because no packet bound with RSSI
2977
2978 if ((BITbIsBitOn(pDevice->dwIsr, ISR_RXDMA0)) &&
2979 (pDevice->byLocalID != REV_ID_VT3253_B0) &&
2980 (pDevice->bBSSIDFilter == TRUE)) {
2981 // update RSSI
2982 //BBbReadEmbeded(pDevice->PortOffset, 0x3E, &byRSSI);
2983 //pDevice->uCurrRSSI = byRSSI;
2984 }
2985 */
2986
2987 handled = 1;
2988 MACvIntDisable(pDevice->PortOffset);
2989 spin_lock_irq(&pDevice->lock);
2990
2991 //Make sure current page is 0
2992 VNSvInPortB(pDevice->PortOffset + MAC_REG_PAGE1SEL, &byOrgPageSel);
2993 if (byOrgPageSel == 1) {
2994 MACvSelectPage0(pDevice->PortOffset);
2995 }
2996 else
2997 byOrgPageSel = 0;
2998
2999 MACvReadMIBCounter(pDevice->PortOffset, &dwMIBCounter);
3000 // TBD....
3001 // Must do this after doing rx/tx, cause ISR bit is slow
3002 // than RD/TD write back
3003 // update ISR counter
3004 STAvUpdate802_11Counter(&pDevice->s802_11Counter, &pDevice->scStatistic , dwMIBCounter);
3005 while (pDevice->dwIsr != 0) {
3006
3007 STAvUpdateIsrStatCounter(&pDevice->scStatistic, pDevice->dwIsr);
3008 MACvWriteISR(pDevice->PortOffset, pDevice->dwIsr);
3009
3010 if (pDevice->dwIsr & ISR_FETALERR){
3011 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO " ISR_FETALERR \n");
3012 VNSvOutPortB(pDevice->PortOffset + MAC_REG_SOFTPWRCTL, 0);
3013 VNSvOutPortW(pDevice->PortOffset + MAC_REG_SOFTPWRCTL, SOFTPWRCTL_SWPECTI);
3014 device_error(pDevice, pDevice->dwIsr);
3015 }
3016
3017 if (pDevice->byLocalID > REV_ID_VT3253_B1) {
3018
3019 if (BITbIsBitOn(pDevice->dwIsr, ISR_MEASURESTART)) {
3020 // 802.11h measure start
3021 pDevice->byOrgChannel = pDevice->byCurrentCh;
3022 VNSvInPortB(pDevice->PortOffset + MAC_REG_RCR, &(pDevice->byOrgRCR));
3023 VNSvOutPortB(pDevice->PortOffset + MAC_REG_RCR, (RCR_RXALLTYPE | RCR_UNICAST | RCR_BROADCAST | RCR_MULTICAST | RCR_WPAERR));
3024 MACvSelectPage1(pDevice->PortOffset);
3025 VNSvInPortD(pDevice->PortOffset + MAC_REG_MAR0, &(pDevice->dwOrgMAR0));
3026 VNSvInPortD(pDevice->PortOffset + MAC_REG_MAR4, &(pDevice->dwOrgMAR4));
3027 MACvSelectPage0(pDevice->PortOffset);
3028 //xxxx
3029 // WCMDbFlushCommandQueue(pDevice->pMgmt, TRUE);
3030 if (CARDbSetChannel(pDevice, pDevice->pCurrMeasureEID->sReq.byChannel) == TRUE) {
3031 pDevice->bMeasureInProgress = TRUE;
3032 MACvSelectPage1(pDevice->PortOffset);
3033 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_MSRCTL, MSRCTL_READY);
3034 MACvSelectPage0(pDevice->PortOffset);
3035 pDevice->byBasicMap = 0;
3036 pDevice->byCCAFraction = 0;
3037 for(ii=0;ii<8;ii++) {
3038 pDevice->dwRPIs[ii] = 0;
3039 }
3040 } else {
3041 // can not measure because set channel fail
3042 // WCMDbResetCommandQueue(pDevice->pMgmt);
3043 // clear measure control
3044 MACvRegBitsOff(pDevice->PortOffset, MAC_REG_MSRCTL, MSRCTL_EN);
3045 s_vCompleteCurrentMeasure(pDevice, MEASURE_MODE_INCAPABLE);
3046 MACvSelectPage1(pDevice->PortOffset);
3047 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_MSRCTL+1, MSRCTL1_TXPAUSE);
3048 MACvSelectPage0(pDevice->PortOffset);
3049 }
3050 }
3051 if (BITbIsBitOn(pDevice->dwIsr, ISR_MEASUREEND)) {
3052 // 802.11h measure end
3053 pDevice->bMeasureInProgress = FALSE;
3054 VNSvOutPortB(pDevice->PortOffset + MAC_REG_RCR, pDevice->byOrgRCR);
3055 MACvSelectPage1(pDevice->PortOffset);
3056 VNSvOutPortD(pDevice->PortOffset + MAC_REG_MAR0, pDevice->dwOrgMAR0);
3057 VNSvOutPortD(pDevice->PortOffset + MAC_REG_MAR4, pDevice->dwOrgMAR4);
3058 VNSvInPortB(pDevice->PortOffset + MAC_REG_MSRBBSTS, &byData);
3059 pDevice->byBasicMap |= (byData >> 4);
3060 VNSvInPortB(pDevice->PortOffset + MAC_REG_CCAFRACTION, &pDevice->byCCAFraction);
3061 VNSvInPortB(pDevice->PortOffset + MAC_REG_MSRCTL, &byData);
3062 // clear measure control
3063 MACvRegBitsOff(pDevice->PortOffset, MAC_REG_MSRCTL, MSRCTL_EN);
3064 MACvSelectPage0(pDevice->PortOffset);
3065 CARDbSetChannel(pDevice, pDevice->byOrgChannel);
3066 // WCMDbResetCommandQueue(pDevice->pMgmt);
3067 MACvSelectPage1(pDevice->PortOffset);
3068 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_MSRCTL+1, MSRCTL1_TXPAUSE);
3069 MACvSelectPage0(pDevice->PortOffset);
3070 if (BITbIsBitOn(byData, MSRCTL_FINISH)) {
3071 // measure success
3072 s_vCompleteCurrentMeasure(pDevice, 0);
3073 } else {
3074 // can not measure because not ready before end of measure time
3075 s_vCompleteCurrentMeasure(pDevice, MEASURE_MODE_LATE);
3076 }
3077 }
3078 if (BITbIsBitOn(pDevice->dwIsr, ISR_QUIETSTART)) {
3079 do {
3080 ;
3081 } while (CARDbStartQuiet(pDevice) == FALSE);
3082 }
3083 }
3084
3085 if (pDevice->dwIsr & ISR_TBTT) {
3086 if (pDevice->bEnableFirstQuiet == TRUE) {
3087 pDevice->byQuietStartCount--;
3088 if (pDevice->byQuietStartCount == 0) {
3089 pDevice->bEnableFirstQuiet = FALSE;
3090 MACvSelectPage1(pDevice->PortOffset);
3091 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_MSRCTL, (MSRCTL_QUIETTXCHK | MSRCTL_QUIETEN));
3092 MACvSelectPage0(pDevice->PortOffset);
3093 }
3094 }
3095 if ((pDevice->bChannelSwitch == TRUE) &&
3096 (pDevice->eOPMode == OP_MODE_INFRASTRUCTURE)) {
3097 pDevice->byChannelSwitchCount--;
3098 if (pDevice->byChannelSwitchCount == 0) {
3099 pDevice->bChannelSwitch = FALSE;
3100 CARDbSetChannel(pDevice, pDevice->byNewChannel);
3101 VNTWIFIbChannelSwitch(pDevice->pMgmt, pDevice->byNewChannel);
3102 MACvSelectPage1(pDevice->PortOffset);
3103 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_MSRCTL+1, MSRCTL1_TXPAUSE);
3104 MACvSelectPage0(pDevice->PortOffset);
3105 CARDbStartTxPacket(pDevice, PKT_TYPE_802_11_ALL);
3106
3107 }
3108 }
3109 if (pDevice->eOPMode == OP_MODE_ADHOC) {
3110 //pDevice->bBeaconSent = FALSE;
3111 } else {
3112 if ((pDevice->bUpdateBBVGA) && (pDevice->bLinkPass == TRUE) && (pDevice->uCurrRSSI != 0)) {
3113 LONG ldBm;
3114
3115 RFvRSSITodBm(pDevice, (BYTE) pDevice->uCurrRSSI, &ldBm);
3116 for (ii=0;ii<BB_VGA_LEVEL;ii++) {
3117 if (ldBm < pDevice->ldBmThreshold[ii]) {
3118 pDevice->byBBVGANew = pDevice->abyBBVGA[ii];
3119 break;
3120 }
3121 }
3122 if (pDevice->byBBVGANew != pDevice->byBBVGACurrent) {
3123 pDevice->uBBVGADiffCount++;
3124 if (pDevice->uBBVGADiffCount == 1) {
3125 // first VGA diff gain
3126 BBvSetVGAGainOffset(pDevice, pDevice->byBBVGANew);
3127 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"First RSSI[%d] NewGain[%d] OldGain[%d] Count[%d]\n",
3128 (int)ldBm, pDevice->byBBVGANew, pDevice->byBBVGACurrent, (int)pDevice->uBBVGADiffCount);
3129 }
3130 if (pDevice->uBBVGADiffCount >= BB_VGA_CHANGE_THRESHOLD) {
3131 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"RSSI[%d] NewGain[%d] OldGain[%d] Count[%d]\n",
3132 (int)ldBm, pDevice->byBBVGANew, pDevice->byBBVGACurrent, (int)pDevice->uBBVGADiffCount);
3133 BBvSetVGAGainOffset(pDevice, pDevice->byBBVGANew);
3134 }
3135 } else {
3136 pDevice->uBBVGADiffCount = 1;
3137 }
3138 }
3139 }
3140
3141 pDevice->bBeaconSent = FALSE;
3142 if (pDevice->bEnablePSMode) {
3143 PSbIsNextTBTTWakeUp((HANDLE)pDevice);
3144 };
3145
3146 if ((pDevice->eOPMode == OP_MODE_AP) ||
3147 (pDevice->eOPMode == OP_MODE_ADHOC)) {
3148
3149 MACvOneShotTimer1MicroSec(pDevice->PortOffset,
3150 (pMgmt->wIBSSBeaconPeriod - MAKE_BEACON_RESERVED) << 10);
3151 }
3152
3153 if (pDevice->eOPMode == OP_MODE_ADHOC && pDevice->pMgmt->wCurrATIMWindow > 0) {
3154 // todo adhoc PS mode
3155 };
3156
3157 }
3158
3159 if (pDevice->dwIsr & ISR_BNTX) {
3160
3161 if (pDevice->eOPMode == OP_MODE_ADHOC) {
3162 pDevice->bIsBeaconBufReadySet = FALSE;
3163 pDevice->cbBeaconBufReadySetCnt = 0;
3164 };
3165
3166 if (pDevice->eOPMode == OP_MODE_AP) {
3167 if(pMgmt->byDTIMCount > 0) {
3168 pMgmt->byDTIMCount --;
3169 pMgmt->sNodeDBTable[0].bRxPSPoll = FALSE;
3170 }
3171 else {
3172 if(pMgmt->byDTIMCount == 0) {
3173 // check if mutltcast tx bufferring
3174 pMgmt->byDTIMCount = pMgmt->byDTIMPeriod - 1;
3175 pMgmt->sNodeDBTable[0].bRxPSPoll = TRUE;
3176 bScheduleCommand((HANDLE)pDevice, WLAN_CMD_RX_PSPOLL, NULL);
3177 }
3178 }
3179 }
3180 pDevice->bBeaconSent = TRUE;
3181
3182 if (pDevice->bChannelSwitch == TRUE) {
3183 pDevice->byChannelSwitchCount--;
3184 if (pDevice->byChannelSwitchCount == 0) {
3185 pDevice->bChannelSwitch = FALSE;
3186 CARDbSetChannel(pDevice, pDevice->byNewChannel);
3187 VNTWIFIbChannelSwitch(pDevice->pMgmt, pDevice->byNewChannel);
3188 MACvSelectPage1(pDevice->PortOffset);
3189 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_MSRCTL+1, MSRCTL1_TXPAUSE);
3190 MACvSelectPage0(pDevice->PortOffset);
3191 //VNTWIFIbSendBeacon(pDevice->pMgmt);
3192 CARDbStartTxPacket(pDevice, PKT_TYPE_802_11_ALL);
3193 }
3194 }
3195
3196 }
3197
3198 if (pDevice->dwIsr & ISR_RXDMA0) {
3199 max_count += device_rx_srv(pDevice, TYPE_RXDMA0);
3200 }
3201 if (pDevice->dwIsr & ISR_RXDMA1) {
3202 max_count += device_rx_srv(pDevice, TYPE_RXDMA1);
3203 }
3204 if (pDevice->dwIsr & ISR_TXDMA0){
3205 max_count += device_tx_srv(pDevice, TYPE_TXDMA0);
3206 }
3207 if (pDevice->dwIsr & ISR_AC0DMA){
3208 max_count += device_tx_srv(pDevice, TYPE_AC0DMA);
3209 }
3210 if (pDevice->dwIsr & ISR_SOFTTIMER) {
3211
3212 }
3213 if (pDevice->dwIsr & ISR_SOFTTIMER1) {
3214 if (pDevice->eOPMode == OP_MODE_AP) {
3215 if (pDevice->bShortSlotTime)
3216 pMgmt->wCurrCapInfo |= WLAN_SET_CAP_INFO_SHORTSLOTTIME(1);
3217 else
3218 pMgmt->wCurrCapInfo &= ~(WLAN_SET_CAP_INFO_SHORTSLOTTIME(1));
3219 }
3220 bMgrPrepareBeaconToSend(pDevice, pMgmt);
3221 pDevice->byCntMeasure = 0;
3222 }
3223
3224 MACvReadISR(pDevice->PortOffset, &pDevice->dwIsr);
3225
3226 MACvReceive0(pDevice->PortOffset);
3227 MACvReceive1(pDevice->PortOffset);
3228
3229 if (max_count>pDevice->sOpts.int_works)
3230 break;
3231 }
3232
3233 if (byOrgPageSel == 1) {
3234 MACvSelectPage1(pDevice->PortOffset);
3235 }
3236
3237 spin_unlock_irq(&pDevice->lock);
3238 MACvIntEnable(pDevice->PortOffset, IMR_MASK_VALUE);
3239
3240 return IRQ_RETVAL(handled);
3241}
3242
3243
3244static unsigned const ethernet_polynomial = 0x04c11db7U;
3245static inline u32 ether_crc(int length, unsigned char *data)
3246{
3247 int crc = -1;
3248
3249 while(--length >= 0) {
3250 unsigned char current_octet = *data++;
3251 int bit;
3252 for (bit = 0; bit < 8; bit++, current_octet >>= 1) {
3253 crc = (crc << 1) ^
3254 ((crc < 0) ^ (current_octet & 1) ? ethernet_polynomial : 0);
3255 }
3256 }
3257 return crc;
3258}
3259
3260//2008-8-4 <add> by chester
3261static int Config_FileGetParameter(UCHAR *string, UCHAR *dest,UCHAR *source)
3262{
3263 UCHAR buf1[100];
3264 int source_len = strlen(source);
3265
3266 memset(buf1,0,100);
3267 strcat(buf1, string);
3268 strcat(buf1, "=");
3269 source+=strlen(buf1);
3270
3271 memcpy(dest,source,source_len-strlen(buf1));
3272 return TRUE;
3273}
3274
3275int Config_FileOperation(PSDevice pDevice,BOOL fwrite,unsigned char *Parameter) {
3276 UCHAR *config_path=CONFIG_PATH;
3277 UCHAR *buffer=NULL;
3278 UCHAR tmpbuffer[20];
3279 struct file *filp=NULL;
3280 mm_segment_t old_fs = get_fs();
3281 int oldfsuid=0,oldfsgid=0;
3282 int result=0;
3283
3284 set_fs (KERNEL_DS);
3285//Make sure a caller can read or write power as root
3286 oldfsuid=current->fsuid;
3287 oldfsgid=current->fsgid;
3288 current->fsuid = 0;
3289 current->fsgid = 0;
3290
3291 //open file
3292 filp = filp_open(config_path, O_RDWR, 0);
3293 if (IS_ERR(filp)) {
3294 printk("Config_FileOperation:open file fail?\n");
3295 result=-1;
3296 goto error2;
3297 }
3298
3299 if(!(filp->f_op) || !(filp->f_op->read) ||!(filp->f_op->write)) {
3300 printk("file %s cann't readable or writable?\n",config_path);
3301 result = -1;
3302 goto error1;
3303 }
3304
3305buffer = (UCHAR *)kmalloc(1024, GFP_KERNEL);
3306if(buffer==NULL) {
3307 printk("alllocate mem for file fail?\n");
3308 result = -1;
3309 goto error1;
3310}
3311
3312if(filp->f_op->read(filp, buffer, 1024, &filp->f_pos)<0) {
3313 printk("read file error?\n");
3314 result = -1;
3315 goto error1;
3316}
3317
3318if(Config_FileGetParameter("ZONETYPE",tmpbuffer,buffer)!=TRUE) {
3319 printk("get parameter error?\n");
3320 result = -1;
3321 goto error1;
3322}
3323
3324if(memcmp(tmpbuffer,"USA",3)==0) {
3325 result=ZoneType_USA;
3326}
3327else if(memcmp(tmpbuffer,"JAPAN",5)==0) {
3328 result=ZoneType_Japan;
3329}
3330else if(memcmp(tmpbuffer,"EUROPE",5)==0) {
3331 result=ZoneType_Europe;
3332}
3333else {
3334 result = -1;
3335 printk("Unknown Zonetype[%s]?\n",tmpbuffer);
3336}
3337
3338error1:
3339 if(buffer)
3340 kfree(buffer);
3341
3342 if(filp_close(filp,NULL))
3343 printk("Config_FileOperation:close file fail\n");
3344
3345error2:
3346 set_fs (old_fs);
3347 current->fsuid=oldfsuid;
3348 current->fsgid=oldfsgid;
3349
3350 return result;
3351}
3352
3353
3354#ifdef PRIVATE_OBJ
3355
3356void __device_set_multi(HANDLE pExDevice) {
3357 PSDevice_info pDevice_info = (PSDevice_info)pExDevice;
3358 ref_net_device *dev = &(pDevice_info->ref_dev);
3359 PSDevice pDevice = (PSDevice)(pDevice_info->pWDevice);
3360
3361#else
3362
3363static void device_set_multi(struct net_device *dev) {
3364 PSDevice pDevice = (PSDevice) dev->priv;
3365#endif
3366
3367 PSMgmtObject pMgmt = pDevice->pMgmt;
3368 u32 mc_filter[2];
3369 int i;
3370 struct dev_mc_list *mclist;
3371
3372
3373 VNSvInPortB(pDevice->PortOffset + MAC_REG_RCR, &(pDevice->byRxMode));
3374
3375#ifdef PRIVATE_OBJ
3376 if (*(dev->flags) & IFF_PROMISC) { /* Set promiscuous. */
3377 DEVICE_PRT(MSG_LEVEL_ERR,KERN_ERR "%s: Promiscuous mode enabled.\n", pDevice->dev->name);
3378
3379#else
3380 if (dev->flags & IFF_PROMISC) { /* Set promiscuous. */
3381 DEVICE_PRT(MSG_LEVEL_ERR,KERN_NOTICE "%s: Promiscuous mode enabled.\n", dev->name);
3382#endif
3383 /* Unconditionally log net taps. */
3384 pDevice->byRxMode |= (RCR_MULTICAST|RCR_BROADCAST|RCR_UNICAST);
3385 }
3386#ifdef PRIVATE_OBJ
3387 else if ((*(dev->mc_count) > pDevice->multicast_limit)
3388 || (*(dev->flags) & IFF_ALLMULTI)) {
3389#else
3390 else if ((dev->mc_count > pDevice->multicast_limit)
3391 || (dev->flags & IFF_ALLMULTI)) {
3392#endif
3393 MACvSelectPage1(pDevice->PortOffset);
3394 VNSvOutPortD(pDevice->PortOffset + MAC_REG_MAR0, 0xffffffff);
3395 VNSvOutPortD(pDevice->PortOffset + MAC_REG_MAR0 + 4, 0xffffffff);
3396 MACvSelectPage0(pDevice->PortOffset);
3397 pDevice->byRxMode |= (RCR_MULTICAST|RCR_BROADCAST);
3398 }
3399 else {
3400 memset(mc_filter, 0, sizeof(mc_filter));
3401#ifdef PRIVATE_OBJ
3402 for (i = 0, mclist = dev->mc_list; mclist && i < *(dev->mc_count);
3403 i++, mclist = mclist->next) {
3404#else
3405 for (i = 0, mclist = dev->mc_list; mclist && i < dev->mc_count;
3406 i++, mclist = mclist->next) {
3407#endif
3408 int bit_nr = ether_crc(ETH_ALEN, mclist->dmi_addr) >> 26;
3409 mc_filter[bit_nr >> 5] |= cpu_to_le32(1 << (bit_nr & 31));
3410 }
3411 MACvSelectPage1(pDevice->PortOffset);
3412 VNSvOutPortD(pDevice->PortOffset + MAC_REG_MAR0, mc_filter[0]);
3413 VNSvOutPortD(pDevice->PortOffset + MAC_REG_MAR0 + 4, mc_filter[1]);
3414 MACvSelectPage0(pDevice->PortOffset);
3415 pDevice->byRxMode &= ~(RCR_UNICAST);
3416 pDevice->byRxMode |= (RCR_MULTICAST|RCR_BROADCAST);
3417 }
3418
3419 if (pMgmt->eConfigMode == WMAC_CONFIG_AP) {
3420 // If AP mode, don't enable RCR_UNICAST. Since hw only compare addr1 with local mac.
3421 pDevice->byRxMode |= (RCR_MULTICAST|RCR_BROADCAST);
3422 pDevice->byRxMode &= ~(RCR_UNICAST);
3423 }
3424
3425 VNSvOutPortB(pDevice->PortOffset + MAC_REG_RCR, pDevice->byRxMode);
3426 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "pDevice->byRxMode = %x\n", pDevice->byRxMode );
3427}
3428
3429
3430#ifdef PRIVATE_OBJ
3431
3432struct net_device_stats *__device_get_stats(HANDLE pExDevice) {
3433 PSDevice_info pDevice_info = (PSDevice_info)pExDevice;
3434 PSDevice pDevice = (PSDevice)(pDevice_info->pWDevice);
3435
3436#else
3437static struct net_device_stats *device_get_stats(struct net_device *dev) {
3438 PSDevice pDevice=(PSDevice) dev->priv;
3439#endif
3440
3441 return &pDevice->stats;
3442}
3443
3444
3445#ifdef PRIVATE_OBJ
3446
3447int __device_ioctl(HANDLE pExDevice, struct ifreq *rq, int cmd) {
3448 PSDevice_info pDevice_info = (PSDevice_info)pExDevice;
3449 struct net_device *dev = pDevice_info->dev;
3450 PSDevice pDevice = (PSDevice)(pDevice_info->pWDevice);
3451
3452#else
3453
3454static int device_ioctl(struct net_device *dev, struct ifreq *rq, int cmd) {
3455 PSDevice pDevice = (PSDevice)dev->priv;
3456#endif
3457
3458#ifdef WIRELESS_EXT
3459 struct iwreq *wrq = (struct iwreq *) rq;
3460 int rc =0;
3461#endif
3462 PSMgmtObject pMgmt = pDevice->pMgmt;
3463 PSCmdRequest pReq;
3464
3465
3466 if (pMgmt == NULL) {
3467 rc = -EFAULT;
3468 return rc;
3469 }
3470
3471 switch(cmd) {
3472
3473#ifdef WIRELESS_EXT
3474//#if WIRELESS_EXT < 13
3475
3476 case SIOCGIWNAME:
3477 rc = iwctl_giwname(dev, NULL, (char *)&(wrq->u.name), NULL);
3478 break;
3479
3480 case SIOCGIWNWID: //0x8b03 support
3481 #ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
3482 rc = iwctl_giwnwid(dev, NULL, &(wrq->u.nwid), NULL);
3483 #else
3484 rc = -EOPNOTSUPP;
3485 #endif
3486 break;
3487
3488 // Set frequency/channel
3489 case SIOCSIWFREQ:
3490 rc = iwctl_siwfreq(dev, NULL, &(wrq->u.freq), NULL);
3491 break;
3492
3493 // Get frequency/channel
3494 case SIOCGIWFREQ:
3495 rc = iwctl_giwfreq(dev, NULL, &(wrq->u.freq), NULL);
3496 break;
3497
3498 // Set desired network name (ESSID)
3499 case SIOCSIWESSID:
3500
3501 {
3502 char essid[IW_ESSID_MAX_SIZE+1];
3503 if (wrq->u.essid.length > IW_ESSID_MAX_SIZE) {
3504 rc = -E2BIG;
3505 break;
3506 }
3507 if (copy_from_user(essid, wrq->u.essid.pointer,
3508 wrq->u.essid.length)) {
3509 rc = -EFAULT;
3510 break;
3511 }
3512 rc = iwctl_siwessid(dev, NULL,
3513 &(wrq->u.essid), essid);
3514 }
3515 break;
3516
3517
3518 // Get current network name (ESSID)
3519 case SIOCGIWESSID:
3520
3521 {
3522 char essid[IW_ESSID_MAX_SIZE+1];
3523 if (wrq->u.essid.pointer)
3524 rc = iwctl_giwessid(dev, NULL,
3525 &(wrq->u.essid), essid);
3526 if (copy_to_user(wrq->u.essid.pointer,
3527 essid,
3528 wrq->u.essid.length) )
3529 rc = -EFAULT;
3530 }
3531 break;
3532
3533 case SIOCSIWAP:
3534
3535 rc = iwctl_siwap(dev, NULL, &(wrq->u.ap_addr), NULL);
3536 break;
3537
3538
3539 // Get current Access Point (BSSID)
3540 case SIOCGIWAP:
3541 rc = iwctl_giwap(dev, NULL, &(wrq->u.ap_addr), NULL);
3542 break;
3543
3544
3545 // Set desired station name
3546 case SIOCSIWNICKN:
3547 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWNICKN \n");
3548 rc = -EOPNOTSUPP;
3549 break;
3550
3551 // Get current station name
3552 case SIOCGIWNICKN:
3553 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWNICKN \n");
3554 rc = -EOPNOTSUPP;
3555 break;
3556
3557 // Set the desired bit-rate
3558 case SIOCSIWRATE:
3559 rc = iwctl_siwrate(dev, NULL, &(wrq->u.bitrate), NULL);
3560 break;
3561
3562 // Get the current bit-rate
3563 case SIOCGIWRATE:
3564
3565 rc = iwctl_giwrate(dev, NULL, &(wrq->u.bitrate), NULL);
3566 break;
3567
3568 // Set the desired RTS threshold
3569 case SIOCSIWRTS:
3570
3571 rc = iwctl_siwrts(dev, NULL, &(wrq->u.rts), NULL);
3572 break;
3573
3574 // Get the current RTS threshold
3575 case SIOCGIWRTS:
3576
3577 rc = iwctl_giwrts(dev, NULL, &(wrq->u.rts), NULL);
3578 break;
3579
3580 // Set the desired fragmentation threshold
3581 case SIOCSIWFRAG:
3582
3583 rc = iwctl_siwfrag(dev, NULL, &(wrq->u.frag), NULL);
3584 break;
3585
3586 // Get the current fragmentation threshold
3587 case SIOCGIWFRAG:
3588
3589 rc = iwctl_giwfrag(dev, NULL, &(wrq->u.frag), NULL);
3590 break;
3591
3592 // Set mode of operation
3593 case SIOCSIWMODE:
3594 rc = iwctl_siwmode(dev, NULL, &(wrq->u.mode), NULL);
3595 break;
3596
3597 // Get mode of operation
3598 case SIOCGIWMODE:
3599 rc = iwctl_giwmode(dev, NULL, &(wrq->u.mode), NULL);
3600 break;
3601
3602 // Set WEP keys and mode
3603 case SIOCSIWENCODE:
3604 {
3605 char abyKey[WLAN_WEP232_KEYLEN];
3606
3607 if (wrq->u.encoding.pointer) {
3608
3609
3610 if (wrq->u.encoding.length > WLAN_WEP232_KEYLEN) {
3611 rc = -E2BIG;
3612 break;
3613 }
3614 memset(abyKey, 0, WLAN_WEP232_KEYLEN);
3615 if (copy_from_user(abyKey,
3616 wrq->u.encoding.pointer,
3617 wrq->u.encoding.length)) {
3618 rc = -EFAULT;
3619 break;
3620 }
3621 } else if (wrq->u.encoding.length != 0) {
3622 rc = -EINVAL;
3623 break;
3624 }
3625 rc = iwctl_siwencode(dev, NULL, &(wrq->u.encoding), abyKey);
3626 }
3627 break;
3628
3629 // Get the WEP keys and mode
3630 case SIOCGIWENCODE:
3631
3632 if (!capable(CAP_NET_ADMIN)) {
3633 rc = -EPERM;
3634 break;
3635 }
3636 {
3637 char abyKey[WLAN_WEP232_KEYLEN];
3638
3639 rc = iwctl_giwencode(dev, NULL, &(wrq->u.encoding), abyKey);
3640 if (rc != 0) break;
3641 if (wrq->u.encoding.pointer) {
3642 if (copy_to_user(wrq->u.encoding.pointer,
3643 abyKey,
3644 wrq->u.encoding.length))
3645 rc = -EFAULT;
3646 }
3647 }
3648 break;
3649
3650#if WIRELESS_EXT > 9
3651 // Get the current Tx-Power
3652 case SIOCGIWTXPOW:
3653 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWTXPOW \n");
3654 rc = -EOPNOTSUPP;
3655 break;
3656
3657 case SIOCSIWTXPOW:
3658 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWTXPOW \n");
3659 rc = -EOPNOTSUPP;
3660 break;
3661
3662#endif // WIRELESS_EXT > 9
3663
3664#if WIRELESS_EXT > 10
3665 case SIOCSIWRETRY:
3666
3667 rc = iwctl_siwretry(dev, NULL, &(wrq->u.retry), NULL);
3668 break;
3669
3670 case SIOCGIWRETRY:
3671
3672 rc = iwctl_giwretry(dev, NULL, &(wrq->u.retry), NULL);
3673 break;
3674
3675#endif // WIRELESS_EXT > 10
3676
3677 // Get range of parameters
3678 case SIOCGIWRANGE:
3679
3680 {
3681 struct iw_range range;
3682
3683 rc = iwctl_giwrange(dev, NULL, &(wrq->u.data), (char *) &range);
3684 if (copy_to_user(wrq->u.data.pointer, &range, sizeof(struct iw_range)))
3685 rc = -EFAULT;
3686 }
3687
3688 break;
3689
3690 case SIOCGIWPOWER:
3691
3692 rc = iwctl_giwpower(dev, NULL, &(wrq->u.power), NULL);
3693 break;
3694
3695
3696 case SIOCSIWPOWER:
3697
3698 rc = iwctl_siwpower(dev, NULL, &(wrq->u.power), NULL);
3699 break;
3700
3701
3702 case SIOCGIWSENS:
3703
3704 rc = iwctl_giwsens(dev, NULL, &(wrq->u.sens), NULL);
3705 break;
3706
3707 case SIOCSIWSENS:
3708 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWSENS \n");
3709 rc = -EOPNOTSUPP;
3710 break;
3711
3712 case SIOCGIWAPLIST:
3713 {
3714 char buffer[IW_MAX_AP * (sizeof(struct sockaddr) + sizeof(struct iw_quality))];
3715
3716 if (wrq->u.data.pointer) {
3717 rc = iwctl_giwaplist(dev, NULL, &(wrq->u.data), buffer);
3718 if (rc == 0) {
3719 if (copy_to_user(wrq->u.data.pointer,
3720 buffer,
3721 (wrq->u.data.length * (sizeof(struct sockaddr) + sizeof(struct iw_quality)))
3722 ))
3723 rc = -EFAULT;
3724 }
3725 }
3726 }
3727 break;
3728
3729
3730#ifdef WIRELESS_SPY
3731 // Set the spy list
3732 case SIOCSIWSPY:
3733
3734 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWSPY \n");
3735 rc = -EOPNOTSUPP;
3736 break;
3737
3738 // Get the spy list
3739 case SIOCGIWSPY:
3740
3741 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWSPY \n");
3742 rc = -EOPNOTSUPP;
3743 break;
3744
3745#endif // WIRELESS_SPY
3746
3747 case SIOCGIWPRIV:
3748 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWPRIV \n");
3749 rc = -EOPNOTSUPP;
3750/*
3751 if(wrq->u.data.pointer) {
3752 wrq->u.data.length = sizeof(iwctl_private_args) / sizeof( iwctl_private_args[0]);
3753
3754 if(copy_to_user(wrq->u.data.pointer,
3755 (u_char *) iwctl_private_args,
3756 sizeof(iwctl_private_args)))
3757 rc = -EFAULT;
3758 }
3759*/
3760 break;
3761
3762
3763//#endif // WIRELESS_EXT < 13
3764//2008-0409-07, <Add> by Einsn Liu
3765#ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
3766 case SIOCSIWAUTH:
3767 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWAUTH \n");
3768 rc = iwctl_siwauth(dev, NULL, &(wrq->u.param), NULL);
3769 break;
3770
3771 case SIOCGIWAUTH:
3772 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWAUTH \n");
3773 rc = iwctl_giwauth(dev, NULL, &(wrq->u.param), NULL);
3774 break;
3775
3776 case SIOCSIWGENIE:
3777 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWGENIE \n");
3778 rc = iwctl_siwgenie(dev, NULL, &(wrq->u.data), wrq->u.data.pointer);
3779 break;
3780
3781 case SIOCGIWGENIE:
3782 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWGENIE \n");
3783 rc = iwctl_giwgenie(dev, NULL, &(wrq->u.data), wrq->u.data.pointer);
3784 break;
3785
3786 case SIOCSIWENCODEEXT:
3787 {
3788 char extra[sizeof(struct iw_encode_ext)+MAX_KEY_LEN+1];
3789 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWENCODEEXT \n");
3790 if(wrq->u.encoding.pointer){
3791 memset(extra, 0, sizeof(struct iw_encode_ext)+MAX_KEY_LEN+1);
3792 if(wrq->u.encoding.length > (sizeof(struct iw_encode_ext)+ MAX_KEY_LEN)){
3793 rc = -E2BIG;
3794 break;
3795 }
3796 if(copy_from_user(extra, wrq->u.encoding.pointer,wrq->u.encoding.length)){
3797 rc = -EFAULT;
3798 break;
3799 }
3800 }else if(wrq->u.encoding.length != 0){
3801 rc = -EINVAL;
3802 break;
3803 }
3804 rc = iwctl_siwencodeext(dev, NULL, &(wrq->u.encoding), extra);
3805 }
3806 break;
3807
3808 case SIOCGIWENCODEEXT:
3809 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWENCODEEXT \n");
3810 rc = iwctl_giwencodeext(dev, NULL, &(wrq->u.encoding), NULL);
3811 break;
3812
3813 case SIOCSIWMLME:
3814 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWMLME \n");
3815 rc = iwctl_siwmlme(dev, NULL, &(wrq->u.data), wrq->u.data.pointer);
3816 break;
3817
3818#endif // #ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
3819//End Add -- //2008-0409-07, <Add> by Einsn Liu
3820
3821#endif // WIRELESS_EXT
3822
3823 case IOCTL_CMD_TEST:
3824
3825 if (!(pDevice->flags & DEVICE_FLAGS_OPENED)) {
3826 rc = -EFAULT;
3827 break;
3828 } else {
3829 rc = 0;
3830 }
3831 pReq = (PSCmdRequest)rq;
3832 pReq->wResult = MAGIC_CODE;
3833 break;
3834
3835 case IOCTL_CMD_SET:
3836
3837 #ifdef SndEvt_ToAPI
3838 if((((PSCmdRequest)rq)->wCmdCode !=WLAN_CMD_SET_EVT) &&
3839 !(pDevice->flags & DEVICE_FLAGS_OPENED))
3840 #else
3841 if (!(pDevice->flags & DEVICE_FLAGS_OPENED) &&
3842 (((PSCmdRequest)rq)->wCmdCode !=WLAN_CMD_SET_WPA))
3843 #endif
3844 {
3845 rc = -EFAULT;
3846 break;
3847 } else {
3848 rc = 0;
3849 }
3850
3851 if (test_and_set_bit( 0, (void*)&(pMgmt->uCmdBusy))) {
3852 return -EBUSY;
3853 }
3854 rc = private_ioctl(pDevice, rq);
3855 clear_bit( 0, (void*)&(pMgmt->uCmdBusy));
3856 break;
3857
3858 case IOCTL_CMD_HOSTAPD:
3859
3860
3861#if WIRELESS_EXT > 8
3862 rc = hostap_ioctl(pDevice, &wrq->u.data);
3863#else // WIRELESS_EXT > 8
3864 rc = hostap_ioctl(pDevice, (struct iw_point *) &wrq->u.data);
3865#endif // WIRELESS_EXT > 8
3866 break;
3867
3868 case IOCTL_CMD_WPA:
3869
3870#if WIRELESS_EXT > 8
3871 rc = wpa_ioctl(pDevice, &wrq->u.data);
3872#else // WIRELESS_EXT > 8
3873 rc = wpa_ioctl(pDevice, (struct iw_point *) &wrq->u.data);
3874#endif // WIRELESS_EXT > 8
3875 break;
3876
3877 case SIOCETHTOOL:
3878 return ethtool_ioctl(dev, (void *) rq->ifr_data);
3879 // All other calls are currently unsupported
3880
3881 default:
3882 rc = -EOPNOTSUPP;
3883 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Ioctl command not support..%x\n", cmd);
3884
3885
3886 }
3887
3888 if (pDevice->bCommit) {
3889 if (pMgmt->eConfigMode == WMAC_CONFIG_AP) {
3890 netif_stop_queue(pDevice->dev);
3891 spin_lock_irq(&pDevice->lock);
3892 bScheduleCommand((HANDLE)pDevice, WLAN_CMD_RUN_AP, NULL);
3893 spin_unlock_irq(&pDevice->lock);
3894 }
3895 else {
3896 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Commit the settings\n");
3897 spin_lock_irq(&pDevice->lock);
3898 pDevice->bLinkPass = FALSE;
3899 memset(pMgmt->abyCurrBSSID, 0, 6);
3900 pMgmt->eCurrState = WMAC_STATE_IDLE;
3901 netif_stop_queue(pDevice->dev);
3902 #ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
3903 pMgmt->eScanType = WMAC_SCAN_ACTIVE;
3904 if(pDevice->bWPASuppWextEnabled !=TRUE)
3905 #endif
3906 bScheduleCommand((HANDLE) pDevice, WLAN_CMD_BSSID_SCAN, pMgmt->abyDesireSSID);
3907 bScheduleCommand((HANDLE) pDevice, WLAN_CMD_SSID, NULL);
3908 spin_unlock_irq(&pDevice->lock);
3909 }
3910 pDevice->bCommit = FALSE;
3911 }
3912
3913 return rc;
3914}
3915
3916
3917static int ethtool_ioctl(struct net_device *dev, void *useraddr)
3918{
3919 u32 ethcmd;
3920
3921 if (copy_from_user(&ethcmd, useraddr, sizeof(ethcmd)))
3922 return -EFAULT;
3923
3924 switch (ethcmd) {
3925 case ETHTOOL_GDRVINFO: {
3926 struct ethtool_drvinfo info = {ETHTOOL_GDRVINFO};
3927 strncpy(info.driver, DEVICE_NAME, sizeof(info.driver)-1);
3928 strncpy(info.version, DEVICE_VERSION, sizeof(info.version)-1);
3929 if (copy_to_user(useraddr, &info, sizeof(info)))
3930 return -EFAULT;
3931 return 0;
3932 }
3933
3934 }
3935
3936 return -EOPNOTSUPP;
3937}
3938
3939/*------------------------------------------------------------------*/
3940#ifndef PRIVATE_OBJ
3941
3942MODULE_DEVICE_TABLE(pci, device_id_table);
3943
3944static struct pci_driver device_driver = {
3945 name: DEVICE_NAME,
3946 id_table: device_id_table,
3947 probe: device_found1,
3948 remove: device_remove1,
3949#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,9)
3950#ifdef CONFIG_PM
3951 suspend: viawget_suspend,
3952 resume: viawget_resume,
3953#endif
3954#endif
3955};
3956
3957static int __init device_init_module(void)
3958{
3959 int ret;
3960
3961
3962// ret=pci_module_init(&device_driver);
3963 //ret = pcie_port_service_register(&device_driver);
3964#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,22)
3965 ret = pci_register_driver(&device_driver);
3966#else
3967 ret = pci_module_init(&device_driver);
3968#endif
3969#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,9)
3970#ifdef CONFIG_PM
3971 if(ret >= 0)
3972 register_reboot_notifier(&device_notifier);
3973#endif
3974#endif
3975
3976 return ret;
3977}
3978
3979static void __exit device_cleanup_module(void)
3980{
3981
3982
3983#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,9)
3984#ifdef CONFIG_PM
3985 unregister_reboot_notifier(&device_notifier);
3986#endif
3987#endif
3988 pci_unregister_driver(&device_driver);
3989
3990}
3991
3992module_init(device_init_module);
3993module_exit(device_cleanup_module);
3994
3995
3996#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,9)
3997#ifdef CONFIG_PM
3998static int
3999device_notify_reboot(struct notifier_block *nb, unsigned long event, void *p)
4000{
4001 struct pci_dev *pdev = NULL;
4002 switch(event) {
4003 case SYS_DOWN:
4004 case SYS_HALT:
4005 case SYS_POWER_OFF:
4006#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
4007 while ((pdev = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, pdev)) != NULL) {
4008#else
4009 pci_for_each_dev(pdev) {
4010#endif
4011 if(pci_dev_driver(pdev) == &device_driver) {
4012 if (pci_get_drvdata(pdev))
4013 viawget_suspend(pdev, 3);
4014 }
4015 }
4016 }
4017 return NOTIFY_DONE;
4018}
4019
4020static int
4021viawget_suspend(struct pci_dev *pcid, u32 state)
4022{
4023 int power_status; // to silence the compiler
4024
4025 PSDevice pDevice=pci_get_drvdata(pcid);
4026 PSMgmtObject pMgmt = pDevice->pMgmt;
4027
4028 netif_stop_queue(pDevice->dev);
4029 spin_lock_irq(&pDevice->lock);
4030#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,10)
4031 pci_save_state(pcid);
4032#else
4033 pci_save_state(pcid, pDevice->pci_state);
4034#endif
4035 del_timer(&pDevice->sTimerCommand);
4036 del_timer(&pMgmt->sTimerSecondCallback);
4037 pDevice->cbFreeCmdQueue = CMD_Q_SIZE;
4038 pDevice->uCmdDequeueIdx = 0;
4039 pDevice->uCmdEnqueueIdx = 0;
4040 pDevice->bCmdRunning = FALSE;
4041 MACbShutdown(pDevice->PortOffset);
4042 MACvSaveContext(pDevice->PortOffset, pDevice->abyMacContext);
4043 pDevice->bLinkPass = FALSE;
4044 memset(pMgmt->abyCurrBSSID, 0, 6);
4045 pMgmt->eCurrState = WMAC_STATE_IDLE;
4046 pci_disable_device(pcid);
4047 power_status = pci_set_power_state(pcid, state);
4048 spin_unlock_irq(&pDevice->lock);
4049 return 0;
4050}
4051
4052static int
4053viawget_resume(struct pci_dev *pcid)
4054{
4055 PSDevice pDevice=pci_get_drvdata(pcid);
4056 PSMgmtObject pMgmt = pDevice->pMgmt;
4057 int power_status; // to silence the compiler
4058
4059
4060 power_status = pci_set_power_state(pcid, 0);
4061 power_status = pci_enable_wake(pcid, 0, 0);
4062#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,10)
4063 pci_restore_state(pcid);
4064#else
4065 pci_restore_state(pcid, pDevice->pci_state);
4066#endif
4067 if (netif_running(pDevice->dev)) {
4068 spin_lock_irq(&pDevice->lock);
4069 MACvRestoreContext(pDevice->PortOffset, pDevice->abyMacContext);
4070 device_init_registers(pDevice, DEVICE_INIT_DXPL);
4071 if (pMgmt->sNodeDBTable[0].bActive == TRUE) { // Assoc with BSS
4072 pMgmt->sNodeDBTable[0].bActive = FALSE;
4073 pDevice->bLinkPass = FALSE;
4074 if(pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) {
4075 // In Adhoc, BSS state set back to started.
4076 pMgmt->eCurrState = WMAC_STATE_STARTED;
4077 }
4078 else {
4079 pMgmt->eCurrMode = WMAC_MODE_STANDBY;
4080 pMgmt->eCurrState = WMAC_STATE_IDLE;
4081 }
4082 }
4083 init_timer(&pMgmt->sTimerSecondCallback);
4084 init_timer(&pDevice->sTimerCommand);
4085 MACvIntEnable(pDevice->PortOffset, IMR_MASK_VALUE);
4086 BSSvClearBSSList((HANDLE)pDevice, pDevice->bLinkPass);
4087 bScheduleCommand((HANDLE) pDevice, WLAN_CMD_BSSID_SCAN, NULL);
4088 bScheduleCommand((HANDLE) pDevice, WLAN_CMD_SSID, NULL);
4089 spin_unlock_irq(&pDevice->lock);
4090 }
4091 return 0;
4092}
4093
4094#endif
4095#endif
4096
4097#endif //#ifndef PRIVATE_OBJ
4098
4099#ifdef PRIVATE_OBJ
4100
4101
4102int __device_hw_reset(HANDLE pExDevice){
4103 PSDevice_info pDevice_info = (PSDevice_info)pExDevice;
4104
4105 return MACbSoftwareReset(pDevice_info->port_offset);
4106}
4107
4108
4109int __device_hw_init(HANDLE pExDevice){
4110 PSDevice_info pDevice_info = (PSDevice_info)pExDevice;
4111 PSDevice pDevice;
4112
4113
4114 pDevice = (PSDevice)kmalloc(sizeof(DEVICE_INFO), (int)GFP_ATOMIC);
4115 if (pDevice == NULL)
4116 return FALSE;
4117
4118 memset(pDevice, 0, sizeof(DEVICE_INFO));
4119 pDevice_info->pWDevice = pDevice;
4120 pDevice->PortOffset = pDevice_info->port_offset;
4121 pDevice->dev = pDevice_info->dev;
4122 pDevice->pcid = pDevice_info->pcid;
4123 pDevice->chip_id = pDevice_info->chip_id;
4124 pDevice->memaddr = pDevice_info->mem_addr;
4125 pDevice->ioaddr = pDevice_info->io_addr;
4126 pDevice->io_size = pDevice_info->io_size;
4127 pDevice->nTxQueues = pDevice_info->nTxQueues;
4128 pDevice->multicast_limit = pDevice_info->multicast_limit;
4129 pDevice->sMgmtObj.pAdapter = (PVOID)pDevice;
4130 pDevice->pMgmt = &(pDevice->sMgmtObj);
4131 MACvInitialize(pDevice->PortOffset);
4132 device_get_options(pDevice, 0 , pDevice_info->dev->name);
4133 device_set_options(pDevice);
4134 pDevice->sOpts.flags &= pDevice_info->flags;
4135 pDevice->flags = pDevice->sOpts.flags | (pDevice_info->flags & 0xFF000000UL);
4136 spin_lock_init(&(pDevice->lock));
4137
4138 return TRUE;
4139}
4140
4141
4142void __device_read_mac(HANDLE pExDevice, PBYTE dev_addr){
4143 PSDevice_info pDevice_info = (PSDevice_info)pExDevice;
4144 PSDevice pDevice = (PSDevice)(pDevice_info->pWDevice);
4145
4146 MACvReadEtherAddress(pDevice->PortOffset, dev_addr);
4147 return;
4148}
4149
4150
4151#endif
4152
4153
diff --git a/drivers/staging/vt6655/dpc.c b/drivers/staging/vt6655/dpc.c
new file mode 100644
index 000000000000..05366b9754f0
--- /dev/null
+++ b/drivers/staging/vt6655/dpc.c
@@ -0,0 +1,1688 @@
1/*
2 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
3 * All rights reserved.
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * File: dpc.c
20 *
21 * Purpose: handle dpc rx functions
22 *
23 * Author: Lyndon Chen
24 *
25 * Date: May 20, 2003
26 *
27 * Functions:
28 * device_receive_frame - Rcv 802.11 frame function
29 * s_bAPModeRxCtl- AP Rcv frame filer Ctl.
30 * s_bAPModeRxData- AP Rcv data frame handle
31 * s_bHandleRxEncryption- Rcv decrypted data via on-fly
32 * s_bHostWepRxEncryption- Rcv encrypted data via host
33 * s_byGetRateIdx- get rate index
34 * s_vGetDASA- get data offset
35 * s_vProcessRxMACHeader- Rcv 802.11 and translate to 802.3
36 *
37 * Revision History:
38 *
39 */
40
41
42#if !defined(__DEVICE_H__)
43#include "device.h"
44#endif
45#if !defined(__RXTX_H__)
46#include "rxtx.h"
47#endif
48#if !defined(__TETHER_H__)
49#include "tether.h"
50#endif
51#if !defined(__CARD_H__)
52#include "card.h"
53#endif
54#if !defined(__BSSDB_H__)
55#include "bssdb.h"
56#endif
57#if !defined(__MAC_H__)
58#include "mac.h"
59#endif
60#if !defined(__BASEBAND_H__)
61#include "baseband.h"
62#endif
63#if !defined(__UMEM_H__)
64#include "umem.h"
65#endif
66#if !defined(__MICHAEL_H__)
67#include "michael.h"
68#endif
69#if !defined(__TKIP_H__)
70#include "tkip.h"
71#endif
72#if !defined(__TCRC_H__)
73#include "tcrc.h"
74#endif
75#if !defined(__WCTL_H__)
76#include "wctl.h"
77#endif
78#if !defined(__WROUTE_H__)
79#include "wroute.h"
80#endif
81#if !defined(__TBIT_H__)
82#include "tbit.h"
83#endif
84#if !defined(__HOSTAP_H__)
85#include "hostap.h"
86#endif
87#if !defined(__RF_H__)
88#include "rf.h"
89#endif
90#if !defined(__IOWPA_H__)
91#include "iowpa.h"
92#endif
93#if !defined(__AES_H__)
94#include "aes_ccmp.h"
95#endif
96
97//#define PLICE_DEBUG
98
99
100/*--------------------- Static Definitions -------------------------*/
101
102/*--------------------- Static Classes ----------------------------*/
103
104/*--------------------- Static Variables --------------------------*/
105//static int msglevel =MSG_LEVEL_DEBUG;
106static int msglevel =MSG_LEVEL_INFO;
107
108const BYTE acbyRxRate[MAX_RATE] =
109{2, 4, 11, 22, 12, 18, 24, 36, 48, 72, 96, 108};
110
111
112/*--------------------- Static Functions --------------------------*/
113
114/*--------------------- Static Definitions -------------------------*/
115
116/*--------------------- Static Functions --------------------------*/
117
118static BYTE s_byGetRateIdx(IN BYTE byRate);
119
120
121static
122VOID
123s_vGetDASA(
124 IN PBYTE pbyRxBufferAddr,
125 OUT PUINT pcbHeaderSize,
126 OUT PSEthernetHeader psEthHeader
127 );
128
129static
130VOID
131s_vProcessRxMACHeader (
132 IN PSDevice pDevice,
133 IN PBYTE pbyRxBufferAddr,
134 IN UINT cbPacketSize,
135 IN BOOL bIsWEP,
136 IN BOOL bExtIV,
137 OUT PUINT pcbHeadSize
138 );
139
140static BOOL s_bAPModeRxCtl(
141 IN PSDevice pDevice,
142 IN PBYTE pbyFrame,
143 IN INT iSANodeIndex
144 );
145
146#ifdef PRIVATE_OBJ
147
148static BOOL s_bAPModeRxData (
149 IN PSDevice pDevice,
150 IN ref_sk_buff* skb,
151 IN UINT FrameSize,
152 IN UINT cbHeaderOffset,
153 IN INT iSANodeIndex,
154 IN INT iDANodeIndex
155 );
156#else
157
158static BOOL s_bAPModeRxData (
159 IN PSDevice pDevice,
160 IN struct sk_buff* skb,
161 IN UINT FrameSize,
162 IN UINT cbHeaderOffset,
163 IN INT iSANodeIndex,
164 IN INT iDANodeIndex
165 );
166#endif
167
168
169static BOOL s_bHandleRxEncryption(
170 IN PSDevice pDevice,
171 IN PBYTE pbyFrame,
172 IN UINT FrameSize,
173 IN PBYTE pbyRsr,
174 OUT PBYTE pbyNewRsr,
175 OUT PSKeyItem *pKeyOut,
176 OUT PBOOL pbExtIV,
177 OUT PWORD pwRxTSC15_0,
178 OUT PDWORD pdwRxTSC47_16
179 );
180
181static BOOL s_bHostWepRxEncryption(
182
183 IN PSDevice pDevice,
184 IN PBYTE pbyFrame,
185 IN UINT FrameSize,
186 IN PBYTE pbyRsr,
187 IN BOOL bOnFly,
188 IN PSKeyItem pKey,
189 OUT PBYTE pbyNewRsr,
190 OUT PBOOL pbExtIV,
191 OUT PWORD pwRxTSC15_0,
192 OUT PDWORD pdwRxTSC47_16
193
194 );
195
196/*--------------------- Export Variables --------------------------*/
197
198/*+
199 *
200 * Description:
201 * Translate Rcv 802.11 header to 802.3 header with Rx buffer
202 *
203 * Parameters:
204 * In:
205 * pDevice
206 * dwRxBufferAddr - Address of Rcv Buffer
207 * cbPacketSize - Rcv Packet size
208 * bIsWEP - If Rcv with WEP
209 * Out:
210 * pcbHeaderSize - 802.11 header size
211 *
212 * Return Value: None
213 *
214-*/
215static
216VOID
217s_vProcessRxMACHeader (
218 IN PSDevice pDevice,
219 IN PBYTE pbyRxBufferAddr,
220 IN UINT cbPacketSize,
221 IN BOOL bIsWEP,
222 IN BOOL bExtIV,
223 OUT PUINT pcbHeadSize
224 )
225{
226 PBYTE pbyRxBuffer;
227 UINT cbHeaderSize = 0;
228 PWORD pwType;
229 PS802_11Header pMACHeader;
230 int ii;
231
232
233 pMACHeader = (PS802_11Header) (pbyRxBufferAddr + cbHeaderSize);
234
235 s_vGetDASA((PBYTE)pMACHeader, &cbHeaderSize, &pDevice->sRxEthHeader);
236
237 if (bIsWEP) {
238 if (bExtIV) {
239 // strip IV&ExtIV , add 8 byte
240 cbHeaderSize += (WLAN_HDR_ADDR3_LEN + 8);
241 } else {
242 // strip IV , add 4 byte
243 cbHeaderSize += (WLAN_HDR_ADDR3_LEN + 4);
244 }
245 }
246 else {
247 cbHeaderSize += WLAN_HDR_ADDR3_LEN;
248 };
249
250 pbyRxBuffer = (PBYTE) (pbyRxBufferAddr + cbHeaderSize);
251 if (IS_ETH_ADDRESS_EQUAL(pbyRxBuffer, &pDevice->abySNAP_Bridgetunnel[0])) {
252 cbHeaderSize += 6;
253 }
254 else if (IS_ETH_ADDRESS_EQUAL(pbyRxBuffer, &pDevice->abySNAP_RFC1042[0])) {
255 cbHeaderSize += 6;
256 pwType = (PWORD) (pbyRxBufferAddr + cbHeaderSize);
257 if ((*pwType!= TYPE_PKT_IPX) && (*pwType != cpu_to_le16(0xF380))) {
258 }
259 else {
260 cbHeaderSize -= 8;
261 pwType = (PWORD) (pbyRxBufferAddr + cbHeaderSize);
262 if (bIsWEP) {
263 if (bExtIV) {
264 *pwType = htons(cbPacketSize - WLAN_HDR_ADDR3_LEN - 8); // 8 is IV&ExtIV
265 } else {
266 *pwType = htons(cbPacketSize - WLAN_HDR_ADDR3_LEN - 4); // 4 is IV
267 }
268 }
269 else {
270 *pwType = htons(cbPacketSize - WLAN_HDR_ADDR3_LEN);
271 }
272 }
273 }
274 else {
275 cbHeaderSize -= 2;
276 pwType = (PWORD) (pbyRxBufferAddr + cbHeaderSize);
277 if (bIsWEP) {
278 if (bExtIV) {
279 *pwType = htons(cbPacketSize - WLAN_HDR_ADDR3_LEN - 8); // 8 is IV&ExtIV
280 } else {
281 *pwType = htons(cbPacketSize - WLAN_HDR_ADDR3_LEN - 4); // 4 is IV
282 }
283 }
284 else {
285 *pwType = htons(cbPacketSize - WLAN_HDR_ADDR3_LEN);
286 }
287 }
288
289 cbHeaderSize -= (U_ETHER_ADDR_LEN * 2);
290 pbyRxBuffer = (PBYTE) (pbyRxBufferAddr + cbHeaderSize);
291 for(ii=0;ii<U_ETHER_ADDR_LEN;ii++)
292 *pbyRxBuffer++ = pDevice->sRxEthHeader.abyDstAddr[ii];
293 for(ii=0;ii<U_ETHER_ADDR_LEN;ii++)
294 *pbyRxBuffer++ = pDevice->sRxEthHeader.abySrcAddr[ii];
295
296 *pcbHeadSize = cbHeaderSize;
297}
298
299
300
301
302static BYTE s_byGetRateIdx (IN BYTE byRate)
303{
304 BYTE byRateIdx;
305
306 for (byRateIdx = 0; byRateIdx <MAX_RATE ; byRateIdx++) {
307 if (acbyRxRate[byRateIdx%MAX_RATE] == byRate)
308 return byRateIdx;
309 }
310 return 0;
311}
312
313
314static
315VOID
316s_vGetDASA (
317 IN PBYTE pbyRxBufferAddr,
318 OUT PUINT pcbHeaderSize,
319 OUT PSEthernetHeader psEthHeader
320 )
321{
322 UINT cbHeaderSize = 0;
323 PS802_11Header pMACHeader;
324 int ii;
325
326 pMACHeader = (PS802_11Header) (pbyRxBufferAddr + cbHeaderSize);
327
328 if ((pMACHeader->wFrameCtl & FC_TODS) == 0) {
329 if (pMACHeader->wFrameCtl & FC_FROMDS) {
330 for(ii=0;ii<U_ETHER_ADDR_LEN;ii++) {
331 psEthHeader->abyDstAddr[ii] = pMACHeader->abyAddr1[ii];
332 psEthHeader->abySrcAddr[ii] = pMACHeader->abyAddr3[ii];
333 }
334 }
335 else {
336 // IBSS mode
337 for(ii=0;ii<U_ETHER_ADDR_LEN;ii++) {
338 psEthHeader->abyDstAddr[ii] = pMACHeader->abyAddr1[ii];
339 psEthHeader->abySrcAddr[ii] = pMACHeader->abyAddr2[ii];
340 }
341 }
342 }
343 else {
344 // Is AP mode..
345 if (pMACHeader->wFrameCtl & FC_FROMDS) {
346 for(ii=0;ii<U_ETHER_ADDR_LEN;ii++) {
347 psEthHeader->abyDstAddr[ii] = pMACHeader->abyAddr3[ii];
348 psEthHeader->abySrcAddr[ii] = pMACHeader->abyAddr4[ii];
349 cbHeaderSize += 6;
350 }
351 }
352 else {
353 for(ii=0;ii<U_ETHER_ADDR_LEN;ii++) {
354 psEthHeader->abyDstAddr[ii] = pMACHeader->abyAddr3[ii];
355 psEthHeader->abySrcAddr[ii] = pMACHeader->abyAddr2[ii];
356 }
357 }
358 };
359 *pcbHeaderSize = cbHeaderSize;
360}
361
362
363
364
365//PLICE_DEBUG ->
366
367VOID MngWorkItem(PVOID Context)
368{
369 PSRxMgmtPacket pRxMgmtPacket;
370 PSDevice pDevice = (PSDevice) Context;
371 //printk("Enter MngWorkItem,Queue packet num is %d\n",pDevice->rxManeQueue.packet_num);
372 spin_lock_irq(&pDevice->lock);
373 while(pDevice->rxManeQueue.packet_num != 0)
374 {
375 pRxMgmtPacket = DeQueue(pDevice);
376 vMgrRxManagePacket(pDevice, pDevice->pMgmt, pRxMgmtPacket);
377 }
378 spin_unlock_irq(&pDevice->lock);
379}
380
381
382//PLICE_DEBUG<-
383
384
385
386BOOL
387device_receive_frame (
388 IN PSDevice pDevice,
389 IN PSRxDesc pCurrRD
390 )
391{
392
393 PDEVICE_RD_INFO pRDInfo = pCurrRD->pRDInfo;
394#ifdef PLICE_DEBUG
395 //printk("device_receive_frame:pCurrRD is %x,pRDInfo is %x\n",pCurrRD,pCurrRD->pRDInfo);
396#endif
397 struct net_device_stats* pStats=&pDevice->stats;
398#ifdef PRIVATE_OBJ
399 ref_sk_buff* skb;
400#else
401 struct sk_buff* skb;
402#endif
403 PSMgmtObject pMgmt = pDevice->pMgmt;
404 PSRxMgmtPacket pRxPacket = &(pDevice->pMgmt->sRxPacket);
405 PS802_11Header p802_11Header;
406 PBYTE pbyRsr;
407 PBYTE pbyNewRsr;
408 PBYTE pbyRSSI;
409 PQWORD pqwTSFTime;
410 PWORD pwFrameSize;
411 PBYTE pbyFrame;
412 BOOL bDeFragRx = FALSE;
413 BOOL bIsWEP = FALSE;
414 UINT cbHeaderOffset;
415 UINT FrameSize;
416 WORD wEtherType = 0;
417 INT iSANodeIndex = -1;
418 INT iDANodeIndex = -1;
419 UINT ii;
420 UINT cbIVOffset;
421 BOOL bExtIV = FALSE;
422 PBYTE pbyRxSts;
423 PBYTE pbyRxRate;
424 PBYTE pbySQ;
425 UINT cbHeaderSize;
426 PSKeyItem pKey = NULL;
427 WORD wRxTSC15_0 = 0;
428 DWORD dwRxTSC47_16 = 0;
429 SKeyItem STempKey;
430 // 802.11h RPI
431 DWORD dwDuration = 0;
432 LONG ldBm = 0;
433 LONG ldBmThreshold = 0;
434 PS802_11Header pMACHeader;
435 BOOL bRxeapol_key = FALSE;
436
437// DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"---------- device_receive_frame---\n");
438#ifdef PRIVATE_OBJ
439 skb = &(pRDInfo->ref_skb);
440#else
441
442 skb = pRDInfo->skb;
443#endif
444
445
446//PLICE_DEBUG->
447#if 1
448 pci_unmap_single(pDevice->pcid, pRDInfo->skb_dma,
449 pDevice->rx_buf_sz, PCI_DMA_FROMDEVICE);
450#endif
451//PLICE_DEBUG<-
452 pwFrameSize = (PWORD)(skb->data + 2);
453 FrameSize = cpu_to_le16(pCurrRD->m_rd1RD1.wReqCount) - cpu_to_le16(pCurrRD->m_rd0RD0.wResCount);
454
455 // Max: 2312Payload + 30HD +4CRC + 2Padding + 4Len + 8TSF + 4RSR
456 // Min (ACK): 10HD +4CRC + 2Padding + 4Len + 8TSF + 4RSR
457 if ((FrameSize > 2364)||(FrameSize <= 32)) {
458 // Frame Size error drop this packet.
459 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"---------- WRONG Length 1 \n");
460 return FALSE;
461 }
462
463 pbyRxSts = (PBYTE) (skb->data);
464 pbyRxRate = (PBYTE) (skb->data + 1);
465 pbyRsr = (PBYTE) (skb->data + FrameSize - 1);
466 pbyRSSI = (PBYTE) (skb->data + FrameSize - 2);
467 pbyNewRsr = (PBYTE) (skb->data + FrameSize - 3);
468 pbySQ = (PBYTE) (skb->data + FrameSize - 4);
469 pqwTSFTime = (PQWORD) (skb->data + FrameSize - 12);
470 pbyFrame = (PBYTE)(skb->data + 4);
471
472 // get packet size
473 FrameSize = cpu_to_le16(*pwFrameSize);
474
475 if ((FrameSize > 2346)|(FrameSize < 14)) { // Max: 2312Payload + 30HD +4CRC
476 // Min: 14 bytes ACK
477 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"---------- WRONG Length 2 \n");
478 return FALSE;
479 }
480//PLICE_DEBUG->
481#if 1
482 // update receive statistic counter
483 STAvUpdateRDStatCounter(&pDevice->scStatistic,
484 *pbyRsr,
485 *pbyNewRsr,
486 *pbyRxRate,
487 pbyFrame,
488 FrameSize);
489
490#endif
491
492 pMACHeader=(PS802_11Header)((PBYTE) (skb->data)+8);
493//PLICE_DEBUG<-
494 if (pDevice->bMeasureInProgress == TRUE) {
495 if ((*pbyRsr & RSR_CRCOK) != 0) {
496 pDevice->byBasicMap |= 0x01;
497 }
498 dwDuration = (FrameSize << 4);
499 dwDuration /= acbyRxRate[*pbyRxRate%MAX_RATE];
500 if (*pbyRxRate <= RATE_11M) {
501 if (BITbIsBitOn(*pbyRxSts, 0x01)) {
502 // long preamble
503 dwDuration += 192;
504 } else {
505 // short preamble
506 dwDuration += 96;
507 }
508 } else {
509 dwDuration += 16;
510 }
511 RFvRSSITodBm(pDevice, *pbyRSSI, &ldBm);
512 ldBmThreshold = -57;
513 for (ii = 7; ii > 0;) {
514 if (ldBm > ldBmThreshold) {
515 break;
516 }
517 ldBmThreshold -= 5;
518 ii--;
519 }
520 pDevice->dwRPIs[ii] += dwDuration;
521 return FALSE;
522 }
523
524 if (!IS_MULTICAST_ADDRESS(pbyFrame) && !IS_BROADCAST_ADDRESS(pbyFrame)) {
525 if (WCTLbIsDuplicate(&(pDevice->sDupRxCache), (PS802_11Header) (skb->data + 4))) {
526 pDevice->s802_11Counter.FrameDuplicateCount++;
527 return FALSE;
528 }
529 }
530
531
532 // Use for TKIP MIC
533 s_vGetDASA(skb->data+4, &cbHeaderSize, &pDevice->sRxEthHeader);
534
535 // filter packet send from myself
536 if (IS_ETH_ADDRESS_EQUAL((PBYTE)&(pDevice->sRxEthHeader.abySrcAddr[0]), pDevice->abyCurrentNetAddr))
537 return FALSE;
538
539 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_AP) || (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA)) {
540 if (IS_CTL_PSPOLL(pbyFrame) || !IS_TYPE_CONTROL(pbyFrame)) {
541 p802_11Header = (PS802_11Header) (pbyFrame);
542 // get SA NodeIndex
543 if (BSSDBbIsSTAInNodeDB(pMgmt, (PBYTE)(p802_11Header->abyAddr2), &iSANodeIndex)) {
544#ifdef PRIVATE_OBJ
545 pMgmt->sNodeDBTable[iSANodeIndex].ulLastRxJiffer = get_jiffies();
546#else
547 pMgmt->sNodeDBTable[iSANodeIndex].ulLastRxJiffer = jiffies;
548#endif
549 pMgmt->sNodeDBTable[iSANodeIndex].uInActiveCount = 0;
550 }
551 }
552 }
553
554 if (pMgmt->eCurrMode == WMAC_MODE_ESS_AP) {
555 if (s_bAPModeRxCtl(pDevice, pbyFrame, iSANodeIndex) == TRUE) {
556 return FALSE;
557 }
558 }
559 if (IS_FC_WEP(pbyFrame)) {
560 BOOL bRxDecryOK = FALSE;
561
562 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"rx WEP pkt\n");
563 bIsWEP = TRUE;
564 if ((pDevice->bEnableHostWEP) && (iSANodeIndex >= 0)) {
565 pKey = &STempKey;
566 pKey->byCipherSuite = pMgmt->sNodeDBTable[iSANodeIndex].byCipherSuite;
567 pKey->dwKeyIndex = pMgmt->sNodeDBTable[iSANodeIndex].dwKeyIndex;
568 pKey->uKeyLength = pMgmt->sNodeDBTable[iSANodeIndex].uWepKeyLength;
569 pKey->dwTSC47_16 = pMgmt->sNodeDBTable[iSANodeIndex].dwTSC47_16;
570 pKey->wTSC15_0 = pMgmt->sNodeDBTable[iSANodeIndex].wTSC15_0;
571 memcpy(pKey->abyKey,
572 &pMgmt->sNodeDBTable[iSANodeIndex].abyWepKey[0],
573 pKey->uKeyLength
574 );
575
576 bRxDecryOK = s_bHostWepRxEncryption(pDevice,
577 pbyFrame,
578 FrameSize,
579 pbyRsr,
580 pMgmt->sNodeDBTable[iSANodeIndex].bOnFly,
581 pKey,
582 pbyNewRsr,
583 &bExtIV,
584 &wRxTSC15_0,
585 &dwRxTSC47_16);
586 } else {
587 bRxDecryOK = s_bHandleRxEncryption(pDevice,
588 pbyFrame,
589 FrameSize,
590 pbyRsr,
591 pbyNewRsr,
592 &pKey,
593 &bExtIV,
594 &wRxTSC15_0,
595 &dwRxTSC47_16);
596 }
597
598 if (bRxDecryOK) {
599 if ((*pbyNewRsr & NEWRSR_DECRYPTOK) == 0) {
600 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"ICV Fail\n");
601 if ( (pDevice->pMgmt->eAuthenMode == WMAC_AUTH_WPA) ||
602 (pDevice->pMgmt->eAuthenMode == WMAC_AUTH_WPAPSK) ||
603 (pDevice->pMgmt->eAuthenMode == WMAC_AUTH_WPANONE) ||
604 (pDevice->pMgmt->eAuthenMode == WMAC_AUTH_WPA2) ||
605 (pDevice->pMgmt->eAuthenMode == WMAC_AUTH_WPA2PSK)) {
606
607 if ((pKey != NULL) && (pKey->byCipherSuite == KEY_CTL_TKIP)) {
608 pDevice->s802_11Counter.TKIPICVErrors++;
609 } else if ((pKey != NULL) && (pKey->byCipherSuite == KEY_CTL_CCMP)) {
610 pDevice->s802_11Counter.CCMPDecryptErrors++;
611 } else if ((pKey != NULL) && (pKey->byCipherSuite == KEY_CTL_WEP)) {
612// pDevice->s802_11Counter.WEPICVErrorCount.QuadPart++;
613 }
614 }
615 return FALSE;
616 }
617 } else {
618 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"WEP Func Fail\n");
619 return FALSE;
620 }
621 if ((pKey != NULL) && (pKey->byCipherSuite == KEY_CTL_CCMP))
622 FrameSize -= 8; // Message Integrity Code
623 else
624 FrameSize -= 4; // 4 is ICV
625 }
626
627
628 //
629 // RX OK
630 //
631 //remove the CRC length
632 FrameSize -= U_CRC_LEN;
633
634 if ((BITbIsAllBitsOff(*pbyRsr, (RSR_ADDRBROAD | RSR_ADDRMULTI))) && // unicast address
635 (IS_FRAGMENT_PKT((skb->data+4)))
636 ) {
637 // defragment
638 bDeFragRx = WCTLbHandleFragment(pDevice, (PS802_11Header) (skb->data+4), FrameSize, bIsWEP, bExtIV);
639 pDevice->s802_11Counter.ReceivedFragmentCount++;
640 if (bDeFragRx) {
641 // defrag complete
642#ifdef PRIVATE_OBJ
643 skb = &(pDevice->sRxDFCB[pDevice->uCurrentDFCBIdx].ref_skb);
644#else
645 skb = pDevice->sRxDFCB[pDevice->uCurrentDFCBIdx].skb;
646#endif
647 FrameSize = pDevice->sRxDFCB[pDevice->uCurrentDFCBIdx].cbFrameLength;
648
649 }
650 else {
651 return FALSE;
652 }
653 }
654
655
656// Management & Control frame Handle
657 if ((IS_TYPE_DATA((skb->data+4))) == FALSE) {
658 // Handle Control & Manage Frame
659
660 if (IS_TYPE_MGMT((skb->data+4))) {
661 PBYTE pbyData1;
662 PBYTE pbyData2;
663
664 pRxPacket->p80211Header = (PUWLAN_80211HDR)(skb->data+4);
665 pRxPacket->cbMPDULen = FrameSize;
666 pRxPacket->uRSSI = *pbyRSSI;
667 pRxPacket->bySQ = *pbySQ;
668 HIDWORD(pRxPacket->qwLocalTSF) = cpu_to_le32(HIDWORD(*pqwTSFTime));
669 LODWORD(pRxPacket->qwLocalTSF) = cpu_to_le32(LODWORD(*pqwTSFTime));
670 if (bIsWEP) {
671 // strip IV
672 pbyData1 = WLAN_HDR_A3_DATA_PTR(skb->data+4);
673 pbyData2 = WLAN_HDR_A3_DATA_PTR(skb->data+4) + 4;
674 for (ii = 0; ii < (FrameSize - 4); ii++) {
675 *pbyData1 = *pbyData2;
676 pbyData1++;
677 pbyData2++;
678 }
679 }
680 pRxPacket->byRxRate = s_byGetRateIdx(*pbyRxRate);
681 pRxPacket->byRxChannel = (*pbyRxSts) >> 2;
682//PLICE_DEBUG->
683//EnQueue(pDevice,pRxPacket);
684
685#ifdef THREAD
686 EnQueue(pDevice,pRxPacket);
687
688 //printk("enque time is %x\n",jiffies);
689 //up(&pDevice->mlme_semaphore);
690 //Enque (pDevice->FirstRecvMngList,pDevice->LastRecvMngList,pMgmt);
691#else
692
693#ifdef TASK_LET
694 EnQueue(pDevice,pRxPacket);
695 tasklet_schedule(&pDevice->RxMngWorkItem);
696#else
697//printk("RxMan\n");
698 vMgrRxManagePacket((HANDLE)pDevice, pDevice->pMgmt, pRxPacket);
699 //tasklet_schedule(&pDevice->RxMngWorkItem);
700#endif
701
702#endif
703//PLICE_DEBUG<-
704 //vMgrRxManagePacket((HANDLE)pDevice, pDevice->pMgmt, pRxPacket);
705 // hostap Deamon handle 802.11 management
706 if (pDevice->bEnableHostapd) {
707 skb->dev = pDevice->apdev;
708#ifdef PRIVATE_OBJ
709 ref_skb_add_offset(skb->skb, 4);
710 ref_skb_set_dev(pDevice->apdev, skb->skb);
711 skb_put(skb->skb, FrameSize);
712#if LINUX_VERSION_CODE > KERNEL_VERSION(2,6,21)
713 skb->mac_header = skb->data;
714#else
715 skb->mac.raw = skb->data;
716#endif
717 *(skb->pkt_type) = PACKET_OTHERHOST;
718 *(skb->protocol) = htons(ETH_P_802_2);
719 memset(skb->cb, 0, sizeof(skb->cb));
720 netif_rx(skb->skb);
721#else
722 skb->data += 4;
723 skb->tail += 4;
724 skb_put(skb, FrameSize);
725#if LINUX_VERSION_CODE > KERNEL_VERSION (2,6,21)
726 skb->mac_header = skb->data;
727#else
728 skb->mac.raw = skb->data;
729#endif
730 skb->pkt_type = PACKET_OTHERHOST;
731 skb->protocol = htons(ETH_P_802_2);
732 memset(skb->cb, 0, sizeof(skb->cb));
733 netif_rx(skb);
734#endif
735 return TRUE;
736 }
737 }
738 else {
739 // Control Frame
740 };
741 return FALSE;
742 }
743 else {
744 if (pMgmt->eCurrMode == WMAC_MODE_ESS_AP) {
745 //In AP mode, hw only check addr1(BSSID or RA) if equal to local MAC.
746 if (BITbIsBitOff(*pbyRsr, RSR_BSSIDOK)) {
747 if (bDeFragRx) {
748 if (!device_alloc_frag_buf(pDevice, &pDevice->sRxDFCB[pDevice->uCurrentDFCBIdx])) {
749 DEVICE_PRT(MSG_LEVEL_ERR,KERN_ERR "%s: can not alloc more frag bufs\n",
750 pDevice->dev->name);
751 }
752 }
753 return FALSE;
754 }
755 }
756 else {
757 // discard DATA packet while not associate || BSSID error
758 if ((pDevice->bLinkPass == FALSE) ||
759 BITbIsBitOff(*pbyRsr, RSR_BSSIDOK)) {
760 if (bDeFragRx) {
761 if (!device_alloc_frag_buf(pDevice, &pDevice->sRxDFCB[pDevice->uCurrentDFCBIdx])) {
762 DEVICE_PRT(MSG_LEVEL_ERR,KERN_ERR "%s: can not alloc more frag bufs\n",
763 pDevice->dev->name);
764 }
765 }
766 return FALSE;
767 }
768
769 //mike add:station mode check eapol-key challenge--->
770 {
771 BYTE Protocol_Version; //802.1x Authentication
772 BYTE Packet_Type; //802.1x Authentication
773 if (bIsWEP)
774 cbIVOffset = 8;
775 else
776 cbIVOffset = 0;
777 wEtherType = (skb->data[cbIVOffset + 8 + 24 + 6] << 8) |
778 skb->data[cbIVOffset + 8 + 24 + 6 + 1];
779 Protocol_Version = skb->data[cbIVOffset + 8 + 24 + 6 + 1 +1];
780 Packet_Type = skb->data[cbIVOffset + 8 + 24 + 6 + 1 +1+1];
781 if (wEtherType == ETH_P_PAE) { //Protocol Type in LLC-Header
782 if(((Protocol_Version==1) ||(Protocol_Version==2)) &&
783 (Packet_Type==3)) { //802.1x OR eapol-key challenge frame receive
784 bRxeapol_key = TRUE;
785 }
786 }
787 }
788 //mike add:station mode check eapol-key challenge<---
789 }
790 }
791
792// Data frame Handle
793
794 if (pDevice->bEnablePSMode) {
795 if (IS_FC_MOREDATA((skb->data+4))) {
796 if (BITbIsBitOn(*pbyRsr, RSR_ADDROK)) {
797 //PSbSendPSPOLL((PSDevice)pDevice);
798 }
799 }
800 else {
801 if (pDevice->pMgmt->bInTIMWake == TRUE) {
802 pDevice->pMgmt->bInTIMWake = FALSE;
803 }
804 }
805 };
806
807 // Now it only supports 802.11g Infrastructure Mode, and support rate must up to 54 Mbps
808 if (pDevice->bDiversityEnable && (FrameSize>50) &&
809 (pDevice->eOPMode == OP_MODE_INFRASTRUCTURE) &&
810 (pDevice->bLinkPass == TRUE)) {
811 //printk("device_receive_frame: RxRate is %d\n",*pbyRxRate);
812 BBvAntennaDiversity(pDevice, s_byGetRateIdx(*pbyRxRate), 0);
813 }
814
815
816 if (pDevice->byLocalID != REV_ID_VT3253_B1) {
817 pDevice->uCurrRSSI = *pbyRSSI;
818 }
819 pDevice->byCurrSQ = *pbySQ;
820
821 if ((*pbyRSSI != 0) &&
822 (pMgmt->pCurrBSS!=NULL)) {
823 RFvRSSITodBm(pDevice, *pbyRSSI, &ldBm);
824 // Moniter if RSSI is too strong.
825 pMgmt->pCurrBSS->byRSSIStatCnt++;
826 pMgmt->pCurrBSS->byRSSIStatCnt %= RSSI_STAT_COUNT;
827 pMgmt->pCurrBSS->ldBmAverage[pMgmt->pCurrBSS->byRSSIStatCnt] = ldBm;
828 for(ii=0;ii<RSSI_STAT_COUNT;ii++) {
829 if (pMgmt->pCurrBSS->ldBmAverage[ii] != 0) {
830 pMgmt->pCurrBSS->ldBmMAX = max(pMgmt->pCurrBSS->ldBmAverage[ii], ldBm);
831 }
832 }
833 }
834
835 // -----------------------------------------------
836
837 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_AP) && (pDevice->bEnable8021x == TRUE)){
838 BYTE abyMacHdr[24];
839
840 // Only 802.1x packet incoming allowed
841 if (bIsWEP)
842 cbIVOffset = 8;
843 else
844 cbIVOffset = 0;
845 wEtherType = (skb->data[cbIVOffset + 4 + 24 + 6] << 8) |
846 skb->data[cbIVOffset + 4 + 24 + 6 + 1];
847
848 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"wEtherType = %04x \n", wEtherType);
849 if (wEtherType == ETH_P_PAE) {
850 skb->dev = pDevice->apdev;
851
852 if (bIsWEP == TRUE) {
853 // strip IV header(8)
854 memcpy(&abyMacHdr[0], (skb->data + 4), 24);
855 memcpy((skb->data + 4 + cbIVOffset), &abyMacHdr[0], 24);
856 }
857#ifdef PRIVATE_OBJ
858 ref_skb_add_offset(skb->skb, (cbIVOffset + 4));
859 ref_skb_set_dev(pDevice->apdev, skb->skb);
860 skb_put(skb->skb, FrameSize);
861#if LINUX_VERSION_CODE > KERNEL_VERSION(2,6,21)
862 skb->mac_header = skb->data;
863#else
864 skb->mac.raw = skb->data;
865#endif
866 *(skb->pkt_type) = PACKET_OTHERHOST;
867 *(skb->protocol) = htons(ETH_P_802_2);
868 memset(skb->cb, 0, sizeof(skb->cb));
869 netif_rx(skb->skb);
870#else
871 skb->data += (cbIVOffset + 4);
872 skb->tail += (cbIVOffset + 4);
873 skb_put(skb, FrameSize);
874#if LINUX_VERSION_CODE > KERNEL_VERSION(2,6,21)
875 skb->mac_header = skb->data;
876#else
877 skb->mac.raw = skb->data;
878#endif
879
880 skb->pkt_type = PACKET_OTHERHOST;
881 skb->protocol = htons(ETH_P_802_2);
882 memset(skb->cb, 0, sizeof(skb->cb));
883 netif_rx(skb);
884#endif
885 return TRUE;
886
887}
888 // check if 802.1x authorized
889 if (!(pMgmt->sNodeDBTable[iSANodeIndex].dwFlags & WLAN_STA_AUTHORIZED))
890 return FALSE;
891 }
892
893
894 if ((pKey != NULL) && (pKey->byCipherSuite == KEY_CTL_TKIP)) {
895 if (bIsWEP) {
896 FrameSize -= 8; //MIC
897 }
898 }
899
900 //--------------------------------------------------------------------------------
901 // Soft MIC
902 if ((pKey != NULL) && (pKey->byCipherSuite == KEY_CTL_TKIP)) {
903 if (bIsWEP) {
904 PDWORD pdwMIC_L;
905 PDWORD pdwMIC_R;
906 DWORD dwMIC_Priority;
907 DWORD dwMICKey0 = 0, dwMICKey1 = 0;
908 DWORD dwLocalMIC_L = 0;
909 DWORD dwLocalMIC_R = 0;
910 viawget_wpa_header *wpahdr;
911
912
913 if (pMgmt->eCurrMode == WMAC_MODE_ESS_AP) {
914 dwMICKey0 = cpu_to_le32(*(PDWORD)(&pKey->abyKey[24]));
915 dwMICKey1 = cpu_to_le32(*(PDWORD)(&pKey->abyKey[28]));
916 }
917 else {
918 if (pDevice->pMgmt->eAuthenMode == WMAC_AUTH_WPANONE) {
919 dwMICKey0 = cpu_to_le32(*(PDWORD)(&pKey->abyKey[16]));
920 dwMICKey1 = cpu_to_le32(*(PDWORD)(&pKey->abyKey[20]));
921 } else if ((pKey->dwKeyIndex & BIT28) == 0) {
922 dwMICKey0 = cpu_to_le32(*(PDWORD)(&pKey->abyKey[16]));
923 dwMICKey1 = cpu_to_le32(*(PDWORD)(&pKey->abyKey[20]));
924 } else {
925 dwMICKey0 = cpu_to_le32(*(PDWORD)(&pKey->abyKey[24]));
926 dwMICKey1 = cpu_to_le32(*(PDWORD)(&pKey->abyKey[28]));
927 }
928 }
929
930 MIC_vInit(dwMICKey0, dwMICKey1);
931 MIC_vAppend((PBYTE)&(pDevice->sRxEthHeader.abyDstAddr[0]), 12);
932 dwMIC_Priority = 0;
933 MIC_vAppend((PBYTE)&dwMIC_Priority, 4);
934 // 4 is Rcv buffer header, 24 is MAC Header, and 8 is IV and Ext IV.
935 MIC_vAppend((PBYTE)(skb->data + 4 + WLAN_HDR_ADDR3_LEN + 8),
936 FrameSize - WLAN_HDR_ADDR3_LEN - 8);
937 MIC_vGetMIC(&dwLocalMIC_L, &dwLocalMIC_R);
938 MIC_vUnInit();
939
940 pdwMIC_L = (PDWORD)(skb->data + 4 + FrameSize);
941 pdwMIC_R = (PDWORD)(skb->data + 4 + FrameSize + 4);
942 //DBG_PRN_GRP12(("RxL: %lx, RxR: %lx\n", *pdwMIC_L, *pdwMIC_R));
943 //DBG_PRN_GRP12(("LocalL: %lx, LocalR: %lx\n", dwLocalMIC_L, dwLocalMIC_R));
944 //DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"dwMICKey0= %lx,dwMICKey1= %lx \n", dwMICKey0, dwMICKey1);
945
946
947 if ((cpu_to_le32(*pdwMIC_L) != dwLocalMIC_L) || (cpu_to_le32(*pdwMIC_R) != dwLocalMIC_R) ||
948 (pDevice->bRxMICFail == TRUE)) {
949 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"MIC comparison is fail!\n");
950 pDevice->bRxMICFail = FALSE;
951 //pDevice->s802_11Counter.TKIPLocalMICFailures.QuadPart++;
952 pDevice->s802_11Counter.TKIPLocalMICFailures++;
953 if (bDeFragRx) {
954 if (!device_alloc_frag_buf(pDevice, &pDevice->sRxDFCB[pDevice->uCurrentDFCBIdx])) {
955 DEVICE_PRT(MSG_LEVEL_ERR,KERN_ERR "%s: can not alloc more frag bufs\n",
956 pDevice->dev->name);
957 }
958 }
959
960//2008-0409-07, <Add> by Einsn Liu
961 #ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
962 //send event to wpa_supplicant
963 //if(pDevice->bWPADevEnable == TRUE)
964 {
965 union iwreq_data wrqu;
966 struct iw_michaelmicfailure ev;
967 int keyidx = pbyFrame[cbHeaderSize+3] >> 6; //top two-bits
968 memset(&ev, 0, sizeof(ev));
969 ev.flags = keyidx & IW_MICFAILURE_KEY_ID;
970 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_STA) &&
971 (pMgmt->eCurrState == WMAC_STATE_ASSOC) &&
972 (*pbyRsr & (RSR_ADDRBROAD | RSR_ADDRMULTI)) == 0) {
973 ev.flags |= IW_MICFAILURE_PAIRWISE;
974 } else {
975 ev.flags |= IW_MICFAILURE_GROUP;
976 }
977
978 ev.src_addr.sa_family = ARPHRD_ETHER;
979 memcpy(ev.src_addr.sa_data, pMACHeader->abyAddr2, ETH_ALEN);
980 memset(&wrqu, 0, sizeof(wrqu));
981 wrqu.data.length = sizeof(ev);
982 wireless_send_event(pDevice->dev, IWEVMICHAELMICFAILURE, &wrqu, (char *)&ev);
983
984 }
985 #endif
986 if ((pDevice->bWPADEVUp) && (pDevice->skb != NULL)) {
987 wpahdr = (viawget_wpa_header *)pDevice->skb->data;
988 if ((pDevice->pMgmt->eCurrMode == WMAC_MODE_ESS_STA) &&
989 (pDevice->pMgmt->eCurrState == WMAC_STATE_ASSOC) &&
990 (*pbyRsr & (RSR_ADDRBROAD | RSR_ADDRMULTI)) == 0) {
991 //s802_11_Status.Flags = NDIS_802_11_AUTH_REQUEST_PAIRWISE_ERROR;
992 wpahdr->type = VIAWGET_PTK_MIC_MSG;
993 } else {
994 //s802_11_Status.Flags = NDIS_802_11_AUTH_REQUEST_GROUP_ERROR;
995 wpahdr->type = VIAWGET_GTK_MIC_MSG;
996 }
997 wpahdr->resp_ie_len = 0;
998 wpahdr->req_ie_len = 0;
999 skb_put(pDevice->skb, sizeof(viawget_wpa_header));
1000 pDevice->skb->dev = pDevice->wpadev;
1001#if LINUX_VERSION_CODE > KERNEL_VERSION(2,6,21)
1002 pDevice->skb->mac_header = pDevice->skb->data;
1003#else
1004 pDevice->skb->mac.raw=pDevice->skb->data;
1005#endif
1006 pDevice->skb->pkt_type = PACKET_HOST;
1007 pDevice->skb->protocol = htons(ETH_P_802_2);
1008 memset(pDevice->skb->cb, 0, sizeof(pDevice->skb->cb));
1009 netif_rx(pDevice->skb);
1010 pDevice->skb = dev_alloc_skb((int)pDevice->rx_buf_sz);
1011 };
1012
1013 return FALSE;
1014
1015 }
1016 }
1017 } //---end of SOFT MIC-----------------------------------------------------------------------
1018
1019 // ++++++++++ Reply Counter Check +++++++++++++
1020
1021 if ((pKey != NULL) && ((pKey->byCipherSuite == KEY_CTL_TKIP) ||
1022 (pKey->byCipherSuite == KEY_CTL_CCMP))) {
1023 if (bIsWEP) {
1024 WORD wLocalTSC15_0 = 0;
1025 DWORD dwLocalTSC47_16 = 0;
1026 ULONGLONG RSC = 0;
1027 // endian issues
1028 RSC = *((ULONGLONG *) &(pKey->KeyRSC));
1029 wLocalTSC15_0 = (WORD) RSC;
1030 dwLocalTSC47_16 = (DWORD) (RSC>>16);
1031
1032 RSC = dwRxTSC47_16;
1033 RSC <<= 16;
1034 RSC += wRxTSC15_0;
1035 MEMvCopy(&(pKey->KeyRSC), &RSC, sizeof(QWORD));
1036
1037 if ( (pDevice->sMgmtObj.eCurrMode == WMAC_MODE_ESS_STA) &&
1038 (pDevice->sMgmtObj.eCurrState == WMAC_STATE_ASSOC)) {
1039 // check RSC
1040 if ( (wRxTSC15_0 < wLocalTSC15_0) &&
1041 (dwRxTSC47_16 <= dwLocalTSC47_16) &&
1042 !((dwRxTSC47_16 == 0) && (dwLocalTSC47_16 == 0xFFFFFFFF))) {
1043 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"TSC is illegal~~!\n ");
1044 if (pKey->byCipherSuite == KEY_CTL_TKIP)
1045 //pDevice->s802_11Counter.TKIPReplays.QuadPart++;
1046 pDevice->s802_11Counter.TKIPReplays++;
1047 else
1048 //pDevice->s802_11Counter.CCMPReplays.QuadPart++;
1049 pDevice->s802_11Counter.CCMPReplays++;
1050
1051 if (bDeFragRx) {
1052 if (!device_alloc_frag_buf(pDevice, &pDevice->sRxDFCB[pDevice->uCurrentDFCBIdx])) {
1053 DEVICE_PRT(MSG_LEVEL_ERR,KERN_ERR "%s: can not alloc more frag bufs\n",
1054 pDevice->dev->name);
1055 }
1056 }
1057 return FALSE;
1058 }
1059 }
1060 }
1061 } // ----- End of Reply Counter Check --------------------------
1062
1063
1064
1065 if ((pKey != NULL) && (bIsWEP)) {
1066// pDevice->s802_11Counter.DecryptSuccessCount.QuadPart++;
1067 }
1068
1069
1070 s_vProcessRxMACHeader(pDevice, (PBYTE)(skb->data+4), FrameSize, bIsWEP, bExtIV, &cbHeaderOffset);
1071 FrameSize -= cbHeaderOffset;
1072 cbHeaderOffset += 4; // 4 is Rcv buffer header
1073
1074 // Null data, framesize = 14
1075 if (FrameSize < 15)
1076 return FALSE;
1077
1078 if (pMgmt->eCurrMode == WMAC_MODE_ESS_AP) {
1079 if (s_bAPModeRxData(pDevice,
1080 skb,
1081 FrameSize,
1082 cbHeaderOffset,
1083 iSANodeIndex,
1084 iDANodeIndex
1085 ) == FALSE) {
1086
1087 if (bDeFragRx) {
1088 if (!device_alloc_frag_buf(pDevice, &pDevice->sRxDFCB[pDevice->uCurrentDFCBIdx])) {
1089 DEVICE_PRT(MSG_LEVEL_ERR,KERN_ERR "%s: can not alloc more frag bufs\n",
1090 pDevice->dev->name);
1091 }
1092 }
1093 return FALSE;
1094 }
1095
1096// if(pDevice->bRxMICFail == FALSE) {
1097// for (ii =0; ii < 100; ii++)
1098// printk(" %02x", *(skb->data + ii));
1099// printk("\n");
1100// }
1101
1102 }
1103
1104#ifdef PRIVATE_OBJ
1105 ref_skb_add_offset(skb->skb, cbHeaderOffset);
1106 skb_put(skb->skb, FrameSize);
1107 *(skb->protocol)=eth_type_trans(skb->skb, skb->dev);
1108
1109#else
1110 skb->data += cbHeaderOffset;
1111 skb->tail += cbHeaderOffset;
1112 skb_put(skb, FrameSize);
1113 skb->protocol=eth_type_trans(skb, skb->dev);
1114#endif
1115
1116
1117 //drop frame not met IEEE 802.3
1118/*
1119 if (pDevice->flags & DEVICE_FLAGS_VAL_PKT_LEN) {
1120#ifdef PRIVATE_OBJ
1121 if ((*(skb->protocol)==htons(ETH_P_802_3)) &&
1122 (*(skb->len)!=htons(skb->mac.ethernet->h_proto))) {
1123#else
1124 if ((skb->protocol==htons(ETH_P_802_3)) &&
1125 (skb->len!=htons(skb->mac.ethernet->h_proto))) {
1126#endif
1127 pStats->rx_length_errors++;
1128 pStats->rx_dropped++;
1129 if (bDeFragRx) {
1130 if (!device_alloc_frag_buf(pDevice, &pDevice->sRxDFCB[pDevice->uCurrentDFCBIdx])) {
1131 DEVICE_PRT(MSG_LEVEL_ERR,KERN_ERR "%s: can not alloc more frag bufs\n",
1132 pDevice->dev->name);
1133 }
1134 }
1135 return FALSE;
1136 }
1137 }
1138*/
1139
1140#ifdef PRIVATE_OBJ
1141 *(skb->ip_summed)=CHECKSUM_NONE;
1142 pStats->rx_bytes +=*(skb->len);
1143 pStats->rx_packets++;
1144 netif_rx(skb->skb);
1145#else
1146 skb->ip_summed=CHECKSUM_NONE;
1147 pStats->rx_bytes +=skb->len;
1148 pStats->rx_packets++;
1149 netif_rx(skb);
1150#endif
1151
1152 if (bDeFragRx) {
1153 if (!device_alloc_frag_buf(pDevice, &pDevice->sRxDFCB[pDevice->uCurrentDFCBIdx])) {
1154 DEVICE_PRT(MSG_LEVEL_ERR,KERN_ERR "%s: can not alloc more frag bufs\n",
1155 pDevice->dev->name);
1156 }
1157 return FALSE;
1158 }
1159 return TRUE;
1160}
1161
1162
1163static BOOL s_bAPModeRxCtl (
1164 IN PSDevice pDevice,
1165 IN PBYTE pbyFrame,
1166 IN INT iSANodeIndex
1167 )
1168{
1169 PS802_11Header p802_11Header;
1170 CMD_STATUS Status;
1171 PSMgmtObject pMgmt = pDevice->pMgmt;
1172
1173
1174 if (IS_CTL_PSPOLL(pbyFrame) || !IS_TYPE_CONTROL(pbyFrame)) {
1175
1176 p802_11Header = (PS802_11Header) (pbyFrame);
1177 if (!IS_TYPE_MGMT(pbyFrame)) {
1178
1179 // Data & PS-Poll packet
1180 // check frame class
1181 if (iSANodeIndex > 0) {
1182 // frame class 3 fliter & checking
1183 if (pMgmt->sNodeDBTable[iSANodeIndex].eNodeState < NODE_AUTH) {
1184 // send deauth notification
1185 // reason = (6) class 2 received from nonauth sta
1186 vMgrDeAuthenBeginSta(pDevice,
1187 pMgmt,
1188 (PBYTE)(p802_11Header->abyAddr2),
1189 (WLAN_MGMT_REASON_CLASS2_NONAUTH),
1190 &Status
1191 );
1192 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "dpc: send vMgrDeAuthenBeginSta 1\n");
1193 return TRUE;
1194 };
1195 if (pMgmt->sNodeDBTable[iSANodeIndex].eNodeState < NODE_ASSOC) {
1196 // send deassoc notification
1197 // reason = (7) class 3 received from nonassoc sta
1198 vMgrDisassocBeginSta(pDevice,
1199 pMgmt,
1200 (PBYTE)(p802_11Header->abyAddr2),
1201 (WLAN_MGMT_REASON_CLASS3_NONASSOC),
1202 &Status
1203 );
1204 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "dpc: send vMgrDisassocBeginSta 2\n");
1205 return TRUE;
1206 };
1207
1208 if (pMgmt->sNodeDBTable[iSANodeIndex].bPSEnable) {
1209 // delcare received ps-poll event
1210 if (IS_CTL_PSPOLL(pbyFrame)) {
1211 pMgmt->sNodeDBTable[iSANodeIndex].bRxPSPoll = TRUE;
1212 bScheduleCommand((HANDLE)pDevice, WLAN_CMD_RX_PSPOLL, NULL);
1213 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "dpc: WLAN_CMD_RX_PSPOLL 1\n");
1214 }
1215 else {
1216 // check Data PS state
1217 // if PW bit off, send out all PS bufferring packets.
1218 if (!IS_FC_POWERMGT(pbyFrame)) {
1219 pMgmt->sNodeDBTable[iSANodeIndex].bPSEnable = FALSE;
1220 pMgmt->sNodeDBTable[iSANodeIndex].bRxPSPoll = TRUE;
1221 bScheduleCommand((HANDLE)pDevice, WLAN_CMD_RX_PSPOLL, NULL);
1222 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "dpc: WLAN_CMD_RX_PSPOLL 2\n");
1223 }
1224 }
1225 }
1226 else {
1227 if (IS_FC_POWERMGT(pbyFrame)) {
1228 pMgmt->sNodeDBTable[iSANodeIndex].bPSEnable = TRUE;
1229 // Once if STA in PS state, enable multicast bufferring
1230 pMgmt->sNodeDBTable[0].bPSEnable = TRUE;
1231 }
1232 else {
1233 // clear all pending PS frame.
1234 if (pMgmt->sNodeDBTable[iSANodeIndex].wEnQueueCnt > 0) {
1235 pMgmt->sNodeDBTable[iSANodeIndex].bPSEnable = FALSE;
1236 pMgmt->sNodeDBTable[iSANodeIndex].bRxPSPoll = TRUE;
1237 bScheduleCommand((HANDLE)pDevice, WLAN_CMD_RX_PSPOLL, NULL);
1238 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "dpc: WLAN_CMD_RX_PSPOLL 3\n");
1239
1240 }
1241 }
1242 }
1243 }
1244 else {
1245 vMgrDeAuthenBeginSta(pDevice,
1246 pMgmt,
1247 (PBYTE)(p802_11Header->abyAddr2),
1248 (WLAN_MGMT_REASON_CLASS2_NONAUTH),
1249 &Status
1250 );
1251 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "dpc: send vMgrDeAuthenBeginSta 3\n");
1252 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "BSSID:%02x-%02x-%02x=%02x-%02x-%02x \n",
1253 p802_11Header->abyAddr3[0],
1254 p802_11Header->abyAddr3[1],
1255 p802_11Header->abyAddr3[2],
1256 p802_11Header->abyAddr3[3],
1257 p802_11Header->abyAddr3[4],
1258 p802_11Header->abyAddr3[5]
1259 );
1260 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "ADDR2:%02x-%02x-%02x=%02x-%02x-%02x \n",
1261 p802_11Header->abyAddr2[0],
1262 p802_11Header->abyAddr2[1],
1263 p802_11Header->abyAddr2[2],
1264 p802_11Header->abyAddr2[3],
1265 p802_11Header->abyAddr2[4],
1266 p802_11Header->abyAddr2[5]
1267 );
1268 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "ADDR1:%02x-%02x-%02x=%02x-%02x-%02x \n",
1269 p802_11Header->abyAddr1[0],
1270 p802_11Header->abyAddr1[1],
1271 p802_11Header->abyAddr1[2],
1272 p802_11Header->abyAddr1[3],
1273 p802_11Header->abyAddr1[4],
1274 p802_11Header->abyAddr1[5]
1275 );
1276 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "dpc: wFrameCtl= %x\n", p802_11Header->wFrameCtl );
1277 VNSvInPortB(pDevice->PortOffset + MAC_REG_RCR, &(pDevice->byRxMode));
1278 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "dpc:pDevice->byRxMode = %x\n", pDevice->byRxMode );
1279 return TRUE;
1280 }
1281 }
1282 }
1283 return FALSE;
1284
1285}
1286
1287static BOOL s_bHandleRxEncryption (
1288 IN PSDevice pDevice,
1289 IN PBYTE pbyFrame,
1290 IN UINT FrameSize,
1291 IN PBYTE pbyRsr,
1292 OUT PBYTE pbyNewRsr,
1293 OUT PSKeyItem *pKeyOut,
1294 OUT PBOOL pbExtIV,
1295 OUT PWORD pwRxTSC15_0,
1296 OUT PDWORD pdwRxTSC47_16
1297 )
1298{
1299 UINT PayloadLen = FrameSize;
1300 PBYTE pbyIV;
1301 BYTE byKeyIdx;
1302 PSKeyItem pKey = NULL;
1303 BYTE byDecMode = KEY_CTL_WEP;
1304 PSMgmtObject pMgmt = pDevice->pMgmt;
1305
1306
1307 *pwRxTSC15_0 = 0;
1308 *pdwRxTSC47_16 = 0;
1309
1310 pbyIV = pbyFrame + WLAN_HDR_ADDR3_LEN;
1311 if ( WLAN_GET_FC_TODS(*(PWORD)pbyFrame) &&
1312 WLAN_GET_FC_FROMDS(*(PWORD)pbyFrame) ) {
1313 pbyIV += 6; // 6 is 802.11 address4
1314 PayloadLen -= 6;
1315 }
1316 byKeyIdx = (*(pbyIV+3) & 0xc0);
1317 byKeyIdx >>= 6;
1318 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"\nKeyIdx: %d\n", byKeyIdx);
1319
1320 if ((pMgmt->eAuthenMode == WMAC_AUTH_WPA) ||
1321 (pMgmt->eAuthenMode == WMAC_AUTH_WPAPSK) ||
1322 (pMgmt->eAuthenMode == WMAC_AUTH_WPANONE) ||
1323 (pMgmt->eAuthenMode == WMAC_AUTH_WPA2) ||
1324 (pMgmt->eAuthenMode == WMAC_AUTH_WPA2PSK)) {
1325 if (((*pbyRsr & (RSR_ADDRBROAD | RSR_ADDRMULTI)) == 0) &&
1326 (pDevice->pMgmt->byCSSPK != KEY_CTL_NONE)) {
1327 // unicast pkt use pairwise key
1328 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"unicast pkt\n");
1329 if (KeybGetKey(&(pDevice->sKey), pDevice->abyBSSID, 0xFFFFFFFF, &pKey) == TRUE) {
1330 if (pDevice->pMgmt->byCSSPK == KEY_CTL_TKIP)
1331 byDecMode = KEY_CTL_TKIP;
1332 else if (pDevice->pMgmt->byCSSPK == KEY_CTL_CCMP)
1333 byDecMode = KEY_CTL_CCMP;
1334 }
1335 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"unicast pkt: %d, %p\n", byDecMode, pKey);
1336 } else {
1337 // use group key
1338 KeybGetKey(&(pDevice->sKey), pDevice->abyBSSID, byKeyIdx, &pKey);
1339 if (pDevice->pMgmt->byCSSGK == KEY_CTL_TKIP)
1340 byDecMode = KEY_CTL_TKIP;
1341 else if (pDevice->pMgmt->byCSSGK == KEY_CTL_CCMP)
1342 byDecMode = KEY_CTL_CCMP;
1343 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"group pkt: %d, %d, %p\n", byKeyIdx, byDecMode, pKey);
1344 }
1345 }
1346 // our WEP only support Default Key
1347 if (pKey == NULL) {
1348 // use default group key
1349 KeybGetKey(&(pDevice->sKey), pDevice->abyBroadcastAddr, byKeyIdx, &pKey);
1350 if (pDevice->pMgmt->byCSSGK == KEY_CTL_TKIP)
1351 byDecMode = KEY_CTL_TKIP;
1352 else if (pDevice->pMgmt->byCSSGK == KEY_CTL_CCMP)
1353 byDecMode = KEY_CTL_CCMP;
1354 }
1355 *pKeyOut = pKey;
1356
1357 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"AES:%d %d %d\n", pDevice->pMgmt->byCSSPK, pDevice->pMgmt->byCSSGK, byDecMode);
1358
1359 if (pKey == NULL) {
1360 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"pKey == NULL\n");
1361 if (byDecMode == KEY_CTL_WEP) {
1362// pDevice->s802_11Counter.WEPUndecryptableCount.QuadPart++;
1363 } else if (pDevice->bLinkPass == TRUE) {
1364// pDevice->s802_11Counter.DecryptFailureCount.QuadPart++;
1365 }
1366 return FALSE;
1367 }
1368 if (byDecMode != pKey->byCipherSuite) {
1369 if (byDecMode == KEY_CTL_WEP) {
1370// pDevice->s802_11Counter.WEPUndecryptableCount.QuadPart++;
1371 } else if (pDevice->bLinkPass == TRUE) {
1372// pDevice->s802_11Counter.DecryptFailureCount.QuadPart++;
1373 }
1374 *pKeyOut = NULL;
1375 return FALSE;
1376 }
1377 if (byDecMode == KEY_CTL_WEP) {
1378 // handle WEP
1379 if ((pDevice->byLocalID <= REV_ID_VT3253_A1) ||
1380 (((PSKeyTable)(pKey->pvKeyTable))->bSoftWEP == TRUE)) {
1381 // Software WEP
1382 // 1. 3253A
1383 // 2. WEP 256
1384
1385 PayloadLen -= (WLAN_HDR_ADDR3_LEN + 4 + 4); // 24 is 802.11 header,4 is IV, 4 is crc
1386 MEMvCopy(pDevice->abyPRNG, pbyIV, 3);
1387 MEMvCopy(pDevice->abyPRNG + 3, pKey->abyKey, pKey->uKeyLength);
1388 rc4_init(&pDevice->SBox, pDevice->abyPRNG, pKey->uKeyLength + 3);
1389 rc4_encrypt(&pDevice->SBox, pbyIV+4, pbyIV+4, PayloadLen);
1390
1391 if (ETHbIsBufferCrc32Ok(pbyIV+4, PayloadLen)) {
1392 *pbyNewRsr |= NEWRSR_DECRYPTOK;
1393 }
1394 }
1395 } else if ((byDecMode == KEY_CTL_TKIP) ||
1396 (byDecMode == KEY_CTL_CCMP)) {
1397 // TKIP/AES
1398
1399 PayloadLen -= (WLAN_HDR_ADDR3_LEN + 8 + 4); // 24 is 802.11 header, 8 is IV&ExtIV, 4 is crc
1400 *pdwRxTSC47_16 = cpu_to_le32(*(PDWORD)(pbyIV + 4));
1401 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"ExtIV: %lx\n",*pdwRxTSC47_16);
1402 if (byDecMode == KEY_CTL_TKIP) {
1403 *pwRxTSC15_0 = cpu_to_le16(MAKEWORD(*(pbyIV+2), *pbyIV));
1404 } else {
1405 *pwRxTSC15_0 = cpu_to_le16(*(PWORD)pbyIV);
1406 }
1407 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"TSC0_15: %x\n", *pwRxTSC15_0);
1408
1409 if ((byDecMode == KEY_CTL_TKIP) &&
1410 (pDevice->byLocalID <= REV_ID_VT3253_A1)) {
1411 // Software TKIP
1412 // 1. 3253 A
1413 PS802_11Header pMACHeader = (PS802_11Header) (pbyFrame);
1414 TKIPvMixKey(pKey->abyKey, pMACHeader->abyAddr2, *pwRxTSC15_0, *pdwRxTSC47_16, pDevice->abyPRNG);
1415 rc4_init(&pDevice->SBox, pDevice->abyPRNG, TKIP_KEY_LEN);
1416 rc4_encrypt(&pDevice->SBox, pbyIV+8, pbyIV+8, PayloadLen);
1417 if (ETHbIsBufferCrc32Ok(pbyIV+8, PayloadLen)) {
1418 *pbyNewRsr |= NEWRSR_DECRYPTOK;
1419 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"ICV OK!\n");
1420 } else {
1421 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"ICV FAIL!!!\n");
1422 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"PayloadLen = %d\n", PayloadLen);
1423 }
1424 }
1425 }// end of TKIP/AES
1426
1427 if ((*(pbyIV+3) & 0x20) != 0)
1428 *pbExtIV = TRUE;
1429 return TRUE;
1430}
1431
1432
1433static BOOL s_bHostWepRxEncryption (
1434 IN PSDevice pDevice,
1435 IN PBYTE pbyFrame,
1436 IN UINT FrameSize,
1437 IN PBYTE pbyRsr,
1438 IN BOOL bOnFly,
1439 IN PSKeyItem pKey,
1440 OUT PBYTE pbyNewRsr,
1441 OUT PBOOL pbExtIV,
1442 OUT PWORD pwRxTSC15_0,
1443 OUT PDWORD pdwRxTSC47_16
1444 )
1445{
1446 UINT PayloadLen = FrameSize;
1447 PBYTE pbyIV;
1448 BYTE byKeyIdx;
1449 BYTE byDecMode = KEY_CTL_WEP;
1450 PS802_11Header pMACHeader;
1451
1452
1453
1454 *pwRxTSC15_0 = 0;
1455 *pdwRxTSC47_16 = 0;
1456
1457 pbyIV = pbyFrame + WLAN_HDR_ADDR3_LEN;
1458 if ( WLAN_GET_FC_TODS(*(PWORD)pbyFrame) &&
1459 WLAN_GET_FC_FROMDS(*(PWORD)pbyFrame) ) {
1460 pbyIV += 6; // 6 is 802.11 address4
1461 PayloadLen -= 6;
1462 }
1463 byKeyIdx = (*(pbyIV+3) & 0xc0);
1464 byKeyIdx >>= 6;
1465 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"\nKeyIdx: %d\n", byKeyIdx);
1466
1467
1468 if (pDevice->pMgmt->byCSSGK == KEY_CTL_TKIP)
1469 byDecMode = KEY_CTL_TKIP;
1470 else if (pDevice->pMgmt->byCSSGK == KEY_CTL_CCMP)
1471 byDecMode = KEY_CTL_CCMP;
1472
1473 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"AES:%d %d %d\n", pDevice->pMgmt->byCSSPK, pDevice->pMgmt->byCSSGK, byDecMode);
1474
1475 if (byDecMode != pKey->byCipherSuite) {
1476 if (byDecMode == KEY_CTL_WEP) {
1477// pDevice->s802_11Counter.WEPUndecryptableCount.QuadPart++;
1478 } else if (pDevice->bLinkPass == TRUE) {
1479// pDevice->s802_11Counter.DecryptFailureCount.QuadPart++;
1480 }
1481 return FALSE;
1482 }
1483
1484 if (byDecMode == KEY_CTL_WEP) {
1485 // handle WEP
1486 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"byDecMode == KEY_CTL_WEP \n");
1487 if ((pDevice->byLocalID <= REV_ID_VT3253_A1) ||
1488 (((PSKeyTable)(pKey->pvKeyTable))->bSoftWEP == TRUE) ||
1489 (bOnFly == FALSE)) {
1490 // Software WEP
1491 // 1. 3253A
1492 // 2. WEP 256
1493 // 3. NotOnFly
1494
1495 PayloadLen -= (WLAN_HDR_ADDR3_LEN + 4 + 4); // 24 is 802.11 header,4 is IV, 4 is crc
1496 MEMvCopy(pDevice->abyPRNG, pbyIV, 3);
1497 MEMvCopy(pDevice->abyPRNG + 3, pKey->abyKey, pKey->uKeyLength);
1498 rc4_init(&pDevice->SBox, pDevice->abyPRNG, pKey->uKeyLength + 3);
1499 rc4_encrypt(&pDevice->SBox, pbyIV+4, pbyIV+4, PayloadLen);
1500
1501 if (ETHbIsBufferCrc32Ok(pbyIV+4, PayloadLen)) {
1502 *pbyNewRsr |= NEWRSR_DECRYPTOK;
1503 }
1504 }
1505 } else if ((byDecMode == KEY_CTL_TKIP) ||
1506 (byDecMode == KEY_CTL_CCMP)) {
1507 // TKIP/AES
1508
1509 PayloadLen -= (WLAN_HDR_ADDR3_LEN + 8 + 4); // 24 is 802.11 header, 8 is IV&ExtIV, 4 is crc
1510 *pdwRxTSC47_16 = cpu_to_le32(*(PDWORD)(pbyIV + 4));
1511 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"ExtIV: %lx\n",*pdwRxTSC47_16);
1512
1513 if (byDecMode == KEY_CTL_TKIP) {
1514 *pwRxTSC15_0 = cpu_to_le16(MAKEWORD(*(pbyIV+2), *pbyIV));
1515 } else {
1516 *pwRxTSC15_0 = cpu_to_le16(*(PWORD)pbyIV);
1517 }
1518 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"TSC0_15: %x\n", *pwRxTSC15_0);
1519
1520 if (byDecMode == KEY_CTL_TKIP) {
1521 if ((pDevice->byLocalID <= REV_ID_VT3253_A1) || (bOnFly == FALSE)) {
1522 // Software TKIP
1523 // 1. 3253 A
1524 // 2. NotOnFly
1525 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"soft KEY_CTL_TKIP \n");
1526 pMACHeader = (PS802_11Header) (pbyFrame);
1527 TKIPvMixKey(pKey->abyKey, pMACHeader->abyAddr2, *pwRxTSC15_0, *pdwRxTSC47_16, pDevice->abyPRNG);
1528 rc4_init(&pDevice->SBox, pDevice->abyPRNG, TKIP_KEY_LEN);
1529 rc4_encrypt(&pDevice->SBox, pbyIV+8, pbyIV+8, PayloadLen);
1530 if (ETHbIsBufferCrc32Ok(pbyIV+8, PayloadLen)) {
1531 *pbyNewRsr |= NEWRSR_DECRYPTOK;
1532 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"ICV OK!\n");
1533 } else {
1534 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"ICV FAIL!!!\n");
1535 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"PayloadLen = %d\n", PayloadLen);
1536 }
1537 }
1538 }
1539
1540 if (byDecMode == KEY_CTL_CCMP) {
1541 if (bOnFly == FALSE) {
1542 // Software CCMP
1543 // NotOnFly
1544 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"soft KEY_CTL_CCMP\n");
1545 if (AESbGenCCMP(pKey->abyKey, pbyFrame, FrameSize)) {
1546 *pbyNewRsr |= NEWRSR_DECRYPTOK;
1547 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"CCMP MIC compare OK!\n");
1548 } else {
1549 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"CCMP MIC fail!\n");
1550 }
1551 }
1552 }
1553
1554 }// end of TKIP/AES
1555
1556 if ((*(pbyIV+3) & 0x20) != 0)
1557 *pbExtIV = TRUE;
1558 return TRUE;
1559}
1560
1561
1562
1563
1564#ifdef PRIVATE_OBJ
1565
1566static BOOL s_bAPModeRxData (
1567 IN PSDevice pDevice,
1568 IN ref_sk_buff* skb,
1569 IN UINT FrameSize,
1570 IN UINT cbHeaderOffset,
1571 IN INT iSANodeIndex,
1572 IN INT iDANodeIndex
1573 )
1574
1575#else
1576
1577static BOOL s_bAPModeRxData (
1578 IN PSDevice pDevice,
1579 IN struct sk_buff* skb,
1580 IN UINT FrameSize,
1581 IN UINT cbHeaderOffset,
1582 IN INT iSANodeIndex,
1583 IN INT iDANodeIndex
1584 )
1585#endif
1586{
1587 PSMgmtObject pMgmt = pDevice->pMgmt;
1588 BOOL bRelayAndForward = FALSE;
1589 BOOL bRelayOnly = FALSE;
1590 BYTE byMask[8] = {1, 2, 4, 8, 0x10, 0x20, 0x40, 0x80};
1591 WORD wAID;
1592#ifdef PRIVATE_OBJ
1593 struct sk_buff* tmp_skb;
1594 ref_sk_buff s_ref_skb;
1595 ref_sk_buff* skbcpy = &s_ref_skb;
1596#else
1597 struct sk_buff* skbcpy = NULL;
1598#endif
1599
1600
1601
1602 if (FrameSize > CB_MAX_BUF_SIZE)
1603 return FALSE;
1604 // check DA
1605 if(IS_MULTICAST_ADDRESS((PBYTE)(skb->data+cbHeaderOffset))) {
1606 if (pMgmt->sNodeDBTable[0].bPSEnable) {
1607
1608#ifdef PRIVATE_OBJ
1609 tmp_skb = dev_alloc_skb((int)pDevice->rx_buf_sz);
1610 skbcpy = &s_ref_skb;
1611 ref_skb_remap(pDevice->dev, skbcpy, tmp_skb);
1612#else
1613 skbcpy = dev_alloc_skb((int)pDevice->rx_buf_sz);
1614#endif
1615 // if any node in PS mode, buffer packet until DTIM.
1616 if (skbcpy == NULL) {
1617 DEVICE_PRT(MSG_LEVEL_NOTICE, KERN_INFO "relay multicast no skb available \n");
1618 }
1619 else {
1620 skbcpy->dev = pDevice->dev;
1621#ifdef PRIVATE_OBJ
1622 *(skbcpy->len) = FrameSize;
1623 memcpy(skbcpy->data, skb->data+cbHeaderOffset, FrameSize);
1624 skb_queue_tail(&(pMgmt->sNodeDBTable[0].sTxPSQueue), skbcpy->skb);
1625#else
1626 skbcpy->len = FrameSize;
1627 memcpy(skbcpy->data, skb->data+cbHeaderOffset, FrameSize);
1628 skb_queue_tail(&(pMgmt->sNodeDBTable[0].sTxPSQueue), skbcpy);
1629#endif
1630 pMgmt->sNodeDBTable[0].wEnQueueCnt++;
1631 // set tx map
1632 pMgmt->abyPSTxMap[0] |= byMask[0];
1633 }
1634 }
1635 else {
1636 bRelayAndForward = TRUE;
1637 }
1638 }
1639 else {
1640 // check if relay
1641 if (BSSDBbIsSTAInNodeDB(pMgmt, (PBYTE)(skb->data+cbHeaderOffset), &iDANodeIndex)) {
1642 if (pMgmt->sNodeDBTable[iDANodeIndex].eNodeState >= NODE_ASSOC) {
1643 if (pMgmt->sNodeDBTable[iDANodeIndex].bPSEnable) {
1644 // queue this skb until next PS tx, and then release.
1645
1646#ifdef PRIVATE_OBJ
1647 ref_skb_add_offset(skb->skb, cbHeaderOffset);
1648 skb_put(skb->skb, FrameSize);
1649 skb_queue_tail(&pMgmt->sNodeDBTable[iDANodeIndex].sTxPSQueue, skb->skb);
1650#else
1651 skb->data += cbHeaderOffset;
1652 skb->tail += cbHeaderOffset;
1653 skb_put(skb, FrameSize);
1654 skb_queue_tail(&pMgmt->sNodeDBTable[iDANodeIndex].sTxPSQueue, skb);
1655#endif
1656 pMgmt->sNodeDBTable[iDANodeIndex].wEnQueueCnt++;
1657 wAID = pMgmt->sNodeDBTable[iDANodeIndex].wAID;
1658 pMgmt->abyPSTxMap[wAID >> 3] |= byMask[wAID & 7];
1659 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "relay: index= %d, pMgmt->abyPSTxMap[%d]= %d\n",
1660 iDANodeIndex, (wAID >> 3), pMgmt->abyPSTxMap[wAID >> 3]);
1661 return TRUE;
1662 }
1663 else {
1664 bRelayOnly = TRUE;
1665 }
1666 }
1667 };
1668 }
1669
1670 if (bRelayOnly || bRelayAndForward) {
1671 // relay this packet right now
1672 if (bRelayAndForward)
1673 iDANodeIndex = 0;
1674
1675 if ((pDevice->uAssocCount > 1) && (iDANodeIndex >= 0)) {
1676 ROUTEbRelay(pDevice, (PBYTE)(skb->data + cbHeaderOffset), FrameSize, (UINT)iDANodeIndex);
1677 }
1678
1679 if (bRelayOnly)
1680 return FALSE;
1681 }
1682 // none associate, don't forward
1683 if (pDevice->uAssocCount == 0)
1684 return FALSE;
1685
1686 return TRUE;
1687}
1688
diff --git a/drivers/staging/vt6655/dpc.h b/drivers/staging/vt6655/dpc.h
new file mode 100644
index 000000000000..68447c44dc2f
--- /dev/null
+++ b/drivers/staging/vt6655/dpc.h
@@ -0,0 +1,75 @@
1/*
2 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
3 * All rights reserved.
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * File: whdr.h
20 *
21 * Purpose:
22 *
23 * Author: Jerry Chen
24 *
25 * Date: Jun. 27, 2002
26 *
27 */
28
29
30#ifndef __DPC_H__
31#define __DPC_H__
32
33#if !defined(__TTYPE_H__)
34#include "ttype.h"
35#endif
36#if !defined(__DEVICE_H__)
37#include "device.h"
38#endif
39#if !defined(__WCMD_H__)
40#include "wcmd.h"
41#endif
42
43
44/*--------------------- Export Definitions -------------------------*/
45
46/*--------------------- Export Classes ----------------------------*/
47
48/*--------------------- Export Variables --------------------------*/
49
50/*--------------------- Export Functions --------------------------*/
51
52
53#ifdef __cplusplus
54extern "C" { /* Assume C declarations for C++ */
55#endif /* __cplusplus */
56
57
58BOOL
59device_receive_frame (
60 IN PSDevice pDevice,
61 IN PSRxDesc pCurrRD
62 );
63
64
65#ifdef __cplusplus
66} /* End of extern "C" { */
67#endif /* __cplusplus */
68
69
70
71VOID MngWorkItem(PVOID Context);
72#endif // __RXTX_H__
73
74
75
diff --git a/drivers/staging/vt6655/hostap.c b/drivers/staging/vt6655/hostap.c
new file mode 100644
index 000000000000..134de869cb80
--- /dev/null
+++ b/drivers/staging/vt6655/hostap.c
@@ -0,0 +1,907 @@
1/*
2 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
3 * All rights reserved.
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * File: hostap.c
20 *
21 * Purpose: handle hostap deamon ioctl input/out functions
22 *
23 * Author: Lyndon Chen
24 *
25 * Date: Oct. 20, 2003
26 *
27 * Functions:
28 *
29 * Revision History:
30 *
31 */
32
33
34#if !defined(__HOSTAP_H__)
35#include "hostap.h"
36#endif
37#if !defined(__IOCMD_H__)
38#include "iocmd.h"
39#endif
40#if !defined(__MAC_H__)
41#include "mac.h"
42#endif
43#if !defined(__CARD_H__)
44#include "card.h"
45#endif
46#if !defined(__BASEBAND_H__)
47#include "baseband.h"
48#endif
49#if !defined(__WPACTL_H__)
50#include "wpactl.h"
51#endif
52#if !defined(__KEY_H__)
53#include "key.h"
54#endif
55#if !defined(__MAC_H__)
56#include "mac.h"
57#endif
58
59
60#define VIAWGET_HOSTAPD_MAX_BUF_SIZE 1024
61#define HOSTAP_CRYPT_FLAG_SET_TX_KEY BIT0
62#define HOSTAP_CRYPT_FLAG_PERMANENT BIT1
63#define HOSTAP_CRYPT_ERR_UNKNOWN_ALG 2
64#define HOSTAP_CRYPT_ERR_UNKNOWN_ADDR 3
65#define HOSTAP_CRYPT_ERR_CRYPT_INIT_FAILED 4
66#define HOSTAP_CRYPT_ERR_KEY_SET_FAILED 5
67#define HOSTAP_CRYPT_ERR_TX_KEY_SET_FAILED 6
68#define HOSTAP_CRYPT_ERR_CARD_CONF_FAILED 7
69
70
71/*--------------------- Static Definitions -------------------------*/
72
73/*--------------------- Static Classes ----------------------------*/
74
75/*--------------------- Static Variables --------------------------*/
76//static int msglevel =MSG_LEVEL_DEBUG;
77static int msglevel =MSG_LEVEL_INFO;
78
79/*--------------------- Static Functions --------------------------*/
80
81
82
83
84/*--------------------- Export Variables --------------------------*/
85
86
87/*
88 * Description:
89 * register net_device (AP) for hostap deamon
90 *
91 * Parameters:
92 * In:
93 * pDevice -
94 * rtnl_locked -
95 * Out:
96 *
97 * Return Value:
98 *
99 */
100
101static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
102{
103 struct net_device *dev = pDevice->dev;
104 int ret;
105
106 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
107
108#ifdef PRIVATE_OBJ
109 pDevice->apdev = ref_init_apdev(dev);
110
111 if (pDevice->apdev == NULL)
112 return -ENOMEM;
113
114 if (rtnl_locked)
115 ret = register_netdevice(pDevice->apdev);
116 else
117 ret = register_netdev(pDevice->apdev);
118 if (ret) {
119 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: register_netdevice(AP) failed!\n",
120 dev->name);
121 return -1;
122 }
123 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Registered netdevice %s for AP management\n",
124 dev->name, pDevice->apdev->name);
125
126#else
127 pDevice->apdev = (struct net_device *)kmalloc(sizeof(struct net_device), GFP_KERNEL);
128 if (pDevice->apdev == NULL)
129 return -ENOMEM;
130 memset(pDevice->apdev, 0, sizeof(struct net_device));
131
132 pDevice->apdev->priv = pDevice;
133 memcpy(pDevice->apdev->dev_addr, dev->dev_addr, ETH_ALEN);
134 pDevice->apdev->hard_start_xmit = pDevice->tx_80211;
135 pDevice->apdev->type = ARPHRD_IEEE80211;
136
137 pDevice->apdev->base_addr = dev->base_addr;
138 pDevice->apdev->irq = dev->irq;
139 pDevice->apdev->mem_start = dev->mem_start;
140 pDevice->apdev->mem_end = dev->mem_end;
141 sprintf(pDevice->apdev->name, "%sap", dev->name);
142 if (rtnl_locked)
143 ret = register_netdevice(pDevice->apdev);
144 else
145 ret = register_netdev(pDevice->apdev);
146 if (ret) {
147 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: register_netdevice(AP) failed!\n",
148 dev->name);
149 return -1;
150 }
151
152 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Registered netdevice %s for AP management\n",
153 dev->name, pDevice->apdev->name);
154
155 KeyvInitTable(&pDevice->sKey, pDevice->PortOffset);
156#endif
157
158 return 0;
159}
160
161/*
162 * Description:
163 * unregister net_device(AP)
164 *
165 * Parameters:
166 * In:
167 * pDevice -
168 * rtnl_locked -
169 * Out:
170 *
171 * Return Value:
172 *
173 */
174
175static int hostap_disable_hostapd(PSDevice pDevice, int rtnl_locked)
176{
177
178 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: disabling hostapd mode\n", pDevice->dev->name);
179
180 if (pDevice->apdev && pDevice->apdev->name && pDevice->apdev->name[0]) {
181 if (rtnl_locked)
182 unregister_netdevice(pDevice->apdev);
183 else
184 unregister_netdev(pDevice->apdev);
185 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Netdevice %s unregistered\n",
186 pDevice->dev->name, pDevice->apdev->name);
187 }
188 kfree(pDevice->apdev);
189 pDevice->apdev = NULL;
190 pDevice->bEnable8021x = FALSE;
191 pDevice->bEnableHostWEP = FALSE;
192 pDevice->bEncryptionEnable = FALSE;
193
194//4.2007-0118-03,<Add> by EinsnLiu
195//execute some clear work
196pDevice->pMgmt->byCSSPK=KEY_CTL_NONE;
197pDevice->pMgmt->byCSSGK=KEY_CTL_NONE;
198KeyvInitTable(&pDevice->sKey,pDevice->PortOffset);
199
200 return 0;
201}
202
203
204/*
205 * Description:
206 * Set enable/disable hostapd mode
207 *
208 * Parameters:
209 * In:
210 * pDevice -
211 * rtnl_locked -
212 * Out:
213 *
214 * Return Value:
215 *
216 */
217
218int hostap_set_hostapd(PSDevice pDevice, int val, int rtnl_locked)
219{
220 if (val < 0 || val > 1)
221 return -EINVAL;
222
223 if (pDevice->bEnableHostapd == val)
224 return 0;
225
226 pDevice->bEnableHostapd = val;
227
228 if (val)
229 return hostap_enable_hostapd(pDevice, rtnl_locked);
230 else
231 return hostap_disable_hostapd(pDevice, rtnl_locked);
232}
233
234
235/*
236 * Description:
237 * remove station function supported for hostap deamon
238 *
239 * Parameters:
240 * In:
241 * pDevice -
242 * param -
243 * Out:
244 *
245 * Return Value:
246 *
247 */
248static int hostap_remove_sta(PSDevice pDevice,
249 struct viawget_hostapd_param *param)
250{
251 UINT uNodeIndex;
252
253
254 if (BSSDBbIsSTAInNodeDB(pDevice->pMgmt, param->sta_addr, &uNodeIndex)) {
255 BSSvRemoveOneNode(pDevice, uNodeIndex);
256 }
257 else {
258 return -ENOENT;
259 }
260 return 0;
261}
262
263/*
264 * Description:
265 * add a station from hostap deamon
266 *
267 * Parameters:
268 * In:
269 * pDevice -
270 * param -
271 * Out:
272 *
273 * Return Value:
274 *
275 */
276static int hostap_add_sta(PSDevice pDevice,
277 struct viawget_hostapd_param *param)
278{
279 PSMgmtObject pMgmt = pDevice->pMgmt;
280 UINT uNodeIndex;
281
282
283 if (!BSSDBbIsSTAInNodeDB(pMgmt, param->sta_addr, &uNodeIndex)) {
284 BSSvCreateOneNode((PSDevice)pDevice, &uNodeIndex);
285 }
286 memcpy(pMgmt->sNodeDBTable[uNodeIndex].abyMACAddr, param->sta_addr, WLAN_ADDR_LEN);
287 pMgmt->sNodeDBTable[uNodeIndex].eNodeState = NODE_ASSOC;
288 pMgmt->sNodeDBTable[uNodeIndex].wCapInfo = param->u.add_sta.capability;
289// TODO listenInterval
290// pMgmt->sNodeDBTable[uNodeIndex].wListenInterval = 1;
291 pMgmt->sNodeDBTable[uNodeIndex].bPSEnable = FALSE;
292 pMgmt->sNodeDBTable[uNodeIndex].bySuppRate = param->u.add_sta.tx_supp_rates;
293
294 // set max tx rate
295 pMgmt->sNodeDBTable[uNodeIndex].wTxDataRate =
296 pMgmt->sNodeDBTable[uNodeIndex].wMaxSuppRate;
297 // set max basic rate
298 pMgmt->sNodeDBTable[uNodeIndex].wMaxBasicRate = RATE_2M;
299 // Todo: check sta preamble, if ap can't support, set status code
300 pMgmt->sNodeDBTable[uNodeIndex].bShortPreamble =
301 WLAN_GET_CAP_INFO_SHORTPREAMBLE(pMgmt->sNodeDBTable[uNodeIndex].wCapInfo);
302
303 pMgmt->sNodeDBTable[uNodeIndex].wAID = (WORD)param->u.add_sta.aid;
304#ifdef PRIVATE_OBJ
305 pMgmt->sNodeDBTable[uNodeIndex].ulLastRxJiffer = get_jiffies();
306#else
307 pMgmt->sNodeDBTable[uNodeIndex].ulLastRxJiffer = jiffies;
308#endif
309 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Add STA AID= %d \n", pMgmt->sNodeDBTable[uNodeIndex].wAID);
310 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "MAC=%2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X \n",
311 param->sta_addr[0],
312 param->sta_addr[1],
313 param->sta_addr[2],
314 param->sta_addr[3],
315 param->sta_addr[4],
316 param->sta_addr[5]
317 ) ;
318 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Max Support rate = %d \n",
319 pMgmt->sNodeDBTable[uNodeIndex].wMaxSuppRate);
320
321 return 0;
322}
323
324/*
325 * Description:
326 * get station info
327 *
328 * Parameters:
329 * In:
330 * pDevice -
331 * param -
332 * Out:
333 *
334 * Return Value:
335 *
336 */
337
338static int hostap_get_info_sta(PSDevice pDevice,
339 struct viawget_hostapd_param *param)
340{
341 PSMgmtObject pMgmt = pDevice->pMgmt;
342 UINT uNodeIndex;
343
344 if (BSSDBbIsSTAInNodeDB(pMgmt, param->sta_addr, &uNodeIndex)) {
345#ifdef PRIVATE_OBJ
346 param->u.get_info_sta.inactive_sec =
347 (get_jiffies() - pMgmt->sNodeDBTable[uNodeIndex].ulLastRxJiffer) / HZ;
348#else
349 param->u.get_info_sta.inactive_sec =
350 (jiffies - pMgmt->sNodeDBTable[uNodeIndex].ulLastRxJiffer) / HZ;
351#endif
352 //param->u.get_info_sta.txexc = pMgmt->sNodeDBTable[uNodeIndex].uTxAttempts;
353 }
354 else {
355 return -ENOENT;
356 }
357
358 return 0;
359}
360
361/*
362 * Description:
363 * reset txexec
364 *
365 * Parameters:
366 * In:
367 * pDevice -
368 * param -
369 * Out:
370 * TURE, FALSE
371 *
372 * Return Value:
373 *
374 */
375/*
376static int hostap_reset_txexc_sta(PSDevice pDevice,
377 struct viawget_hostapd_param *param)
378{
379 PSMgmtObject pMgmt = pDevice->pMgmt;
380 UINT uNodeIndex;
381
382 if (BSSDBbIsSTAInNodeDB(pMgmt, param->sta_addr, &uNodeIndex)) {
383 pMgmt->sNodeDBTable[uNodeIndex].uTxAttempts = 0;
384 }
385 else {
386 return -ENOENT;
387 }
388
389 return 0;
390}
391*/
392
393/*
394 * Description:
395 * set station flag
396 *
397 * Parameters:
398 * In:
399 * pDevice -
400 * param -
401 * Out:
402 *
403 * Return Value:
404 *
405 */
406static int hostap_set_flags_sta(PSDevice pDevice,
407 struct viawget_hostapd_param *param)
408{
409 PSMgmtObject pMgmt = pDevice->pMgmt;
410 UINT uNodeIndex;
411
412 if (BSSDBbIsSTAInNodeDB(pMgmt, param->sta_addr, &uNodeIndex)) {
413 pMgmt->sNodeDBTable[uNodeIndex].dwFlags |= param->u.set_flags_sta.flags_or;
414 pMgmt->sNodeDBTable[uNodeIndex].dwFlags &= param->u.set_flags_sta.flags_and;
415 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO " dwFlags = %x \n",
416 (UINT)pMgmt->sNodeDBTable[uNodeIndex].dwFlags);
417 }
418 else {
419 return -ENOENT;
420 }
421
422 return 0;
423}
424
425
426
427/*
428 * Description:
429 * set generic element (wpa ie)
430 *
431 * Parameters:
432 * In:
433 * pDevice -
434 * param -
435 * Out:
436 *
437 * Return Value:
438 *
439 */
440static int hostap_set_generic_element(PSDevice pDevice,
441 struct viawget_hostapd_param *param)
442{
443 PSMgmtObject pMgmt = pDevice->pMgmt;
444
445
446
447 memcpy( pMgmt->abyWPAIE,
448 param->u.generic_elem.data,
449 param->u.generic_elem.len
450 );
451
452 pMgmt->wWPAIELen = param->u.generic_elem.len;
453
454 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"pMgmt->wWPAIELen = %d\n", pMgmt->wWPAIELen);
455
456 // disable wpa
457 if (pMgmt->wWPAIELen == 0) {
458 pMgmt->eAuthenMode = WMAC_AUTH_OPEN;
459 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO " No WPAIE, Disable WPA \n");
460 } else {
461 // enable wpa
462 if ((pMgmt->abyWPAIE[0] == WLAN_EID_RSN_WPA) ||
463 (pMgmt->abyWPAIE[0] == WLAN_EID_RSN)) {
464 pMgmt->eAuthenMode = WMAC_AUTH_WPANONE;
465 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Set WPAIE enable WPA\n");
466 } else
467 return -EINVAL;
468 }
469
470 return 0;
471}
472
473/*
474 * Description:
475 * flush station nodes table.
476 *
477 * Parameters:
478 * In:
479 * pDevice -
480 * Out:
481 *
482 * Return Value:
483 *
484 */
485
486static void hostap_flush_sta(PSDevice pDevice)
487{
488 // reserved node index =0 for multicast node.
489 BSSvClearNodeDBTable(pDevice, 1);
490 pDevice->uAssocCount = 0;
491
492 return;
493}
494
495/*
496 * Description:
497 * set each stations encryption key
498 *
499 * Parameters:
500 * In:
501 * pDevice -
502 * param -
503 * Out:
504 *
505 * Return Value:
506 *
507 */
508static int hostap_set_encryption(PSDevice pDevice,
509 struct viawget_hostapd_param *param,
510 int param_len)
511{
512 PSMgmtObject pMgmt = pDevice->pMgmt;
513 DWORD dwKeyIndex = 0;
514 BYTE abyKey[MAX_KEY_LEN];
515 BYTE abySeq[MAX_KEY_LEN];
516 NDIS_802_11_KEY_RSC KeyRSC;
517 BYTE byKeyDecMode = KEY_CTL_WEP;
518 int ret = 0;
519 int iNodeIndex = -1;
520 int ii;
521 BOOL bKeyTableFull = FALSE;
522 WORD wKeyCtl = 0;
523
524
525 param->u.crypt.err = 0;
526/*
527 if (param_len !=
528 (int) ((char *) param->u.crypt.key - (char *) param) +
529 param->u.crypt.key_len)
530 return -EINVAL;
531*/
532
533 if (param->u.crypt.alg > WPA_ALG_CCMP)
534 return -EINVAL;
535
536
537 if ((param->u.crypt.idx > 3) || (param->u.crypt.key_len > MAX_KEY_LEN)) {
538 param->u.crypt.err = HOSTAP_CRYPT_ERR_KEY_SET_FAILED;
539 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO " HOSTAP_CRYPT_ERR_KEY_SET_FAILED\n");
540 return -EINVAL;
541 }
542
543 if (param->sta_addr[0] == 0xff && param->sta_addr[1] == 0xff &&
544 param->sta_addr[2] == 0xff && param->sta_addr[3] == 0xff &&
545 param->sta_addr[4] == 0xff && param->sta_addr[5] == 0xff) {
546 if (param->u.crypt.idx >= MAX_GROUP_KEY)
547 return -EINVAL;
548 iNodeIndex = 0;
549
550 } else {
551 if (BSSDBbIsSTAInNodeDB(pMgmt, param->sta_addr, &iNodeIndex) == FALSE) {
552 param->u.crypt.err = HOSTAP_CRYPT_ERR_UNKNOWN_ADDR;
553 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO " HOSTAP_CRYPT_ERR_UNKNOWN_ADDR\n");
554 return -EINVAL;
555 }
556 }
557 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO " hostap_set_encryption: sta_index %d \n", iNodeIndex);
558 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO " hostap_set_encryption: alg %d \n", param->u.crypt.alg);
559
560 if (param->u.crypt.alg == WPA_ALG_NONE) {
561
562 if (pMgmt->sNodeDBTable[iNodeIndex].bOnFly == TRUE) {
563 if (KeybRemoveKey(&(pDevice->sKey),
564 param->sta_addr,
565 pMgmt->sNodeDBTable[iNodeIndex].dwKeyIndex,
566 pDevice->PortOffset) == FALSE) {
567 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "KeybRemoveKey fail \n");
568 }
569 pMgmt->sNodeDBTable[iNodeIndex].bOnFly = FALSE;
570 }
571 pMgmt->sNodeDBTable[iNodeIndex].byKeyIndex = 0;
572 pMgmt->sNodeDBTable[iNodeIndex].dwKeyIndex = 0;
573 pMgmt->sNodeDBTable[iNodeIndex].uWepKeyLength = 0;
574 pMgmt->sNodeDBTable[iNodeIndex].KeyRSC = 0;
575 pMgmt->sNodeDBTable[iNodeIndex].dwTSC47_16 = 0;
576 pMgmt->sNodeDBTable[iNodeIndex].wTSC15_0 = 0;
577 pMgmt->sNodeDBTable[iNodeIndex].byCipherSuite = 0;
578 memset(&pMgmt->sNodeDBTable[iNodeIndex].abyWepKey[0],
579 0,
580 MAX_KEY_LEN
581 );
582
583 return ret;
584 }
585
586 memcpy(abyKey, param->u.crypt.key, param->u.crypt.key_len);
587 // copy to node key tbl
588 pMgmt->sNodeDBTable[iNodeIndex].byKeyIndex = param->u.crypt.idx;
589 pMgmt->sNodeDBTable[iNodeIndex].uWepKeyLength = param->u.crypt.key_len;
590 memcpy(&pMgmt->sNodeDBTable[iNodeIndex].abyWepKey[0],
591 param->u.crypt.key,
592 param->u.crypt.key_len
593 );
594
595 dwKeyIndex = (DWORD)(param->u.crypt.idx);
596 if (param->u.crypt.flags & HOSTAP_CRYPT_FLAG_SET_TX_KEY) {
597 pDevice->byKeyIndex = (BYTE)dwKeyIndex;
598 pDevice->bTransmitKey = TRUE;
599 dwKeyIndex |= (1 << 31);
600 }
601
602 if (param->u.crypt.alg == WPA_ALG_WEP) {
603
604 if ((pDevice->bEnable8021x == FALSE) || (iNodeIndex == 0)) {
605 KeybSetDefaultKey(&(pDevice->sKey),
606 dwKeyIndex & ~(BIT30 | USE_KEYRSC),
607 param->u.crypt.key_len,
608 NULL,
609 abyKey,
610 KEY_CTL_WEP,
611 pDevice->PortOffset,
612 pDevice->byLocalID);
613
614 } else {
615 // 8021x enable, individual key
616 dwKeyIndex |= (1 << 30); // set pairwise key
617 if (KeybSetKey(&(pDevice->sKey),
618 &param->sta_addr[0],
619 dwKeyIndex & ~(USE_KEYRSC),
620 param->u.crypt.key_len,
621 (PQWORD) &(KeyRSC),
622 (PBYTE)abyKey,
623 KEY_CTL_WEP,
624 pDevice->PortOffset,
625 pDevice->byLocalID) == TRUE) {
626
627 pMgmt->sNodeDBTable[iNodeIndex].bOnFly = TRUE;
628
629 } else {
630 // Key Table Full
631 pMgmt->sNodeDBTable[iNodeIndex].bOnFly = FALSE;
632 bKeyTableFull = TRUE;
633 }
634 }
635 pDevice->eEncryptionStatus = Ndis802_11Encryption1Enabled;
636 pDevice->bEncryptionEnable = TRUE;
637 pMgmt->byCSSPK = KEY_CTL_WEP;
638 pMgmt->byCSSGK = KEY_CTL_WEP;
639 pMgmt->sNodeDBTable[iNodeIndex].byCipherSuite = KEY_CTL_WEP;
640 pMgmt->sNodeDBTable[iNodeIndex].dwKeyIndex = dwKeyIndex;
641 return ret;
642 }
643
644 if (param->u.crypt.seq) {
645 memcpy(&abySeq, param->u.crypt.seq, 8);
646 for (ii = 0 ; ii < 8 ; ii++) {
647 KeyRSC |= (abySeq[ii] << (ii * 8));
648 }
649 dwKeyIndex |= 1 << 29;
650 pMgmt->sNodeDBTable[iNodeIndex].KeyRSC = KeyRSC;
651 }
652
653 if (param->u.crypt.alg == WPA_ALG_TKIP) {
654 if (param->u.crypt.key_len != MAX_KEY_LEN)
655 return -EINVAL;
656 pDevice->eEncryptionStatus = Ndis802_11Encryption2Enabled;
657 byKeyDecMode = KEY_CTL_TKIP;
658 pMgmt->byCSSPK = KEY_CTL_TKIP;
659 pMgmt->byCSSGK = KEY_CTL_TKIP;
660 }
661
662 if (param->u.crypt.alg == WPA_ALG_CCMP) {
663 if ((param->u.crypt.key_len != AES_KEY_LEN) ||
664 (pDevice->byLocalID <= REV_ID_VT3253_A1))
665 return -EINVAL;
666 pDevice->eEncryptionStatus = Ndis802_11Encryption3Enabled;
667 byKeyDecMode = KEY_CTL_CCMP;
668 pMgmt->byCSSPK = KEY_CTL_CCMP;
669 pMgmt->byCSSGK = KEY_CTL_CCMP;
670 }
671
672
673 if (iNodeIndex == 0) {
674 KeybSetDefaultKey(&(pDevice->sKey),
675 dwKeyIndex,
676 param->u.crypt.key_len,
677 (PQWORD) &(KeyRSC),
678 abyKey,
679 byKeyDecMode,
680 pDevice->PortOffset,
681 pDevice->byLocalID);
682 pMgmt->sNodeDBTable[iNodeIndex].bOnFly = TRUE;
683
684 } else {
685 dwKeyIndex |= (1 << 30); // set pairwise key
686 if (KeybSetKey(&(pDevice->sKey),
687 &param->sta_addr[0],
688 dwKeyIndex,
689 param->u.crypt.key_len,
690 (PQWORD) &(KeyRSC),
691 (PBYTE)abyKey,
692 byKeyDecMode,
693 pDevice->PortOffset,
694 pDevice->byLocalID) == TRUE) {
695
696 pMgmt->sNodeDBTable[iNodeIndex].bOnFly = TRUE;
697
698 } else {
699 // Key Table Full
700 pMgmt->sNodeDBTable[iNodeIndex].bOnFly = FALSE;
701 bKeyTableFull = TRUE;
702 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO " Key Table Full\n");
703 }
704
705 }
706
707 if (bKeyTableFull == TRUE) {
708 wKeyCtl &= 0x7F00; // clear all key control filed
709 wKeyCtl |= (byKeyDecMode << 4);
710 wKeyCtl |= (byKeyDecMode);
711 wKeyCtl |= 0x0044; // use group key for all address
712 wKeyCtl |= 0x4000; // disable KeyTable[MAX_KEY_TABLE-1] on-fly to genernate rx int
713 MACvSetDefaultKeyCtl(pDevice->PortOffset, wKeyCtl, MAX_KEY_TABLE-1, pDevice->byLocalID);
714 }
715
716 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO " Set key sta_index= %d \n", iNodeIndex);
717 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO " tx_index=%d len=%d \n", param->u.crypt.idx,
718 param->u.crypt.key_len );
719 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO " key=%x-%x-%x-%x-%x-xxxxx \n",
720 pMgmt->sNodeDBTable[iNodeIndex].abyWepKey[0],
721 pMgmt->sNodeDBTable[iNodeIndex].abyWepKey[1],
722 pMgmt->sNodeDBTable[iNodeIndex].abyWepKey[2],
723 pMgmt->sNodeDBTable[iNodeIndex].abyWepKey[3],
724 pMgmt->sNodeDBTable[iNodeIndex].abyWepKey[4]
725 );
726
727 // set wep key
728 pDevice->bEncryptionEnable = TRUE;
729 pMgmt->sNodeDBTable[iNodeIndex].byCipherSuite = byKeyDecMode;
730 pMgmt->sNodeDBTable[iNodeIndex].dwKeyIndex = dwKeyIndex;
731 pMgmt->sNodeDBTable[iNodeIndex].dwTSC47_16 = 0;
732 pMgmt->sNodeDBTable[iNodeIndex].wTSC15_0 = 0;
733
734 return ret;
735}
736
737
738
739/*
740 * Description:
741 * get each stations encryption key
742 *
743 * Parameters:
744 * In:
745 * pDevice -
746 * param -
747 * Out:
748 *
749 * Return Value:
750 *
751 */
752static int hostap_get_encryption(PSDevice pDevice,
753 struct viawget_hostapd_param *param,
754 int param_len)
755{
756 PSMgmtObject pMgmt = pDevice->pMgmt;
757 int ret = 0;
758 int ii;
759 int iNodeIndex =0;
760
761
762 param->u.crypt.err = 0;
763
764 if (param->sta_addr[0] == 0xff && param->sta_addr[1] == 0xff &&
765 param->sta_addr[2] == 0xff && param->sta_addr[3] == 0xff &&
766 param->sta_addr[4] == 0xff && param->sta_addr[5] == 0xff) {
767 iNodeIndex = 0;
768 } else {
769 if (BSSDBbIsSTAInNodeDB(pMgmt, param->sta_addr, &iNodeIndex) == FALSE) {
770 param->u.crypt.err = HOSTAP_CRYPT_ERR_UNKNOWN_ADDR;
771 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "hostap_get_encryption: HOSTAP_CRYPT_ERR_UNKNOWN_ADDR\n");
772 return -EINVAL;
773 }
774 }
775 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "hostap_get_encryption: %d\n", iNodeIndex);
776 memset(param->u.crypt.seq, 0, 8);
777 for (ii = 0 ; ii < 8 ; ii++) {
778 param->u.crypt.seq[ii] = (BYTE)pMgmt->sNodeDBTable[iNodeIndex].KeyRSC >> (ii * 8);
779 }
780
781 return ret;
782}
783
784
785/*
786 * Description:
787 * hostap_ioctl main function supported for hostap deamon.
788 *
789 * Parameters:
790 * In:
791 * pDevice -
792 * iw_point -
793 * Out:
794 *
795 * Return Value:
796 *
797 */
798
799int hostap_ioctl(PSDevice pDevice, struct iw_point *p)
800{
801 struct viawget_hostapd_param *param;
802 int ret = 0;
803 int ap_ioctl = 0;
804
805 if (p->length < sizeof(struct viawget_hostapd_param) ||
806 p->length > VIAWGET_HOSTAPD_MAX_BUF_SIZE || !p->pointer)
807 return -EINVAL;
808
809 param = (struct viawget_hostapd_param *) kmalloc((int)p->length, (int)GFP_KERNEL);
810 if (param == NULL)
811 return -ENOMEM;
812
813 if (copy_from_user(param, p->pointer, p->length)) {
814 ret = -EFAULT;
815 goto out;
816 }
817
818 switch (param->cmd) {
819 case VIAWGET_HOSTAPD_SET_ENCRYPTION:
820 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "VIAWGET_HOSTAPD_SET_ENCRYPTION \n");
821 spin_lock_irq(&pDevice->lock);
822 ret = hostap_set_encryption(pDevice, param, p->length);
823 spin_unlock_irq(&pDevice->lock);
824 break;
825 case VIAWGET_HOSTAPD_GET_ENCRYPTION:
826 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "VIAWGET_HOSTAPD_GET_ENCRYPTION \n");
827 spin_lock_irq(&pDevice->lock);
828 ret = hostap_get_encryption(pDevice, param, p->length);
829 spin_unlock_irq(&pDevice->lock);
830 break;
831 case VIAWGET_HOSTAPD_SET_ASSOC_AP_ADDR:
832 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "VIAWGET_HOSTAPD_SET_ASSOC_AP_ADDR \n");
833 return -EOPNOTSUPP;
834 break;
835 case VIAWGET_HOSTAPD_FLUSH:
836 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "VIAWGET_HOSTAPD_FLUSH \n");
837 spin_lock_irq(&pDevice->lock);
838 hostap_flush_sta(pDevice);
839 spin_unlock_irq(&pDevice->lock);
840 break;
841 case VIAWGET_HOSTAPD_ADD_STA:
842 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "VIAWGET_HOSTAPD_ADD_STA \n");
843 spin_lock_irq(&pDevice->lock);
844 ret = hostap_add_sta(pDevice, param);
845 spin_unlock_irq(&pDevice->lock);
846 break;
847 case VIAWGET_HOSTAPD_REMOVE_STA:
848 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "VIAWGET_HOSTAPD_REMOVE_STA \n");
849 spin_lock_irq(&pDevice->lock);
850 ret = hostap_remove_sta(pDevice, param);
851 spin_unlock_irq(&pDevice->lock);
852 break;
853 case VIAWGET_HOSTAPD_GET_INFO_STA:
854 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "VIAWGET_HOSTAPD_GET_INFO_STA \n");
855 ret = hostap_get_info_sta(pDevice, param);
856 ap_ioctl = 1;
857 break;
858/*
859 case VIAWGET_HOSTAPD_RESET_TXEXC_STA:
860 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "VIAWGET_HOSTAPD_RESET_TXEXC_STA \n");
861 ret = hostap_reset_txexc_sta(pDevice, param);
862 break;
863*/
864 case VIAWGET_HOSTAPD_SET_FLAGS_STA:
865 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "VIAWGET_HOSTAPD_SET_FLAGS_STA \n");
866 ret = hostap_set_flags_sta(pDevice, param);
867 break;
868
869 case VIAWGET_HOSTAPD_MLME:
870 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "VIAWGET_HOSTAPD_MLME \n");
871 return -EOPNOTSUPP;
872
873 case VIAWGET_HOSTAPD_SET_GENERIC_ELEMENT:
874 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "VIAWGET_HOSTAPD_SET_GENERIC_ELEMENT \n");
875 ret = hostap_set_generic_element(pDevice, param);
876 break;
877
878 case VIAWGET_HOSTAPD_SCAN_REQ:
879 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "VIAWGET_HOSTAPD_SCAN_REQ \n");
880 return -EOPNOTSUPP;
881
882 case VIAWGET_HOSTAPD_STA_CLEAR_STATS:
883 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "VIAWGET_HOSTAPD_STA_CLEAR_STATS \n");
884 return -EOPNOTSUPP;
885
886 default:
887 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "hostap_ioctl: unknown cmd=%d\n",
888 (int)param->cmd);
889 return -EOPNOTSUPP;
890 break;
891 }
892
893
894 if ((ret == 0) && ap_ioctl) {
895 if (copy_to_user(p->pointer, param, p->length)) {
896 ret = -EFAULT;
897 goto out;
898 }
899 }
900
901 out:
902 if (param != NULL)
903 kfree(param);
904
905 return ret;
906}
907
diff --git a/drivers/staging/vt6655/hostap.h b/drivers/staging/vt6655/hostap.h
new file mode 100644
index 000000000000..1fcb2f0788b3
--- /dev/null
+++ b/drivers/staging/vt6655/hostap.h
@@ -0,0 +1,94 @@
1/*
2 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
3 * All rights reserved.
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * File: hostap.h
20 *
21 * Purpose:
22 *
23 * Author: Lyndon Chen
24 *
25 * Date: May 21, 2003
26 *
27 */
28
29
30#ifndef __HOSTAP_H__
31#define __HOSTAP_H__
32
33#if !defined(__DEVICE_H__)
34#include "device.h"
35#endif
36
37
38/*--------------------- Export Definitions -------------------------*/
39
40#if WIRELESS_EXT < 9
41struct iw_point {
42 caddr_t pointer;
43 __u16 length;
44 __u16 flags;
45};
46#endif /* WIRELESS_EXT < 9 */
47
48#define WLAN_RATE_1M BIT0
49#define WLAN_RATE_2M BIT1
50#define WLAN_RATE_5M5 BIT2
51#define WLAN_RATE_11M BIT3
52#define WLAN_RATE_6M BIT4
53#define WLAN_RATE_9M BIT5
54#define WLAN_RATE_12M BIT6
55#define WLAN_RATE_18M BIT7
56#define WLAN_RATE_24M BIT8
57#define WLAN_RATE_36M BIT9
58#define WLAN_RATE_48M BIT10
59#define WLAN_RATE_54M BIT11
60
61
62/*--------------------- Export Classes ----------------------------*/
63
64/*--------------------- Export Variables --------------------------*/
65
66/*--------------------- Export Functions --------------------------*/
67
68
69#ifdef __cplusplus
70extern "C" { /* Assume C declarations for C++ */
71#endif /* __cplusplus */
72
73#ifndef ETH_P_PAE
74#define ETH_P_PAE 0x888E /* Port Access Entity (IEEE 802.1X) */
75#endif /* ETH_P_PAE */
76
77#ifndef ARPHRD_IEEE80211
78#define ARPHRD_IEEE80211 801
79#endif
80
81int hostap_set_hostapd(PSDevice pDevice, int val, int rtnl_locked);
82int hostap_ioctl(PSDevice pDevice, struct iw_point *p);
83
84#ifdef __cplusplus
85} /* End of extern "C" { */
86#endif /* __cplusplus */
87
88
89
90
91#endif // __HOSTAP_H__
92
93
94
diff --git a/drivers/staging/vt6655/ioctl.c b/drivers/staging/vt6655/ioctl.c
new file mode 100644
index 000000000000..4869107a2bca
--- /dev/null
+++ b/drivers/staging/vt6655/ioctl.c
@@ -0,0 +1,775 @@
1/*
2 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
3 * All rights reserved.
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * File: ioctl.c
20 *
21 * Purpose: private ioctl functions
22 *
23 * Author: Lyndon Chen
24 *
25 * Date: Auguest 20, 2003
26 *
27 * Functions:
28 *
29 * Revision History:
30 *
31 */
32
33
34#if !defined(__IOCTL_H__)
35#include "ioctl.h"
36#endif
37#if !defined(__IOCMD_H__)
38#include "iocmd.h"
39#endif
40#if !defined(__MAC_H__)
41#include "mac.h"
42#endif
43#if !defined(__CARD_H__)
44#include "card.h"
45#endif
46#if !defined(__HOSTAP_H__)
47#include "hostap.h"
48#endif
49#if !defined(__UMEM_H__)
50#include "umem.h"
51#endif
52#if !defined(__WPACTL_H__)
53#include "wpactl.h"
54#endif
55#if !defined(__RF_H__)
56#include "rf.h"
57#endif
58
59
60/*--------------------- Static Definitions -------------------------*/
61
62/*--------------------- Static Classes ----------------------------*/
63
64/*--------------------- Static Variables --------------------------*/
65//static int msglevel =MSG_LEVEL_DEBUG;
66static int msglevel =MSG_LEVEL_INFO;
67
68/*--------------------- Static Functions --------------------------*/
69
70#ifdef WPA_SM_Transtatus
71 SWPAResult wpa_Result;
72#endif
73
74
75/*--------------------- Export Variables --------------------------*/
76
77int private_ioctl(PSDevice pDevice, struct ifreq *rq) {
78
79 PSCmdRequest pReq = (PSCmdRequest)rq;
80 PSMgmtObject pMgmt = pDevice->pMgmt;
81 int result = 0;
82 PWLAN_IE_SSID pItemSSID;
83 SCmdBSSJoin sJoinCmd;
84 SCmdZoneTypeSet sZoneTypeCmd;
85 SCmdScan sScanCmd;
86 SCmdStartAP sStartAPCmd;
87 SCmdSetWEP sWEPCmd;
88 SCmdValue sValue;
89 SBSSIDList sList;
90 SNodeList sNodeList;
91 PSBSSIDList pList;
92 PSNodeList pNodeList;
93 UINT cbListCount;
94 PKnownBSS pBSS;
95 PKnownNodeDB pNode;
96 UINT ii, jj;
97 SCmdLinkStatus sLinkStatus;
98 BYTE abySuppRates[] = {WLAN_EID_SUPP_RATES, 4, 0x02, 0x04, 0x0B, 0x16};
99 BYTE abyNullAddr[] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
100 DWORD dwKeyIndex= 0;
101 BYTE abyScanSSID[WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1];
102 LONG ldBm;
103
104
105 pReq->wResult = 0;
106
107 switch(pReq->wCmdCode) {
108
109 case WLAN_CMD_BSS_SCAN:
110
111 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "WLAN_CMD_BSS_SCAN..begin \n");
112 if (copy_from_user(&sScanCmd, pReq->data, sizeof(SCmdScan))) {
113 result = -EFAULT;
114 break;
115 };
116
117 pItemSSID = (PWLAN_IE_SSID)sScanCmd.ssid;
118 if (pItemSSID->len != 0) {
119 memset(abyScanSSID, 0, WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1);
120 memcpy(abyScanSSID, pItemSSID, pItemSSID->len + WLAN_IEHDR_LEN);
121 }
122
123 if (pDevice->bMACSuspend == TRUE) {
124 if (pDevice->bRadioOff == TRUE)
125 CARDbRadioPowerOn(pDevice);
126 vMgrTimerInit(pDevice);
127 MACvIntEnable(pDevice->PortOffset, IMR_MASK_VALUE);
128 add_timer(&pMgmt->sTimerSecondCallback);
129 pDevice->bMACSuspend = FALSE;
130 }
131 spin_lock_irq(&pDevice->lock);
132 if (memcmp(pMgmt->abyCurrBSSID, &abyNullAddr[0], 6) == 0)
133 BSSvClearBSSList((HANDLE)pDevice, FALSE);
134 else
135 BSSvClearBSSList((HANDLE)pDevice, pDevice->bLinkPass);
136
137 if (pItemSSID->len != 0)
138 bScheduleCommand((HANDLE) pDevice, WLAN_CMD_BSSID_SCAN, abyScanSSID);
139 else
140 bScheduleCommand((HANDLE) pDevice, WLAN_CMD_BSSID_SCAN, NULL);
141 spin_unlock_irq(&pDevice->lock);
142 break;
143
144 case WLAN_CMD_ZONETYPE_SET:
145 //mike add :cann't support.
146 result=-EOPNOTSUPP;
147 break;
148
149 if (copy_from_user(&sZoneTypeCmd, pReq->data, sizeof(SCmdZoneTypeSet))) {
150 result = -EFAULT;
151 break;
152 };
153
154 if(sZoneTypeCmd.bWrite==TRUE) {
155 //////write zonetype
156 if(sZoneTypeCmd.ZoneType == ZoneType_USA) {
157 //set to USA
158 printk("set_ZoneType:USA\n");
159 }
160 else if(sZoneTypeCmd.ZoneType == ZoneType_Japan) {
161 //set to Japan
162 printk("set_ZoneType:Japan\n");
163 }
164 else if(sZoneTypeCmd.ZoneType == ZoneType_Europe) {
165 //set to Europe
166 printk("set_ZoneType:Europe\n");
167 }
168 }
169 else {
170 ///////read zonetype
171 BYTE zonetype=0;
172
173
174 if(zonetype == 0x00) { //USA
175 sZoneTypeCmd.ZoneType = ZoneType_USA;
176 }
177 else if(zonetype == 0x01) { //Japan
178 sZoneTypeCmd.ZoneType = ZoneType_Japan;
179 }
180 else if(zonetype == 0x02) { //Europe
181 sZoneTypeCmd.ZoneType = ZoneType_Europe;
182 }
183 else { //Unknow ZoneType
184 printk("Error:ZoneType[%x] Unknown ???\n",zonetype);
185 result = -EFAULT;
186 break;
187 }
188 if (copy_to_user(pReq->data, &sZoneTypeCmd, sizeof(SCmdZoneTypeSet))) {
189 result = -EFAULT;
190 break;
191 };
192 }
193
194 break;
195
196 case WLAN_CMD_BSS_JOIN:
197
198 if (pDevice->bMACSuspend == TRUE) {
199 if (pDevice->bRadioOff == TRUE)
200 CARDbRadioPowerOn(pDevice);
201 vMgrTimerInit(pDevice);
202 MACvIntEnable(pDevice->PortOffset, IMR_MASK_VALUE);
203 add_timer(&pMgmt->sTimerSecondCallback);
204 pDevice->bMACSuspend = FALSE;
205 }
206
207 if (copy_from_user(&sJoinCmd, pReq->data, sizeof(SCmdBSSJoin))) {
208 result = -EFAULT;
209 break;
210 };
211
212 pItemSSID = (PWLAN_IE_SSID)sJoinCmd.ssid;
213 memset(pMgmt->abyDesireSSID, 0, WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1);
214 memcpy(pMgmt->abyDesireSSID, pItemSSID, pItemSSID->len + WLAN_IEHDR_LEN);
215 if (sJoinCmd.wBSSType == ADHOC) {
216 pMgmt->eConfigMode = WMAC_CONFIG_IBSS_STA;
217 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "ioct set to adhoc mode\n");
218 }
219 else {
220 pMgmt->eConfigMode = WMAC_CONFIG_ESS_STA;
221 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "ioct set to STA mode\n");
222 }
223 if (sJoinCmd.bPSEnable == TRUE) {
224 pDevice->ePSMode = WMAC_POWER_FAST;
225// pDevice->ePSMode = WMAC_POWER_MAX;
226 pMgmt->wListenInterval = 2;
227 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Power Saving On\n");
228 }
229 else {
230 pDevice->ePSMode = WMAC_POWER_CAM;
231 pMgmt->wListenInterval = 1;
232 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Power Saving Off \n");
233 }
234
235 if (sJoinCmd.bShareKeyAuth == TRUE){
236 pMgmt->bShareKeyAlgorithm = TRUE;
237 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Share Key \n");
238 }
239 else {
240 pMgmt->bShareKeyAlgorithm = FALSE;
241 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Open System \n");
242 }
243 pDevice->uChannel = sJoinCmd.uChannel;
244 netif_stop_queue(pDevice->dev);
245 spin_lock_irq(&pDevice->lock);
246 pMgmt->eCurrState = WMAC_STATE_IDLE;
247 bScheduleCommand((HANDLE) pDevice, WLAN_CMD_BSSID_SCAN, pMgmt->abyDesireSSID);
248 bScheduleCommand((HANDLE) pDevice, WLAN_CMD_SSID, NULL);
249 spin_unlock_irq(&pDevice->lock);
250 break;
251
252 case WLAN_CMD_SET_WEP:
253
254 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "WLAN_CMD_SET_WEP Key. \n");
255 memset(&sWEPCmd, 0 ,sizeof(SCmdSetWEP));
256 if (copy_from_user(&sWEPCmd, pReq->data, sizeof(SCmdSetWEP))) {
257 result = -EFAULT;
258 break;
259 };
260 if (sWEPCmd.bEnableWep != TRUE) {
261 pDevice->bEncryptionEnable = FALSE;
262 pDevice->eEncryptionStatus = Ndis802_11EncryptionDisabled;
263 MACvDisableDefaultKey(pDevice->PortOffset);
264 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "WEP function disable. \n");
265 break;
266 }
267
268 for (ii = 0; ii < WLAN_WEP_NKEYS; ii ++) {
269 if (sWEPCmd.bWepKeyAvailable[ii]) {
270 if (ii == sWEPCmd.byKeyIndex)
271 //2006-1123-02,<Modify> by EinsnLiu
272 //Evaluate the "dwKeyIndex" error
273 // dwKeyIndex |= (1 << 31);
274 dwKeyIndex =ii|(1 << 31);
275 else
276 dwKeyIndex = ii;
277
278 KeybSetDefaultKey(&(pDevice->sKey),
279 dwKeyIndex,
280 sWEPCmd.auWepKeyLength[ii],
281 NULL,
282 (PBYTE)&sWEPCmd.abyWepKey[ii][0],
283 KEY_CTL_WEP,
284 pDevice->PortOffset,
285 pDevice->byLocalID);
286 }
287 }
288 pDevice->byKeyIndex = sWEPCmd.byKeyIndex;
289 pDevice->bTransmitKey = TRUE;
290 pDevice->bEncryptionEnable = TRUE;
291 pDevice->eEncryptionStatus = Ndis802_11Encryption1Enabled;
292
293 break;
294
295 case WLAN_CMD_GET_LINK:
296 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "WLAN_CMD_GET_LINK status. \n");
297
298 memset(sLinkStatus.abySSID, 0 , WLAN_SSID_MAXLEN + 1);
299
300 if (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA)
301 sLinkStatus.wBSSType = ADHOC;
302 else
303 sLinkStatus.wBSSType = INFRA;
304
305 if (pMgmt->eCurrState == WMAC_STATE_JOINTED)
306 sLinkStatus.byState = ADHOC_JOINTED;
307 else
308 sLinkStatus.byState = ADHOC_STARTED;
309
310 sLinkStatus.uChannel = pMgmt->uCurrChannel;
311 if (pDevice->bLinkPass == TRUE) {
312 sLinkStatus.bLink = TRUE;
313 pItemSSID = (PWLAN_IE_SSID)pMgmt->abyCurrSSID;
314 memcpy(sLinkStatus.abySSID, pItemSSID->abySSID, pItemSSID->len);
315 memcpy(sLinkStatus.abyBSSID, pMgmt->abyCurrBSSID, WLAN_BSSID_LEN);
316 sLinkStatus.uLinkRate = pMgmt->sNodeDBTable[0].wTxDataRate;
317 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO" Link Success ! \n");
318 }
319 else {
320 sLinkStatus.bLink = FALSE;
321 }
322 if (copy_to_user(pReq->data, &sLinkStatus, sizeof(SCmdLinkStatus))) {
323 result = -EFAULT;
324 break;
325 };
326
327 break;
328
329 case WLAN_CMD_GET_LISTLEN:
330 cbListCount = 0;
331 pBSS = &(pMgmt->sBSSList[0]);
332 for (ii = 0; ii < MAX_BSS_NUM; ii++) {
333 pBSS = &(pMgmt->sBSSList[ii]);
334 if (!pBSS->bActive)
335 continue;
336 cbListCount++;
337 };
338 sList.uItem = cbListCount;
339 if (copy_to_user(pReq->data, &sList, sizeof(SBSSIDList))) {
340 result = -EFAULT;
341 break;
342 };
343 pReq->wResult = 0;
344 break;
345
346 case WLAN_CMD_GET_LIST:
347 if (copy_from_user(&sList, pReq->data, sizeof(SBSSIDList))) {
348 result = -EFAULT;
349 break;
350 };
351 pList = (PSBSSIDList)kmalloc(sizeof(SBSSIDList) + (sList.uItem * sizeof(SBSSIDItem)), (int)GFP_ATOMIC);
352 if (pList == NULL) {
353 result = -ENOMEM;
354 break;
355 }
356 pList->uItem = sList.uItem;
357 pBSS = &(pMgmt->sBSSList[0]);
358 for (ii = 0, jj = 0; jj < MAX_BSS_NUM ; jj++) {
359 pBSS = &(pMgmt->sBSSList[jj]);
360 if (pBSS->bActive) {
361 pList->sBSSIDList[ii].uChannel = pBSS->uChannel;
362 pList->sBSSIDList[ii].wBeaconInterval = pBSS->wBeaconInterval;
363 pList->sBSSIDList[ii].wCapInfo = pBSS->wCapInfo;
364// pList->sBSSIDList[ii].uRSSI = pBSS->uRSSI;
365 RFvRSSITodBm(pDevice, (BYTE)(pBSS->uRSSI), &ldBm);
366 pList->sBSSIDList[ii].uRSSI = (UINT)ldBm;
367 memcpy(pList->sBSSIDList[ii].abyBSSID, pBSS->abyBSSID, WLAN_BSSID_LEN);
368 pItemSSID = (PWLAN_IE_SSID)pBSS->abySSID;
369 memset(pList->sBSSIDList[ii].abySSID, 0, WLAN_SSID_MAXLEN + 1);
370 memcpy(pList->sBSSIDList[ii].abySSID, pItemSSID->abySSID, pItemSSID->len);
371 if (WLAN_GET_CAP_INFO_ESS(pBSS->wCapInfo)) {
372 pList->sBSSIDList[ii].byNetType = INFRA;
373 }
374 else {
375 pList->sBSSIDList[ii].byNetType = ADHOC;
376 }
377 if (WLAN_GET_CAP_INFO_PRIVACY(pBSS->wCapInfo)) {
378 pList->sBSSIDList[ii].bWEPOn = TRUE;
379 }
380 else {
381 pList->sBSSIDList[ii].bWEPOn = FALSE;
382 }
383 ii ++;
384 if (ii >= pList->uItem)
385 break;
386 }
387 }
388
389 if (copy_to_user(pReq->data, pList, sizeof(SBSSIDList) + (sList.uItem * sizeof(SBSSIDItem)))) {
390 result = -EFAULT;
391 break;
392 };
393 kfree(pList);
394 pReq->wResult = 0;
395 break;
396
397 case WLAN_CMD_GET_MIB:
398 if (copy_to_user(pReq->data, &(pDevice->s802_11Counter), sizeof(SDot11MIBCount))) {
399 result = -EFAULT;
400 break;
401 };
402 break;
403
404 case WLAN_CMD_GET_STAT:
405 if (copy_to_user(pReq->data, &(pDevice->scStatistic), sizeof(SStatCounter))) {
406 result = -EFAULT;
407 break;
408 };
409 break;
410 case WLAN_CMD_STOP_MAC:
411
412 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "WLAN_CMD_STOP_MAC\n");
413 netif_stop_queue(pDevice->dev);
414
415 spin_lock_irq(&pDevice->lock);
416 if (pDevice->bRadioOff == FALSE) {
417 CARDbRadioPowerOff(pDevice);
418 }
419 pDevice->bLinkPass = FALSE;
420 memset(pMgmt->abyCurrBSSID, 0, 6);
421 pMgmt->eCurrState = WMAC_STATE_IDLE;
422 del_timer(&pDevice->sTimerCommand);
423 del_timer(&pMgmt->sTimerSecondCallback);
424 pDevice->bCmdRunning = FALSE;
425 pDevice->bMACSuspend = TRUE;
426 MACvIntDisable(pDevice->PortOffset);
427 spin_unlock_irq(&pDevice->lock);
428
429 break;
430
431 case WLAN_CMD_START_MAC:
432
433 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "WLAN_CMD_START_MAC\n");
434
435 if (pDevice->bMACSuspend == TRUE) {
436 if (pDevice->bRadioOff == TRUE)
437 CARDbRadioPowerOn(pDevice);
438 vMgrTimerInit(pDevice);
439 MACvIntEnable(pDevice->PortOffset, IMR_MASK_VALUE);
440 add_timer(&pMgmt->sTimerSecondCallback);
441 pDevice->bMACSuspend = FALSE;
442 }
443 break;
444
445 case WLAN_CMD_SET_HOSTAPD:
446
447 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "WLAN_CMD_SET_HOSTAPD\n");
448
449 if (copy_from_user(&sValue, pReq->data, sizeof(SCmdValue))) {
450 result = -EFAULT;
451 break;
452 };
453 if (sValue.dwValue == 1) {
454 if (hostap_set_hostapd(pDevice, 1, 1) == 0){
455 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Enable HOSTAP\n");
456 }
457 else {
458 result = -EFAULT;
459 break;
460 }
461 }
462 else {
463 hostap_set_hostapd(pDevice, 0, 1);
464 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Disable HOSTAP\n");
465 }
466
467 break;
468
469 case WLAN_CMD_SET_HOSTAPD_STA:
470
471 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "WLAN_CMD_SET_HOSTAPD_STA\n");
472
473 break;
474 case WLAN_CMD_SET_802_1X:
475
476 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "WLAN_CMD_SET_802_1X\n");
477 if (copy_from_user(&sValue, pReq->data, sizeof(SCmdValue))) {
478 result = -EFAULT;
479 break;
480 };
481
482 if (sValue.dwValue == 1) {
483 pDevice->bEnable8021x = TRUE;
484 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Enable 802.1x\n");
485 }
486 else {
487 pDevice->bEnable8021x = FALSE;
488 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Disable 802.1x\n");
489 }
490
491 break;
492
493
494 case WLAN_CMD_SET_HOST_WEP:
495
496 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "WLAN_CMD_SET_HOST_WEP\n");
497 if (copy_from_user(&sValue, pReq->data, sizeof(SCmdValue))) {
498 result = -EFAULT;
499 break;
500 };
501
502 if (sValue.dwValue == 1) {
503 pDevice->bEnableHostWEP = TRUE;
504 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Enable HostWEP\n");
505 }
506 else {
507 pDevice->bEnableHostWEP = FALSE;
508 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Disable HostWEP\n");
509 }
510
511 break;
512
513 case WLAN_CMD_SET_WPA:
514 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "WLAN_CMD_SET_WPA\n");
515
516 if (copy_from_user(&sValue, pReq->data, sizeof(SCmdValue))) {
517 result = -EFAULT;
518 break;
519 };
520 if (sValue.dwValue == 1) {
521 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "up wpadev\n");
522 memcpy(pDevice->wpadev->dev_addr, pDevice->dev->dev_addr, U_ETHER_ADDR_LEN);
523 pDevice->bWPADEVUp = TRUE;
524 }
525 else {
526 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "close wpadev\n");
527 pDevice->bWPADEVUp = FALSE;
528 }
529
530 break;
531
532 case WLAN_CMD_AP_START:
533
534 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "WLAN_CMD_AP_START\n");
535 if (pDevice->bRadioOff == TRUE) {
536 CARDbRadioPowerOn(pDevice);
537 vMgrTimerInit(pDevice);
538 MACvIntEnable(pDevice->PortOffset, IMR_MASK_VALUE);
539 add_timer(&pMgmt->sTimerSecondCallback);
540 }
541 if (copy_from_user(&sStartAPCmd, pReq->data, sizeof(SCmdStartAP))) {
542 result = -EFAULT;
543 break;
544 };
545
546 if (sStartAPCmd.wBSSType == AP) {
547 pMgmt->eConfigMode = WMAC_CONFIG_AP;
548 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "ioct set to AP mode\n");
549 }
550 else {
551 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "ioct BSS type not set to AP mode\n");
552 result = -EFAULT;
553 break;
554 }
555
556
557 if (sStartAPCmd.wBBPType == PHY80211g) {
558 pMgmt->byAPBBType = PHY_TYPE_11G;
559 }
560 else if (sStartAPCmd.wBBPType == PHY80211a) {
561 pMgmt->byAPBBType = PHY_TYPE_11A;
562 }
563 else {
564 pMgmt->byAPBBType = PHY_TYPE_11B;
565 }
566
567 pItemSSID = (PWLAN_IE_SSID)sStartAPCmd.ssid;
568 memset(pMgmt->abyDesireSSID, 0, WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1);
569 memcpy(pMgmt->abyDesireSSID, pItemSSID, pItemSSID->len + WLAN_IEHDR_LEN);
570
571 if ((sStartAPCmd.uChannel > 0)&&(sStartAPCmd.uChannel <= 14))
572 pDevice->uChannel = sStartAPCmd.uChannel;
573
574 if ((sStartAPCmd.uBeaconInt >= 20) && (sStartAPCmd.uBeaconInt <= 1000))
575 pMgmt->wIBSSBeaconPeriod = sStartAPCmd.uBeaconInt;
576 else
577 pMgmt->wIBSSBeaconPeriod = 100;
578
579 if (sStartAPCmd.bShareKeyAuth == TRUE){
580 pMgmt->bShareKeyAlgorithm = TRUE;
581 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Share Key \n");
582 }
583 else {
584 pMgmt->bShareKeyAlgorithm = FALSE;
585 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Open System \n");
586 }
587 memcpy(pMgmt->abyIBSSSuppRates, abySuppRates, 6);
588
589 if (sStartAPCmd.byBasicRate & BIT3) {
590 pMgmt->abyIBSSSuppRates[2] |= BIT7;
591 pMgmt->abyIBSSSuppRates[3] |= BIT7;
592 pMgmt->abyIBSSSuppRates[4] |= BIT7;
593 pMgmt->abyIBSSSuppRates[5] |= BIT7;
594 }else if (sStartAPCmd.byBasicRate & BIT2) {
595 pMgmt->abyIBSSSuppRates[2] |= BIT7;
596 pMgmt->abyIBSSSuppRates[3] |= BIT7;
597 pMgmt->abyIBSSSuppRates[4] |= BIT7;
598 }else if (sStartAPCmd.byBasicRate & BIT1) {
599 pMgmt->abyIBSSSuppRates[2] |= BIT7;
600 pMgmt->abyIBSSSuppRates[3] |= BIT7;
601 }else if (sStartAPCmd.byBasicRate & BIT1) {
602 pMgmt->abyIBSSSuppRates[2] |= BIT7;
603 }else {
604 //default 1,2M
605 pMgmt->abyIBSSSuppRates[2] |= BIT7;
606 pMgmt->abyIBSSSuppRates[3] |= BIT7;
607 }
608
609 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Support Rate= %x %x %x %x\n",
610 pMgmt->abyIBSSSuppRates[2],
611 pMgmt->abyIBSSSuppRates[3],
612 pMgmt->abyIBSSSuppRates[4],
613 pMgmt->abyIBSSSuppRates[5]
614 );
615
616 netif_stop_queue(pDevice->dev);
617 spin_lock_irq(&pDevice->lock);
618 bScheduleCommand((HANDLE)pDevice, WLAN_CMD_RUN_AP, NULL);
619 spin_unlock_irq(&pDevice->lock);
620 break;
621
622 case WLAN_CMD_GET_NODE_CNT:
623
624 cbListCount = 0;
625 pNode = &(pMgmt->sNodeDBTable[0]);
626 for (ii = 0; ii < (MAX_NODE_NUM + 1); ii++) {
627 pNode = &(pMgmt->sNodeDBTable[ii]);
628 if (!pNode->bActive)
629 continue;
630 cbListCount++;
631 };
632
633 sNodeList.uItem = cbListCount;
634 if (copy_to_user(pReq->data, &sNodeList, sizeof(SNodeList))) {
635 result = -EFAULT;
636 break;
637 };
638 pReq->wResult = 0;
639 break;
640
641 case WLAN_CMD_GET_NODE_LIST:
642
643 if (copy_from_user(&sNodeList, pReq->data, sizeof(SNodeList))) {
644 result = -EFAULT;
645 break;
646 };
647 pNodeList = (PSNodeList)kmalloc(sizeof(SNodeList) + (sNodeList.uItem * sizeof(SNodeItem)), (int)GFP_ATOMIC);
648 if (pNodeList == NULL) {
649 result = -ENOMEM;
650 break;
651 }
652 pNodeList->uItem = sNodeList.uItem;
653 pNode = &(pMgmt->sNodeDBTable[0]);
654 for (ii = 0, jj = 0; ii < (MAX_NODE_NUM + 1); ii++) {
655 pNode = &(pMgmt->sNodeDBTable[ii]);
656 if (pNode->bActive) {
657 pNodeList->sNodeList[jj].wAID = pNode->wAID;
658 memcpy(pNodeList->sNodeList[jj].abyMACAddr, pNode->abyMACAddr, WLAN_ADDR_LEN);
659 pNodeList->sNodeList[jj].wTxDataRate = pNode->wTxDataRate;
660 pNodeList->sNodeList[jj].wInActiveCount = (WORD)pNode->uInActiveCount;
661 pNodeList->sNodeList[jj].wEnQueueCnt = (WORD)pNode->wEnQueueCnt;
662 pNodeList->sNodeList[jj].wFlags = (WORD)pNode->dwFlags;
663 pNodeList->sNodeList[jj].bPWBitOn = pNode->bPSEnable;
664 pNodeList->sNodeList[jj].byKeyIndex = pNode->byKeyIndex;
665 pNodeList->sNodeList[jj].wWepKeyLength = pNode->uWepKeyLength;
666 memcpy(&(pNodeList->sNodeList[jj].abyWepKey[0]), &(pNode->abyWepKey[0]), WEP_KEYMAXLEN);
667 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "key= %2.2X:%2.2X:%2.2X:%2.2X:%2.2X\n",
668 pNodeList->sNodeList[jj].abyWepKey[0],
669 pNodeList->sNodeList[jj].abyWepKey[1],
670 pNodeList->sNodeList[jj].abyWepKey[2],
671 pNodeList->sNodeList[jj].abyWepKey[3],
672 pNodeList->sNodeList[jj].abyWepKey[4]
673 );
674 pNodeList->sNodeList[jj].bIsInFallback = pNode->bIsInFallback;
675 pNodeList->sNodeList[jj].uTxFailures = pNode->uTxFailures;
676 pNodeList->sNodeList[jj].uTxAttempts = pNode->uTxAttempts;
677 pNodeList->sNodeList[jj].wFailureRatio = (WORD)pNode->uFailureRatio;
678 jj ++;
679 if (jj >= pNodeList->uItem)
680 break;
681 }
682 };
683 if (copy_to_user(pReq->data, pNodeList, sizeof(SNodeList) + (sNodeList.uItem * sizeof(SNodeItem)))) {
684 result = -EFAULT;
685 break;
686 };
687 kfree(pNodeList);
688 pReq->wResult = 0;
689 break;
690
691#ifdef WPA_SM_Transtatus
692 case 0xFF:
693 memset(wpa_Result.ifname,0,sizeof(wpa_Result.ifname));
694 wpa_Result.proto = 0;
695 wpa_Result.key_mgmt = 0;
696 wpa_Result.eap_type = 0;
697 wpa_Result.authenticated = FALSE;
698 pDevice->fWPA_Authened = FALSE;
699 if (copy_from_user(&wpa_Result, pReq->data, sizeof(wpa_Result))) {
700 result = -EFAULT;
701 break;
702 }
703
704 if(wpa_Result.authenticated==TRUE) {
705 #ifdef SndEvt_ToAPI
706 {
707 union iwreq_data wrqu;
708
709 pItemSSID = (PWLAN_IE_SSID)pMgmt->abyCurrSSID;
710
711 memset(&wrqu, 0, sizeof(wrqu));
712 wrqu.data.flags = RT_WPACONNECTED_EVENT_FLAG;
713 wrqu.data.length =pItemSSID->len;
714 wireless_send_event(pDevice->dev, IWEVCUSTOM, &wrqu, pItemSSID->abySSID);
715 }
716 #endif
717 pDevice->fWPA_Authened = TRUE; //is sucessful peer to wpa_Result.authenticated?
718}
719
720 //printk("get private wpa_supplicant announce WPA SM\n");
721 //printk("wpa-->ifname=%s\n",wpa_Result.ifname);
722 //printk("wpa-->proto=%d\n",wpa_Result.proto);
723 //printk("wpa-->key-mgmt=%d\n",wpa_Result.key_mgmt);
724 //printk("wpa-->eap_type=%d\n",wpa_Result.eap_type);
725 //printk("wpa-->authenticated is %s\n",(wpa_Result.authenticated==TRUE)?"TRUE":"FALSE");
726
727 pReq->wResult = 0;
728 break;
729#endif
730
731
732 default:
733 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Private command not support..\n");
734 }
735
736 return result;
737}
738
739/*
740VOID
741vConfigWEPKey (
742 IN PSDevice pDevice,
743 IN DWORD dwKeyIndex,
744 IN PBYTE pbyKey,
745 IN ULONG uKeyLength
746 )
747{
748 int ii;
749
750
751 ZERO_MEMORY(&pDevice->abyWepKey[dwKeyIndex][0], WLAN_WEPMAX_KEYLEN);
752 MEMvCopy(&pDevice->abyWepKey[dwKeyIndex][0], pbyKey, uKeyLength);
753
754 pDevice->bWepKeyAvailable[dwKeyIndex] = TRUE;
755 pDevice->auWepKeyLength[dwKeyIndex] = uKeyLength;
756
757 MACvSetDefaultKeyEntry(pDevice->PortOffset, uKeyLength, dwKeyIndex,
758 (PDWORD) &(pDevice->abyWepKey[dwKeyIndex][0]), pDevice->byLocalID);
759
760 if (pDevice->eEncryptionStatus < Ndis802_11EncryptionNotSupported) {
761 for(ii=0; ii<MAX_GROUP_KEY; ii++) {
762 if ((pDevice->bWepKeyAvailable[ii] == TRUE) &&
763 (pDevice->auWepKeyLength[ii] == WLAN_WEP232_KEYLEN)) {
764 pDevice->uCurrentWEPMode = TX_WEP_SW232;
765 MACvDisableDefaultKey(pDevice->PortOffset);
766 break;
767 }
768 }
769 if ((ii == MAX_GROUP_KEY) &&
770 (pDevice->eEncryptionStatus < Ndis802_11EncryptionNotSupported)) {
771 MACvEnableDefaultKey(pDevice->PortOffset, pDevice->byLocalID);
772 }
773 }
774}
775*/
diff --git a/drivers/staging/vt6655/ioctl.h b/drivers/staging/vt6655/ioctl.h
new file mode 100644
index 000000000000..9c6816eab46c
--- /dev/null
+++ b/drivers/staging/vt6655/ioctl.h
@@ -0,0 +1,74 @@
1/*
2 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
3 * All rights reserved.
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * File: hostap.h
20 *
21 * Purpose:
22 *
23 * Author: Lyndon Chen
24 *
25 * Date: May 21, 2003
26 *
27 */
28
29
30#ifndef __IOCTL_H__
31#define __IOCTL_H__
32
33#if !defined(__DEVICE_H__)
34#include "device.h"
35#endif
36
37
38/*--------------------- Export Definitions -------------------------*/
39
40
41/*--------------------- Export Classes ----------------------------*/
42
43/*--------------------- Export Variables --------------------------*/
44
45/*--------------------- Export Functions --------------------------*/
46
47
48#ifdef __cplusplus
49extern "C" { /* Assume C declarations for C++ */
50#endif /* __cplusplus */
51
52
53int private_ioctl(PSDevice pDevice, struct ifreq *rq);
54
55/*
56VOID vConfigWEPKey (
57 IN PSDevice pDevice,
58 IN DWORD dwKeyIndex,
59 IN PBYTE pbyKey,
60 IN ULONG uKeyLength
61 );
62*/
63
64#ifdef __cplusplus
65} /* End of extern "C" { */
66#endif /* __cplusplus */
67
68
69
70
71#endif // __IOCTL_H__
72
73
74
diff --git a/drivers/staging/vt6655/iwctl.c b/drivers/staging/vt6655/iwctl.c
new file mode 100644
index 000000000000..160baf0abc09
--- /dev/null
+++ b/drivers/staging/vt6655/iwctl.c
@@ -0,0 +1,2453 @@
1/*
2 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
3 * All rights reserved.
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * File: iwctl.c
20 *
21 * Purpose: wireless ext & ioctl functions
22 *
23 * Author: Lyndon Chen
24 *
25 * Date: July 5, 2006
26 *
27 * Functions:
28 *
29 * Revision History:
30 *
31 */
32
33
34#if !defined(__DEVICE_H__)
35#include "device.h"
36#endif
37#if !defined(__IOCTL_H__)
38#include "ioctl.h"
39#endif
40#if !defined(__IOCMD_H__)
41#include "iocmd.h"
42#endif
43#if !defined(__MAC_H__)
44#include "mac.h"
45#endif
46#if !defined(__CARD_H__)
47#include "card.h"
48#endif
49#if !defined(__HOSTAP_H__)
50#include "hostap.h"
51#endif
52#if !defined(__UMEM_H__)
53#include "umem.h"
54#endif
55#if !defined(__POWER_H__)
56#include "power.h"
57#endif
58#if !defined(__RF_H__)
59#include "rf.h"
60#endif
61
62#ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
63#if !defined(__IOWPA_H__)
64#include "iowpa.h"
65#endif
66#if !defined(__WPACTL_H__)
67#include "wpactl.h"
68#endif
69#endif
70
71#if WIRELESS_EXT > 12
72#include <net/iw_handler.h>
73#endif
74extern WORD TxRate_iwconfig;//2008-5-8 <add> by chester
75
76/*--------------------- Static Definitions -------------------------*/
77
78//2008-0409-07, <Add> by Einsn Liu
79#ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
80#define SUPPORTED_WIRELESS_EXT 18
81#else
82#define SUPPORTED_WIRELESS_EXT 17
83#endif
84
85#ifdef WIRELESS_EXT
86
87static const long frequency_list[] = {
88 2412, 2417, 2422, 2427, 2432, 2437, 2442, 2447, 2452, 2457, 2462, 2467, 2472, 2484,
89 4915, 4920, 4925, 4935, 4940, 4945, 4960, 4980,
90 5035, 5040, 5045, 5055, 5060, 5080, 5170, 5180, 5190, 5200, 5210, 5220, 5230, 5240,
91 5260, 5280, 5300, 5320, 5500, 5520, 5540, 5560, 5580, 5600, 5620, 5640, 5660, 5680,
92 5700, 5745, 5765, 5785, 5805, 5825
93 };
94
95#endif
96
97
98/*--------------------- Static Classes ----------------------------*/
99
100
101//static int msglevel =MSG_LEVEL_DEBUG;
102static int msglevel =MSG_LEVEL_INFO;
103
104
105/*--------------------- Static Variables --------------------------*/
106/*--------------------- Static Functions --------------------------*/
107
108/*--------------------- Export Variables --------------------------*/
109
110#ifdef WIRELESS_EXT
111
112#if WIRELESS_EXT > 12
113
114struct iw_statistics *iwctl_get_wireless_stats(struct net_device *dev)
115{
116 PSDevice pDevice = dev->priv;
117 long ldBm;
118 pDevice->wstats.status = pDevice->eOPMode;
119 #ifdef Calcu_LinkQual
120 #if 0
121 if(pDevice->byBBType == BB_TYPE_11B) {
122 if(pDevice->byCurrSQ > 120)
123 pDevice->scStatistic.LinkQuality = 100;
124 else
125 pDevice->scStatistic.LinkQuality = pDevice->byCurrSQ*100/120;
126 }
127 else if(pDevice->byBBType == BB_TYPE_11G) {
128 if(pDevice->byCurrSQ < 20)
129 pDevice->scStatistic.LinkQuality = 100;
130 else if(pDevice->byCurrSQ >96)
131 pDevice->scStatistic.LinkQuality = 0;
132 else
133 pDevice->scStatistic.LinkQuality = (96-pDevice->byCurrSQ)*100/76;
134 }
135 if(pDevice->bLinkPass !=TRUE)
136 pDevice->scStatistic.LinkQuality = 0;
137 #endif
138 if(pDevice->scStatistic.LinkQuality > 100)
139 pDevice->scStatistic.LinkQuality = 100;
140 pDevice->wstats.qual.qual =(BYTE) pDevice->scStatistic.LinkQuality;
141 #else
142 pDevice->wstats.qual.qual = pDevice->byCurrSQ;
143 #endif
144 RFvRSSITodBm(pDevice, (BYTE)(pDevice->uCurrRSSI), &ldBm);
145 pDevice->wstats.qual.level = ldBm;
146 //pDevice->wstats.qual.level = 0x100 - pDevice->uCurrRSSI;
147 pDevice->wstats.qual.noise = 0;
148 pDevice->wstats.qual.updated = 1;
149 pDevice->wstats.discard.nwid = 0;
150 pDevice->wstats.discard.code = 0;
151 pDevice->wstats.discard.fragment = 0;
152 pDevice->wstats.discard.retries = (U32)pDevice->scStatistic.dwTsrErr;
153 pDevice->wstats.discard.misc = 0;
154 pDevice->wstats.miss.beacon = 0;
155
156 return &pDevice->wstats;
157}
158
159#endif
160
161
162
163/*------------------------------------------------------------------*/
164
165
166static int iwctl_commit(struct net_device *dev,
167 struct iw_request_info *info,
168 void *wrq,
169 char *extra)
170{
171 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWCOMMIT \n");
172
173 return 0;
174
175}
176
177/*
178 * Wireless Handler : get protocol name
179 */
180
181int iwctl_giwname(struct net_device *dev,
182 struct iw_request_info *info,
183 char *wrq,
184 char *extra)
185{
186 strcpy(wrq, "802.11-a/b/g");
187 return 0;
188}
189
190int iwctl_giwnwid(struct net_device *dev,
191 struct iw_request_info *info,
192 struct iw_param *wrq,
193 char *extra)
194{
195 //wrq->value = 0x100;
196 //wrq->disabled = 0;
197 //wrq->fixed = 1;
198 //return 0;
199 return -EOPNOTSUPP;
200}
201#if WIRELESS_EXT > 13
202
203/*
204 * Wireless Handler : set scan
205 */
206
207int iwctl_siwscan(struct net_device *dev,
208 struct iw_request_info *info,
209 struct iw_point *wrq,
210 char *extra)
211{
212 PSDevice pDevice = (PSDevice)dev->priv;
213 struct iw_scan_req *req = (struct iw_scan_req *)extra;
214 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
215 BYTE abyScanSSID[WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1];
216 PWLAN_IE_SSID pItemSSID=NULL;
217 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWSCAN \n");
218
219
220if(pDevice->byReAssocCount > 0) { //reject scan when re-associating!
221//send scan event to wpa_Supplicant
222 union iwreq_data wrqu;
223 printk("wireless_send_event--->SIOCGIWSCAN(scan done)\n");
224 memset(&wrqu, 0, sizeof(wrqu));
225 wireless_send_event(pDevice->dev, SIOCGIWSCAN, &wrqu, NULL);
226 return 0;
227}
228
229 spin_lock_irq(&pDevice->lock);
230 BSSvClearBSSList((HANDLE)pDevice, pDevice->bLinkPass);
231
232//mike add: active scan OR passive scan OR desire_ssid scan
233 if(wrq->length == sizeof(struct iw_scan_req)) {
234 if (wrq->flags & IW_SCAN_THIS_ESSID) { //desire_ssid scan
235 memset(abyScanSSID, 0, WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1);
236 pItemSSID = (PWLAN_IE_SSID)abyScanSSID;
237 pItemSSID->byElementID = WLAN_EID_SSID;
238 memcpy(pItemSSID->abySSID, req->essid, (int)req->essid_len);
239 if (pItemSSID->abySSID[req->essid_len - 1] == '\0') {
240 if(req->essid_len>0)
241 pItemSSID->len = req->essid_len - 1;
242 }
243 else
244 pItemSSID->len = req->essid_len;
245 pMgmt->eScanType = WMAC_SCAN_PASSIVE;
246 printk("SIOCSIWSCAN:[desired_ssid=%s,len=%d]\n",((PWLAN_IE_SSID)abyScanSSID)->abySSID,
247 ((PWLAN_IE_SSID)abyScanSSID)->len);
248 bScheduleCommand((HANDLE) pDevice, WLAN_CMD_BSSID_SCAN, abyScanSSID);
249 spin_unlock_irq(&pDevice->lock);
250
251 return 0;
252 }
253 else if(req->scan_type == IW_SCAN_TYPE_PASSIVE) { //passive scan
254 pMgmt->eScanType = WMAC_SCAN_PASSIVE;
255 }
256 }
257 else { //active scan
258 pMgmt->eScanType = WMAC_SCAN_ACTIVE;
259 }
260
261 pMgmt->eScanType = WMAC_SCAN_PASSIVE;
262 bScheduleCommand((HANDLE) pDevice, WLAN_CMD_BSSID_SCAN, NULL);
263 spin_unlock_irq(&pDevice->lock);
264
265 return 0;
266}
267
268
269/*
270 * Wireless Handler : get scan results
271 */
272
273int iwctl_giwscan(struct net_device *dev,
274 struct iw_request_info *info,
275 struct iw_point *wrq,
276 char *extra)
277{
278 int ii, jj, kk;
279 PSDevice pDevice = (PSDevice)dev->priv;
280 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
281 PKnownBSS pBSS;
282 PWLAN_IE_SSID pItemSSID;
283 PWLAN_IE_SUPP_RATES pSuppRates, pExtSuppRates;
284 char *current_ev = extra;
285 char *end_buf = extra + IW_SCAN_MAX_DATA;
286 char *current_val = NULL;
287 struct iw_event iwe;
288 long ldBm;
289#if WIRELESS_EXT > 14
290 char buf[MAX_WPA_IE_LEN * 2 + 30];
291#endif /* WIRELESS_EXT > 14 */
292
293
294 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWSCAN \n");
295
296 if (pMgmt->eScanState == WMAC_IS_SCANNING) {
297 // In scanning..
298 return -EAGAIN;
299 }
300 pBSS = &(pMgmt->sBSSList[0]);
301 for (ii = 0, jj = 0; jj < MAX_BSS_NUM ; jj++) {
302 if (current_ev >= end_buf)
303 break;
304 pBSS = &(pMgmt->sBSSList[jj]);
305 if (pBSS->bActive) {
306 memset(&iwe, 0, sizeof(iwe));
307 iwe.cmd = SIOCGIWAP;
308 iwe.u.ap_addr.sa_family = ARPHRD_ETHER;
309 memcpy(iwe.u.ap_addr.sa_data, pBSS->abyBSSID, WLAN_BSSID_LEN);
310 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,27) //mike add
311 current_ev = iwe_stream_add_event(info,current_ev,end_buf, &iwe, IW_EV_ADDR_LEN);
312 #else
313 current_ev = iwe_stream_add_event(current_ev,end_buf, &iwe, IW_EV_ADDR_LEN);
314 #endif
315 //ADD ssid
316 memset(&iwe, 0, sizeof(iwe));
317 iwe.cmd = SIOCGIWESSID;
318 pItemSSID = (PWLAN_IE_SSID)pBSS->abySSID;
319 iwe.u.data.length = pItemSSID->len;
320 iwe.u.data.flags = 1;
321 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,27) //mike add
322 current_ev = iwe_stream_add_point(info,current_ev,end_buf, &iwe, pItemSSID->abySSID);
323 #else
324 current_ev = iwe_stream_add_point(current_ev,end_buf, &iwe, pItemSSID->abySSID);
325 #endif
326 //ADD mode
327 memset(&iwe, 0, sizeof(iwe));
328 iwe.cmd = SIOCGIWMODE;
329 if (WLAN_GET_CAP_INFO_ESS(pBSS->wCapInfo)) {
330 iwe.u.mode = IW_MODE_INFRA;
331 }
332 else {
333 iwe.u.mode = IW_MODE_ADHOC;
334 }
335 iwe.len = IW_EV_UINT_LEN;
336 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,27) //mike add
337 current_ev = iwe_stream_add_event(info,current_ev, end_buf, &iwe, IW_EV_UINT_LEN);
338 #else
339 current_ev = iwe_stream_add_event(current_ev, end_buf, &iwe, IW_EV_UINT_LEN);
340 #endif
341 //ADD frequency
342 pSuppRates = (PWLAN_IE_SUPP_RATES)pBSS->abySuppRates;
343 pExtSuppRates = (PWLAN_IE_SUPP_RATES)pBSS->abyExtSuppRates;
344 memset(&iwe, 0, sizeof(iwe));
345 iwe.cmd = SIOCGIWFREQ;
346 iwe.u.freq.m = pBSS->uChannel;
347 iwe.u.freq.e = 0;
348 iwe.u.freq.i = 0;
349 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,27) //mike add
350 current_ev = iwe_stream_add_event(info,current_ev,end_buf, &iwe, IW_EV_FREQ_LEN);
351 #else
352 current_ev = iwe_stream_add_event(current_ev,end_buf, &iwe, IW_EV_FREQ_LEN);
353 #endif
354
355
356 //2008-0409-04, <Add> by Einsn Liu
357 {
358 int f = (int)pBSS->uChannel - 1;
359 if(f < 0)f = 0;
360 iwe.u.freq.m = frequency_list[f] * 100000;
361 iwe.u.freq.e = 1;
362 }
363 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,27) //mike add
364 current_ev = iwe_stream_add_event(info,current_ev,end_buf, &iwe, IW_EV_FREQ_LEN);
365 #else
366 current_ev = iwe_stream_add_event(current_ev,end_buf, &iwe, IW_EV_FREQ_LEN);
367 #endif
368 //ADD quality
369 memset(&iwe, 0, sizeof(iwe));
370 iwe.cmd = IWEVQUAL;
371 RFvRSSITodBm(pDevice, (BYTE)(pBSS->uRSSI), &ldBm);
372 iwe.u.qual.level = ldBm;
373 iwe.u.qual.noise = 0;
374//2008-0409-01, <Add> by Einsn Liu
375 if(-ldBm<50){
376 iwe.u.qual.qual = 100;
377 }else if(-ldBm > 90) {
378 iwe.u.qual.qual = 0;
379 }else {
380 iwe.u.qual.qual=(40-(-ldBm-50))*100/40;
381 }
382 iwe.u.qual.updated=7;
383
384 // iwe.u.qual.qual = 0;
385 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,27) //mike add
386 current_ev = iwe_stream_add_event(info,current_ev, end_buf, &iwe, IW_EV_QUAL_LEN);
387 #else
388 current_ev = iwe_stream_add_event(current_ev, end_buf, &iwe, IW_EV_QUAL_LEN);
389 #endif
390
391 memset(&iwe, 0, sizeof(iwe));
392 iwe.cmd = SIOCGIWENCODE;
393 iwe.u.data.length = 0;
394 if (WLAN_GET_CAP_INFO_PRIVACY(pBSS->wCapInfo)) {
395 iwe.u.data.flags =IW_ENCODE_ENABLED | IW_ENCODE_NOKEY;
396 }else {
397 iwe.u.data.flags = IW_ENCODE_DISABLED;
398 }
399 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,27) //mike add
400 current_ev = iwe_stream_add_point(info,current_ev,end_buf, &iwe, pItemSSID->abySSID);
401 #else
402 current_ev = iwe_stream_add_point(current_ev,end_buf, &iwe, pItemSSID->abySSID);
403 #endif
404
405 memset(&iwe, 0, sizeof(iwe));
406 iwe.cmd = SIOCGIWRATE;
407 iwe.u.bitrate.fixed = iwe.u.bitrate.disabled = 0;
408 current_val = current_ev + IW_EV_LCP_LEN;
409
410 for (kk = 0 ; kk < 12 ; kk++) {
411 if (pSuppRates->abyRates[kk] == 0)
412 break;
413 // Bit rate given in 500 kb/s units (+ 0x80)
414 iwe.u.bitrate.value = ((pSuppRates->abyRates[kk] & 0x7f) * 500000);
415 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,27) //mike add
416 current_val = iwe_stream_add_value(info,current_ev, current_val, end_buf, &iwe, IW_EV_PARAM_LEN);
417 #else
418 current_val = iwe_stream_add_value(current_ev, current_val, end_buf, &iwe, IW_EV_PARAM_LEN);
419 #endif
420 }
421 for (kk = 0 ; kk < 8 ; kk++) {
422 if (pExtSuppRates->abyRates[kk] == 0)
423 break;
424 // Bit rate given in 500 kb/s units (+ 0x80)
425 iwe.u.bitrate.value = ((pExtSuppRates->abyRates[kk] & 0x7f) * 500000);
426 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,27) //mike add
427 current_val = iwe_stream_add_value(info,current_ev, current_val, end_buf, &iwe, IW_EV_PARAM_LEN);
428 #else
429 current_val = iwe_stream_add_value(current_ev, current_val, end_buf, &iwe, IW_EV_PARAM_LEN);
430 #endif
431 }
432
433 if((current_val - current_ev) > IW_EV_LCP_LEN)
434 current_ev = current_val;
435
436#if WIRELESS_EXT > 14
437 memset(&iwe, 0, sizeof(iwe));
438 iwe.cmd = IWEVCUSTOM;
439 sprintf(buf, "bcn_int=%d", pBSS->wBeaconInterval);
440 iwe.u.data.length = strlen(buf);
441 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,27) //mike add
442 current_ev = iwe_stream_add_point(info,current_ev, end_buf, &iwe, buf);
443 #else
444 current_ev = iwe_stream_add_point(current_ev, end_buf, &iwe, buf);
445 #endif
446
447#if WIRELESS_EXT > 17
448 if ((pBSS->wWPALen > 0) && (pBSS->wWPALen <= MAX_WPA_IE_LEN)) {
449 memset(&iwe, 0, sizeof(iwe));
450 iwe.cmd = IWEVGENIE;
451 iwe.u.data.length = pBSS->wWPALen;
452 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,27) //mike add
453 current_ev = iwe_stream_add_point(info,current_ev, end_buf, &iwe, pBSS->byWPAIE);
454 #else
455 current_ev = iwe_stream_add_point(current_ev, end_buf, &iwe, pBSS->byWPAIE);
456 #endif
457 }
458
459 if ((pBSS->wRSNLen > 0) && (pBSS->wRSNLen <= MAX_WPA_IE_LEN)) {
460 memset(&iwe, 0, sizeof(iwe));
461 iwe.cmd = IWEVGENIE;
462 iwe.u.data.length = pBSS->wRSNLen;
463 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,27) //mike add
464 current_ev = iwe_stream_add_point(info,current_ev, end_buf, &iwe, pBSS->byRSNIE);
465 #else
466 current_ev = iwe_stream_add_point(current_ev, end_buf, &iwe, pBSS->byRSNIE);
467 #endif
468 }
469
470#else // WIRELESS_EXT > 17
471 if ((pBSS->wWPALen > 0) && (pBSS->wWPALen <= MAX_WPA_IE_LEN)) {
472 u8 *p = buf;
473 memset(&iwe, 0, sizeof(iwe));
474 iwe.cmd = IWEVCUSTOM;
475 p += sprintf(p, "wpa_ie=");
476 for (ii = 0; ii < pBSS->wWPALen; ii++) {
477 p += sprintf(p, "%02x", pBSS->byWPAIE[ii]);
478 }
479 iwe.u.data.length = strlen(buf);
480 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,27) //mike add
481 current_ev = iwe_stream_add_point(info,current_ev, end_buf, &iwe, buf);
482 #else
483 current_ev = iwe_stream_add_point(current_ev, end_buf, &iwe, buf);
484 #endif
485 }
486
487
488 if ((pBSS->wRSNLen > 0) && (pBSS->wRSNLen <= MAX_WPA_IE_LEN)) {
489 u8 *p = buf;
490 memset(&iwe, 0, sizeof(iwe));
491 iwe.cmd = IWEVCUSTOM;
492 p += sprintf(p, "rsn_ie=");
493 for (ii = 0; ii < pBSS->wRSNLen; ii++) {
494 p += sprintf(p, "%02x", pBSS->byRSNIE[ii]);
495 }
496 iwe.u.data.length = strlen(buf);
497 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,27) //mike add
498 current_ev = iwe_stream_add_point(info,current_ev, end_buf, &iwe, buf);
499 #else
500 current_ev = iwe_stream_add_point(current_ev, end_buf, &iwe, buf);
501 #endif
502 }
503#endif
504#endif
505 }
506 }// for
507
508 wrq->length = current_ev - extra;
509 return 0;
510
511}
512
513#endif /* WIRELESS_EXT > 13 */
514
515
516/*
517 * Wireless Handler : set frequence or channel
518 */
519
520int iwctl_siwfreq(struct net_device *dev,
521 struct iw_request_info *info,
522 struct iw_freq *wrq,
523 char *extra)
524{
525 PSDevice pDevice = (PSDevice)dev->priv;
526 int rc = 0;
527
528 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWFREQ \n");
529
530 // If setting by frequency, convert to a channel
531 if((wrq->e == 1) &&
532 (wrq->m >= (int) 2.412e8) &&
533 (wrq->m <= (int) 2.487e8)) {
534 int f = wrq->m / 100000;
535 int c = 0;
536 while((c < 14) && (f != frequency_list[c]))
537 c++;
538 wrq->e = 0;
539 wrq->m = c + 1;
540 }
541 // Setting by channel number
542 if((wrq->m > 14) || (wrq->e > 0))
543 rc = -EOPNOTSUPP;
544 else {
545 int channel = wrq->m;
546 if((channel < 1) || (channel > 14)) {
547 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: New channel value of %d is invalid!\n", dev->name, wrq->m);
548 rc = -EINVAL;
549 } else {
550 // Yes ! We can set it !!!
551 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO " Set to channel = %d\n", channel);
552 pDevice->uChannel = channel;
553 //2007-0207-04,<Add> by EinsnLiu
554 //Make change effect at once
555 pDevice->bCommit = TRUE;
556 }
557 }
558
559 return rc;
560}
561
562/*
563 * Wireless Handler : get frequence or channel
564 */
565
566int iwctl_giwfreq(struct net_device *dev,
567 struct iw_request_info *info,
568 struct iw_freq *wrq,
569 char *extra)
570{
571 PSDevice pDevice = (PSDevice)dev->priv;
572 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
573
574 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWFREQ \n");
575
576#ifdef WEXT_USECHANNELS
577 wrq->m = (int)pMgmt->uCurrChannel;
578 wrq->e = 0;
579#else
580 {
581 int f = (int)pMgmt->uCurrChannel - 1;
582 if(f < 0)
583 f = 0;
584 wrq->m = frequency_list[f] * 100000;
585 wrq->e = 1;
586 }
587#endif
588
589 return 0;
590}
591
592/*
593 * Wireless Handler : set operation mode
594 */
595
596int iwctl_siwmode(struct net_device *dev,
597 struct iw_request_info *info,
598 __u32 *wmode,
599 char *extra)
600{
601 PSDevice pDevice = (PSDevice)dev->priv;
602 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
603 int rc = 0;
604
605 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWMODE \n");
606
607 if (pMgmt->eCurrMode == WMAC_MODE_ESS_AP && pDevice->bEnableHostapd) {
608 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Can't set operation mode, hostapd is running \n");
609 return rc;
610 }
611
612 switch(*wmode) {
613
614 case IW_MODE_ADHOC:
615 if (pMgmt->eConfigMode != WMAC_CONFIG_IBSS_STA) {
616 pMgmt->eConfigMode = WMAC_CONFIG_IBSS_STA;
617 if (pDevice->flags & DEVICE_FLAGS_OPENED) {
618 pDevice->bCommit = TRUE;
619 }
620 }
621 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "set mode to ad-hoc \n");
622 break;
623 case IW_MODE_AUTO:
624 case IW_MODE_INFRA:
625 if (pMgmt->eConfigMode != WMAC_CONFIG_ESS_STA) {
626 pMgmt->eConfigMode = WMAC_CONFIG_ESS_STA;
627 if (pDevice->flags & DEVICE_FLAGS_OPENED) {
628 pDevice->bCommit = TRUE;
629 }
630 }
631 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "set mode to infrastructure \n");
632 break;
633 case IW_MODE_MASTER:
634
635 pMgmt->eConfigMode = WMAC_CONFIG_ESS_STA;
636 rc = -EOPNOTSUPP;
637 break;
638
639 if (pMgmt->eConfigMode != WMAC_CONFIG_AP) {
640 pMgmt->eConfigMode = WMAC_CONFIG_AP;
641 if (pDevice->flags & DEVICE_FLAGS_OPENED) {
642 pDevice->bCommit = TRUE;
643 }
644 }
645 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "set mode to Access Point \n");
646 break;
647
648 case IW_MODE_REPEAT:
649 pMgmt->eConfigMode = WMAC_CONFIG_ESS_STA;
650 rc = -EOPNOTSUPP;
651 break;
652 default:
653 rc = -EINVAL;
654 }
655
656 return rc;
657}
658
659/*
660 * Wireless Handler : get operation mode
661 */
662
663int iwctl_giwmode(struct net_device *dev,
664 struct iw_request_info *info,
665 __u32 *wmode,
666 char *extra)
667{
668 PSDevice pDevice = (PSDevice)dev->priv;
669 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
670
671
672 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWMODE \n");
673 // If not managed, assume it's ad-hoc
674 switch (pMgmt->eConfigMode) {
675 case WMAC_CONFIG_ESS_STA:
676 *wmode = IW_MODE_INFRA;
677 break;
678 case WMAC_CONFIG_IBSS_STA:
679 *wmode = IW_MODE_ADHOC;
680 break;
681 case WMAC_CONFIG_AUTO:
682 *wmode = IW_MODE_INFRA;
683 break;
684 case WMAC_CONFIG_AP:
685 *wmode = IW_MODE_MASTER;
686 break;
687 default:
688 *wmode = IW_MODE_ADHOC;
689 }
690
691 return 0;
692}
693
694
695/*
696 * Wireless Handler : get capability range
697 */
698
699int iwctl_giwrange(struct net_device *dev,
700 struct iw_request_info *info,
701 struct iw_point *wrq,
702 char *extra)
703{
704 struct iw_range *range = (struct iw_range *) extra;
705 int i,k;
706 BYTE abySupportedRates[13]= {0x02, 0x04, 0x0B, 0x16, 0x0c, 0x12, 0x18, 0x24, 0x30, 0x48, 0x60, 0x6C, 0x90};
707
708
709 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWRANGE \n");
710 if (wrq->pointer) {
711 wrq->length = sizeof(struct iw_range);
712 memset(range, 0, sizeof(struct iw_range));
713 range->min_nwid = 0x0000;
714 range->max_nwid = 0x0000;
715 range->num_channels = 14;
716 // Should be based on cap_rid.country to give only
717 // what the current card support
718 k = 0;
719 for(i = 0; i < 14; i++) {
720 range->freq[k].i = i + 1; // List index
721 range->freq[k].m = frequency_list[i] * 100000;
722 range->freq[k++].e = 1; // Values in table in MHz -> * 10^5 * 10
723 }
724 range->num_frequency = k;
725 // Hum... Should put the right values there
726 #ifdef Calcu_LinkQual
727 range->max_qual.qual = 100;
728 #else
729 range->max_qual.qual = 255;
730 #endif
731 range->max_qual.level = 0;
732 range->max_qual.noise = 0;
733 range->sensitivity = 255;
734
735 for(i = 0 ; i < 13 ; i++) {
736 range->bitrate[i] = abySupportedRates[i] * 500000;
737 if(range->bitrate[i] == 0)
738 break;
739 }
740 range->num_bitrates = i;
741
742 // Set an indication of the max TCP throughput
743 // in bit/s that we can expect using this interface.
744 // May be use for QoS stuff... Jean II
745 if(i > 2)
746 range->throughput = 5 * 1000 * 1000;
747 else
748 range->throughput = 1.5 * 1000 * 1000;
749
750 range->min_rts = 0;
751 range->max_rts = 2312;
752 range->min_frag = 256;
753 range->max_frag = 2312;
754
755
756 // the encoding capabilities
757 range->num_encoding_sizes = 3;
758 // 64(40) bits WEP
759 range->encoding_size[0] = 5;
760 // 128(104) bits WEP
761 range->encoding_size[1] = 13;
762 // 256 bits for WPA-PSK
763 range->encoding_size[2] = 32;
764 // 4 keys are allowed
765 range->max_encoding_tokens = 4;
766
767#if WIRELESS_EXT > 17
768 range->enc_capa = IW_ENC_CAPA_WPA | IW_ENC_CAPA_WPA2 |
769 IW_ENC_CAPA_CIPHER_TKIP | IW_ENC_CAPA_CIPHER_CCMP;
770#endif
771
772#if WIRELESS_EXT > 9
773 range->min_pmp = 0;
774 range->max_pmp = 1000000;// 1 secs
775 range->min_pmt = 0;
776 range->max_pmt = 1000000;// 1 secs
777 range->pmp_flags = IW_POWER_PERIOD;
778 range->pmt_flags = IW_POWER_TIMEOUT;
779 range->pm_capa = IW_POWER_PERIOD | IW_POWER_TIMEOUT | IW_POWER_ALL_R;
780
781 // Transmit Power - values are in mW
782
783 range->txpower[0] = 100;
784 range->num_txpower = 1;
785 range->txpower_capa = IW_TXPOW_MWATT;
786#endif // WIRELESS_EXT > 9
787#if WIRELESS_EXT > 10
788 range->we_version_source = SUPPORTED_WIRELESS_EXT;
789 range->we_version_compiled = WIRELESS_EXT;
790 range->retry_capa = IW_RETRY_LIMIT | IW_RETRY_LIFETIME;
791 range->retry_flags = IW_RETRY_LIMIT;
792 range->r_time_flags = IW_RETRY_LIFETIME;
793 range->min_retry = 1;
794 range->max_retry = 65535;
795 range->min_r_time = 1024;
796 range->max_r_time = 65535 * 1024;
797#endif // WIRELESS_EXT > 10
798#if WIRELESS_EXT > 11
799 // Experimental measurements - boundary 11/5.5 Mb/s
800 // Note : with or without the (local->rssi), results
801 // are somewhat different. - Jean II
802 range->avg_qual.qual = 6;
803 range->avg_qual.level = 176; // -80 dBm
804 range->avg_qual.noise = 0;
805#endif // WIRELESS_EXT > 11
806 }
807
808
809 return 0;
810}
811
812
813/*
814 * Wireless Handler : set ap mac address
815 */
816
817int iwctl_siwap(struct net_device *dev,
818 struct iw_request_info *info,
819 struct sockaddr *wrq,
820 char *extra)
821{
822 PSDevice pDevice = (PSDevice)dev->priv;
823 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
824 int rc = 0;
825 BYTE ZeroBSSID[WLAN_BSSID_LEN]={0x00,0x00,0x00,0x00,0x00,0x00};
826
827 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWAP \n");
828if (pMgmt->eScanState == WMAC_IS_SCANNING) {
829 // In scanning..
830 printk("SIOCSIWAP(??)-->In scanning...\n");
831 // return -EAGAIN;
832 }
833 if (wrq->sa_family != ARPHRD_ETHER)
834 rc = -EINVAL;
835 else {
836 memset(pMgmt->abyDesireBSSID, 0xFF, 6);
837 memcpy(pMgmt->abyDesireBSSID, wrq->sa_data, 6);
838 //2008-0409-05, <Add> by Einsn Liu
839 if((pDevice->bLinkPass == TRUE) &&
840 (memcmp(pMgmt->abyDesireBSSID, pMgmt->abyCurrBSSID, 6)== 0)){
841 return rc;
842 }
843 //mike :add
844 if ((IS_BROADCAST_ADDRESS(pMgmt->abyDesireBSSID)) ||
845 (memcmp(pMgmt->abyDesireBSSID, ZeroBSSID, 6) == 0)){
846 printk("SIOCSIWAP:invalid desired BSSID return!\n");
847 return rc;
848 }
849 //mike add: if desired AP is hidden ssid(there are two same BSSID in list),
850 // then ignore,because you don't known which one to be connect with??
851 {
852 UINT ii , uSameBssidNum=0;
853 for (ii = 0; ii < MAX_BSS_NUM; ii++) {
854 if (pMgmt->sBSSList[ii].bActive &&
855 IS_ETH_ADDRESS_EQUAL(pMgmt->sBSSList[ii].abyBSSID,pMgmt->abyDesireBSSID)) {
856 uSameBssidNum++;
857 }
858 }
859 if(uSameBssidNum >= 2) { //hit: desired AP is in hidden ssid mode!!!
860 printk("SIOCSIWAP:ignore for desired AP in hidden mode\n");
861 return rc;
862 }
863 }
864 if (pDevice->flags & DEVICE_FLAGS_OPENED) {
865 pDevice->bCommit = TRUE;
866 }
867 }
868 return rc;
869}
870
871/*
872 * Wireless Handler : get ap mac address
873 */
874
875int iwctl_giwap(struct net_device *dev,
876 struct iw_request_info *info,
877 struct sockaddr *wrq,
878 char *extra)
879{
880 PSDevice pDevice = (PSDevice)dev->priv;
881 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
882
883
884 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWAP \n");
885
886 memcpy(wrq->sa_data, pMgmt->abyCurrBSSID, 6);
887 //2008-0410,<Modify> by Einsn Liu
888 if ((pDevice->bLinkPass == FALSE) && (pMgmt->eCurrMode != WMAC_MODE_ESS_AP))
889 memset(wrq->sa_data, 0, 6);
890
891 if (pMgmt->eCurrMode == WMAC_MODE_ESS_AP) {
892 memcpy(wrq->sa_data, pMgmt->abyCurrBSSID, 6);
893 }
894
895 wrq->sa_family = ARPHRD_ETHER;
896
897 return 0;
898
899}
900
901
902/*
903 * Wireless Handler : get ap list
904 */
905
906int iwctl_giwaplist(struct net_device *dev,
907 struct iw_request_info *info,
908 struct iw_point *wrq,
909 char *extra)
910{
911 int ii,jj, rc = 0;
912 struct sockaddr sock[IW_MAX_AP];
913 struct iw_quality qual[IW_MAX_AP];
914 PSDevice pDevice = (PSDevice)dev->priv;
915 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
916
917
918 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWAPLIST \n");
919 // Only super-user can see AP list
920
921 if (!capable(CAP_NET_ADMIN)) {
922 rc = -EPERM;
923 return rc;
924 }
925
926 if (wrq->pointer) {
927
928 PKnownBSS pBSS = &(pMgmt->sBSSList[0]);
929
930 for (ii = 0, jj= 0; ii < MAX_BSS_NUM; ii++) {
931 pBSS = &(pMgmt->sBSSList[ii]);
932 if (!pBSS->bActive)
933 continue;
934 if ( jj >= IW_MAX_AP)
935 break;
936 memcpy(sock[jj].sa_data, pBSS->abyBSSID, 6);
937 sock[jj].sa_family = ARPHRD_ETHER;
938 qual[jj].level = pBSS->uRSSI;
939 qual[jj].qual = qual[jj].noise = 0;
940 qual[jj].updated = 2;
941 jj++;
942 }
943
944 wrq->flags = 1; // Should be define'd
945 wrq->length = jj;
946 memcpy(extra, sock, sizeof(struct sockaddr)*jj);
947 memcpy(extra + sizeof(struct sockaddr)*jj, qual, sizeof(struct iw_quality)*jj);
948 }
949
950 return rc;
951}
952
953
954/*
955 * Wireless Handler : set essid
956 */
957
958int iwctl_siwessid(struct net_device *dev,
959 struct iw_request_info *info,
960 struct iw_point *wrq,
961 char *extra)
962{
963 PSDevice pDevice = (PSDevice)dev->priv;
964 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
965 PWLAN_IE_SSID pItemSSID;
966 //2008-0409-05, <Add> by Einsn Liu
967 BYTE len;
968
969
970 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWESSID \n");
971 pDevice->fWPA_Authened = FALSE;
972if (pMgmt->eScanState == WMAC_IS_SCANNING) {
973 // In scanning..
974 printk("SIOCSIWESSID(??)-->In scanning...\n");
975 // return -EAGAIN;
976 }
977 // Check if we asked for `any'
978 if(wrq->flags == 0) {
979 // Just send an empty SSID list
980 // Just send an empty SSID list
981 memset(pMgmt->abyDesireSSID, 0, WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1);
982 memset(pMgmt->abyDesireBSSID, 0xFF,6);
983 printk("set essid to 'any' \n");
984 #ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
985 //Unknown desired AP,so here need not associate??
986 //if(pDevice->bWPASuppWextEnabled == TRUE) {
987 return 0;
988 // }
989 #endif
990 } else {
991 // Set the SSID
992 memset(pMgmt->abyDesireSSID, 0, WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1);
993 pItemSSID = (PWLAN_IE_SSID)pMgmt->abyDesireSSID;
994 pItemSSID->byElementID = WLAN_EID_SSID;
995 memcpy(pItemSSID->abySSID, extra, wrq->length);
996 if (pItemSSID->abySSID[wrq->length - 1] == '\0') {
997 if(wrq->length>0)
998 pItemSSID->len = wrq->length - 1;
999 }
1000 else
1001 pItemSSID->len = wrq->length;
1002 printk("set essid to %s \n",pItemSSID->abySSID);
1003 //2008-0409-05, <Add> by Einsn Liu
1004 len=(pItemSSID->len > ((PWLAN_IE_SSID)pMgmt->abyCurrSSID)->len)?pItemSSID->len:((PWLAN_IE_SSID)pMgmt->abyCurrSSID)->len;
1005 if((pDevice->bLinkPass == TRUE) &&
1006 (memcmp(pItemSSID->abySSID,((PWLAN_IE_SSID)pMgmt->abyCurrSSID)->abySSID,len)==0))
1007 return 0;
1008
1009 //mike:need clear desiredBSSID
1010 if(pItemSSID->len==0) {
1011 memset(pMgmt->abyDesireBSSID, 0xFF,6);
1012 return 0;
1013 }
1014
1015#ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
1016 //Wext wil order another command of siwap to link with desired AP,
1017 //so here need not associate??
1018 if(pDevice->bWPASuppWextEnabled == TRUE) {
1019 /*******search if in hidden ssid mode ****/
1020 {
1021 PKnownBSS pCurr = NULL;
1022 BYTE abyTmpDesireSSID[WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1];
1023 UINT ii , uSameBssidNum=0;
1024
1025 memset(abyTmpDesireSSID,0,sizeof(abyTmpDesireSSID));
1026 memcpy(abyTmpDesireSSID,pMgmt->abyDesireSSID,sizeof(abyTmpDesireSSID));
1027 pCurr = BSSpSearchBSSList(pDevice,
1028 NULL,
1029 abyTmpDesireSSID,
1030 pMgmt->eConfigPHYMode
1031 );
1032
1033 if (pCurr == NULL){
1034 printk("SIOCSIWESSID:hidden ssid site survey before associate.......\n");
1035 vResetCommandTimer((HANDLE) pDevice);
1036 pMgmt->eScanType = WMAC_SCAN_ACTIVE;
1037 bScheduleCommand((HANDLE) pDevice, WLAN_CMD_BSSID_SCAN, pMgmt->abyDesireSSID);
1038 bScheduleCommand((HANDLE) pDevice, WLAN_CMD_SSID, pMgmt->abyDesireSSID);
1039 }
1040 else { //mike:to find out if that desired SSID is a hidden-ssid AP ,
1041 // by means of judging if there are two same BSSID exist in list ?
1042 for (ii = 0; ii < MAX_BSS_NUM; ii++) {
1043 if (pMgmt->sBSSList[ii].bActive &&
1044 IS_ETH_ADDRESS_EQUAL(pMgmt->sBSSList[ii].abyBSSID, pCurr->abyBSSID)) {
1045 uSameBssidNum++;
1046 }
1047 }
1048 if(uSameBssidNum >= 2) { //hit: desired AP is in hidden ssid mode!!!
1049 printk("SIOCSIWESSID:hidden ssid directly associate.......\n");
1050 vResetCommandTimer((HANDLE) pDevice);
1051 pMgmt->eScanType = WMAC_SCAN_PASSIVE; //this scan type,you'll submit scan result!
1052 bScheduleCommand((HANDLE) pDevice, WLAN_CMD_BSSID_SCAN, pMgmt->abyDesireSSID);
1053 bScheduleCommand((HANDLE) pDevice, WLAN_CMD_SSID, pMgmt->abyDesireSSID);
1054 }
1055 }
1056 }
1057 return 0;
1058 }
1059 #endif
1060
1061 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "set essid = %s \n", pItemSSID->abySSID);
1062/*
1063 #if WIRELESS_EXT < 21
1064 DEVICE_PRT(MSG_LEVEL_INFO, KERN_INFO " SIOCSIWESSID1 \n");
1065 pItemSSID->len = wrq->length - 1;
1066 #else
1067 DEVICE_PRT(MSG_LEVEL_INFO, KERN_INFO " SIOCSIWESSID2 \n");
1068 pItemSSID->len = wrq->length;
1069 #endif
1070 */
1071 }
1072
1073 if (pDevice->flags & DEVICE_FLAGS_OPENED) {
1074 pDevice->bCommit = TRUE;
1075 }
1076
1077
1078 return 0;
1079}
1080
1081
1082/*
1083 * Wireless Handler : get essid
1084 */
1085
1086int iwctl_giwessid(struct net_device *dev,
1087 struct iw_request_info *info,
1088 struct iw_point *wrq,
1089 char *extra)
1090{
1091
1092 PSDevice pDevice = (PSDevice)dev->priv;
1093 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
1094 PWLAN_IE_SSID pItemSSID;
1095
1096 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWESSID \n");
1097
1098 // Note : if wrq->u.data.flags != 0, we should
1099 // get the relevant SSID from the SSID list...
1100
1101 // Get the current SSID
1102 pItemSSID = (PWLAN_IE_SSID)pMgmt->abyCurrSSID;
1103 //pItemSSID = (PWLAN_IE_SSID)pMgmt->abyDesireSSID;
1104 memcpy(extra, pItemSSID->abySSID , pItemSSID->len);
1105 extra[pItemSSID->len] = '\0';
1106 wrq->length = pItemSSID->len + 1;
1107 //2008-0409-03, <Add> by Einsn Liu
1108 #if WIRELESS_EXT < 21
1109 wrq->length = pItemSSID->len + 1;
1110 #else
1111 wrq->length = pItemSSID->len;
1112 #endif
1113 wrq->flags = 1; // active
1114
1115
1116 return 0;
1117}
1118
1119/*
1120 * Wireless Handler : set data rate
1121 */
1122
1123int iwctl_siwrate(struct net_device *dev,
1124 struct iw_request_info *info,
1125 struct iw_param *wrq,
1126 char *extra)
1127{
1128 PSDevice pDevice = (PSDevice)dev->priv;
1129 int rc = 0;
1130 u8 brate = 0;
1131 int i;
1132 BYTE abySupportedRates[13]= {0x02, 0x04, 0x0B, 0x16, 0x0c, 0x12, 0x18, 0x24, 0x30, 0x48, 0x60, 0x6C, 0x90};
1133
1134
1135 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWRATE \n");
1136 if (!(pDevice->flags & DEVICE_FLAGS_OPENED)) {
1137 rc = -EINVAL;
1138 return rc;
1139 }
1140
1141 // First : get a valid bit rate value
1142
1143 // Which type of value
1144 if((wrq->value < 13) &&
1145 (wrq->value >= 0)) {
1146 // Setting by rate index
1147 // Find value in the magic rate table
1148 brate = wrq->value;
1149 } else {
1150 // Setting by frequency value
1151 u8 normvalue = (u8) (wrq->value/500000);
1152
1153 // Check if rate is valid
1154 for(i = 0 ; i < 13 ; i++) {
1155 if(normvalue == abySupportedRates[i]) {
1156 brate = i;
1157 break;
1158 }
1159 }
1160 }
1161 // -1 designed the max rate (mostly auto mode)
1162 if(wrq->value == -1) {
1163 // Get the highest available rate
1164 for(i = 0 ; i < 13 ; i++) {
1165 if(abySupportedRates[i] == 0)
1166 break;
1167 }
1168 if(i != 0)
1169 brate = i - 1;
1170
1171 }
1172 // Check that it is valid
1173 // brate is index of abySupportedRates[]
1174 if(brate > 13 ) {
1175 rc = -EINVAL;
1176 return rc;
1177 }
1178
1179 // Now, check if we want a fixed or auto value
1180 if(wrq->fixed != 0) {
1181 // Fixed mode
1182 // One rate, fixed
1183 printk("Rate Fix\n");
1184 pDevice->bFixRate = TRUE;
1185 if ((pDevice->byBBType == BB_TYPE_11B)&& (brate > 3)) {
1186
1187 pDevice->uConnectionRate = 3;
1188 }
1189 else {
1190 pDevice->uConnectionRate = brate;
1191 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Fixed to Rate %d \n", pDevice->uConnectionRate);
1192 }
1193
1194 }
1195 else {
1196 pDevice->bFixRate = FALSE;
1197 pDevice->uConnectionRate = 13;
1198 printk("auto rate:connection_rate is 13\n");
1199}
1200
1201 return rc;
1202}
1203
1204/*
1205 * Wireless Handler : get data rate
1206 */
1207
1208int iwctl_giwrate(struct net_device *dev,
1209 struct iw_request_info *info,
1210 struct iw_param *wrq,
1211 char *extra)
1212{
1213 PSDevice pDevice = (PSDevice)dev->priv;
1214//2007-0118-05,<Mark> by EinsnLiu
1215//Mark the unnecessary sentences.
1216// PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
1217
1218 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWRATE \n");
1219 {
1220 BYTE abySupportedRates[13]= {0x02, 0x04, 0x0B, 0x16, 0x0c, 0x12, 0x18, 0x24, 0x30, 0x48, 0x60, 0x6C, 0x90};
1221 int brate = 0;
1222//2008-5-8 <modify> by chester
1223if(pDevice->bLinkPass){
1224if(pDevice->bFixRate == TRUE){
1225 if (pDevice->uConnectionRate < 13) {
1226 brate = abySupportedRates[pDevice->uConnectionRate];
1227 }else {
1228 if (pDevice->byBBType == BB_TYPE_11B)
1229 brate = 0x16;
1230 if (pDevice->byBBType == BB_TYPE_11G)
1231 brate = 0x6C;
1232 if (pDevice->byBBType == BB_TYPE_11A)
1233 brate = 0x6C;
1234 }
1235}
1236else
1237{
1238
1239 brate = abySupportedRates[TxRate_iwconfig];
1240}
1241}
1242else brate =0;
1243//2007-0118-05,<Mark> by EinsnLiu
1244//Mark the unnecessary sentences.
1245/*
1246 if (pMgmt->eCurrMode == WMAC_MODE_ESS_AP) {
1247 if (pDevice->byBBType == BB_TYPE_11B)
1248 brate = 0x16;
1249 if (pDevice->byBBType == BB_TYPE_11G)
1250 brate = 0x6C;
1251 if (pDevice->byBBType == BB_TYPE_11A)
1252 brate = 0x6C;
1253 }
1254*/
1255
1256// if (pDevice->uConnectionRate == 13)
1257// brate = abySupportedRates[pDevice->wCurrentRate];
1258 wrq->value = brate * 500000;
1259 // If more than one rate, set auto
1260 if (pDevice->bFixRate == TRUE)
1261 wrq->fixed = TRUE;
1262 }
1263
1264
1265 return 0;
1266}
1267
1268
1269
1270/*
1271 * Wireless Handler : set rts threshold
1272 */
1273
1274int iwctl_siwrts(struct net_device *dev,
1275 struct iw_request_info *info,
1276 struct iw_param *wrq,
1277 char *extra)
1278{
1279 PSDevice pDevice = (PSDevice)dev->priv;
1280 int rc = 0;
1281
1282 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWRTS \n");
1283
1284 {
1285 int rthr = wrq->value;
1286 if(wrq->disabled)
1287 rthr = 2312;
1288 if((rthr < 0) || (rthr > 2312)) {
1289 rc = -EINVAL;
1290 }else {
1291 pDevice->wRTSThreshold = rthr;
1292 }
1293 }
1294
1295 return 0;
1296}
1297
1298/*
1299 * Wireless Handler : get rts
1300 */
1301
1302int iwctl_giwrts(struct net_device *dev,
1303 struct iw_request_info *info,
1304 struct iw_param *wrq,
1305 char *extra)
1306{
1307 PSDevice pDevice = (PSDevice)dev->priv;
1308
1309 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWRTS \n");
1310 wrq->value = pDevice->wRTSThreshold;
1311 wrq->disabled = (wrq->value >= 2312);
1312 wrq->fixed = 1;
1313
1314 return 0;
1315}
1316
1317/*
1318 * Wireless Handler : set fragment threshold
1319 */
1320
1321int iwctl_siwfrag(struct net_device *dev,
1322 struct iw_request_info *info,
1323 struct iw_param *wrq,
1324 char *extra)
1325{
1326 PSDevice pDevice = (PSDevice)dev->priv;
1327 int rc = 0;
1328 int fthr = wrq->value;
1329
1330
1331 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWFRAG \n");
1332
1333
1334 if (wrq->disabled)
1335 fthr = 2312;
1336 if((fthr < 256) || (fthr > 2312)) {
1337 rc = -EINVAL;
1338 }else {
1339 fthr &= ~0x1; // Get an even value
1340 pDevice->wFragmentationThreshold = (u16)fthr;
1341 }
1342
1343 return rc;
1344}
1345
1346/*
1347 * Wireless Handler : get fragment threshold
1348 */
1349
1350int iwctl_giwfrag(struct net_device *dev,
1351 struct iw_request_info *info,
1352 struct iw_param *wrq,
1353 char *extra)
1354{
1355 PSDevice pDevice = (PSDevice)dev->priv;
1356
1357 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWFRAG \n");
1358 wrq->value = pDevice->wFragmentationThreshold;
1359 wrq->disabled = (wrq->value >= 2312);
1360 wrq->fixed = 1;
1361
1362 return 0;
1363}
1364
1365
1366
1367/*
1368 * Wireless Handler : set retry threshold
1369 */
1370int iwctl_siwretry(struct net_device *dev,
1371 struct iw_request_info *info,
1372 struct iw_param *wrq,
1373 char *extra)
1374{
1375 PSDevice pDevice = (PSDevice)dev->priv;
1376 int rc = 0;
1377
1378
1379 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWRETRY \n");
1380
1381 if (wrq->disabled) {
1382 rc = -EINVAL;
1383 return rc;
1384 }
1385
1386 if (wrq->flags & IW_RETRY_LIMIT) {
1387 if(wrq->flags & IW_RETRY_MAX)
1388 pDevice->byLongRetryLimit = wrq->value;
1389 else if (wrq->flags & IW_RETRY_MIN)
1390 pDevice->byShortRetryLimit = wrq->value;
1391 else {
1392 // No modifier : set both
1393 pDevice->byShortRetryLimit = wrq->value;
1394 pDevice->byLongRetryLimit = wrq->value;
1395 }
1396 }
1397 if (wrq->flags & IW_RETRY_LIFETIME) {
1398 pDevice->wMaxTransmitMSDULifetime = wrq->value;
1399 }
1400
1401
1402 return rc;
1403}
1404
1405/*
1406 * Wireless Handler : get retry threshold
1407 */
1408int iwctl_giwretry(struct net_device *dev,
1409 struct iw_request_info *info,
1410 struct iw_param *wrq,
1411 char *extra)
1412{
1413 PSDevice pDevice = (PSDevice)dev->priv;
1414 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWRETRY \n");
1415 wrq->disabled = 0; // Can't be disabled
1416
1417 // Note : by default, display the min retry number
1418 if((wrq->flags & IW_RETRY_TYPE) == IW_RETRY_LIFETIME) {
1419 wrq->flags = IW_RETRY_LIFETIME;
1420 wrq->value = (int)pDevice->wMaxTransmitMSDULifetime; //ms
1421 } else if((wrq->flags & IW_RETRY_MAX)) {
1422 wrq->flags = IW_RETRY_LIMIT | IW_RETRY_MAX;
1423 wrq->value = (int)pDevice->byLongRetryLimit;
1424 } else {
1425 wrq->flags = IW_RETRY_LIMIT;
1426 wrq->value = (int)pDevice->byShortRetryLimit;
1427 if((int)pDevice->byShortRetryLimit != (int)pDevice->byLongRetryLimit)
1428 wrq->flags |= IW_RETRY_MIN;
1429 }
1430
1431
1432 return 0;
1433}
1434
1435
1436/*
1437 * Wireless Handler : set encode mode
1438 */
1439int iwctl_siwencode(struct net_device *dev,
1440 struct iw_request_info *info,
1441 struct iw_point *wrq,
1442 char *extra)
1443{
1444 PSDevice pDevice = (PSDevice)dev->priv;
1445 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
1446 DWORD dwKeyIndex = (DWORD)(wrq->flags & IW_ENCODE_INDEX);
1447 int ii,uu, rc = 0;
1448 int index = (wrq->flags & IW_ENCODE_INDEX);
1449
1450//2007-0207-07,<Modify> by EinsnLiu
1451//There are some problems when using iwconfig encode/key command to set the WEP key.
1452//I almost rewrite this function.
1453//now it support:(assume the wireless interface's name is eth0)
1454//iwconfig eth0 key [1] 1122334455 open /*set key stirng to index 1,and driver using key index is set to 1*/
1455//iwconfig eth0 key [3] /*set driver using key index to 3,the key string no change */
1456//iwconfig eth0 key 1122334455 /*set key string to driver using index*/
1457//iwconfig eth0 key restricted /*enable share key*/
1458
1459 PSKeyTable pkeytab;
1460
1461 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWENCODE \n");
1462
1463if((wrq->flags & IW_ENCODE_DISABLED)==0){
1464 //Not disable encryption
1465
1466 if (dwKeyIndex > WLAN_WEP_NKEYS) {
1467 rc = -EINVAL;
1468 return rc;
1469 }
1470
1471 if(dwKeyIndex<1&&((wrq->flags&IW_ENCODE_NOKEY)==0)){//set default key
1472 if(pDevice->byKeyIndex<WLAN_WEP_NKEYS){
1473 dwKeyIndex=pDevice->byKeyIndex;
1474 }
1475 else dwKeyIndex=0;
1476 }else dwKeyIndex--;
1477
1478
1479 // Check the size of the key
1480 if (wrq->length > WLAN_WEP232_KEYLEN) {
1481 rc = -EINVAL;
1482 return rc;
1483 }
1484
1485 if(wrq->length>0){//have key
1486
1487 if (wrq->length == WLAN_WEP232_KEYLEN) {
1488 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Set 232 bit wep key\n");
1489 }
1490 else if (wrq->length == WLAN_WEP104_KEYLEN) {
1491 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Set 104 bit wep key\n");
1492 }
1493 else if (wrq->length == WLAN_WEP40_KEYLEN) {
1494 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Set 40 bit wep key, index= %d\n", (int)dwKeyIndex);
1495 }else {//no support length
1496 rc = -EINVAL;
1497 return rc;
1498 }
1499 memset(pDevice->abyKey, 0, WLAN_WEP232_KEYLEN);
1500 memcpy(pDevice->abyKey, extra, wrq->length);
1501
1502 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"abyKey: ");
1503 for (ii = 0; ii < wrq->length; ii++) {
1504 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%02x ", pDevice->abyKey[ii]);
1505 }
1506
1507 if (pDevice->flags & DEVICE_FLAGS_OPENED) {
1508 spin_lock_irq(&pDevice->lock);
1509 KeybSetDefaultKey(&(pDevice->sKey),
1510 (DWORD)(dwKeyIndex | (1 << 31)),
1511 wrq->length,
1512 NULL,
1513 pDevice->abyKey,
1514 KEY_CTL_WEP,
1515 pDevice->PortOffset,
1516 pDevice->byLocalID
1517 );
1518 spin_unlock_irq(&pDevice->lock);
1519 }
1520 pDevice->byKeyIndex = (BYTE)dwKeyIndex;
1521 pDevice->uKeyLength = wrq->length;
1522 pDevice->bTransmitKey = TRUE;
1523 pDevice->bEncryptionEnable = TRUE;
1524 pDevice->eEncryptionStatus = Ndis802_11Encryption1Enabled;
1525
1526 }else if(index>0){
1527 //when the length is 0 the request only changes the default transmit key index
1528 //check the new key has a non zero lenget
1529 if(pDevice->bEncryptionEnable==FALSE)
1530 {
1531 rc = -EINVAL;
1532 return rc;
1533 }
1534 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Just set Default key Index:\n");
1535 pkeytab=&(pDevice->sKey.KeyTable[MAX_KEY_TABLE-1]);
1536 if(pkeytab->GroupKey[(BYTE)dwKeyIndex].uKeyLength==0){
1537 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Default key len is 0\n");
1538 rc = -EINVAL;
1539 return rc;
1540 }
1541 pDevice->byKeyIndex =(BYTE)dwKeyIndex;
1542 pkeytab->dwGTKeyIndex =dwKeyIndex | (1 << 31);
1543 pkeytab->GroupKey[(BYTE)dwKeyIndex].dwKeyIndex=dwKeyIndex | (1 << 31);
1544 }
1545
1546}else {//disable the key
1547 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Disable WEP function\n");
1548 if(pDevice->bEncryptionEnable==FALSE)
1549 return 0;
1550 pMgmt->bShareKeyAlgorithm = FALSE;
1551 pDevice->bEncryptionEnable = FALSE;
1552 pDevice->eEncryptionStatus = Ndis802_11EncryptionDisabled;
1553 if (pDevice->flags & DEVICE_FLAGS_OPENED) {
1554 spin_lock_irq(&pDevice->lock);
1555 for(uu=0;uu<MAX_KEY_TABLE;uu++)
1556 MACvDisableKeyEntry(pDevice->PortOffset, uu);
1557 spin_unlock_irq(&pDevice->lock);
1558 }
1559}
1560//End Modify,Einsn
1561
1562/*
1563 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWENCODE \n");
1564
1565 // Check the size of the key
1566 if (wrq->length > WLAN_WEP232_KEYLEN) {
1567 rc = -EINVAL;
1568 return rc;
1569 }
1570
1571 if (dwKeyIndex > WLAN_WEP_NKEYS) {
1572 rc = -EINVAL;
1573 return rc;
1574 }
1575
1576 if (dwKeyIndex > 0)
1577 dwKeyIndex--;
1578
1579 // Send the key to the card
1580 if (wrq->length > 0) {
1581
1582 if (wrq->length == WLAN_WEP232_KEYLEN) {
1583 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Set 232 bit wep key\n");
1584 }
1585 else if (wrq->length == WLAN_WEP104_KEYLEN) {
1586 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Set 104 bit wep key\n");
1587 }
1588 else if (wrq->length == WLAN_WEP40_KEYLEN) {
1589 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Set 40 bit wep key, index= %d\n", (int)dwKeyIndex);
1590 }
1591 memset(pDevice->abyKey, 0, WLAN_WEP232_KEYLEN);
1592 memcpy(pDevice->abyKey, extra, wrq->length);
1593
1594 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"abyKey: ");
1595 for (ii = 0; ii < wrq->length; ii++) {
1596 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%02x ", pDevice->abyKey[ii]);
1597 }
1598
1599 if (pDevice->flags & DEVICE_FLAGS_OPENED) {
1600 spin_lock_irq(&pDevice->lock);
1601 KeybSetDefaultKey(&(pDevice->sKey),
1602 (DWORD)(pDevice->byKeyIndex | (1 << 31)),
1603 pDevice->uKeyLength,
1604 NULL,
1605 pDevice->abyKey,
1606 KEY_CTL_WEP,
1607 pDevice->PortOffset,
1608 pDevice->byLocalID
1609 );
1610 spin_unlock_irq(&pDevice->lock);
1611 }
1612 pDevice->byKeyIndex = (BYTE)dwKeyIndex;
1613 pDevice->uKeyLength = wrq->length;
1614 pDevice->bTransmitKey = TRUE;
1615 pDevice->bEncryptionEnable = TRUE;
1616 pDevice->eEncryptionStatus = Ndis802_11Encryption1Enabled;
1617
1618 // Do we want to just set the transmit key index ?
1619 if ( index < 4 ) {
1620 pDevice->byKeyIndex = index;
1621 }
1622 else if(!wrq->flags & IW_ENCODE_MODE) {
1623 rc = -EINVAL;
1624 return rc;
1625 }
1626 }
1627 // Read the flags
1628 if(wrq->flags & IW_ENCODE_DISABLED){
1629
1630 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Disable WEP function\n");
1631 pMgmt->bShareKeyAlgorithm = FALSE;
1632 pDevice->bEncryptionEnable = FALSE;
1633 pDevice->eEncryptionStatus = Ndis802_11EncryptionDisabled;
1634 if (pDevice->flags & DEVICE_FLAGS_OPENED) {
1635 spin_lock_irq(&pDevice->lock);
1636 for(uu=0;uu<MAX_KEY_TABLE;uu++)
1637 MACvDisableKeyEntry(pDevice->PortOffset, uu);
1638 spin_unlock_irq(&pDevice->lock);
1639 }
1640 }
1641*/
1642
1643 if(wrq->flags & IW_ENCODE_RESTRICTED) {
1644 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Enable WEP & ShareKey System\n");
1645 pMgmt->bShareKeyAlgorithm = TRUE;
1646 }
1647 if(wrq->flags & IW_ENCODE_OPEN) {
1648 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Enable WEP & Open System\n");
1649 pMgmt->bShareKeyAlgorithm = FALSE;
1650 }
1651 return rc;
1652}
1653
1654/*
1655 * Wireless Handler : get encode mode
1656 */
1657 /*
1658int iwctl_giwencode(struct net_device *dev,
1659 struct iw_request_info *info,
1660 struct iw_point *wrq,
1661 char *extra)
1662{
1663 PSDevice pDevice = (PSDevice)dev->priv;
1664 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
1665 int rc = 0;
1666 char abyKey[WLAN_WEP232_KEYLEN];
1667 UINT index = (UINT)(wrq->flags & IW_ENCODE_INDEX);
1668 PSKeyItem pKey = NULL;
1669
1670 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWENCODE\n");
1671//2007-0207-06,<Add> by EinsnLiu
1672//the key index in iwconfig is 1-4 when our driver is 0-3
1673//so it can't be used directly.
1674//if the index is 0,we should used the index set by driver.
1675 if (index > WLAN_WEP_NKEYS) {
1676 rc = -EINVAL;
1677 return rc;
1678 }
1679 if(index<1){//set default key
1680 if(pDevice->byKeyIndex<WLAN_WEP_NKEYS){
1681 index=pDevice->byKeyIndex;
1682 }
1683 else index=0;
1684 }else index--;
1685//End Add,Einsn
1686
1687 memset(abyKey, 0, sizeof(abyKey));
1688 // Check encryption mode
1689 wrq->flags = IW_ENCODE_NOKEY;
1690 // Is WEP enabled ???
1691 if (pDevice->bEncryptionEnable)
1692 wrq->flags |= IW_ENCODE_ENABLED;
1693 else
1694 wrq->flags |= IW_ENCODE_DISABLED;
1695
1696 if (pMgmt->bShareKeyAlgorithm)
1697 wrq->flags |= IW_ENCODE_RESTRICTED;
1698 else
1699 wrq->flags |= IW_ENCODE_OPEN;
1700
1701 if (KeybGetKey(&(pDevice->sKey), pDevice->abyBroadcastAddr, (BYTE)index , &pKey)){
1702 wrq->length = pKey->uKeyLength;
1703 memcpy(abyKey, pKey->abyKey, pKey->uKeyLength);
1704//2007-0207-06,<Modify> by EinsnLiu
1705//only get key success need to copy data
1706//index should +1.
1707//there is not necessary to return -EINVAL when get key failed
1708//if return -EINVAL,the encryption item can't be display by the command "iwconfig".
1709 wrq->flags |= index+1;
1710 memcpy(extra, abyKey, WLAN_WEP232_KEYLEN);
1711 }
1712
1713 //else {
1714 // rc = -EINVAL;
1715 // return rc;
1716 // }
1717
1718
1719//End Modify,Einsn
1720
1721 return 0;
1722}
1723*/
1724
1725//2008-0409-06, <Add> by Einsn Liu
1726
1727int iwctl_giwencode(struct net_device *dev,
1728 struct iw_request_info *info,
1729 struct iw_point *wrq,
1730 char *extra)
1731{
1732 PSDevice pDevice = (PSDevice)dev->priv;
1733 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
1734 char abyKey[WLAN_WEP232_KEYLEN];
1735
1736 UINT index = (UINT)(wrq->flags & IW_ENCODE_INDEX);
1737 PSKeyItem pKey = NULL;
1738
1739 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWENCODE\n");
1740
1741 if (index > WLAN_WEP_NKEYS) {
1742 return -EINVAL;
1743 }
1744 if(index<1){//get default key
1745 if(pDevice->byKeyIndex<WLAN_WEP_NKEYS){
1746 index=pDevice->byKeyIndex;
1747 } else
1748 index=0;
1749 }else
1750 index--;
1751
1752 memset(abyKey, 0, WLAN_WEP232_KEYLEN);
1753 // Check encryption mode
1754 wrq->flags = IW_ENCODE_NOKEY;
1755 // Is WEP enabled ???
1756 if (pDevice->bEncryptionEnable)
1757 wrq->flags |= IW_ENCODE_ENABLED;
1758 else
1759 wrq->flags |= IW_ENCODE_DISABLED;
1760
1761 if (pMgmt->bShareKeyAlgorithm)
1762 wrq->flags |= IW_ENCODE_RESTRICTED;
1763 else
1764 wrq->flags |= IW_ENCODE_OPEN;
1765 wrq->length=0;
1766
1767 if((index==0)&&(pDevice->eEncryptionStatus == Ndis802_11Encryption2Enabled||
1768 pDevice->eEncryptionStatus == Ndis802_11Encryption3Enabled)){//get wpa pairwise key
1769 if (KeybGetKey(&(pDevice->sKey),pMgmt->abyCurrBSSID, 0xffffffff, &pKey)){
1770 wrq->length = pKey->uKeyLength;
1771 memcpy(abyKey, pKey->abyKey, pKey->uKeyLength);
1772 memcpy(extra, abyKey, WLAN_WEP232_KEYLEN);
1773 }
1774 }else if (KeybGetKey(&(pDevice->sKey), pDevice->abyBroadcastAddr, (BYTE)index , &pKey)){
1775 wrq->length = pKey->uKeyLength;
1776 memcpy(abyKey, pKey->abyKey, pKey->uKeyLength);
1777 memcpy(extra, abyKey, WLAN_WEP232_KEYLEN);
1778 }
1779
1780 wrq->flags |= index+1;
1781
1782 return 0;
1783}
1784
1785/*
1786 * Wireless Handler : set power mode
1787 */
1788int iwctl_siwpower(struct net_device *dev,
1789 struct iw_request_info *info,
1790 struct iw_param *wrq,
1791 char *extra)
1792{
1793 PSDevice pDevice = (PSDevice)dev->priv;
1794 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
1795 int rc = 0;
1796
1797 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWPOWER \n");
1798
1799 if (!(pDevice->flags & DEVICE_FLAGS_OPENED)) {
1800 rc = -EINVAL;
1801 return rc;
1802 }
1803
1804 if (wrq->disabled) {
1805 pDevice->ePSMode = WMAC_POWER_CAM;
1806 PSvDisablePowerSaving(pDevice);
1807 return rc;
1808 }
1809 if ((wrq->flags & IW_POWER_TYPE) == IW_POWER_TIMEOUT) {
1810 pDevice->ePSMode = WMAC_POWER_FAST;
1811 PSvEnablePowerSaving((HANDLE)pDevice, pMgmt->wListenInterval);
1812
1813 } else if ((wrq->flags & IW_POWER_TYPE) == IW_POWER_PERIOD) {
1814 pDevice->ePSMode = WMAC_POWER_FAST;
1815 PSvEnablePowerSaving((HANDLE)pDevice, pMgmt->wListenInterval);
1816 }
1817 switch (wrq->flags & IW_POWER_MODE) {
1818 case IW_POWER_UNICAST_R:
1819 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWPOWER: IW_POWER_UNICAST_R \n");
1820 rc = -EINVAL;
1821 break;
1822 case IW_POWER_ALL_R:
1823 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWPOWER: IW_POWER_ALL_R \n");
1824 rc = -EINVAL;
1825 case IW_POWER_ON:
1826 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWPOWER: IW_POWER_ON \n");
1827 break;
1828 default:
1829 rc = -EINVAL;
1830 }
1831
1832 return rc;
1833}
1834
1835/*
1836 * Wireless Handler : get power mode
1837 */
1838int iwctl_giwpower(struct net_device *dev,
1839 struct iw_request_info *info,
1840 struct iw_param *wrq,
1841 char *extra)
1842{
1843 PSDevice pDevice = (PSDevice)dev->priv;
1844 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
1845 int mode = pDevice->ePSMode;
1846
1847
1848 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWPOWER \n");
1849
1850
1851 if ((wrq->disabled = (mode == WMAC_POWER_CAM)))
1852 return 0;
1853
1854 if ((wrq->flags & IW_POWER_TYPE) == IW_POWER_TIMEOUT) {
1855 wrq->value = (int)((pMgmt->wListenInterval * pMgmt->wCurrBeaconPeriod) << 10);
1856 wrq->flags = IW_POWER_TIMEOUT;
1857 } else {
1858 wrq->value = (int)((pMgmt->wListenInterval * pMgmt->wCurrBeaconPeriod) << 10);
1859 wrq->flags = IW_POWER_PERIOD;
1860 }
1861 wrq->flags |= IW_POWER_ALL_R;
1862
1863 return 0;
1864}
1865
1866
1867/*
1868 * Wireless Handler : get Sensitivity
1869 */
1870int iwctl_giwsens(struct net_device *dev,
1871 struct iw_request_info *info,
1872 struct iw_param *wrq,
1873 char *extra)
1874{
1875 PSDevice pDevice = (PSDevice)dev->priv;
1876 long ldBm;
1877
1878 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWSENS \n");
1879 if (pDevice->bLinkPass == TRUE) {
1880 RFvRSSITodBm(pDevice, (BYTE)(pDevice->uCurrRSSI), &ldBm);
1881 wrq->value = ldBm;
1882 }
1883 else {
1884 wrq->value = 0;
1885 };
1886 wrq->disabled = (wrq->value == 0);
1887 wrq->fixed = 1;
1888
1889
1890 return 0;
1891}
1892
1893//2008-0409-07, <Add> by Einsn Liu
1894#ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
1895
1896int iwctl_siwauth(struct net_device *dev,
1897 struct iw_request_info *info,
1898 struct iw_param *wrq,
1899 char *extra)
1900{
1901 PSDevice pDevice = (PSDevice)dev->priv;
1902 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
1903 int ret=0;
1904 static int wpa_version=0; //must be static to save the last value,einsn liu
1905 static int pairwise=0;
1906
1907 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWAUTH \n");
1908 switch (wrq->flags & IW_AUTH_INDEX) {
1909 case IW_AUTH_WPA_VERSION:
1910 wpa_version = wrq->value;
1911 if(wrq->value == IW_AUTH_WPA_VERSION_DISABLED) {
1912 printk("iwctl_siwauth:set WPADEV to disable at 1??????\n");
1913 //pDevice->bWPADevEnable = FALSE;
1914 }
1915 else if(wrq->value == IW_AUTH_WPA_VERSION_WPA) {
1916 printk("iwctl_siwauth:set WPADEV to WPA1******\n");
1917 }
1918 else {
1919 printk("iwctl_siwauth:set WPADEV to WPA2******\n");
1920 }
1921 //pDevice->bWPASuppWextEnabled =TRUE;
1922 break;
1923 case IW_AUTH_CIPHER_PAIRWISE:
1924 pairwise = wrq->value;
1925
1926 if(pairwise == IW_AUTH_CIPHER_CCMP){
1927 pDevice->eEncryptionStatus = Ndis802_11Encryption3Enabled;
1928 }else if(pairwise == IW_AUTH_CIPHER_TKIP){
1929 pDevice->eEncryptionStatus = Ndis802_11Encryption2Enabled;
1930 }else if(pairwise == IW_AUTH_CIPHER_WEP40||pairwise == IW_AUTH_CIPHER_WEP104){
1931 pDevice->eEncryptionStatus = Ndis802_11Encryption1Enabled;
1932 }else if(pairwise == IW_AUTH_CIPHER_NONE){
1933 //do nothing,einsn liu
1934 }else pDevice->eEncryptionStatus = Ndis802_11EncryptionDisabled;
1935
1936 break;
1937 case IW_AUTH_CIPHER_GROUP:
1938 if(wpa_version == IW_AUTH_WPA_VERSION_DISABLED)
1939 break;
1940 if(pairwise == IW_AUTH_CIPHER_NONE){
1941 if(wrq->value == IW_AUTH_CIPHER_CCMP){
1942 pDevice->eEncryptionStatus = Ndis802_11Encryption3Enabled;
1943 }else {
1944 pDevice->eEncryptionStatus = Ndis802_11Encryption2Enabled;
1945 }
1946 }
1947 break;
1948 case IW_AUTH_KEY_MGMT:
1949
1950 if(wpa_version == IW_AUTH_WPA_VERSION_WPA2){
1951 if(wrq->value == IW_AUTH_KEY_MGMT_PSK)
1952 pMgmt->eAuthenMode = WMAC_AUTH_WPA2PSK;
1953 else pMgmt->eAuthenMode = WMAC_AUTH_WPA2;
1954 }else if(wpa_version == IW_AUTH_WPA_VERSION_WPA){
1955 if(wrq->value == 0){
1956 pMgmt->eAuthenMode = WMAC_AUTH_WPANONE;
1957 }else if(wrq->value == IW_AUTH_KEY_MGMT_PSK)
1958 pMgmt->eAuthenMode = WMAC_AUTH_WPAPSK;
1959 else pMgmt->eAuthenMode = WMAC_AUTH_WPA;
1960 }
1961
1962 break;
1963 case IW_AUTH_TKIP_COUNTERMEASURES:
1964 break; /* FIXME */
1965 case IW_AUTH_DROP_UNENCRYPTED:
1966 break;
1967 case IW_AUTH_80211_AUTH_ALG:
1968 if(wrq->value==IW_AUTH_ALG_OPEN_SYSTEM){
1969 pMgmt->bShareKeyAlgorithm=FALSE;
1970 }else if(wrq->value==IW_AUTH_ALG_SHARED_KEY){
1971 pMgmt->bShareKeyAlgorithm=TRUE;
1972 }
1973 break;
1974 case IW_AUTH_WPA_ENABLED:
1975 //pDevice->bWPADevEnable = !! wrq->value;
1976 break;
1977 case IW_AUTH_RX_UNENCRYPTED_EAPOL:
1978 break;
1979 case IW_AUTH_ROAMING_CONTROL:
1980 ret = -EOPNOTSUPP;
1981 break;
1982 case IW_AUTH_PRIVACY_INVOKED:
1983 pDevice->bEncryptionEnable = !!wrq->value;
1984 if(pDevice->bEncryptionEnable == FALSE){
1985 wpa_version = 0;
1986 pairwise = 0;
1987 pDevice->eEncryptionStatus = Ndis802_11EncryptionDisabled;
1988 pMgmt->bShareKeyAlgorithm = FALSE;
1989 pMgmt->eAuthenMode = FALSE;
1990 //pDevice->bWPADevEnable = FALSE;
1991 }
1992
1993 break;
1994 default:
1995 ret = -EOPNOTSUPP;
1996 break;
1997 }
1998/*
1999 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "wpa_version = %d\n",wpa_version);
2000 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "pairwise = %d\n",pairwise);
2001 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "pDevice->eEncryptionStatus = %d\n",pDevice->eEncryptionStatus);
2002 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "pMgmt->eAuthenMode = %d\n",pMgmt->eAuthenMode);
2003 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "pMgmt->bShareKeyAlgorithm = %s\n",pMgmt->bShareKeyAlgorithm?"TRUE":"FALSE");
2004 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "pDevice->bEncryptionEnable = %s\n",pDevice->bEncryptionEnable?"TRUE":"FALSE");
2005 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "pDevice->bWPADevEnable = %s\n",pDevice->bWPADevEnable?"TRUE":"FALSE");
2006*/
2007 return ret;
2008}
2009
2010
2011int iwctl_giwauth(struct net_device *dev,
2012 struct iw_request_info *info,
2013 struct iw_param *wrq,
2014 char *extra)
2015{
2016 return -EOPNOTSUPP;
2017}
2018
2019
2020
2021int iwctl_siwgenie(struct net_device *dev,
2022 struct iw_request_info *info,
2023 struct iw_point *wrq,
2024 char *extra)
2025{
2026 PSDevice pDevice = (PSDevice)dev->priv;
2027 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
2028 int ret=0;
2029
2030 if(wrq->length){
2031 if ((wrq->length < 2) || (extra[1]+2 != wrq->length)) {
2032 ret = -EINVAL;
2033 goto out;
2034 }
2035 if(wrq->length > MAX_WPA_IE_LEN){
2036 ret = -ENOMEM;
2037 goto out;
2038 }
2039 memset(pMgmt->abyWPAIE, 0, MAX_WPA_IE_LEN);
2040 if(copy_from_user(pMgmt->abyWPAIE, extra, wrq->length)){
2041 ret = -EFAULT;
2042 goto out;
2043 }
2044 pMgmt->wWPAIELen = wrq->length;
2045 }else {
2046 memset(pMgmt->abyWPAIE, 0, MAX_WPA_IE_LEN);
2047 pMgmt->wWPAIELen = 0;
2048 }
2049
2050 out://not completely ...not necessary in wpa_supplicant 0.5.8
2051 return 0;
2052}
2053
2054int iwctl_giwgenie(struct net_device *dev,
2055 struct iw_request_info *info,
2056 struct iw_point *wrq,
2057 char *extra)
2058{
2059 PSDevice pDevice = (PSDevice)dev->priv;
2060 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
2061 int ret=0;
2062 int space = wrq->length;
2063
2064 wrq->length = 0;
2065 if(pMgmt->wWPAIELen > 0){
2066 wrq->length = pMgmt->wWPAIELen;
2067 if(pMgmt->wWPAIELen <= space){
2068 if(copy_to_user(extra, pMgmt->abyWPAIE, pMgmt->wWPAIELen)){
2069 ret = -EFAULT;
2070 }
2071 }else
2072 ret = -E2BIG;
2073 }
2074
2075 return ret;
2076}
2077
2078
2079int iwctl_siwencodeext(struct net_device *dev,
2080 struct iw_request_info *info,
2081 struct iw_point *wrq,
2082 char *extra)
2083{
2084 PSDevice pDevice = (PSDevice)dev->priv;
2085 struct iw_encode_ext *ext = (struct iw_encode_ext*)extra;
2086 struct viawget_wpa_param *param=NULL;
2087//original member
2088 wpa_alg alg_name;
2089 u8 addr[6];
2090 int key_idx, set_tx;
2091 u8 seq[IW_ENCODE_SEQ_MAX_SIZE];
2092 u8 key[64];
2093 size_t seq_len,key_len=0;
2094//
2095 // int ii;
2096 u8 *buf;
2097 size_t blen;
2098 u8 key_array[64];
2099 int ret=0;
2100
2101printk("SIOCSIWENCODEEXT...... \n");
2102
2103blen = sizeof(*param);
2104buf = kmalloc((int)blen, (int)GFP_KERNEL);
2105if (buf == NULL)
2106 return -ENOMEM;
2107memset(buf, 0, blen);
2108param = (struct viawget_wpa_param *) buf;
2109
2110//recover alg_name
2111switch (ext->alg) {
2112 case IW_ENCODE_ALG_NONE:
2113 alg_name = WPA_ALG_NONE;
2114 break;
2115 case IW_ENCODE_ALG_WEP:
2116 alg_name = WPA_ALG_WEP;
2117 break;
2118 case IW_ENCODE_ALG_TKIP:
2119 alg_name = WPA_ALG_TKIP;
2120 break;
2121 case IW_ENCODE_ALG_CCMP:
2122 alg_name = WPA_ALG_CCMP;
2123 break;
2124 default:
2125 printk("Unknown alg = %d\n",ext->alg);
2126 ret= -ENOMEM;
2127 goto error;
2128 }
2129//recover addr
2130 memcpy(addr, ext->addr.sa_data, ETH_ALEN);
2131//recover key_idx
2132 key_idx = (wrq->flags&IW_ENCODE_INDEX) - 1;
2133//recover set_tx
2134if(ext->ext_flags & IW_ENCODE_EXT_SET_TX_KEY)
2135 set_tx = 1;
2136//recover seq,seq_len
2137 if(ext->ext_flags & IW_ENCODE_EXT_RX_SEQ_VALID) {
2138 seq_len=IW_ENCODE_SEQ_MAX_SIZE;
2139 memcpy(seq, ext->rx_seq, seq_len);
2140 }
2141//recover key,key_len
2142if(ext->key_len) {
2143 key_len=ext->key_len;
2144 memcpy(key, &ext->key[0], key_len);
2145 }
2146
2147memset(key_array, 0, 64);
2148if ( key_len > 0) {
2149 memcpy(key_array, key, key_len);
2150 if (key_len == 32) {
2151 // notice ! the oder
2152 memcpy(&key_array[16], &key[24], 8);
2153 memcpy(&key_array[24], &key[16], 8);
2154 }
2155 }
2156
2157/**************Translate iw_encode_ext to viawget_wpa_param****************/
2158memcpy(param->addr, addr, ETH_ALEN);
2159param->u.wpa_key.alg_name = (int)alg_name;
2160param->u.wpa_key.set_tx = set_tx;
2161param->u.wpa_key.key_index = key_idx;
2162param->u.wpa_key.key_len = key_len;
2163param->u.wpa_key.key = (u8 *)key_array;
2164param->u.wpa_key.seq = (u8 *)seq;
2165param->u.wpa_key.seq_len = seq_len;
2166
2167#if 0
2168int ii;
2169printk("param->u.wpa_key.alg_name =%d\n",param->u.wpa_key.alg_name);
2170printk("param->addr=%02x:%02x:%02x:%02x:%02x:%02x\n",
2171 param->addr[0],param->addr[1],param->addr[2],
2172 param->addr[3],param->addr[4],param->addr[5]);
2173printk("param->u.wpa_key.set_tx =%d\n",param->u.wpa_key.set_tx);
2174printk("param->u.wpa_key.key_index =%d\n",param->u.wpa_key.key_index);
2175printk("param->u.wpa_key.key_len =%d\n",param->u.wpa_key.key_len);
2176printk("param->u.wpa_key.key =");
2177for(ii=0;ii<param->u.wpa_key.key_len;ii++)
2178 printk("%02x:",param->u.wpa_key.key[ii]);
2179 printk("\n");
2180printk("param->u.wpa_key.seq_len =%d\n",param->u.wpa_key.seq_len);
2181printk("param->u.wpa_key.seq =");
2182for(ii=0;ii<param->u.wpa_key.seq_len;ii++)
2183 printk("%02x:",param->u.wpa_key.seq[ii]);
2184 printk("\n");
2185
2186printk("...........\n");
2187#endif
2188//****set if current action is Network Manager count??
2189//****this method is so foolish,but there is no other way???
2190if(param->u.wpa_key.alg_name == WPA_ALG_NONE) {
2191 if(param->u.wpa_key.key_index ==0) {
2192 pDevice->bwextcount++;
2193 }
2194 if((pDevice->bwextcount == 1)&&(param->u.wpa_key.key_index ==1)) {
2195 pDevice->bwextcount++;
2196 }
2197 if((pDevice->bwextcount ==2)&&(param->u.wpa_key.key_index ==2)) {
2198 pDevice->bwextcount++;
2199 }
2200 if((pDevice->bwextcount ==3)&&(param->u.wpa_key.key_index ==3)) {
2201 pDevice->bwextcount++;
2202 }
2203 }
2204if( pDevice->bwextcount == 4) {
2205 printk("SIOCSIWENCODEEXT:Enable WPA WEXT SUPPORT!!!!!\n");
2206 pDevice->bwextcount=0;
2207 pDevice->bWPASuppWextEnabled = TRUE;
2208 }
2209//******
2210
2211 spin_lock_irq(&pDevice->lock);
2212 ret = wpa_set_keys(pDevice, param, TRUE);
2213 spin_unlock_irq(&pDevice->lock);
2214
2215error:
2216kfree(param);
2217 return ret;
2218}
2219
2220
2221
2222int iwctl_giwencodeext(struct net_device *dev,
2223 struct iw_request_info *info,
2224 struct iw_point *wrq,
2225 char *extra)
2226{
2227 return -EOPNOTSUPP;;
2228}
2229
2230int iwctl_siwmlme(struct net_device *dev,
2231 struct iw_request_info * info,
2232 struct iw_point *wrq,
2233 char *extra)
2234{
2235 PSDevice pDevice = (PSDevice)dev->priv;
2236 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
2237 struct iw_mlme *mlme = (struct iw_mlme *)extra;
2238 //u16 reason = cpu_to_le16(mlme->reason_code);
2239 int ret = 0;
2240
2241 if(memcmp(pMgmt->abyCurrBSSID, mlme->addr.sa_data, ETH_ALEN)){
2242 ret = -EINVAL;
2243 return ret;
2244 }
2245 switch(mlme->cmd){
2246 case IW_MLME_DEAUTH:
2247 //this command seems to be not complete,please test it --einsnliu
2248 //bScheduleCommand((HANDLE) pDevice, WLAN_CMD_DEAUTH, (PBYTE)&reason);
2249 break;
2250 case IW_MLME_DISASSOC:
2251 if(pDevice->bLinkPass == TRUE){
2252 printk("iwctl_siwmlme--->send DISASSOCIATE\n");
2253 //clear related flags
2254 memset(pMgmt->abyDesireBSSID, 0xFF,6);
2255 KeyvInitTable(&pDevice->sKey, pDevice->PortOffset);
2256 bScheduleCommand((HANDLE)pDevice, WLAN_CMD_DISASSOCIATE, NULL);
2257 }
2258 break;
2259 default:
2260 ret = -EOPNOTSUPP;
2261 }
2262
2263 return ret;
2264
2265}
2266
2267#endif
2268
2269
2270/*------------------------------------------------------------------*/
2271/*
2272 * Structures to export the Wireless Handlers
2273 */
2274
2275
2276#if WIRELESS_EXT > 12
2277
2278/*
2279static const iw_handler iwctl_handler[] =
2280{
2281 (iw_handler) iwctl_commit, // SIOCSIWCOMMIT
2282 (iw_handler) iwctl_giwname, // SIOCGIWNAME
2283 (iw_handler) NULL, // SIOCSIWNWID
2284 (iw_handler) NULL, // SIOCGIWNWID
2285 (iw_handler) iwctl_siwfreq, // SIOCSIWFREQ
2286 (iw_handler) iwctl_giwfreq, // SIOCGIWFREQ
2287 (iw_handler) iwctl_siwmode, // SIOCSIWMODE
2288 (iw_handler) iwctl_giwmode, // SIOCGIWMODE
2289 (iw_handler) NULL, // SIOCSIWSENS
2290 (iw_handler) iwctl_giwsens, // SIOCGIWSENS
2291 (iw_handler) NULL, // SIOCSIWRANGE
2292 (iw_handler) iwctl_giwrange, // SIOCGIWRANGE
2293 (iw_handler) NULL, // SIOCSIWPRIV
2294 (iw_handler) NULL, // SIOCGIWPRIV
2295 (iw_handler) NULL, // SIOCSIWSTATS
2296 (iw_handler) NULL, // SIOCGIWSTATS
2297 (iw_handler) NULL, // SIOCSIWSPY
2298 (iw_handler) NULL, // SIOCGIWSPY
2299 (iw_handler) NULL, // -- hole --
2300 (iw_handler) NULL, // -- hole --
2301 (iw_handler) iwctl_siwap, // SIOCSIWAP
2302 (iw_handler) iwctl_giwap, // SIOCGIWAP
2303 (iw_handler) NULL, // -- hole -- 0x16
2304 (iw_handler) iwctl_giwaplist, // SIOCGIWAPLIST
2305#if WIRELESS_EXT > 13
2306 (iw_handler) iwctl_siwscan, // SIOCSIWSCAN
2307 (iw_handler) iwctl_giwscan, // SIOCGIWSCAN
2308#else
2309 (iw_handler) NULL,
2310 (iw_handler) NULL,
2311#endif
2312 (iw_handler) iwctl_siwessid, // SIOCSIWESSID
2313 (iw_handler) iwctl_giwessid, // SIOCGIWESSID
2314 (iw_handler) NULL, // SIOCSIWNICKN
2315 (iw_handler) NULL, // SIOCGIWNICKN
2316 (iw_handler) NULL, // -- hole --
2317 (iw_handler) NULL, // -- hole --
2318 (iw_handler) iwctl_siwrate, // SIOCSIWRATE 0x20
2319 (iw_handler) iwctl_giwrate, // SIOCGIWRATE
2320 (iw_handler) iwctl_siwrts, // SIOCSIWRTS
2321 (iw_handler) iwctl_giwrts, // SIOCGIWRTS
2322 (iw_handler) iwctl_siwfrag, // SIOCSIWFRAG
2323 (iw_handler) iwctl_giwfrag, // SIOCGIWFRAG
2324 (iw_handler) NULL, // SIOCSIWTXPOW
2325 (iw_handler) NULL, // SIOCGIWTXPOW
2326 (iw_handler) iwctl_siwretry, // SIOCSIWRETRY
2327 (iw_handler) iwctl_giwretry, // SIOCGIWRETRY
2328 (iw_handler) iwctl_siwencode, // SIOCSIWENCODE
2329 (iw_handler) iwctl_giwencode, // SIOCGIWENCODE
2330 (iw_handler) iwctl_siwpower, // SIOCSIWPOWER
2331 (iw_handler) iwctl_giwpower, // SIOCGIWPOWER
2332#if WIRELESS_EXT > 17
2333 (iw_handler) NULL, // -- hole --
2334 (iw_handler) NULL, // -- hole --
2335 (iw_handler) iwctl_siwgenie, // SIOCSIWGENIE
2336 (iw_handler) iwctl_giwgenie, // SIOCGIWGENIE
2337 (iw_handler) iwctl_siwauth, // SIOCSIWAUTH
2338 (iw_handler) iwctl_giwauth, // SIOCGIWAUTH
2339 (iw_handler) iwctl_siwencodeext, // SIOCSIWENCODEEXT
2340 (iw_handler) iwctl_giwencodeext, // SIOCGIWENCODEEXT
2341 (iw_handler) NULL, // SIOCSIWPMKSA
2342 (iw_handler) NULL, // -- hole --
2343#endif // WIRELESS_EXT > 17
2344
2345};
2346*/
2347
2348static const iw_handler iwctl_handler[] =
2349{
2350 (iw_handler) iwctl_commit, // SIOCSIWCOMMIT
2351 (iw_handler) NULL, // SIOCGIWNAME
2352 (iw_handler) NULL, // SIOCSIWNWID
2353 (iw_handler) NULL, // SIOCGIWNWID
2354 (iw_handler) NULL, // SIOCSIWFREQ
2355 (iw_handler) NULL, // SIOCGIWFREQ
2356 (iw_handler) NULL, // SIOCSIWMODE
2357 (iw_handler) NULL, // SIOCGIWMODE
2358 (iw_handler) NULL, // SIOCSIWSENS
2359 (iw_handler) NULL, // SIOCGIWSENS
2360 (iw_handler) NULL, // SIOCSIWRANGE
2361 (iw_handler) iwctl_giwrange, // SIOCGIWRANGE
2362 (iw_handler) NULL, // SIOCSIWPRIV
2363 (iw_handler) NULL, // SIOCGIWPRIV
2364 (iw_handler) NULL, // SIOCSIWSTATS
2365 (iw_handler) NULL, // SIOCGIWSTATS
2366 (iw_handler) NULL, // SIOCSIWSPY
2367 (iw_handler) NULL, // SIOCGIWSPY
2368 (iw_handler) NULL, // -- hole --
2369 (iw_handler) NULL, // -- hole --
2370 (iw_handler) NULL, // SIOCSIWAP
2371 (iw_handler) NULL, // SIOCGIWAP
2372 (iw_handler) NULL, // -- hole -- 0x16
2373 (iw_handler) NULL, // SIOCGIWAPLIST
2374#if WIRELESS_EXT > 13
2375 (iw_handler) iwctl_siwscan, // SIOCSIWSCAN
2376 (iw_handler) iwctl_giwscan, // SIOCGIWSCAN
2377#else
2378 (iw_handler) NULL,
2379 (iw_handler) NULL,
2380#endif
2381 (iw_handler) NULL, // SIOCSIWESSID
2382 (iw_handler) NULL, // SIOCGIWESSID
2383 (iw_handler) NULL, // SIOCSIWNICKN
2384 (iw_handler) NULL, // SIOCGIWNICKN
2385 (iw_handler) NULL, // -- hole --
2386 (iw_handler) NULL, // -- hole --
2387 (iw_handler) NULL, // SIOCSIWRATE 0x20
2388 (iw_handler) NULL, // SIOCGIWRATE
2389 (iw_handler) NULL, // SIOCSIWRTS
2390 (iw_handler) NULL, // SIOCGIWRTS
2391 (iw_handler) NULL, // SIOCSIWFRAG
2392 (iw_handler) NULL, // SIOCGIWFRAG
2393 (iw_handler) NULL, // SIOCSIWTXPOW
2394 (iw_handler) NULL, // SIOCGIWTXPOW
2395 (iw_handler) NULL, // SIOCSIWRETRY
2396 (iw_handler) NULL, // SIOCGIWRETRY
2397 (iw_handler) NULL, // SIOCSIWENCODE
2398 (iw_handler) NULL, // SIOCGIWENCODE
2399 (iw_handler) NULL, // SIOCSIWPOWER
2400 (iw_handler) NULL, // SIOCGIWPOWER
2401
2402//2008-0409-07, <Add> by Einsn Liu
2403#if WIRELESS_EXT > 17
2404 (iw_handler) NULL, // -- hole --
2405 (iw_handler) NULL, // -- hole --
2406 (iw_handler) NULL, // SIOCSIWGENIE
2407 (iw_handler) NULL, // SIOCGIWGENIE
2408 (iw_handler) NULL, // SIOCSIWAUTH
2409 (iw_handler) NULL, // SIOCGIWAUTH
2410 (iw_handler) NULL, // SIOCSIWENCODEEXT
2411 (iw_handler) NULL, // SIOCGIWENCODEEXT
2412 (iw_handler) NULL, // SIOCSIWPMKSA
2413 (iw_handler) NULL, // -- hole --
2414#endif // WIRELESS_EXT > 17
2415};
2416
2417
2418static const iw_handler iwctl_private_handler[] =
2419{
2420 NULL, // SIOCIWFIRSTPRIV
2421};
2422
2423
2424struct iw_priv_args iwctl_private_args[] = {
2425{ IOCTL_CMD_SET,
2426 IW_PRIV_TYPE_CHAR | 1024, 0,
2427 "set"},
2428};
2429
2430
2431
2432const struct iw_handler_def iwctl_handler_def =
2433{
2434#if WIRELESS_EXT > 16
2435 .get_wireless_stats = &iwctl_get_wireless_stats,
2436#endif
2437 .num_standard = sizeof(iwctl_handler)/sizeof(iw_handler),
2438// .num_private = sizeof(iwctl_private_handler)/sizeof(iw_handler),
2439// .num_private_args = sizeof(iwctl_private_args)/sizeof(struct iw_priv_args),
2440 .num_private = 0,
2441 .num_private_args = 0,
2442 .standard = (iw_handler *) iwctl_handler,
2443// .private = (iw_handler *) iwctl_private_handler,
2444// .private_args = (struct iw_priv_args *)iwctl_private_args,
2445 .private = NULL,
2446 .private_args = NULL,
2447};
2448
2449
2450#endif // WIRELESS_EXT > 12
2451
2452
2453#endif // WIRELESS_EXT
diff --git a/drivers/staging/vt6655/iwctl.h b/drivers/staging/vt6655/iwctl.h
new file mode 100644
index 000000000000..07554e14d5f2
--- /dev/null
+++ b/drivers/staging/vt6655/iwctl.h
@@ -0,0 +1,332 @@
1/*
2 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
3 * All rights reserved.
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * File: iwctl.h
20 *
21 * Purpose:
22 *
23 * Author: Lyndon Chen
24 *
25 * Date: May 21, 2004
26 *
27 */
28
29
30#ifndef __IWCTL_H__
31#define __IWCTL_H__
32
33#if !defined(__DEVICE_H__)
34#include "device.h"
35#endif
36
37
38/*--------------------- Export Definitions -------------------------*/
39
40
41/*--------------------- Export Classes ----------------------------*/
42
43/*--------------------- Export Variables --------------------------*/
44
45/*--------------------- Export Functions --------------------------*/
46
47
48#ifdef __cplusplus
49extern "C" { /* Assume C declarations for C++ */
50#endif /* __cplusplus */
51
52
53#if WIRELESS_EXT < 18
54
55
56#define SIOCSIWMLME 0x8B16
57#define SIOCSIWGENIE 0x8B30
58
59// WPA : Authentication mode parameters
60#define SIOCSIWAUTH 0x8B32
61#define SIOCGIWAUTH 0x8B33
62
63// WPA : Extended version of encoding configuration
64#define SIOCSIWENCODEEXT 0x8B34
65#define SIOCGIWENCODEEXT 0x8B35
66
67#define IW_AUTH_WPA_VERSION 0
68#define IW_AUTH_CIPHER_PAIRWISE 1
69#define IW_AUTH_CIPHER_GROUP 2
70#define IW_AUTH_KEY_MGMT 3
71#define IW_AUTH_TKIP_COUNTERMEASURES 4
72#define IW_AUTH_DROP_UNENCRYPTED 5
73#define IW_AUTH_80211_AUTH_ALG 6
74#define IW_AUTH_WPA_ENABLED 7
75#define IW_AUTH_RX_UNENCRYPTED_EAPOL 8
76#define IW_AUTH_ROAMING_CONTROL 9
77#define IW_AUTH_PRIVACY_INVOKED 10
78
79#define IW_AUTH_WPA_VERSION_DISABLED 0x00000001
80#define IW_AUTH_WPA_VERSION_WPA 0x00000002
81#define IW_AUTH_WPA_VERSION_WPA2 0x00000004
82
83#define IW_AUTH_CIPHER_NONE 0x00000001
84#define IW_AUTH_CIPHER_WEP40 0x00000002
85#define IW_AUTH_CIPHER_TKIP 0x00000004
86#define IW_AUTH_CIPHER_CCMP 0x00000008
87#define IW_AUTH_CIPHER_WEP104 0x00000010
88
89#define IW_AUTH_KEY_MGMT_802_1X 1
90#define IW_AUTH_KEY_MGMT_PSK 2
91
92#define IW_AUTH_ALG_OPEN_SYSTEM 0x00000001
93#define IW_AUTH_ALG_SHARED_KEY 0x00000002
94#define IW_AUTH_ALG_LEAP 0x00000004
95
96#define IW_AUTH_ROAMING_ENABLE 0
97#define IW_AUTH_ROAMING_DISABLE 1
98
99#define IW_ENCODE_SEQ_MAX_SIZE 8
100
101#define IW_ENCODE_ALG_NONE 0
102#define IW_ENCODE_ALG_WEP 1
103#define IW_ENCODE_ALG_TKIP 2
104#define IW_ENCODE_ALG_CCMP 3
105
106
107struct iw_encode_ext
108{
109 __u32 ext_flags; // IW_ENCODE_EXT_*
110 __u8 tx_seq[IW_ENCODE_SEQ_MAX_SIZE]; // LSB first
111 __u8 rx_seq[IW_ENCODE_SEQ_MAX_SIZE]; // LSB first
112 struct sockaddr addr; // ff:ff:ff:ff:ff:ff for broadcast/multicast
113 // (group) keys or unicast address for
114 // individual keys
115 __u16 alg; // IW_ENCODE_ALG_*
116 __u16 key_len;
117 __u8 key[0];
118};
119
120
121struct iw_mlme
122{
123 __u16 cmd; /* IW_MLME_* */
124 __u16 reason_code;
125 struct sockaddr addr;
126};
127
128#endif // WIRELESS_EXT < 18
129
130
131
132#ifdef WIRELESS_EXT
133
134struct iw_statistics *iwctl_get_wireless_stats (struct net_device *dev);
135
136
137int iwctl_siwap(struct net_device *dev,
138 struct iw_request_info *info,
139 struct sockaddr *wrq,
140 char *extra);
141
142int iwctl_giwrange(struct net_device *dev,
143 struct iw_request_info *info,
144 struct iw_point *wrq,
145 char *extra);
146
147
148int iwctl_giwmode(struct net_device *dev,
149 struct iw_request_info *info,
150 __u32 *wmode,
151 char *extra);
152
153int iwctl_siwmode(struct net_device *dev,
154 struct iw_request_info *info,
155 __u32 *wmode,
156 char *extra);
157
158int iwctl_giwfreq(struct net_device *dev,
159 struct iw_request_info *info,
160 struct iw_freq *wrq,
161 char *extra);
162
163int iwctl_siwfreq(struct net_device *dev,
164 struct iw_request_info *info,
165 struct iw_freq *wrq,
166 char *extra);
167
168int iwctl_giwname(struct net_device *dev,
169 struct iw_request_info *info,
170 char *wrq,
171 char *extra);
172
173int iwctl_giwnwid(struct net_device *dev,
174 struct iw_request_info *info,
175 struct iw_param *wrq,
176 char *extra) ;
177
178int iwctl_giwsens(struct net_device *dev,
179 struct iw_request_info *info,
180 struct iw_param *wrq,
181 char *extra);
182
183int iwctl_giwap(struct net_device *dev,
184 struct iw_request_info *info,
185 struct sockaddr *wrq,
186 char *extra);
187
188int iwctl_giwaplist(struct net_device *dev,
189 struct iw_request_info *info,
190 struct iw_point *wrq,
191 char *extra);
192
193int iwctl_siwessid(struct net_device *dev,
194 struct iw_request_info *info,
195 struct iw_point *wrq,
196 char *extra);
197
198int iwctl_giwessid(struct net_device *dev,
199 struct iw_request_info *info,
200 struct iw_point *wrq,
201 char *extra);
202
203int iwctl_siwrate(struct net_device *dev,
204 struct iw_request_info *info,
205 struct iw_param *wrq,
206 char *extra);
207
208int iwctl_giwrate(struct net_device *dev,
209 struct iw_request_info *info,
210 struct iw_param *wrq,
211 char *extra);
212
213int iwctl_siwrts(struct net_device *dev,
214 struct iw_request_info *info,
215 struct iw_param *wrq,
216 char *extra);
217
218
219int iwctl_giwrts(struct net_device *dev,
220 struct iw_request_info *info,
221 struct iw_param *wrq,
222 char *extra);
223
224int iwctl_siwfrag(struct net_device *dev,
225 struct iw_request_info *info,
226 struct iw_param *wrq,
227 char *extra);
228
229int iwctl_giwfrag(struct net_device *dev,
230 struct iw_request_info *info,
231 struct iw_param *wrq,
232 char *extra);
233
234int iwctl_siwretry(struct net_device *dev,
235 struct iw_request_info *info,
236 struct iw_param *wrq,
237 char *extra);
238
239int iwctl_giwretry(struct net_device *dev,
240 struct iw_request_info *info,
241 struct iw_param *wrq,
242 char *extra);
243
244int iwctl_siwencode(struct net_device *dev,
245 struct iw_request_info *info,
246 struct iw_point *wrq,
247 char *extra);
248
249int iwctl_giwencode(struct net_device *dev,
250 struct iw_request_info *info,
251 struct iw_point *wrq,
252 char *extra);
253
254int iwctl_siwpower(struct net_device *dev,
255 struct iw_request_info *info,
256 struct iw_param *wrq,
257 char *extra);
258
259int iwctl_giwpower(struct net_device *dev,
260 struct iw_request_info *info,
261 struct iw_param *wrq,
262 char *extra);
263
264int iwctl_giwscan(struct net_device *dev,
265 struct iw_request_info *info,
266 struct iw_point *wrq,
267 char *extra);
268
269int iwctl_siwscan(struct net_device *dev,
270 struct iw_request_info *info,
271 struct iw_param *wrq,
272 char *extra);
273
274//2008-0409-07, <Add> by Einsn Liu
275#ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
276int iwctl_siwauth(struct net_device *dev,
277 struct iw_request_info *info,
278 struct iw_param *wrq,
279 char *extra);
280
281int iwctl_giwauth(struct net_device *dev,
282 struct iw_request_info *info,
283 struct iw_param *wrq,
284 char *extra);
285
286int iwctl_siwgenie(struct net_device *dev,
287 struct iw_request_info *info,
288 struct iw_point *wrq,
289 char *extra);
290
291int iwctl_giwgenie(struct net_device *dev,
292 struct iw_request_info *info,
293 struct iw_point *wrq,
294 char *extra);
295
296int iwctl_siwencodeext(struct net_device *dev,
297 struct iw_request_info *info,
298 struct iw_point *wrq,
299 char *extra);
300
301int iwctl_giwencodeext(struct net_device *dev,
302 struct iw_request_info *info,
303 struct iw_point *wrq,
304 char *extra);
305
306int iwctl_siwmlme(struct net_device *dev,
307 struct iw_request_info * info,
308 struct iw_point *wrq,
309 char *extra);
310#endif // #ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
311
312
313#endif
314
315#if WIRELESS_EXT > 12
316extern const struct iw_handler_def iwctl_handler_def;
317extern const struct iw_priv_args iwctl_private_args;
318#else
319struct iw_request_info {};
320#endif //WIRELESS_EXT > 12
321
322#ifdef __cplusplus
323} /* End of extern "C" { */
324#endif /* __cplusplus */
325
326
327
328
329#endif // __IWCTL_H__
330
331
332
diff --git a/drivers/staging/vt6655/kcompat.h b/drivers/staging/vt6655/kcompat.h
new file mode 100644
index 000000000000..693939df6675
--- /dev/null
+++ b/drivers/staging/vt6655/kcompat.h
@@ -0,0 +1,302 @@
1/*
2 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
3 * All rights reserved.
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 *
20 * File: kcompat.h
21 *
22 * Purpose: define kernel compatibility header
23 *
24 * Author: Lyndon Chen
25 *
26 * Date: Apr 8, 2002
27 *
28 */
29#ifndef _KCOMPAT_H
30#define _KCOMPAT_H
31
32#include <linux/version.h>
33
34#ifndef __init
35#define __init
36#endif
37
38#ifndef __exit
39#define __exit
40#endif
41
42#ifndef __devexit
43#define __devexit
44#endif
45
46#ifndef __devinitdata
47#define __devinitdata
48#endif
49
50#ifndef MODULE_LICENSE
51#define MODULE_LICENSE(license)
52#endif
53
54#ifndef MOD_INC_USE_COUNT
55#define MOD_INC_USE_COUNT do {} while (0)
56#endif
57
58#ifndef MOD_DEC_USE_COUNT
59#define MOD_DEC_USE_COUNT do {} while (0)
60#endif
61
62#ifndef HAVE_NETDEV_PRIV
63#define netdev_priv(dev) (dev->priv)
64#endif
65
66#ifndef IRQ_RETVAL
67typedef void irqreturn_t;
68
69#ifdef PRIVATE_OBJ
70#define IRQ_RETVAL(x) (int)x
71#else
72#define IRQ_RETVAL(x)
73#endif
74
75#endif
76
77#if LINUX_VERSION_CODE < KERNEL_VERSION(2,2,18)
78
79typedef unsigned long dma_addr_t;
80typedef struct wait_queue *wait_queue_head_t;
81#define init_waitqueue_head(x) *(x)=NULL
82#define set_current_state(status) { current->state = (status); mb(); }
83
84#ifdef MODULE
85
86#define module_init(fn) int init_module (void) { return fn(); }
87#define module_exit(fn) void cleanup_module(void) { return fn(); }
88
89#else /* MODULE */
90
91#define module_init(fn) int e100_probe (void) { return fn(); }
92#define module_exit(fn) /* NOTHING */
93
94#endif /* MODULE */
95
96#endif /* LINUX_VERSION_CODE < KERNEL_VERSION(2,2,18) */
97
98#if LINUX_VERSION_CODE < KERNEL_VERSION(2,3,0)
99
100#ifdef MODVERSIONS
101#include <linux/modversions.h>
102#endif
103
104#include <linux/types.h>
105#include <linux/pci.h>
106#include <linux/slab.h>
107#include <asm/io.h>
108
109#define pci_resource_start(dev, bar) \
110 (((dev)->base_address[(bar)] & PCI_BASE_ADDRESS_SPACE_IO) ? \
111 ((dev)->base_address[(bar)] & PCI_BASE_ADDRESS_IO_MASK) : \
112 ((dev)->base_address[(bar)] & PCI_BASE_ADDRESS_MEM_MASK))
113
114static inline int pci_enable_device(struct pci_dev *dev)
115{
116 1112
117 return 0;
118}
119#define __constant_cpu_to_le32 cpu_to_le32
120#define __constant_cpu_to_le16 cpu_to_le16
121
122#define PCI_DMA_TODEVICE 1
123#define PCI_DMA_FROMDEVICE 2
124
125extern inline void *pci_alloc_consistent (struct pci_dev *dev,
126 size_t size,
127 dma_addr_t *dma_handle) {
128 void *vaddr = kmalloc(size, GFP_ATOMIC);
129 if(vaddr != NULL) {
130 *dma_handle = virt_to_bus(vaddr);
131 }
132 return vaddr;
133}
134
135#define pci_dma_sync_single(dev,dma_handle,size,direction) do{} while(0)
136#define pci_dma_supported(dev, addr_mask) (1)
137#define pci_free_consistent(dev, size, cpu_addr, dma_handle) kfree(cpu_addr)
138#define pci_map_single(dev, addr, size, direction) virt_to_bus(addr)
139#define pci_unmap_single(dev, dma_handle, size, direction) do{} while(0)
140
141
142#define spin_lock_bh spin_lock_irq
143#define spin_unlock_bh spin_unlock_irq
144#define del_timer_sync(timer) del_timer(timer)
145#define net_device device
146
147#define netif_start_queue(dev) ( clear_bit(0, &(dev)->tbusy))
148#define netif_stop_queue(dev) ( set_bit(0, &(dev)->tbusy))
149#define netif_wake_queue(dev) { clear_bit(0, &(dev)->tbusy); \
150 mark_bh(NET_BH); }
151#define netif_running(dev) ( test_bit(0, &(dev)->start))
152#define netif_queue_stopped(dev) ( test_bit(0, &(dev)->tbusy))
153
154#define netif_device_attach(dev) \
155 do{ (dev)->start = 1; netif_start_queue(dev); } while (0)
156#define netif_device_detach(dev) \
157 do{ (dev)->start = 0; netif_stop_queue(dev); } while (0)
158
159#define dev_kfree_skb_irq(skb) dev_kfree_skb(skb)
160
161#define netif_carrier_on(dev) do {} while (0)
162#define netif_carrier_off(dev) do {} while (0)
163
164
165#define PCI_ANY_ID (~0U)
166
167struct pci_device_id {
168 unsigned int vendor, device;
169 unsigned int subvendor, subdevice;
170 unsigned int class, classmask;
171 unsigned long driver_data;
172};
173
174#define MODULE_DEVICE_TABLE(bus, dev_table)
175#define PCI_MAX_NUM_NICS 256
176
177struct pci_driver {
178 char *name;
179 struct pci_device_id *id_table;
180 int (*probe)(struct pci_dev *dev, const struct pci_device_id *id);
181 void (*remove)(struct pci_dev *dev);
182 void (*suspend)(struct pci_dev *dev);
183 void (*resume)(struct pci_dev *dev);
184 struct pci_dev *pcimap[PCI_MAX_NUM_NICS];
185};
186
187static inline int pci_module_init(struct pci_driver *drv)
188{
189 struct pci_dev *pdev;
190 struct pci_device_id *pcid;
191 uint16_t subvendor, subdevice;
192 int board_count = 0;
193
194 /* walk the global pci device list looking for matches */
195 for (pdev = pci_devices; pdev && (board_count < PCI_MAX_NUM_NICS); pdev = pdev->next) {
196
197 pcid = &drv->id_table[0];
198 pci_read_config_word(pdev, PCI_SUBSYSTEM_VENDOR_ID, &subvendor);
199 pci_read_config_word(pdev, PCI_SUBSYSTEM_ID, &subdevice);
200
201 while (pcid->vendor != 0) {
202 if (((pcid->vendor == pdev->vendor) || (pcid->vendor == PCI_ANY_ID)) &&
203 ((pcid->device == pdev->device) || (pcid->device == PCI_ANY_ID)) &&
204 ((pcid->subvendor == subvendor) || (pcid->subvendor == PCI_ANY_ID)) &&
205 ((pcid->subdevice == subdevice) || (pcid->subdevice == PCI_ANY_ID))) {
206
207 if (drv->probe(pdev, pcid) == 0) {
208 drv->pcimap[board_count] = pdev;
209 board_count++;
210 }
211 break;
212 }
213 pcid++;
214 }
215 }
216
217 if (board_count < PCI_MAX_NUM_NICS) {
218 drv->pcimap[board_count] = NULL;
219 }
220
221 return (board_count > 0) ? 0 : -ENODEV;
222}
223
224static inline void pci_unregister_driver(struct pci_driver *drv)
225{
226 int i;
227
228 for (i = 0; i < PCI_MAX_NUM_NICS; i++) {
229 if (!drv->pcimap[i])
230 break;
231
232 drv->remove(drv->pcimap[i]);
233 }
234}
235
236
237#define pci_set_drvdata(pcid, data)
238
239#define pci_get_drvdata(pcid) ({ \
240 PSDevice pInfo; \
241 for (pInfo = pDevice_Infos; \
242 pInfo; pInfo = pInfo->next) { \
243 if (pInfo->pcid == pcid) \
244 break; \
245 } \
246 pInfo; })
247
248#endif /* LINUX_VERSION_CODE < KERNEL_VERSION(2,3,0) */
249
250#if LINUX_VERSION_CODE < KERNEL_VERSION(2,4,5)
251
252#define skb_linearize(skb, gfp_mask) ({ \
253 struct sk_buff *tmp_skb; \
254 tmp_skb = skb; \
255 skb = skb_copy(tmp_skb, gfp_mask); \
256 dev_kfree_skb_irq(tmp_skb); })
257
258#endif /* LINUX_VERSION_CODE < KERNEL_VERSION(2,4,5) */
259
260#ifndef MODULE_LICESEN
261#define MODULE_LICESEN(x)
262#endif
263
264#if LINUX_VERSION_CODE < KERNEL_VERSION(2,4,6)
265
266#include <linux/types.h>
267#include <linux/pci.h>
268
269#if LINUX_VERSION_CODE < KERNEL_VERSION(2,4,2)
270static inline int pci_set_power_state(struct pci_dev* pcid, int state) { return 0; }
271#endif
272
273#define PMCSR 0xe0
274#define PM_ENABLE_BIT 0x0100
275#define PM_CLEAR_BIT 0x8000
276#define PM_STATE_MASK 0xFFFC
277#define PM_STATE_D1 0x0001
278
279static inline int
280pci_enable_wake(struct pci_dev *dev, u32 state, int enable)
281{
282 u16 p_state;
283
284 pci_read_config_word(dev, PMCSR, &p_state);
285 pci_write_config_word(dev, PMCSR, p_state | PM_CLEAR_BIT);
286
287 if (enable == 0) {
288 p_state &= ~PM_ENABLE_BIT;
289 } else {
290 p_state |= PM_ENABLE_BIT;
291 }
292 p_state &= PM_STATE_MASK;
293 p_state |= state;
294
295 pci_write_config_word(dev, PMCSR, p_state);
296
297 return 0;
298}
299#endif /* LINUX_VERSION_CODE < KERNEL_VERSION(2,4,6) */
300
301#endif
302
diff --git a/drivers/staging/vt6655/key.c b/drivers/staging/vt6655/key.c
new file mode 100644
index 000000000000..168ebd3be944
--- /dev/null
+++ b/drivers/staging/vt6655/key.c
@@ -0,0 +1,836 @@
1/*
2 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
3 * All rights reserved.
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 *
20 * File: key.c
21 *
22 * Purpose: Implement functions for 802.11i Key management
23 *
24 * Author: Jerry Chen
25 *
26 * Date: May 29, 2003
27 *
28 * Functions:
29 * KeyvInitTable - Init Key management table
30 * KeybGetKey - Get Key from table
31 * KeybSetKey - Set Key to table
32 * KeybRemoveKey - Remove Key from table
33 * KeybGetTransmitKey - Get Transmit Key from table
34 *
35 * Revision History:
36 *
37 */
38
39
40#if !defined(__TMACRO_H__)
41#include "tmacro.h"
42#endif
43#if !defined(__TBIT_H__)
44#include "tbit.h"
45#endif
46#if !defined(__KEY_H__)
47#include "key.h"
48#endif
49#if !defined(__UMEM_H__)
50#include "umem.h"
51#endif
52#if !defined(__MAC_H__)
53#include "mac.h"
54#endif
55
56
57/*--------------------- Static Definitions -------------------------*/
58
59/*--------------------- Static Classes ----------------------------*/
60
61/*--------------------- Static Variables --------------------------*/
62static int msglevel =MSG_LEVEL_INFO;
63//static int msglevel =MSG_LEVEL_DEBUG;
64/*--------------------- Static Functions --------------------------*/
65
66/*--------------------- Export Variables --------------------------*/
67
68/*--------------------- Static Definitions -------------------------*/
69
70/*--------------------- Static Classes ----------------------------*/
71
72/*--------------------- Static Variables --------------------------*/
73
74/*--------------------- Static Functions --------------------------*/
75static VOID
76s_vCheckKeyTableValid (PSKeyManagement pTable, DWORD_PTR dwIoBase)
77{
78 int i;
79
80 for (i=0;i<MAX_KEY_TABLE;i++) {
81 if ((pTable->KeyTable[i].bInUse == TRUE) &&
82 (pTable->KeyTable[i].PairwiseKey.bKeyValid == FALSE) &&
83 (pTable->KeyTable[i].GroupKey[0].bKeyValid == FALSE) &&
84 (pTable->KeyTable[i].GroupKey[1].bKeyValid == FALSE) &&
85 (pTable->KeyTable[i].GroupKey[2].bKeyValid == FALSE) &&
86 (pTable->KeyTable[i].GroupKey[3].bKeyValid == FALSE)
87 ) {
88 pTable->KeyTable[i].bInUse = FALSE;
89 pTable->KeyTable[i].wKeyCtl = 0;
90 pTable->KeyTable[i].bSoftWEP = FALSE;
91 MACvDisableKeyEntry(dwIoBase, i);
92 }
93 }
94}
95
96
97/*--------------------- Export Functions --------------------------*/
98
99
100/*
101 * Description: Init Key management table
102 *
103 * Parameters:
104 * In:
105 * pTable - Pointer to Key table
106 * Out:
107 * none
108 *
109 * Return Value: none
110 *
111 */
112VOID KeyvInitTable (PSKeyManagement pTable, DWORD_PTR dwIoBase)
113{
114 int i;
115 int jj;
116
117 for (i=0;i<MAX_KEY_TABLE;i++) {
118 pTable->KeyTable[i].bInUse = FALSE;
119 pTable->KeyTable[i].PairwiseKey.bKeyValid = FALSE;
120 pTable->KeyTable[i].PairwiseKey.pvKeyTable = (PVOID)&pTable->KeyTable[i];
121 for (jj=0; jj < MAX_GROUP_KEY; jj++) {
122 pTable->KeyTable[i].GroupKey[jj].bKeyValid = FALSE;
123 pTable->KeyTable[i].GroupKey[jj].pvKeyTable = (PVOID)&pTable->KeyTable[i];
124 }
125 pTable->KeyTable[i].wKeyCtl = 0;
126 pTable->KeyTable[i].dwGTKeyIndex = 0;
127 pTable->KeyTable[i].bSoftWEP = FALSE;
128 MACvDisableKeyEntry(dwIoBase, i);
129 }
130}
131
132
133/*
134 * Description: Get Key from table
135 *
136 * Parameters:
137 * In:
138 * pTable - Pointer to Key table
139 * pbyBSSID - BSSID of Key
140 * dwKeyIndex - Key Index (0xFFFFFFFF means pairwise key)
141 * Out:
142 * pKey - Key return
143 *
144 * Return Value: TRUE if found otherwise FALSE
145 *
146 */
147BOOL KeybGetKey (
148 IN PSKeyManagement pTable,
149 IN PBYTE pbyBSSID,
150 IN DWORD dwKeyIndex,
151 OUT PSKeyItem *pKey
152 )
153{
154 int i;
155
156 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"KeybGetKey() \n");
157
158 *pKey = NULL;
159 for (i=0;i<MAX_KEY_TABLE;i++) {
160 if ((pTable->KeyTable[i].bInUse == TRUE) &&
161 IS_ETH_ADDRESS_EQUAL(pTable->KeyTable[i].abyBSSID,pbyBSSID)) {
162 if (dwKeyIndex == 0xFFFFFFFF) {
163 if (pTable->KeyTable[i].PairwiseKey.bKeyValid == TRUE) {
164 *pKey = &(pTable->KeyTable[i].PairwiseKey);
165 return (TRUE);
166 }
167 else {
168 return (FALSE);
169 }
170 } else if (dwKeyIndex < MAX_GROUP_KEY) {
171 if (pTable->KeyTable[i].GroupKey[dwKeyIndex].bKeyValid == TRUE) {
172 *pKey = &(pTable->KeyTable[i].GroupKey[dwKeyIndex]);
173 return (TRUE);
174 }
175 else {
176 return (FALSE);
177 }
178 }
179 else {
180 return (FALSE);
181 }
182 }
183 }
184 return (FALSE);
185}
186
187
188/*
189 * Description: Set Key to table
190 *
191 * Parameters:
192 * In:
193 * pTable - Pointer to Key table
194 * pbyBSSID - BSSID of Key
195 * dwKeyIndex - Key index (reference to NDIS DDK)
196 * uKeyLength - Key length
197 * KeyRSC - Key RSC
198 * pbyKey - Pointer to key
199 * Out:
200 * none
201 *
202 * Return Value: TRUE if success otherwise FALSE
203 *
204 */
205BOOL KeybSetKey (
206 PSKeyManagement pTable,
207 PBYTE pbyBSSID,
208 DWORD dwKeyIndex,
209 ULONG uKeyLength,
210 PQWORD pKeyRSC,
211 PBYTE pbyKey,
212 BYTE byKeyDecMode,
213 DWORD_PTR dwIoBase,
214 BYTE byLocalID
215 )
216{
217 int i,j;
218 UINT ii;
219 PSKeyItem pKey;
220 UINT uKeyIdx;
221
222 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Enter KeybSetKey: %lX\n", dwKeyIndex);
223
224 j = (MAX_KEY_TABLE-1);
225 for (i=0;i<(MAX_KEY_TABLE-1);i++) {
226 if ((pTable->KeyTable[i].bInUse == FALSE) &&
227 (j == (MAX_KEY_TABLE-1))) {
228 // found empty table
229 j = i;
230 }
231 if ((pTable->KeyTable[i].bInUse == TRUE) &&
232 IS_ETH_ADDRESS_EQUAL(pTable->KeyTable[i].abyBSSID,pbyBSSID)) {
233 // found table already exist
234 if ((dwKeyIndex & PAIRWISE_KEY) != 0) {
235 // Pairwise key
236 pKey = &(pTable->KeyTable[i].PairwiseKey);
237 pTable->KeyTable[i].wKeyCtl &= 0xFFF0; // clear pairwise key control filed
238 pTable->KeyTable[i].wKeyCtl |= byKeyDecMode;
239 uKeyIdx = 4; // use HW key entry 4 for pairwise key
240 } else {
241 // Group key
242 if ((dwKeyIndex & 0x000000FF) >= MAX_GROUP_KEY)
243 return (FALSE);
244 pKey = &(pTable->KeyTable[i].GroupKey[dwKeyIndex & 0x000000FF]);
245 if ((dwKeyIndex & TRANSMIT_KEY) != 0) {
246 // Group transmit key
247 pTable->KeyTable[i].dwGTKeyIndex = dwKeyIndex;
248 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Group transmit key(R)[%lX]: %d\n", pTable->KeyTable[i].dwGTKeyIndex, i);
249 }
250 pTable->KeyTable[i].wKeyCtl &= 0xFF0F; // clear group key control filed
251 pTable->KeyTable[i].wKeyCtl |= (byKeyDecMode << 4);
252 pTable->KeyTable[i].wKeyCtl |= 0x0040; // use group key for group address
253 uKeyIdx = (dwKeyIndex & 0x000000FF);
254 }
255 pTable->KeyTable[i].wKeyCtl |= 0x8000; // enable on-fly
256
257 pKey->bKeyValid = TRUE;
258 pKey->uKeyLength = uKeyLength;
259 pKey->dwKeyIndex = dwKeyIndex;
260 pKey->byCipherSuite = byKeyDecMode;
261 MEMvCopy(pKey->abyKey, pbyKey, uKeyLength);
262 if (byKeyDecMode == KEY_CTL_WEP) {
263 if (uKeyLength == WLAN_WEP40_KEYLEN)
264 pKey->abyKey[15] &= 0x7F;
265 if (uKeyLength == WLAN_WEP104_KEYLEN)
266 pKey->abyKey[15] |= 0x80;
267 }
268 MACvSetKeyEntry(dwIoBase, pTable->KeyTable[i].wKeyCtl, i, uKeyIdx, pbyBSSID, (PDWORD)pKey->abyKey, byLocalID);
269
270 if ((dwKeyIndex & USE_KEYRSC) == 0) {
271 // RSC set by NIC
272 ZERO_MEMORY(&(pKey->KeyRSC), sizeof(QWORD));
273 }
274 else {
275 MEMvCopy(&(pKey->KeyRSC), pKeyRSC, sizeof(QWORD));
276 }
277 pKey->dwTSC47_16 = 0;
278 pKey->wTSC15_0 = 0;
279
280 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"KeybSetKey(R): \n");
281 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"pKey->bKeyValid: %d\n ", pKey->bKeyValid);
282 //DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"pKey->uKeyLength: %d\n ", pKey->uKeyLength);
283 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"pKey->abyKey: ");
284 for (ii = 0; ii < pKey->uKeyLength; ii++) {
285 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%02x ", pKey->abyKey[ii]);
286 }
287 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"\n");
288
289 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"pKey->dwTSC47_16: %lx\n ", pKey->dwTSC47_16);
290 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"pKey->wTSC15_0: %x\n ", pKey->wTSC15_0);
291 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"pKey->dwKeyIndex: %lx\n ", pKey->dwKeyIndex);
292
293 return (TRUE);
294 }
295 }
296 if (j < (MAX_KEY_TABLE-1)) {
297 MEMvCopy(pTable->KeyTable[j].abyBSSID,pbyBSSID,U_ETHER_ADDR_LEN);
298 pTable->KeyTable[j].bInUse = TRUE;
299 if ((dwKeyIndex & PAIRWISE_KEY) != 0) {
300 // Pairwise key
301 pKey = &(pTable->KeyTable[j].PairwiseKey);
302 pTable->KeyTable[j].wKeyCtl &= 0xFFF0; // clear pairwise key control filed
303 pTable->KeyTable[j].wKeyCtl |= byKeyDecMode;
304 uKeyIdx = 4; // use HW key entry 4 for pairwise key
305 } else {
306 // Group key
307 if ((dwKeyIndex & 0x000000FF) >= MAX_GROUP_KEY)
308 return (FALSE);
309 pKey = &(pTable->KeyTable[j].GroupKey[dwKeyIndex & 0x000000FF]);
310 if ((dwKeyIndex & TRANSMIT_KEY) != 0) {
311 // Group transmit key
312 pTable->KeyTable[j].dwGTKeyIndex = dwKeyIndex;
313 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Group transmit key(N)[%lX]: %d\n", pTable->KeyTable[j].dwGTKeyIndex, j);
314 }
315 pTable->KeyTable[j].wKeyCtl &= 0xFF0F; // clear group key control filed
316 pTable->KeyTable[j].wKeyCtl |= (byKeyDecMode << 4);
317 pTable->KeyTable[j].wKeyCtl |= 0x0040; // use group key for group address
318 uKeyIdx = (dwKeyIndex & 0x000000FF);
319 }
320 pTable->KeyTable[j].wKeyCtl |= 0x8000; // enable on-fly
321
322 pKey->bKeyValid = TRUE;
323 pKey->uKeyLength = uKeyLength;
324 pKey->dwKeyIndex = dwKeyIndex;
325 pKey->byCipherSuite = byKeyDecMode;
326 MEMvCopy(pKey->abyKey, pbyKey, uKeyLength);
327 if (byKeyDecMode == KEY_CTL_WEP) {
328 if (uKeyLength == WLAN_WEP40_KEYLEN)
329 pKey->abyKey[15] &= 0x7F;
330 if (uKeyLength == WLAN_WEP104_KEYLEN)
331 pKey->abyKey[15] |= 0x80;
332 }
333 MACvSetKeyEntry(dwIoBase, pTable->KeyTable[j].wKeyCtl, j, uKeyIdx, pbyBSSID, (PDWORD)pKey->abyKey, byLocalID);
334
335 if ((dwKeyIndex & USE_KEYRSC) == 0) {
336 // RSC set by NIC
337 ZERO_MEMORY(&(pKey->KeyRSC), sizeof(QWORD));
338 }
339 else {
340 MEMvCopy(&(pKey->KeyRSC), pKeyRSC, sizeof(QWORD));
341 }
342 pKey->dwTSC47_16 = 0;
343 pKey->wTSC15_0 = 0;
344
345 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"KeybSetKey(N): \n");
346 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"pKey->bKeyValid: %d\n ", pKey->bKeyValid);
347 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"pKey->uKeyLength: %d\n ", (int)pKey->uKeyLength);
348 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"pKey->abyKey: ");
349 for (ii = 0; ii < pKey->uKeyLength; ii++) {
350 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%02x ", pKey->abyKey[ii]);
351 }
352 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"\n");
353
354 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"pKey->dwTSC47_16: %lx\n ", pKey->dwTSC47_16);
355 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"pKey->wTSC15_0: %x\n ", pKey->wTSC15_0);
356 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"pKey->dwKeyIndex: %lx\n ", pKey->dwKeyIndex);
357
358 return (TRUE);
359 }
360 return (FALSE);
361}
362
363
364/*
365 * Description: Remove Key from table
366 *
367 * Parameters:
368 * In:
369 * pTable - Pointer to Key table
370 * pbyBSSID - BSSID of Key
371 * dwKeyIndex - Key Index (reference to NDIS DDK)
372 * Out:
373 * none
374 *
375 * Return Value: TRUE if success otherwise FALSE
376 *
377 */
378BOOL KeybRemoveKey (
379 PSKeyManagement pTable,
380 PBYTE pbyBSSID,
381 DWORD dwKeyIndex,
382 DWORD_PTR dwIoBase
383 )
384{
385 int i;
386
387 if (IS_BROADCAST_ADDRESS(pbyBSSID)) {
388 // dealte all key
389 if ((dwKeyIndex & PAIRWISE_KEY) != 0) {
390 for (i=0;i<MAX_KEY_TABLE;i++) {
391 pTable->KeyTable[i].PairwiseKey.bKeyValid = FALSE;
392 }
393 s_vCheckKeyTableValid(pTable, dwIoBase);
394 return TRUE;
395 }
396 else if ((dwKeyIndex & 0x000000FF) < MAX_GROUP_KEY) {
397 for (i=0;i<MAX_KEY_TABLE;i++) {
398 pTable->KeyTable[i].GroupKey[dwKeyIndex & 0x000000FF].bKeyValid = FALSE;
399 if ((dwKeyIndex & 0x7FFFFFFF) == (pTable->KeyTable[i].dwGTKeyIndex & 0x7FFFFFFF)) {
400 // remove Group transmit key
401 pTable->KeyTable[i].dwGTKeyIndex = 0;
402 }
403 }
404 s_vCheckKeyTableValid(pTable, dwIoBase);
405 return TRUE;
406 }
407 else {
408 return FALSE;
409 }
410 }
411
412 for (i=0;i<MAX_KEY_TABLE;i++) {
413 if ((pTable->KeyTable[i].bInUse == TRUE) &&
414 IS_ETH_ADDRESS_EQUAL(pTable->KeyTable[i].abyBSSID,pbyBSSID)) {
415 if ((dwKeyIndex & PAIRWISE_KEY) != 0) {
416 pTable->KeyTable[i].PairwiseKey.bKeyValid = FALSE;
417 s_vCheckKeyTableValid(pTable, dwIoBase);
418 return (TRUE);
419 }
420 else if ((dwKeyIndex & 0x000000FF) < MAX_GROUP_KEY) {
421 pTable->KeyTable[i].GroupKey[dwKeyIndex & 0x000000FF].bKeyValid = FALSE;
422 if ((dwKeyIndex & 0x7FFFFFFF) == (pTable->KeyTable[i].dwGTKeyIndex & 0x7FFFFFFF)) {
423 // remove Group transmit key
424 pTable->KeyTable[i].dwGTKeyIndex = 0;
425 }
426 s_vCheckKeyTableValid(pTable, dwIoBase);
427 return (TRUE);
428 }
429 else {
430 return (FALSE);
431 }
432 }
433 }
434 return (FALSE);
435}
436
437
438/*
439 * Description: Remove Key from table
440 *
441 * Parameters:
442 * In:
443 * pTable - Pointer to Key table
444 * pbyBSSID - BSSID of Key
445 * Out:
446 * none
447 *
448 * Return Value: TRUE if success otherwise FALSE
449 *
450 */
451BOOL KeybRemoveAllKey (
452 PSKeyManagement pTable,
453 PBYTE pbyBSSID,
454 DWORD_PTR dwIoBase
455 )
456{
457 int i,u;
458
459 for (i=0;i<MAX_KEY_TABLE;i++) {
460 if ((pTable->KeyTable[i].bInUse == TRUE) &&
461 IS_ETH_ADDRESS_EQUAL(pTable->KeyTable[i].abyBSSID,pbyBSSID)) {
462 pTable->KeyTable[i].PairwiseKey.bKeyValid = FALSE;
463 for(u=0;u<MAX_GROUP_KEY;u++) {
464 pTable->KeyTable[i].GroupKey[u].bKeyValid = FALSE;
465 }
466 pTable->KeyTable[i].dwGTKeyIndex = 0;
467 s_vCheckKeyTableValid(pTable, dwIoBase);
468 return (TRUE);
469 }
470 }
471 return (FALSE);
472}
473
474/*
475 * Description: Remove WEP Key from table
476 *
477 * Parameters:
478 * In:
479 * pTable - Pointer to Key table
480 * Out:
481 * none
482 *
483 * Return Value: TRUE if success otherwise FALSE
484 *
485 */
486VOID KeyvRemoveWEPKey (
487 PSKeyManagement pTable,
488 DWORD dwKeyIndex,
489 DWORD_PTR dwIoBase
490 )
491{
492
493 if ((dwKeyIndex & 0x000000FF) < MAX_GROUP_KEY) {
494 if (pTable->KeyTable[MAX_KEY_TABLE-1].bInUse == TRUE) {
495 if (pTable->KeyTable[MAX_KEY_TABLE-1].GroupKey[dwKeyIndex & 0x000000FF].byCipherSuite == KEY_CTL_WEP) {
496 pTable->KeyTable[MAX_KEY_TABLE-1].GroupKey[dwKeyIndex & 0x000000FF].bKeyValid = FALSE;
497 if ((dwKeyIndex & 0x7FFFFFFF) == (pTable->KeyTable[MAX_KEY_TABLE-1].dwGTKeyIndex & 0x7FFFFFFF)) {
498 // remove Group transmit key
499 pTable->KeyTable[MAX_KEY_TABLE-1].dwGTKeyIndex = 0;
500 }
501 }
502 }
503 s_vCheckKeyTableValid(pTable, dwIoBase);
504 }
505 return;
506}
507
508VOID KeyvRemoveAllWEPKey (
509 PSKeyManagement pTable,
510 DWORD_PTR dwIoBase
511 )
512{
513 int i;
514
515 for(i=0;i<MAX_GROUP_KEY;i++) {
516 KeyvRemoveWEPKey(pTable, i, dwIoBase);
517 }
518}
519
520/*
521 * Description: Get Transmit Key from table
522 *
523 * Parameters:
524 * In:
525 * pTable - Pointer to Key table
526 * pbyBSSID - BSSID of Key
527 * Out:
528 * pKey - Key return
529 *
530 * Return Value: TRUE if found otherwise FALSE
531 *
532 */
533BOOL KeybGetTransmitKey (
534 IN PSKeyManagement pTable,
535 IN PBYTE pbyBSSID,
536 IN DWORD dwKeyType,
537 OUT PSKeyItem *pKey
538 )
539{
540 int i, ii;
541
542 *pKey = NULL;
543 for (i=0;i<MAX_KEY_TABLE;i++) {
544 if ((pTable->KeyTable[i].bInUse == TRUE) &&
545 IS_ETH_ADDRESS_EQUAL(pTable->KeyTable[i].abyBSSID,pbyBSSID)) {
546
547 if (dwKeyType == PAIRWISE_KEY) {
548
549 if (pTable->KeyTable[i].PairwiseKey.bKeyValid == TRUE) {
550 *pKey = &(pTable->KeyTable[i].PairwiseKey);
551
552 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"KeybGetTransmitKey:");
553 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"PAIRWISE_KEY: KeyTable.abyBSSID: ");
554 for (ii = 0; ii < 6; ii++) {
555 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"%x ", pTable->KeyTable[i].abyBSSID[ii]);
556 }
557 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"\n");
558
559
560 return (TRUE);
561 }
562 else {
563 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"PairwiseKey.bKeyValid == FALSE\n");
564 return (FALSE);
565 }
566 } // End of Type == PAIRWISE
567 else {
568 if (pTable->KeyTable[i].dwGTKeyIndex == 0) {
569 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"ERROR: dwGTKeyIndex == 0 !!!\n");
570 return FALSE;
571 }
572 if (pTable->KeyTable[i].GroupKey[(pTable->KeyTable[i].dwGTKeyIndex&0x000000FF)].bKeyValid == TRUE) {
573 *pKey = &(pTable->KeyTable[i].GroupKey[(pTable->KeyTable[i].dwGTKeyIndex&0x000000FF)]);
574
575 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"KeybGetTransmitKey:");
576 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"GROUP_KEY: KeyTable.abyBSSID\n");
577 for (ii = 0; ii < 6; ii++) {
578 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"%x ", pTable->KeyTable[i].abyBSSID[ii]);
579 }
580 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"\n");
581 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"dwGTKeyIndex: %lX\n", pTable->KeyTable[i].dwGTKeyIndex);
582
583 return (TRUE);
584 }
585 else {
586 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"GroupKey.bKeyValid == FALSE\n");
587 return (FALSE);
588 }
589 } // End of Type = GROUP
590 } // BSSID match
591 }
592 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"ERROR: NO Match BSSID !!! ");
593 for (ii = 0; ii < 6; ii++) {
594 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"%02x ", *(pbyBSSID+ii));
595 }
596 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"\n");
597 return (FALSE);
598}
599
600
601/*
602 * Description: Check Pairewise Key
603 *
604 * Parameters:
605 * In:
606 * pTable - Pointer to Key table
607 * Out:
608 * none
609 *
610 * Return Value: TRUE if found otherwise FALSE
611 *
612 */
613BOOL KeybCheckPairewiseKey (
614 IN PSKeyManagement pTable,
615 OUT PSKeyItem *pKey
616 )
617{
618 int i;
619
620 *pKey = NULL;
621 for (i=0;i<MAX_KEY_TABLE;i++) {
622 if ((pTable->KeyTable[i].bInUse == TRUE) &&
623 (pTable->KeyTable[i].PairwiseKey.bKeyValid == TRUE)) {
624 *pKey = &(pTable->KeyTable[i].PairwiseKey);
625 return (TRUE);
626 }
627 }
628 return (FALSE);
629}
630
631/*
632 * Description: Set Key to table
633 *
634 * Parameters:
635 * In:
636 * pTable - Pointer to Key table
637 * dwKeyIndex - Key index (reference to NDIS DDK)
638 * uKeyLength - Key length
639 * KeyRSC - Key RSC
640 * pbyKey - Pointer to key
641 * Out:
642 * none
643 *
644 * Return Value: TRUE if success otherwise FALSE
645 *
646 */
647BOOL KeybSetDefaultKey (
648 PSKeyManagement pTable,
649 DWORD dwKeyIndex,
650 ULONG uKeyLength,
651 PQWORD pKeyRSC,
652 PBYTE pbyKey,
653 BYTE byKeyDecMode,
654 DWORD_PTR dwIoBase,
655 BYTE byLocalID
656 )
657{
658 UINT ii;
659 PSKeyItem pKey;
660 UINT uKeyIdx;
661
662 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Enter KeybSetDefaultKey: %1x, %d \n", (int)dwKeyIndex, (int)uKeyLength);
663
664
665 if ((dwKeyIndex & PAIRWISE_KEY) != 0) { // Pairwise key
666 return (FALSE);
667 } else if ((dwKeyIndex & 0x000000FF) >= MAX_GROUP_KEY) {
668 return (FALSE);
669 }
670
671 pTable->KeyTable[MAX_KEY_TABLE-1].bInUse = TRUE;
672 for(ii=0;ii<U_ETHER_ADDR_LEN;ii++)
673 pTable->KeyTable[MAX_KEY_TABLE-1].abyBSSID[ii] = 0xFF;
674
675 // Group key
676 pKey = &(pTable->KeyTable[MAX_KEY_TABLE-1].GroupKey[dwKeyIndex & 0x000000FF]);
677 if ((dwKeyIndex & TRANSMIT_KEY) != 0) {
678 // Group transmit key
679 pTable->KeyTable[MAX_KEY_TABLE-1].dwGTKeyIndex = dwKeyIndex;
680 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Group transmit key(R)[%lX]: %d\n", pTable->KeyTable[MAX_KEY_TABLE-1].dwGTKeyIndex, MAX_KEY_TABLE-1);
681
682 }
683 pTable->KeyTable[MAX_KEY_TABLE-1].wKeyCtl &= 0x7F00; // clear all key control filed
684 pTable->KeyTable[MAX_KEY_TABLE-1].wKeyCtl |= (byKeyDecMode << 4);
685 pTable->KeyTable[MAX_KEY_TABLE-1].wKeyCtl |= (byKeyDecMode);
686 pTable->KeyTable[MAX_KEY_TABLE-1].wKeyCtl |= 0x0044; // use group key for all address
687 uKeyIdx = (dwKeyIndex & 0x000000FF);
688
689 if ((uKeyLength == WLAN_WEP232_KEYLEN) &&
690 (byKeyDecMode == KEY_CTL_WEP)) {
691 pTable->KeyTable[MAX_KEY_TABLE-1].wKeyCtl |= 0x4000; // disable on-fly disable address match
692 pTable->KeyTable[MAX_KEY_TABLE-1].bSoftWEP = TRUE;
693 } else {
694 if (pTable->KeyTable[MAX_KEY_TABLE-1].bSoftWEP == FALSE)
695 pTable->KeyTable[MAX_KEY_TABLE-1].wKeyCtl |= 0xC000; // enable on-fly disable address match
696 }
697
698 pKey->bKeyValid = TRUE;
699 pKey->uKeyLength = uKeyLength;
700 pKey->dwKeyIndex = dwKeyIndex;
701 pKey->byCipherSuite = byKeyDecMode;
702 MEMvCopy(pKey->abyKey, pbyKey, uKeyLength);
703 if (byKeyDecMode == KEY_CTL_WEP) {
704 if (uKeyLength == WLAN_WEP40_KEYLEN)
705 pKey->abyKey[15] &= 0x7F;
706 if (uKeyLength == WLAN_WEP104_KEYLEN)
707 pKey->abyKey[15] |= 0x80;
708 }
709 MACvSetKeyEntry(dwIoBase, pTable->KeyTable[MAX_KEY_TABLE-1].wKeyCtl, MAX_KEY_TABLE-1, uKeyIdx, pTable->KeyTable[MAX_KEY_TABLE-1].abyBSSID, (PDWORD)pKey->abyKey, byLocalID);
710
711 if ((dwKeyIndex & USE_KEYRSC) == 0) {
712 // RSC set by NIC
713 ZERO_MEMORY(&(pKey->KeyRSC), sizeof(QWORD));
714 } else {
715 MEMvCopy(&(pKey->KeyRSC), pKeyRSC, sizeof(QWORD));
716 }
717 pKey->dwTSC47_16 = 0;
718 pKey->wTSC15_0 = 0;
719
720
721 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"KeybSetKey(R): \n");
722 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"pKey->bKeyValid: %d\n", pKey->bKeyValid);
723 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"pKey->uKeyLength: %d\n", (int)pKey->uKeyLength);
724 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"pKey->abyKey: \n");
725 for (ii = 0; ii < pKey->uKeyLength; ii++) {
726 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"%x", pKey->abyKey[ii]);
727 }
728 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"\n");
729
730 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"pKey->dwTSC47_16: %lx\n", pKey->dwTSC47_16);
731 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"pKey->wTSC15_0: %x\n", pKey->wTSC15_0);
732 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"pKey->dwKeyIndex: %lx\n", pKey->dwKeyIndex);
733
734 return (TRUE);
735}
736
737
738/*
739 * Description: Set Key to table
740 *
741 * Parameters:
742 * In:
743 * pTable - Pointer to Key table
744 * dwKeyIndex - Key index (reference to NDIS DDK)
745 * uKeyLength - Key length
746 * KeyRSC - Key RSC
747 * pbyKey - Pointer to key
748 * Out:
749 * none
750 *
751 * Return Value: TRUE if success otherwise FALSE
752 *
753 */
754BOOL KeybSetAllGroupKey (
755 PSKeyManagement pTable,
756 DWORD dwKeyIndex,
757 ULONG uKeyLength,
758 PQWORD pKeyRSC,
759 PBYTE pbyKey,
760 BYTE byKeyDecMode,
761 DWORD_PTR dwIoBase,
762 BYTE byLocalID
763 )
764{
765 int i;
766 UINT ii;
767 PSKeyItem pKey;
768 UINT uKeyIdx;
769
770 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Enter KeybSetAllGroupKey: %lX\n", dwKeyIndex);
771
772
773 if ((dwKeyIndex & PAIRWISE_KEY) != 0) { // Pairwise key
774 return (FALSE);
775 } else if ((dwKeyIndex & 0x000000FF) >= MAX_GROUP_KEY) {
776 return (FALSE);
777 }
778
779 for (i=0; i < MAX_KEY_TABLE-1; i++) {
780 if (pTable->KeyTable[i].bInUse == TRUE) {
781 // found table already exist
782 // Group key
783 pKey = &(pTable->KeyTable[i].GroupKey[dwKeyIndex & 0x000000FF]);
784 if ((dwKeyIndex & TRANSMIT_KEY) != 0) {
785 // Group transmit key
786 pTable->KeyTable[i].dwGTKeyIndex = dwKeyIndex;
787 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Group transmit key(R)[%lX]: %d\n", pTable->KeyTable[i].dwGTKeyIndex, i);
788
789 }
790 pTable->KeyTable[i].wKeyCtl &= 0xFF0F; // clear group key control filed
791 pTable->KeyTable[i].wKeyCtl |= (byKeyDecMode << 4);
792 pTable->KeyTable[i].wKeyCtl |= 0x0040; // use group key for group address
793 uKeyIdx = (dwKeyIndex & 0x000000FF);
794
795 pTable->KeyTable[i].wKeyCtl |= 0x8000; // enable on-fly
796
797 pKey->bKeyValid = TRUE;
798 pKey->uKeyLength = uKeyLength;
799 pKey->dwKeyIndex = dwKeyIndex;
800 pKey->byCipherSuite = byKeyDecMode;
801 MEMvCopy(pKey->abyKey, pbyKey, uKeyLength);
802 if (byKeyDecMode == KEY_CTL_WEP) {
803 if (uKeyLength == WLAN_WEP40_KEYLEN)
804 pKey->abyKey[15] &= 0x7F;
805 if (uKeyLength == WLAN_WEP104_KEYLEN)
806 pKey->abyKey[15] |= 0x80;
807 }
808 MACvSetKeyEntry(dwIoBase, pTable->KeyTable[i].wKeyCtl, i, uKeyIdx, pTable->KeyTable[i].abyBSSID, (PDWORD)pKey->abyKey, byLocalID);
809
810 if ((dwKeyIndex & USE_KEYRSC) == 0) {
811 // RSC set by NIC
812 ZERO_MEMORY(&(pKey->KeyRSC), sizeof(QWORD));
813 }
814 else {
815 MEMvCopy(&(pKey->KeyRSC), pKeyRSC, sizeof(QWORD));
816 }
817 pKey->dwTSC47_16 = 0;
818 pKey->wTSC15_0 = 0;
819
820 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"KeybSetKey(R): \n");
821 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"pKey->bKeyValid: %d\n ", pKey->bKeyValid);
822 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"pKey->uKeyLength: %d\n ", (int)pKey->uKeyLength);
823 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"pKey->abyKey: ");
824 for (ii = 0; ii < pKey->uKeyLength; ii++) {
825 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"%02x ", pKey->abyKey[ii]);
826 }
827 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"\n");
828
829 //DBG_PRN_GRP12(("pKey->dwTSC47_16: %lX\n ", pKey->dwTSC47_16));
830 //DBG_PRN_GRP12(("pKey->wTSC15_0: %X\n ", pKey->wTSC15_0));
831 //DBG_PRN_GRP12(("pKey->dwKeyIndex: %lX\n ", pKey->dwKeyIndex));
832
833 } // (pTable->KeyTable[i].bInUse == TRUE)
834 }
835 return (TRUE);
836}
diff --git a/drivers/staging/vt6655/key.h b/drivers/staging/vt6655/key.h
new file mode 100644
index 000000000000..9c7d335ea088
--- /dev/null
+++ b/drivers/staging/vt6655/key.h
@@ -0,0 +1,202 @@
1/*
2 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
3 * All rights reserved.
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 *
20 * File: key.h
21 *
22 * Purpose: Implement functions for 802.11i Key management
23 *
24 * Author: Jerry Chen
25 *
26 * Date: May 29, 2003
27 *
28 */
29
30
31#ifndef __KEY_H__
32#define __KEY_H__
33
34#if !defined(__TTYPE_H__)
35#include "ttype.h"
36#endif
37
38#if !defined(__TETHER_H__)
39#include "tether.h"
40#endif
41
42#if !defined(__80211MGR_H__)
43#include "80211mgr.h"
44#endif
45
46/*--------------------- Export Definitions -------------------------*/
47#define MAX_GROUP_KEY 4
48#define MAX_KEY_TABLE 11
49#define MAX_KEY_LEN 32
50#define AES_KEY_LEN 16
51
52
53#define AUTHENTICATOR_KEY 0x10000000
54#define USE_KEYRSC 0x20000000
55#define PAIRWISE_KEY 0x40000000
56#define TRANSMIT_KEY 0x80000000
57
58#define GROUP_KEY 0x00000000
59
60#define KEY_CTL_WEP 0x00
61#define KEY_CTL_NONE 0x01
62#define KEY_CTL_TKIP 0x02
63#define KEY_CTL_CCMP 0x03
64#define KEY_CTL_INVALID 0xFF
65
66
67typedef struct tagSKeyItem
68{
69 BOOL bKeyValid;
70 ULONG uKeyLength;
71 BYTE abyKey[MAX_KEY_LEN];
72 QWORD KeyRSC;
73 DWORD dwTSC47_16;
74 WORD wTSC15_0;
75 BYTE byCipherSuite;
76 BYTE byReserved0;
77 DWORD dwKeyIndex;
78 PVOID pvKeyTable;
79} SKeyItem, DEF* PSKeyItem; //64
80
81typedef struct tagSKeyTable
82{
83 BYTE abyBSSID[U_ETHER_ADDR_LEN]; //6
84 BYTE byReserved0[2]; //8
85 SKeyItem PairwiseKey;
86 SKeyItem GroupKey[MAX_GROUP_KEY]; //64*5 = 320, 320+8=328
87 DWORD dwGTKeyIndex; // GroupTransmitKey Index
88 BOOL bInUse;
89 //2006-1116-01,<Modify> by NomadZhao
90 //WORD wKeyCtl;
91 //BOOL bSoftWEP;
92 BOOL bSoftWEP;
93 WORD wKeyCtl; // for address of wKeyCtl at align 4
94
95 BYTE byReserved1[6];
96} SKeyTable, DEF* PSKeyTable; //348
97
98typedef struct tagSKeyManagement
99{
100 SKeyTable KeyTable[MAX_KEY_TABLE];
101} SKeyManagement, DEF* PSKeyManagement;
102
103/*--------------------- Export Types ------------------------------*/
104
105/*--------------------- Export Macros ------------------------------*/
106
107/*--------------------- Export Classes ----------------------------*/
108
109/*--------------------- Export Variables --------------------------*/
110
111/*--------------------- Export Functions --------------------------*/
112#ifdef __cplusplus
113extern "C" { /* Assume C declarations for C++ */
114#endif /* __cplusplus */
115
116VOID KeyvInitTable(PSKeyManagement pTable, DWORD_PTR dwIoBase);
117
118BOOL KeybGetKey(
119 IN PSKeyManagement pTable,
120 IN PBYTE pbyBSSID,
121 IN DWORD dwKeyIndex,
122 OUT PSKeyItem *pKey
123 );
124
125BOOL KeybSetKey(
126 PSKeyManagement pTable,
127 PBYTE pbyBSSID,
128 DWORD dwKeyIndex,
129 ULONG uKeyLength,
130 PQWORD pKeyRSC,
131 PBYTE pbyKey,
132 BYTE byKeyDecMode,
133 DWORD_PTR dwIoBase,
134 BYTE byLocalID
135 );
136
137BOOL KeybSetDefaultKey(
138 PSKeyManagement pTable,
139 DWORD dwKeyIndex,
140 ULONG uKeyLength,
141 PQWORD pKeyRSC,
142 PBYTE pbyKey,
143 BYTE byKeyDecMode,
144 DWORD_PTR dwIoBase,
145 BYTE byLocalID
146 );
147
148BOOL KeybRemoveKey(
149 PSKeyManagement pTable,
150 PBYTE pbyBSSID,
151 DWORD dwKeyIndex,
152 DWORD_PTR dwIoBase
153 );
154
155BOOL KeybGetTransmitKey(
156 IN PSKeyManagement pTable,
157 IN PBYTE pbyBSSID,
158 IN DWORD dwKeyType,
159 OUT PSKeyItem *pKey
160 );
161
162BOOL KeybCheckPairewiseKey(
163 IN PSKeyManagement pTable,
164 OUT PSKeyItem *pKey
165 );
166
167BOOL KeybRemoveAllKey(
168 PSKeyManagement pTable,
169 PBYTE pbyBSSID,
170 DWORD_PTR dwIoBase
171 );
172
173VOID KeyvRemoveWEPKey(
174 PSKeyManagement pTable,
175 DWORD dwKeyIndex,
176 DWORD_PTR dwIoBase
177 );
178
179VOID KeyvRemoveAllWEPKey(
180 PSKeyManagement pTable,
181 DWORD_PTR dwIoBase
182 );
183
184BOOL KeybSetAllGroupKey (
185 PSKeyManagement pTable,
186 DWORD dwKeyIndex,
187 ULONG uKeyLength,
188 PQWORD pKeyRSC,
189 PBYTE pbyKey,
190 BYTE byKeyDecMode,
191 DWORD_PTR dwIoBase,
192 BYTE byLocalID
193 );
194
195#ifdef __cplusplus
196} /* End of extern "C" { */
197
198#endif /* __cplusplus */
199
200
201#endif // __KEY_H__
202
diff --git a/drivers/staging/vt6655/mac.c b/drivers/staging/vt6655/mac.c
new file mode 100644
index 000000000000..0283ed3bedd4
--- /dev/null
+++ b/drivers/staging/vt6655/mac.c
@@ -0,0 +1,1752 @@
1/*
2 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
3 * All rights reserved.
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * File: mac.c
20 *
21 * Purpose: MAC routines
22 *
23 * Author: Tevin Chen
24 *
25 * Date: May 21, 1996
26 *
27 * Functions:
28 * MACvReadAllRegs - Read All MAC Registers to buffer
29 * MACbIsRegBitsOn - Test if All test Bits On
30 * MACbIsRegBitsOff - Test if All test Bits Off
31 * MACbIsIntDisable - Test if MAC interrupt disable
32 * MACbyReadMultiAddr - Read Multicast Address Mask Pattern
33 * MACvWriteMultiAddr - Write Multicast Address Mask Pattern
34 * MACvSetMultiAddrByHash - Set Multicast Address Mask by Hash value
35 * MACvResetMultiAddrByHash - Clear Multicast Address Mask by Hash value
36 * MACvSetRxThreshold - Set Rx Threshold value
37 * MACvGetRxThreshold - Get Rx Threshold value
38 * MACvSetTxThreshold - Set Tx Threshold value
39 * MACvGetTxThreshold - Get Tx Threshold value
40 * MACvSetDmaLength - Set Dma Length value
41 * MACvGetDmaLength - Get Dma Length value
42 * MACvSetShortRetryLimit - Set 802.11 Short Retry limit
43 * MACvGetShortRetryLimit - Get 802.11 Short Retry limit
44 * MACvSetLongRetryLimit - Set 802.11 Long Retry limit
45 * MACvGetLongRetryLimit - Get 802.11 Long Retry limit
46 * MACvSetLoopbackMode - Set MAC Loopback Mode
47 * MACbIsInLoopbackMode - Test if MAC in Loopback mode
48 * MACvSetPacketFilter - Set MAC Address Filter
49 * MACvSaveContext - Save Context of MAC Registers
50 * MACvRestoreContext - Restore Context of MAC Registers
51 * MACbCompareContext - Compare if values of MAC Registers same as Context
52 * MACbSoftwareReset - Software Reset MAC
53 * MACbSafeRxOff - Turn Off MAC Rx
54 * MACbSafeTxOff - Turn Off MAC Tx
55 * MACbSafeStop - Stop MAC function
56 * MACbShutdown - Shut down MAC
57 * MACvInitialize - Initialize MAC
58 * MACvSetCurrRxDescAddr - Set Rx Descriptos Address
59 * MACvSetCurrTx0DescAddr - Set Tx0 Descriptos Address
60 * MACvSetCurrTx1DescAddr - Set Tx1 Descriptos Address
61 * MACvTimer0MicroSDelay - Micro Second Delay Loop by MAC
62 *
63 * Revision History:
64 * 08-22-2003 Kyle Hsu : Porting MAC functions from sim53
65 * 09-03-2003 Bryan YC Fan : Add MACvClearBusSusInd()& MACvEnableBusSusEn()
66 * 09-18-2003 Jerry Chen : Add MACvSetKeyEntry & MACvDisableKeyEntry
67 *
68 */
69
70#if !defined(__TMACRO_H__)
71#include "tmacro.h"
72#endif
73#if !defined(__TBIT_H__)
74#include "tbit.h"
75#endif
76#if !defined(__TETHER_H__)
77#include "tether.h"
78#endif
79#if !defined(__MAC_H__)
80#include "mac.h"
81#endif
82
83
84WORD TxRate_iwconfig;//2008-5-8 <add> by chester
85/*--------------------- Static Definitions -------------------------*/
86//static int msglevel =MSG_LEVEL_DEBUG;
87static int msglevel =MSG_LEVEL_INFO;
88/*--------------------- Static Classes ----------------------------*/
89
90/*--------------------- Static Variables --------------------------*/
91
92/*--------------------- Static Functions --------------------------*/
93
94/*--------------------- Export Variables --------------------------*/
95
96/*--------------------- Export Functions --------------------------*/
97
98/*
99 * Description:
100 * Read All MAC Registers to buffer
101 *
102 * Parameters:
103 * In:
104 * dwIoBase - Base Address for MAC
105 * Out:
106 * pbyMacRegs - buffer to read
107 *
108 * Return Value: none
109 *
110 */
111VOID MACvReadAllRegs (DWORD_PTR dwIoBase, PBYTE pbyMacRegs)
112{
113 int ii;
114
115 // read page0 register
116 for (ii = 0; ii < MAC_MAX_CONTEXT_SIZE_PAGE0; ii++) {
117 VNSvInPortB(dwIoBase + ii, pbyMacRegs);
118 pbyMacRegs++;
119 }
120
121 MACvSelectPage1(dwIoBase);
122
123 // read page1 register
124 for (ii = 0; ii < MAC_MAX_CONTEXT_SIZE_PAGE1; ii++) {
125 VNSvInPortB(dwIoBase + ii, pbyMacRegs);
126 pbyMacRegs++;
127 }
128
129 MACvSelectPage0(dwIoBase);
130
131}
132
133/*
134 * Description:
135 * Test if all test bits on
136 *
137 * Parameters:
138 * In:
139 * dwIoBase - Base Address for MAC
140 * byRegOfs - Offset of MAC Register
141 * byTestBits - Test bits
142 * Out:
143 * none
144 *
145 * Return Value: TRUE if all test bits On; otherwise FALSE
146 *
147 */
148BOOL MACbIsRegBitsOn (DWORD_PTR dwIoBase, BYTE byRegOfs, BYTE byTestBits)
149{
150 BYTE byData;
151
152 VNSvInPortB(dwIoBase + byRegOfs, &byData);
153 return BITbIsAllBitsOn(byData, byTestBits);
154}
155
156/*
157 * Description:
158 * Test if all test bits off
159 *
160 * Parameters:
161 * In:
162 * dwIoBase - Base Address for MAC
163 * byRegOfs - Offset of MAC Register
164 * byTestBits - Test bits
165 * Out:
166 * none
167 *
168 * Return Value: TRUE if all test bits Off; otherwise FALSE
169 *
170 */
171BOOL MACbIsRegBitsOff (DWORD_PTR dwIoBase, BYTE byRegOfs, BYTE byTestBits)
172{
173 BYTE byData;
174
175 VNSvInPortB(dwIoBase + byRegOfs, &byData);
176 return BITbIsAllBitsOff(byData, byTestBits);
177}
178
179/*
180 * Description:
181 * Test if MAC interrupt disable
182 *
183 * Parameters:
184 * In:
185 * dwIoBase - Base Address for MAC
186 * Out:
187 * none
188 *
189 * Return Value: TRUE if interrupt is disable; otherwise FALSE
190 *
191 */
192BOOL MACbIsIntDisable (DWORD_PTR dwIoBase)
193{
194 DWORD dwData;
195
196 VNSvInPortD(dwIoBase + MAC_REG_IMR, &dwData);
197 if (dwData != 0)
198 return FALSE;
199
200 return TRUE;
201}
202
203/*
204 * Description:
205 * Read MAC Multicast Address Mask
206 *
207 * Parameters:
208 * In:
209 * dwIoBase - Base Address for MAC
210 * uByteidx - Index of Mask
211 * Out:
212 * none
213 *
214 * Return Value: Mask Value read
215 *
216 */
217BYTE MACbyReadMultiAddr (DWORD_PTR dwIoBase, UINT uByteIdx)
218{
219 BYTE byData;
220
221 MACvSelectPage1(dwIoBase);
222 VNSvInPortB(dwIoBase + MAC_REG_MAR0 + uByteIdx, &byData);
223 MACvSelectPage0(dwIoBase);
224 return byData;
225}
226
227/*
228 * Description:
229 * Write MAC Multicast Address Mask
230 *
231 * Parameters:
232 * In:
233 * dwIoBase - Base Address for MAC
234 * uByteidx - Index of Mask
235 * byData - Mask Value to write
236 * Out:
237 * none
238 *
239 * Return Value: none
240 *
241 */
242VOID MACvWriteMultiAddr (DWORD_PTR dwIoBase, UINT uByteIdx, BYTE byData)
243{
244 MACvSelectPage1(dwIoBase);
245 VNSvOutPortB(dwIoBase + MAC_REG_MAR0 + uByteIdx, byData);
246 MACvSelectPage0(dwIoBase);
247}
248
249/*
250 * Description:
251 * Set this hash index into multicast address register bit
252 *
253 * Parameters:
254 * In:
255 * dwIoBase - Base Address for MAC
256 * byHashIdx - Hash index to set
257 * Out:
258 * none
259 *
260 * Return Value: none
261 *
262 */
263void MACvSetMultiAddrByHash (DWORD_PTR dwIoBase, BYTE byHashIdx)
264{
265 UINT uByteIdx;
266 BYTE byBitMask;
267 BYTE byOrgValue;
268
269 // calculate byte position
270 uByteIdx = byHashIdx / 8;
271 ASSERT(uByteIdx < 8);
272 // calculate bit position
273 byBitMask = 1;
274 byBitMask <<= (byHashIdx % 8);
275 // turn on the bit
276 byOrgValue = MACbyReadMultiAddr(dwIoBase, uByteIdx);
277 MACvWriteMultiAddr(dwIoBase, uByteIdx, (BYTE)(byOrgValue | byBitMask));
278}
279
280/*
281 * Description:
282 * Reset this hash index into multicast address register bit
283 *
284 * Parameters:
285 * In:
286 * dwIoBase - Base Address for MAC
287 * byHashIdx - Hash index to clear
288 * Out:
289 * none
290 *
291 * Return Value: none
292 *
293 */
294void MACvResetMultiAddrByHash (DWORD_PTR dwIoBase, BYTE byHashIdx)
295{
296 UINT uByteIdx;
297 BYTE byBitMask;
298 BYTE byOrgValue;
299
300 // calculate byte position
301 uByteIdx = byHashIdx / 8;
302 ASSERT(uByteIdx < 8);
303 // calculate bit position
304 byBitMask = 1;
305 byBitMask <<= (byHashIdx % 8);
306 // turn off the bit
307 byOrgValue = MACbyReadMultiAddr(dwIoBase, uByteIdx);
308 MACvWriteMultiAddr(dwIoBase, uByteIdx, (BYTE)(byOrgValue & (~byBitMask)));
309}
310
311/*
312 * Description:
313 * Set Rx Threshold
314 *
315 * Parameters:
316 * In:
317 * dwIoBase - Base Address for MAC
318 * byThreshold - Threshold Value
319 * Out:
320 * none
321 *
322 * Return Value: none
323 *
324 */
325void MACvSetRxThreshold (DWORD_PTR dwIoBase, BYTE byThreshold)
326{
327 BYTE byOrgValue;
328
329 ASSERT(byThreshold < 4);
330
331 // set FCR0
332 VNSvInPortB(dwIoBase + MAC_REG_FCR0, &byOrgValue);
333 byOrgValue = (byOrgValue & 0xCF) | (byThreshold << 4);
334 VNSvOutPortB(dwIoBase + MAC_REG_FCR0, byOrgValue);
335}
336
337/*
338 * Description:
339 * Get Rx Threshold
340 *
341 * Parameters:
342 * In:
343 * dwIoBase - Base Address for MAC
344 * Out:
345 * pbyThreshold- Threshold Value Get
346 *
347 * Return Value: none
348 *
349 */
350void MACvGetRxThreshold (DWORD_PTR dwIoBase, PBYTE pbyThreshold)
351{
352 // get FCR0
353 VNSvInPortB(dwIoBase + MAC_REG_FCR0, pbyThreshold);
354 *pbyThreshold = (*pbyThreshold >> 4) & 0x03;
355}
356
357/*
358 * Description:
359 * Set Tx Threshold
360 *
361 * Parameters:
362 * In:
363 * dwIoBase - Base Address for MAC
364 * byThreshold - Threshold Value
365 * Out:
366 * none
367 *
368 * Return Value: none
369 *
370 */
371void MACvSetTxThreshold (DWORD_PTR dwIoBase, BYTE byThreshold)
372{
373 BYTE byOrgValue;
374
375 ASSERT(byThreshold < 4);
376
377 // set FCR0
378 VNSvInPortB(dwIoBase + MAC_REG_FCR0, &byOrgValue);
379 byOrgValue = (byOrgValue & 0xF3) | (byThreshold << 2);
380 VNSvOutPortB(dwIoBase + MAC_REG_FCR0, byOrgValue);
381}
382
383/*
384 * Description:
385 * Get Tx Threshold
386 *
387 * Parameters:
388 * In:
389 * dwIoBase - Base Address for MAC
390 * Out:
391 * pbyThreshold- Threshold Value Get
392 *
393 * Return Value: none
394 *
395 */
396void MACvGetTxThreshold (DWORD_PTR dwIoBase, PBYTE pbyThreshold)
397{
398 // get FCR0
399 VNSvInPortB(dwIoBase + MAC_REG_FCR0, pbyThreshold);
400 *pbyThreshold = (*pbyThreshold >> 2) & 0x03;
401}
402
403/*
404 * Description:
405 * Set Dma Length
406 *
407 * Parameters:
408 * In:
409 * dwIoBase - Base Address for MAC
410 * byDmaLength - Dma Length Value
411 * Out:
412 * none
413 *
414 * Return Value: none
415 *
416 */
417void MACvSetDmaLength (DWORD_PTR dwIoBase, BYTE byDmaLength)
418{
419 BYTE byOrgValue;
420
421 ASSERT(byDmaLength < 4);
422
423 // set FCR0
424 VNSvInPortB(dwIoBase + MAC_REG_FCR0, &byOrgValue);
425 byOrgValue = (byOrgValue & 0xFC) | byDmaLength;
426 VNSvOutPortB(dwIoBase + MAC_REG_FCR0, byOrgValue);
427}
428
429/*
430 * Description:
431 * Get Dma Length
432 *
433 * Parameters:
434 * In:
435 * dwIoBase - Base Address for MAC
436 * Out:
437 * pbyDmaLength- Dma Length Value Get
438 *
439 * Return Value: none
440 *
441 */
442void MACvGetDmaLength (DWORD_PTR dwIoBase, PBYTE pbyDmaLength)
443{
444 // get FCR0
445 VNSvInPortB(dwIoBase + MAC_REG_FCR0, pbyDmaLength);
446 *pbyDmaLength &= 0x03;
447}
448
449/*
450 * Description:
451 * Set 802.11 Short Retry Limit
452 *
453 * Parameters:
454 * In:
455 * dwIoBase - Base Address for MAC
456 * byRetryLimit- Retry Limit
457 * Out:
458 * none
459 *
460 * Return Value: none
461 *
462 */
463void MACvSetShortRetryLimit (DWORD_PTR dwIoBase, BYTE byRetryLimit)
464{
465 // set SRT
466 VNSvOutPortB(dwIoBase + MAC_REG_SRT, byRetryLimit);
467}
468
469/*
470 * Description:
471 * Get 802.11 Short Retry Limit
472 *
473 * Parameters:
474 * In:
475 * dwIoBase - Base Address for MAC
476 * Out:
477 * pbyRetryLimit - Retry Limit Get
478 *
479 * Return Value: none
480 *
481 */
482void MACvGetShortRetryLimit (DWORD_PTR dwIoBase, PBYTE pbyRetryLimit)
483{
484 // get SRT
485 VNSvInPortB(dwIoBase + MAC_REG_SRT, pbyRetryLimit);
486}
487
488/*
489 * Description:
490 * Set 802.11 Long Retry Limit
491 *
492 * Parameters:
493 * In:
494 * dwIoBase - Base Address for MAC
495 * byRetryLimit- Retry Limit
496 * Out:
497 * none
498 *
499 * Return Value: none
500 *
501 */
502void MACvSetLongRetryLimit (DWORD_PTR dwIoBase, BYTE byRetryLimit)
503{
504 // set LRT
505 VNSvOutPortB(dwIoBase + MAC_REG_LRT, byRetryLimit);
506}
507
508/*
509 * Description:
510 * Get 802.11 Long Retry Limit
511 *
512 * Parameters:
513 * In:
514 * dwIoBase - Base Address for MAC
515 * Out:
516 * pbyRetryLimit - Retry Limit Get
517 *
518 * Return Value: none
519 *
520 */
521void MACvGetLongRetryLimit (DWORD_PTR dwIoBase, PBYTE pbyRetryLimit)
522{
523 // get LRT
524 VNSvInPortB(dwIoBase + MAC_REG_LRT, pbyRetryLimit);
525}
526
527/*
528 * Description:
529 * Set MAC Loopback mode
530 *
531 * Parameters:
532 * In:
533 * dwIoBase - Base Address for MAC
534 * byLoopbackMode - Loopback Mode
535 * Out:
536 * none
537 *
538 * Return Value: none
539 *
540 */
541void MACvSetLoopbackMode (DWORD_PTR dwIoBase, BYTE byLoopbackMode)
542{
543 BYTE byOrgValue;
544
545 ASSERT(byLoopbackMode < 3);
546 byLoopbackMode <<= 6;
547 // set TCR
548 VNSvInPortB(dwIoBase + MAC_REG_TEST, &byOrgValue);
549 byOrgValue = byOrgValue & 0x3F;
550 byOrgValue = byOrgValue | byLoopbackMode;
551 VNSvOutPortB(dwIoBase + MAC_REG_TEST, byOrgValue);
552}
553
554/*
555 * Description:
556 * Test if MAC in Loopback mode
557 *
558 * Parameters:
559 * In:
560 * dwIoBase - Base Address for MAC
561 * Out:
562 * none
563 *
564 * Return Value: TRUE if in Loopback mode; otherwise FALSE
565 *
566 */
567BOOL MACbIsInLoopbackMode (DWORD_PTR dwIoBase)
568{
569 BYTE byOrgValue;
570
571 VNSvInPortB(dwIoBase + MAC_REG_TEST, &byOrgValue);
572 if (BITbIsAnyBitsOn(byOrgValue, (TEST_LBINT | TEST_LBEXT)))
573 return TRUE;
574 return FALSE;
575}
576
577/*
578 * Description:
579 * Set MAC Address filter
580 *
581 * Parameters:
582 * In:
583 * dwIoBase - Base Address for MAC
584 * wFilterType - Filter Type
585 * Out:
586 * none
587 *
588 * Return Value: none
589 *
590 */
591void MACvSetPacketFilter (DWORD_PTR dwIoBase, WORD wFilterType)
592{
593 BYTE byOldRCR;
594 BYTE byNewRCR = 0;
595
596 // if only in DIRECTED mode, multicast-address will set to zero,
597 // but if other mode exist (e.g. PROMISCUOUS), multicast-address
598 // will be open
599 if (BITbIsBitOn(wFilterType, PKT_TYPE_DIRECTED)) {
600 // set multicast address to accept none
601 MACvSelectPage1(dwIoBase);
602 VNSvOutPortD(dwIoBase + MAC_REG_MAR0, 0L);
603 VNSvOutPortD(dwIoBase + MAC_REG_MAR0 + sizeof(DWORD), 0L);
604 MACvSelectPage0(dwIoBase);
605 }
606
607 if (BITbIsAnyBitsOn(wFilterType, PKT_TYPE_PROMISCUOUS | PKT_TYPE_ALL_MULTICAST)) {
608 // set multicast address to accept all
609 MACvSelectPage1(dwIoBase);
610 VNSvOutPortD(dwIoBase + MAC_REG_MAR0, 0xFFFFFFFFL);
611 VNSvOutPortD(dwIoBase + MAC_REG_MAR0 + sizeof(DWORD), 0xFFFFFFFFL);
612 MACvSelectPage0(dwIoBase);
613 }
614
615 if (BITbIsBitOn(wFilterType, PKT_TYPE_PROMISCUOUS)) {
616
617 byNewRCR |= (RCR_RXALLTYPE | RCR_UNICAST | RCR_MULTICAST | RCR_BROADCAST);
618
619 byNewRCR &= ~RCR_BSSID;
620 }
621
622 if (BITbIsAnyBitsOn(wFilterType, (PKT_TYPE_ALL_MULTICAST | PKT_TYPE_MULTICAST)))
623 byNewRCR |= RCR_MULTICAST;
624
625 if (BITbIsBitOn(wFilterType, PKT_TYPE_BROADCAST))
626 byNewRCR |= RCR_BROADCAST;
627
628 if (BITbIsBitOn(wFilterType, PKT_TYPE_ERROR_CRC))
629 byNewRCR |= RCR_ERRCRC;
630
631 VNSvInPortB(dwIoBase + MAC_REG_RCR, &byOldRCR);
632 if (byNewRCR != byOldRCR) {
633 // Modify the Receive Command Register
634 VNSvOutPortB(dwIoBase + MAC_REG_RCR, byNewRCR);
635 }
636}
637
638/*
639 * Description:
640 * Save MAC registers to context buffer
641 *
642 * Parameters:
643 * In:
644 * dwIoBase - Base Address for MAC
645 * Out:
646 * pbyCxtBuf - Context buffer
647 *
648 * Return Value: none
649 *
650 */
651void MACvSaveContext (DWORD_PTR dwIoBase, PBYTE pbyCxtBuf)
652{
653 int ii;
654
655 // read page0 register
656 for (ii = 0; ii < MAC_MAX_CONTEXT_SIZE_PAGE0; ii++) {
657 VNSvInPortB((dwIoBase + ii), (pbyCxtBuf + ii));
658 }
659
660 MACvSelectPage1(dwIoBase);
661
662 // read page1 register
663 for (ii = 0; ii < MAC_MAX_CONTEXT_SIZE_PAGE1; ii++) {
664 VNSvInPortB((dwIoBase + ii), (pbyCxtBuf + MAC_MAX_CONTEXT_SIZE_PAGE0 + ii));
665 }
666
667 MACvSelectPage0(dwIoBase);
668}
669
670/*
671 * Description:
672 * Restore MAC registers from context buffer
673 *
674 * Parameters:
675 * In:
676 * dwIoBase - Base Address for MAC
677 * pbyCxtBuf - Context buffer
678 * Out:
679 * none
680 *
681 * Return Value: none
682 *
683 */
684VOID MACvRestoreContext (DWORD_PTR dwIoBase, PBYTE pbyCxtBuf)
685{
686 int ii;
687
688 MACvSelectPage1(dwIoBase);
689 // restore page1
690 for (ii = 0; ii < MAC_MAX_CONTEXT_SIZE_PAGE1; ii++) {
691 VNSvOutPortB((dwIoBase + ii), *(pbyCxtBuf + MAC_MAX_CONTEXT_SIZE_PAGE0 + ii));
692 }
693 MACvSelectPage0(dwIoBase);
694
695 // restore RCR,TCR,IMR...
696 for (ii = MAC_REG_RCR; ii < MAC_REG_ISR; ii++) {
697 VNSvOutPortB(dwIoBase + ii, *(pbyCxtBuf + ii));
698 }
699 // restore MAC Config.
700 for (ii = MAC_REG_LRT; ii < MAC_REG_PAGE1SEL; ii++) {
701 VNSvOutPortB(dwIoBase + ii, *(pbyCxtBuf + ii));
702 }
703 VNSvOutPortB(dwIoBase + MAC_REG_CFG, *(pbyCxtBuf + MAC_REG_CFG));
704
705 // restore PS Config.
706 for (ii = MAC_REG_PSCFG; ii < MAC_REG_BBREGCTL; ii++) {
707 VNSvOutPortB(dwIoBase + ii, *(pbyCxtBuf + ii));
708 }
709
710 // restore CURR_RX_DESC_ADDR, CURR_TX_DESC_ADDR
711 VNSvOutPortD(dwIoBase + MAC_REG_TXDMAPTR0, *(PDWORD)(pbyCxtBuf + MAC_REG_TXDMAPTR0));
712 VNSvOutPortD(dwIoBase + MAC_REG_AC0DMAPTR, *(PDWORD)(pbyCxtBuf + MAC_REG_AC0DMAPTR));
713 VNSvOutPortD(dwIoBase + MAC_REG_BCNDMAPTR, *(PDWORD)(pbyCxtBuf + MAC_REG_BCNDMAPTR));
714
715
716 VNSvOutPortD(dwIoBase + MAC_REG_RXDMAPTR0, *(PDWORD)(pbyCxtBuf + MAC_REG_RXDMAPTR0));
717
718 VNSvOutPortD(dwIoBase + MAC_REG_RXDMAPTR1, *(PDWORD)(pbyCxtBuf + MAC_REG_RXDMAPTR1));
719
720}
721
722/*
723 * Description:
724 * Compare if MAC registers same as context buffer
725 *
726 * Parameters:
727 * In:
728 * dwIoBase - Base Address for MAC
729 * pbyCxtBuf - Context buffer
730 * Out:
731 * none
732 *
733 * Return Value: TRUE if all values are the same; otherwise FALSE
734 *
735 */
736BOOL MACbCompareContext (DWORD_PTR dwIoBase, PBYTE pbyCxtBuf)
737{
738 DWORD dwData;
739
740 // compare MAC context to determine if this is a power lost init,
741 // return TRUE for power remaining init, return FALSE for power lost init
742
743 // compare CURR_RX_DESC_ADDR, CURR_TX_DESC_ADDR
744 VNSvInPortD(dwIoBase + MAC_REG_TXDMAPTR0, &dwData);
745 if (dwData != *(PDWORD)(pbyCxtBuf + MAC_REG_TXDMAPTR0)) {
746 return FALSE;
747 }
748
749 VNSvInPortD(dwIoBase + MAC_REG_AC0DMAPTR, &dwData);
750 if (dwData != *(PDWORD)(pbyCxtBuf + MAC_REG_AC0DMAPTR)) {
751 return FALSE;
752 }
753
754 VNSvInPortD(dwIoBase + MAC_REG_RXDMAPTR0, &dwData);
755 if (dwData != *(PDWORD)(pbyCxtBuf + MAC_REG_RXDMAPTR0)) {
756 return FALSE;
757 }
758
759 VNSvInPortD(dwIoBase + MAC_REG_RXDMAPTR1, &dwData);
760 if (dwData != *(PDWORD)(pbyCxtBuf + MAC_REG_RXDMAPTR1)) {
761 return FALSE;
762 }
763
764
765 return TRUE;
766}
767
768/*
769 * Description:
770 * Software Reset MAC
771 *
772 * Parameters:
773 * In:
774 * dwIoBase - Base Address for MAC
775 * Out:
776 * none
777 *
778 * Return Value: TRUE if Reset Success; otherwise FALSE
779 *
780 */
781BOOL MACbSoftwareReset (DWORD_PTR dwIoBase)
782{
783 BYTE byData;
784 WORD ww;
785
786 // turn on HOSTCR_SOFTRST, just write 0x01 to reset
787 //MACvRegBitsOn(dwIoBase, MAC_REG_HOSTCR, HOSTCR_SOFTRST);
788 VNSvOutPortB(dwIoBase+ MAC_REG_HOSTCR, 0x01);
789
790 for (ww = 0; ww < W_MAX_TIMEOUT; ww++) {
791 VNSvInPortB(dwIoBase + MAC_REG_HOSTCR, &byData);
792 if (BITbIsBitOff(byData, HOSTCR_SOFTRST))
793 break;
794 }
795 if (ww == W_MAX_TIMEOUT)
796 return FALSE;
797 return TRUE;
798
799}
800
801/*
802 * Description:
803 * save some important register's value, then do reset, then restore register's value
804 *
805 * Parameters:
806 * In:
807 * dwIoBase - Base Address for MAC
808 * Out:
809 * none
810 *
811 * Return Value: TRUE if success; otherwise FALSE
812 *
813 */
814BOOL MACbSafeSoftwareReset (DWORD_PTR dwIoBase)
815{
816 BYTE abyTmpRegData[MAC_MAX_CONTEXT_SIZE_PAGE0+MAC_MAX_CONTEXT_SIZE_PAGE1];
817 BOOL bRetVal;
818
819 // PATCH....
820 // save some important register's value, then do
821 // reset, then restore register's value
822
823 // save MAC context
824 MACvSaveContext(dwIoBase, abyTmpRegData);
825 // do reset
826 bRetVal = MACbSoftwareReset(dwIoBase);
827 //BBvSoftwareReset(pDevice->PortOffset);
828 // restore MAC context, except CR0
829 MACvRestoreContext(dwIoBase, abyTmpRegData);
830
831 return bRetVal;
832}
833
834/*
835 * Description:
836 * Trun Off MAC Rx
837 *
838 * Parameters:
839 * In:
840 * dwIoBase - Base Address for MAC
841 * Out:
842 * none
843 *
844 * Return Value: TRUE if success; otherwise FALSE
845 *
846 */
847BOOL MACbSafeRxOff (DWORD_PTR dwIoBase)
848{
849 WORD ww;
850 DWORD dwData;
851 BYTE byData;
852
853 // turn off wow temp for turn off Rx safely
854
855 // Clear RX DMA0,1
856 VNSvOutPortD(dwIoBase + MAC_REG_RXDMACTL0, DMACTL_CLRRUN);
857 VNSvOutPortD(dwIoBase + MAC_REG_RXDMACTL1, DMACTL_CLRRUN);
858 for (ww = 0; ww < W_MAX_TIMEOUT; ww++) {
859 VNSvInPortD(dwIoBase + MAC_REG_RXDMACTL0, &dwData);
860 if (BITbIsAllBitsOff(dwData, DMACTL_RUN))
861 break;
862 }
863 if (ww == W_MAX_TIMEOUT) {
864 DBG_PORT80(0x10);
865 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO" DBG_PORT80(0x10)\n");
866 return(FALSE);
867 }
868 for (ww = 0; ww < W_MAX_TIMEOUT; ww++) {
869 VNSvInPortD(dwIoBase + MAC_REG_RXDMACTL1, &dwData);
870 if (BITbIsAllBitsOff(dwData, DMACTL_RUN))
871 break;
872 }
873 if (ww == W_MAX_TIMEOUT) {
874 DBG_PORT80(0x11);
875 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO" DBG_PORT80(0x11)\n");
876 return(FALSE);
877 }
878
879 // try to safe shutdown RX
880 MACvRegBitsOff(dwIoBase, MAC_REG_HOSTCR, HOSTCR_RXON);
881 // W_MAX_TIMEOUT is the timeout period
882 for (ww = 0; ww < W_MAX_TIMEOUT; ww++) {
883 VNSvInPortB(dwIoBase + MAC_REG_HOSTCR, &byData);
884 if (BITbIsAllBitsOff(byData, HOSTCR_RXONST))
885 break;
886 }
887 if (ww == W_MAX_TIMEOUT) {
888 DBG_PORT80(0x12);
889 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO" DBG_PORT80(0x12)\n");
890 return(FALSE);
891 }
892 return TRUE;
893}
894
895/*
896 * Description:
897 * Trun Off MAC Tx
898 *
899 * Parameters:
900 * In:
901 * dwIoBase - Base Address for MAC
902 * Out:
903 * none
904 *
905 * Return Value: TRUE if success; otherwise FALSE
906 *
907 */
908BOOL MACbSafeTxOff (DWORD_PTR dwIoBase)
909{
910 WORD ww;
911 DWORD dwData;
912 BYTE byData;
913
914 // Clear TX DMA
915 //Tx0
916 VNSvOutPortD(dwIoBase + MAC_REG_TXDMACTL0, DMACTL_CLRRUN);
917 //AC0
918 VNSvOutPortD(dwIoBase + MAC_REG_AC0DMACTL, DMACTL_CLRRUN);
919
920
921 for (ww = 0; ww < W_MAX_TIMEOUT; ww++) {
922 VNSvInPortD(dwIoBase + MAC_REG_TXDMACTL0, &dwData);
923 if (BITbIsAllBitsOff(dwData, DMACTL_RUN))
924 break;
925 }
926 if (ww == W_MAX_TIMEOUT) {
927 DBG_PORT80(0x20);
928 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO" DBG_PORT80(0x20)\n");
929 return(FALSE);
930 }
931 for (ww = 0; ww < W_MAX_TIMEOUT; ww++) {
932 VNSvInPortD(dwIoBase + MAC_REG_AC0DMACTL, &dwData);
933 if (BITbIsAllBitsOff(dwData, DMACTL_RUN))
934 break;
935 }
936 if (ww == W_MAX_TIMEOUT) {
937 DBG_PORT80(0x21);
938 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO" DBG_PORT80(0x21)\n");
939 return(FALSE);
940 }
941
942 // try to safe shutdown TX
943 MACvRegBitsOff(dwIoBase, MAC_REG_HOSTCR, HOSTCR_TXON);
944
945 // W_MAX_TIMEOUT is the timeout period
946 for (ww = 0; ww < W_MAX_TIMEOUT; ww++) {
947 VNSvInPortB(dwIoBase + MAC_REG_HOSTCR, &byData);
948 if (BITbIsAllBitsOff(byData, HOSTCR_TXONST))
949 break;
950 }
951 if (ww == W_MAX_TIMEOUT) {
952 DBG_PORT80(0x24);
953 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO" DBG_PORT80(0x24)\n");
954 return(FALSE);
955 }
956 return TRUE;
957}
958
959/*
960 * Description:
961 * Stop MAC function
962 *
963 * Parameters:
964 * In:
965 * dwIoBase - Base Address for MAC
966 * Out:
967 * none
968 *
969 * Return Value: TRUE if success; otherwise FALSE
970 *
971 */
972BOOL MACbSafeStop (DWORD_PTR dwIoBase)
973{
974 MACvRegBitsOff(dwIoBase, MAC_REG_TCR, TCR_AUTOBCNTX);
975
976 if (MACbSafeRxOff(dwIoBase) == FALSE) {
977 DBG_PORT80(0xA1);
978 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO" MACbSafeRxOff == FALSE)\n");
979 MACbSafeSoftwareReset(dwIoBase);
980 return FALSE;
981 }
982 if (MACbSafeTxOff(dwIoBase) == FALSE) {
983 DBG_PORT80(0xA2);
984 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO" MACbSafeTxOff == FALSE)\n");
985 MACbSafeSoftwareReset(dwIoBase);
986 return FALSE;
987 }
988
989 MACvRegBitsOff(dwIoBase, MAC_REG_HOSTCR, HOSTCR_MACEN);
990
991 return TRUE;
992}
993
994/*
995 * Description:
996 * Shut Down MAC
997 *
998 * Parameters:
999 * In:
1000 * dwIoBase - Base Address for MAC
1001 * Out:
1002 * none
1003 *
1004 * Return Value: TRUE if success; otherwise FALSE
1005 *
1006 */
1007BOOL MACbShutdown (DWORD_PTR dwIoBase)
1008{
1009 // disable MAC IMR
1010 MACvIntDisable(dwIoBase);
1011 MACvSetLoopbackMode(dwIoBase, MAC_LB_INTERNAL);
1012 // stop the adapter
1013 if (!MACbSafeStop(dwIoBase)) {
1014 MACvSetLoopbackMode(dwIoBase, MAC_LB_NONE);
1015 return FALSE;
1016 }
1017 MACvSetLoopbackMode(dwIoBase, MAC_LB_NONE);
1018 return TRUE;
1019}
1020
1021/*
1022 * Description:
1023 * Initialize MAC
1024 *
1025 * Parameters:
1026 * In:
1027 * dwIoBase - Base Address for MAC
1028 * Out:
1029 * none
1030 *
1031 * Return Value: none
1032 *
1033 */
1034void MACvInitialize (DWORD_PTR dwIoBase)
1035{
1036 // clear sticky bits
1037 MACvClearStckDS(dwIoBase);
1038 // disable force PME-enable
1039 VNSvOutPortB(dwIoBase + MAC_REG_PMC1, PME_OVR);
1040 // only 3253 A
1041 /*
1042 MACvPwrEvntDisable(dwIoBase);
1043 // clear power status
1044 VNSvOutPortW(dwIoBase + MAC_REG_WAKEUPSR0, 0x0F0F);
1045 */
1046
1047 // do reset
1048 MACbSoftwareReset(dwIoBase);
1049
1050 // issue AUTOLD in EECSR to reload eeprom
1051 //MACvRegBitsOn(dwIoBase, MAC_REG_I2MCSR, I2MCSR_AUTOLD);
1052 // wait until EEPROM loading complete
1053 //while (TRUE) {
1054 // U8 u8Data;
1055 // VNSvInPortB(dwIoBase + MAC_REG_I2MCSR, &u8Data);
1056 // if (BITbIsBitOff(u8Data, I2MCSR_AUTOLD))
1057 // break;
1058 //}
1059
1060 // reset TSF counter
1061 VNSvOutPortB(dwIoBase + MAC_REG_TFTCTL, TFTCTL_TSFCNTRST);
1062 // enable TSF counter
1063 VNSvOutPortB(dwIoBase + MAC_REG_TFTCTL, TFTCTL_TSFCNTREN);
1064
1065
1066 // set packet filter
1067 // receive directed and broadcast address
1068
1069 MACvSetPacketFilter(dwIoBase, PKT_TYPE_DIRECTED | PKT_TYPE_BROADCAST);
1070
1071}
1072
1073/*
1074 * Description:
1075 * Set the chip with current rx descriptor address
1076 *
1077 * Parameters:
1078 * In:
1079 * dwIoBase - Base Address for MAC
1080 * dwCurrDescAddr - Descriptor Address
1081 * Out:
1082 * none
1083 *
1084 * Return Value: none
1085 *
1086 */
1087void MACvSetCurrRx0DescAddr (DWORD_PTR dwIoBase, DWORD dwCurrDescAddr)
1088{
1089WORD ww;
1090BYTE byData;
1091BYTE byOrgDMACtl;
1092
1093 VNSvInPortB(dwIoBase + MAC_REG_RXDMACTL0, &byOrgDMACtl);
1094 if (BITbIsAllBitsOn(byOrgDMACtl, DMACTL_RUN)) {
1095 VNSvOutPortB(dwIoBase + MAC_REG_RXDMACTL0+2, DMACTL_RUN);
1096 }
1097 for (ww = 0; ww < W_MAX_TIMEOUT; ww++) {
1098 VNSvInPortB(dwIoBase + MAC_REG_RXDMACTL0, &byData);
1099 if (BITbIsAllBitsOff(byData, DMACTL_RUN))
1100 break;
1101 }
1102 if (ww == W_MAX_TIMEOUT) {
1103 DBG_PORT80(0x13);
1104 }
1105 VNSvOutPortD(dwIoBase + MAC_REG_RXDMAPTR0, dwCurrDescAddr);
1106 if (BITbIsAllBitsOn(byOrgDMACtl, DMACTL_RUN)) {
1107 VNSvOutPortB(dwIoBase + MAC_REG_RXDMACTL0, DMACTL_RUN);
1108 }
1109}
1110
1111/*
1112 * Description:
1113 * Set the chip with current rx descriptor address
1114 *
1115 * Parameters:
1116 * In:
1117 * dwIoBase - Base Address for MAC
1118 * dwCurrDescAddr - Descriptor Address
1119 * Out:
1120 * none
1121 *
1122 * Return Value: none
1123 *
1124 */
1125void MACvSetCurrRx1DescAddr (DWORD_PTR dwIoBase, DWORD dwCurrDescAddr)
1126{
1127WORD ww;
1128BYTE byData;
1129BYTE byOrgDMACtl;
1130
1131 VNSvInPortB(dwIoBase + MAC_REG_RXDMACTL1, &byOrgDMACtl);
1132 if (BITbIsAllBitsOn(byOrgDMACtl, DMACTL_RUN)) {
1133 VNSvOutPortB(dwIoBase + MAC_REG_RXDMACTL1+2, DMACTL_RUN);
1134 }
1135 for (ww = 0; ww < W_MAX_TIMEOUT; ww++) {
1136 VNSvInPortB(dwIoBase + MAC_REG_RXDMACTL1, &byData);
1137 if (BITbIsAllBitsOff(byData, DMACTL_RUN))
1138 break;
1139 }
1140 if (ww == W_MAX_TIMEOUT) {
1141 DBG_PORT80(0x14);
1142 }
1143 VNSvOutPortD(dwIoBase + MAC_REG_RXDMAPTR1, dwCurrDescAddr);
1144 if (BITbIsAllBitsOn(byOrgDMACtl, DMACTL_RUN)) {
1145 VNSvOutPortB(dwIoBase + MAC_REG_RXDMACTL1, DMACTL_RUN);
1146 }
1147}
1148
1149/*
1150 * Description:
1151 * Set the chip with current tx0 descriptor address
1152 *
1153 * Parameters:
1154 * In:
1155 * dwIoBase - Base Address for MAC
1156 * dwCurrDescAddr - Descriptor Address
1157 * Out:
1158 * none
1159 *
1160 * Return Value: none
1161 *
1162 */
1163void MACvSetCurrTx0DescAddrEx (DWORD_PTR dwIoBase, DWORD dwCurrDescAddr)
1164{
1165WORD ww;
1166BYTE byData;
1167BYTE byOrgDMACtl;
1168
1169 VNSvInPortB(dwIoBase + MAC_REG_TXDMACTL0, &byOrgDMACtl);
1170 if (BITbIsAllBitsOn(byOrgDMACtl, DMACTL_RUN)) {
1171 VNSvOutPortB(dwIoBase + MAC_REG_TXDMACTL0+2, DMACTL_RUN);
1172 }
1173 for (ww = 0; ww < W_MAX_TIMEOUT; ww++) {
1174 VNSvInPortB(dwIoBase + MAC_REG_TXDMACTL0, &byData);
1175 if (BITbIsAllBitsOff(byData, DMACTL_RUN))
1176 break;
1177 }
1178 if (ww == W_MAX_TIMEOUT) {
1179 DBG_PORT80(0x25);
1180 }
1181 VNSvOutPortD(dwIoBase + MAC_REG_TXDMAPTR0, dwCurrDescAddr);
1182 if (BITbIsAllBitsOn(byOrgDMACtl, DMACTL_RUN)) {
1183 VNSvOutPortB(dwIoBase + MAC_REG_TXDMACTL0, DMACTL_RUN);
1184 }
1185}
1186
1187/*
1188 * Description:
1189 * Set the chip with current AC0 descriptor address
1190 *
1191 * Parameters:
1192 * In:
1193 * dwIoBase - Base Address for MAC
1194 * dwCurrDescAddr - Descriptor Address
1195 * Out:
1196 * none
1197 *
1198 * Return Value: none
1199 *
1200 */
1201 //TxDMA1 = AC0DMA
1202void MACvSetCurrAC0DescAddrEx (DWORD_PTR dwIoBase, DWORD dwCurrDescAddr)
1203{
1204WORD ww;
1205BYTE byData;
1206BYTE byOrgDMACtl;
1207
1208 VNSvInPortB(dwIoBase + MAC_REG_AC0DMACTL, &byOrgDMACtl);
1209 if (BITbIsAllBitsOn(byOrgDMACtl, DMACTL_RUN)) {
1210 VNSvOutPortB(dwIoBase + MAC_REG_AC0DMACTL+2, DMACTL_RUN);
1211 }
1212 for (ww = 0; ww < W_MAX_TIMEOUT; ww++) {
1213 VNSvInPortB(dwIoBase + MAC_REG_AC0DMACTL, &byData);
1214 if (BITbIsAllBitsOff(byData, DMACTL_RUN))
1215 break;
1216 }
1217 if (ww == W_MAX_TIMEOUT) {
1218 DBG_PORT80(0x26);
1219 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO" DBG_PORT80(0x26)\n");
1220 }
1221 VNSvOutPortD(dwIoBase + MAC_REG_AC0DMAPTR, dwCurrDescAddr);
1222 if (BITbIsAllBitsOn(byOrgDMACtl, DMACTL_RUN)) {
1223 VNSvOutPortB(dwIoBase + MAC_REG_AC0DMACTL, DMACTL_RUN);
1224 }
1225}
1226
1227
1228
1229void MACvSetCurrTXDescAddr (int iTxType, DWORD_PTR dwIoBase, DWORD dwCurrDescAddr)
1230{
1231 if(iTxType == TYPE_AC0DMA){
1232 MACvSetCurrAC0DescAddrEx(dwIoBase, dwCurrDescAddr);
1233 }else if(iTxType == TYPE_TXDMA0){
1234 MACvSetCurrTx0DescAddrEx(dwIoBase, dwCurrDescAddr);
1235 }
1236}
1237
1238/*
1239 * Description:
1240 * Micro Second Delay via MAC
1241 *
1242 * Parameters:
1243 * In:
1244 * dwIoBase - Base Address for MAC
1245 * uDelay - Delay time (timer resolution is 4 us)
1246 * Out:
1247 * none
1248 *
1249 * Return Value: none
1250 *
1251 */
1252VOID MACvTimer0MicroSDelay (DWORD_PTR dwIoBase, UINT uDelay)
1253{
1254BYTE byValue;
1255UINT uu,ii;
1256
1257 VNSvOutPortB(dwIoBase + MAC_REG_TMCTL0, 0);
1258 VNSvOutPortD(dwIoBase + MAC_REG_TMDATA0, uDelay);
1259 VNSvOutPortB(dwIoBase + MAC_REG_TMCTL0, (TMCTL_TMD | TMCTL_TE));
1260 for(ii=0;ii<66;ii++) { // assume max PCI clock is 66Mhz
1261 for (uu = 0; uu < uDelay; uu++) {
1262 VNSvInPortB(dwIoBase + MAC_REG_TMCTL0, &byValue);
1263 if ((byValue == 0) ||
1264 (BITbIsAllBitsOn(byValue, TMCTL_TSUSP))) {
1265 VNSvOutPortB(dwIoBase + MAC_REG_TMCTL0, 0);
1266 return;
1267 }
1268 }
1269 }
1270 VNSvOutPortB(dwIoBase + MAC_REG_TMCTL0, 0);
1271
1272}
1273
1274/*
1275 * Description:
1276 * Micro Second One shot timer via MAC
1277 *
1278 * Parameters:
1279 * In:
1280 * dwIoBase - Base Address for MAC
1281 * uDelay - Delay time
1282 * Out:
1283 * none
1284 *
1285 * Return Value: none
1286 *
1287 */
1288void MACvOneShotTimer0MicroSec (DWORD_PTR dwIoBase, UINT uDelayTime)
1289{
1290 VNSvOutPortB(dwIoBase + MAC_REG_TMCTL0, 0);
1291 VNSvOutPortD(dwIoBase + MAC_REG_TMDATA0, uDelayTime);
1292 VNSvOutPortB(dwIoBase + MAC_REG_TMCTL0, (TMCTL_TMD | TMCTL_TE));
1293}
1294
1295/*
1296 * Description:
1297 * Micro Second One shot timer via MAC
1298 *
1299 * Parameters:
1300 * In:
1301 * dwIoBase - Base Address for MAC
1302 * uDelay - Delay time
1303 * Out:
1304 * none
1305 *
1306 * Return Value: none
1307 *
1308 */
1309void MACvOneShotTimer1MicroSec (DWORD_PTR dwIoBase, UINT uDelayTime)
1310{
1311 VNSvOutPortB(dwIoBase + MAC_REG_TMCTL1, 0);
1312 VNSvOutPortD(dwIoBase + MAC_REG_TMDATA1, uDelayTime);
1313 VNSvOutPortB(dwIoBase + MAC_REG_TMCTL1, (TMCTL_TMD | TMCTL_TE));
1314}
1315
1316
1317void MACvSetMISCFifo (DWORD_PTR dwIoBase, WORD wOffset, DWORD dwData)
1318{
1319 if (wOffset > 273)
1320 return;
1321 VNSvOutPortW(dwIoBase + MAC_REG_MISCFFNDEX, wOffset);
1322 VNSvOutPortD(dwIoBase + MAC_REG_MISCFFDATA, dwData);
1323 VNSvOutPortW(dwIoBase + MAC_REG_MISCFFCTL, MISCFFCTL_WRITE);
1324}
1325
1326
1327BOOL MACbTxDMAOff (DWORD_PTR dwIoBase, UINT idx)
1328{
1329BYTE byData;
1330UINT ww = 0;
1331
1332 if (idx == TYPE_TXDMA0) {
1333 VNSvOutPortB(dwIoBase + MAC_REG_TXDMACTL0+2, DMACTL_RUN);
1334 for (ww = 0; ww < W_MAX_TIMEOUT; ww++) {
1335 VNSvInPortB(dwIoBase + MAC_REG_TXDMACTL0, &byData);
1336 if (BITbIsAllBitsOff(byData, DMACTL_RUN))
1337 break;
1338 }
1339 } else if (idx == TYPE_AC0DMA) {
1340 VNSvOutPortB(dwIoBase + MAC_REG_AC0DMACTL+2, DMACTL_RUN);
1341 for (ww = 0; ww < W_MAX_TIMEOUT; ww++) {
1342 VNSvInPortB(dwIoBase + MAC_REG_AC0DMACTL, &byData);
1343 if (BITbIsAllBitsOff(byData, DMACTL_RUN))
1344 break;
1345 }
1346 }
1347 if (ww == W_MAX_TIMEOUT) {
1348 DBG_PORT80(0x29);
1349 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO" DBG_PORT80(0x29)\n");
1350 return FALSE;
1351 }
1352 return TRUE;
1353}
1354
1355void MACvClearBusSusInd (DWORD_PTR dwIoBase)
1356{
1357 DWORD dwOrgValue;
1358 UINT ww;
1359 // check if BcnSusInd enabled
1360 VNSvInPortD(dwIoBase + MAC_REG_ENCFG , &dwOrgValue);
1361 if(BITbIsBitOff(dwOrgValue, EnCFG_BcnSusInd))
1362 return;
1363 //Set BcnSusClr
1364 dwOrgValue = dwOrgValue | EnCFG_BcnSusClr;
1365 VNSvOutPortD(dwIoBase + MAC_REG_ENCFG, dwOrgValue);
1366 for (ww = 0; ww < W_MAX_TIMEOUT; ww++) {
1367 VNSvInPortD(dwIoBase + MAC_REG_ENCFG , &dwOrgValue);
1368 if(BITbIsBitOff(dwOrgValue, EnCFG_BcnSusInd))
1369 break;
1370 }
1371 if (ww == W_MAX_TIMEOUT) {
1372 DBG_PORT80(0x33);
1373 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO" DBG_PORT80(0x33)\n");
1374 }
1375}
1376
1377void MACvEnableBusSusEn (DWORD_PTR dwIoBase)
1378{
1379 BYTE byOrgValue;
1380 DWORD dwOrgValue;
1381 UINT ww;
1382 // check if BcnSusInd enabled
1383 VNSvInPortB(dwIoBase + MAC_REG_CFG , &byOrgValue);
1384
1385 //Set BcnSusEn
1386 byOrgValue = byOrgValue | CFG_BCNSUSEN;
1387 VNSvOutPortB(dwIoBase + MAC_REG_ENCFG, byOrgValue);
1388 for (ww = 0; ww < W_MAX_TIMEOUT; ww++) {
1389 VNSvInPortD(dwIoBase + MAC_REG_ENCFG , &dwOrgValue);
1390 if(BITbIsBitOn(dwOrgValue, EnCFG_BcnSusInd))
1391 break;
1392 }
1393 if (ww == W_MAX_TIMEOUT) {
1394 DBG_PORT80(0x34);
1395 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO" DBG_PORT80(0x34)\n");
1396 }
1397}
1398
1399BOOL MACbFlushSYNCFifo (DWORD_PTR dwIoBase)
1400{
1401 BYTE byOrgValue;
1402 UINT ww;
1403 // Read MACCR
1404 VNSvInPortB(dwIoBase + MAC_REG_MACCR , &byOrgValue);
1405
1406 // Set SYNCFLUSH
1407 byOrgValue = byOrgValue | MACCR_SYNCFLUSH;
1408 VNSvOutPortB(dwIoBase + MAC_REG_MACCR, byOrgValue);
1409
1410 // Check if SyncFlushOK
1411 for (ww = 0; ww < W_MAX_TIMEOUT; ww++) {
1412 VNSvInPortB(dwIoBase + MAC_REG_MACCR , &byOrgValue);
1413 if(BITbIsBitOn(byOrgValue, MACCR_SYNCFLUSHOK))
1414 break;
1415 }
1416 if (ww == W_MAX_TIMEOUT) {
1417 DBG_PORT80(0x35);
1418 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO" DBG_PORT80(0x33)\n");
1419 }
1420 return TRUE;
1421}
1422
1423BOOL MACbPSWakeup (DWORD_PTR dwIoBase)
1424{
1425 BYTE byOrgValue;
1426 UINT ww;
1427 // Read PSCTL
1428 if (MACbIsRegBitsOff(dwIoBase, MAC_REG_PSCTL, PSCTL_PS)) {
1429 return TRUE;
1430 }
1431 // Disable PS
1432 MACvRegBitsOff(dwIoBase, MAC_REG_PSCTL, PSCTL_PSEN);
1433
1434 // Check if SyncFlushOK
1435 for (ww = 0; ww < W_MAX_TIMEOUT; ww++) {
1436 VNSvInPortB(dwIoBase + MAC_REG_PSCTL , &byOrgValue);
1437 if(BITbIsBitOn(byOrgValue, PSCTL_WAKEDONE))
1438 break;
1439 }
1440 if (ww == W_MAX_TIMEOUT) {
1441 DBG_PORT80(0x36);
1442 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO" DBG_PORT80(0x33)\n");
1443 return FALSE;
1444 }
1445 return TRUE;
1446}
1447
1448/*
1449 * Description:
1450 * Set the Key by MISCFIFO
1451 *
1452 * Parameters:
1453 * In:
1454 * dwIoBase - Base Address for MAC
1455 *
1456 * Out:
1457 * none
1458 *
1459 * Return Value: none
1460 *
1461 */
1462
1463void MACvSetKeyEntry (DWORD_PTR dwIoBase, WORD wKeyCtl, UINT uEntryIdx, UINT uKeyIdx, PBYTE pbyAddr, PDWORD pdwKey, BYTE byLocalID)
1464{
1465WORD wOffset;
1466DWORD dwData;
1467int ii;
1468
1469 if (byLocalID <= 1)
1470 return;
1471
1472
1473 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"MACvSetKeyEntry\n");
1474 wOffset = MISCFIFO_KEYETRY0;
1475 wOffset += (uEntryIdx * MISCFIFO_KEYENTRYSIZE);
1476
1477 dwData = 0;
1478 dwData |= wKeyCtl;
1479 dwData <<= 16;
1480 dwData |= MAKEWORD(*(pbyAddr+4), *(pbyAddr+5));
1481 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"1. wOffset: %d, Data: %lX, KeyCtl:%X\n", wOffset, dwData, wKeyCtl);
1482
1483 VNSvOutPortW(dwIoBase + MAC_REG_MISCFFNDEX, wOffset);
1484 VNSvOutPortD(dwIoBase + MAC_REG_MISCFFDATA, dwData);
1485 VNSvOutPortW(dwIoBase + MAC_REG_MISCFFCTL, MISCFFCTL_WRITE);
1486 wOffset++;
1487
1488 dwData = 0;
1489 dwData |= *(pbyAddr+3);
1490 dwData <<= 8;
1491 dwData |= *(pbyAddr+2);
1492 dwData <<= 8;
1493 dwData |= *(pbyAddr+1);
1494 dwData <<= 8;
1495 dwData |= *(pbyAddr+0);
1496 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"2. wOffset: %d, Data: %lX\n", wOffset, dwData);
1497
1498 VNSvOutPortW(dwIoBase + MAC_REG_MISCFFNDEX, wOffset);
1499 VNSvOutPortD(dwIoBase + MAC_REG_MISCFFDATA, dwData);
1500 VNSvOutPortW(dwIoBase + MAC_REG_MISCFFCTL, MISCFFCTL_WRITE);
1501 wOffset++;
1502
1503 wOffset += (uKeyIdx * 4);
1504 for (ii=0;ii<4;ii++) {
1505 // alway push 128 bits
1506 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"3.(%d) wOffset: %d, Data: %lX\n", ii, wOffset+ii, *pdwKey);
1507 VNSvOutPortW(dwIoBase + MAC_REG_MISCFFNDEX, wOffset+ii);
1508 VNSvOutPortD(dwIoBase + MAC_REG_MISCFFDATA, *pdwKey++);
1509 VNSvOutPortW(dwIoBase + MAC_REG_MISCFFCTL, MISCFFCTL_WRITE);
1510 }
1511}
1512
1513
1514
1515/*
1516 * Description:
1517 * Disable the Key Entry by MISCFIFO
1518 *
1519 * Parameters:
1520 * In:
1521 * dwIoBase - Base Address for MAC
1522 *
1523 * Out:
1524 * none
1525 *
1526 * Return Value: none
1527 *
1528 */
1529void MACvDisableKeyEntry (DWORD_PTR dwIoBase, UINT uEntryIdx)
1530{
1531WORD wOffset;
1532
1533 wOffset = MISCFIFO_KEYETRY0;
1534 wOffset += (uEntryIdx * MISCFIFO_KEYENTRYSIZE);
1535
1536 VNSvOutPortW(dwIoBase + MAC_REG_MISCFFNDEX, wOffset);
1537 VNSvOutPortD(dwIoBase + MAC_REG_MISCFFDATA, 0);
1538 VNSvOutPortW(dwIoBase + MAC_REG_MISCFFCTL, MISCFFCTL_WRITE);
1539}
1540
1541
1542/*
1543 * Description:
1544 * Set the default Key (KeyEntry[10]) by MISCFIFO
1545 *
1546 * Parameters:
1547 * In:
1548 * dwIoBase - Base Address for MAC
1549 *
1550 * Out:
1551 * none
1552 *
1553 * Return Value: none
1554 *
1555 */
1556
1557void MACvSetDefaultKeyEntry (DWORD_PTR dwIoBase, UINT uKeyLen, UINT uKeyIdx, PDWORD pdwKey, BYTE byLocalID)
1558{
1559WORD wOffset;
1560DWORD dwData;
1561int ii;
1562
1563 if (byLocalID <= 1)
1564 return;
1565
1566 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"MACvSetDefaultKeyEntry\n");
1567 wOffset = MISCFIFO_KEYETRY0;
1568 wOffset += (10 * MISCFIFO_KEYENTRYSIZE);
1569
1570 wOffset++;
1571 wOffset++;
1572 wOffset += (uKeyIdx * 4);
1573 // alway push 128 bits
1574 for (ii=0; ii<3; ii++) {
1575 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"(%d) wOffset: %d, Data: %lX\n", ii, wOffset+ii, *pdwKey);
1576 VNSvOutPortW(dwIoBase + MAC_REG_MISCFFNDEX, wOffset+ii);
1577 VNSvOutPortD(dwIoBase + MAC_REG_MISCFFDATA, *pdwKey++);
1578 VNSvOutPortW(dwIoBase + MAC_REG_MISCFFCTL, MISCFFCTL_WRITE);
1579 }
1580 dwData = *pdwKey;
1581 if (uKeyLen == WLAN_WEP104_KEYLEN) {
1582 dwData |= 0x80000000;
1583 }
1584 VNSvOutPortW(dwIoBase + MAC_REG_MISCFFNDEX, wOffset+3);
1585 VNSvOutPortD(dwIoBase + MAC_REG_MISCFFDATA, dwData);
1586 VNSvOutPortW(dwIoBase + MAC_REG_MISCFFCTL, MISCFFCTL_WRITE);
1587 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"End. wOffset: %d, Data: %lX\n", wOffset+3, dwData);
1588
1589}
1590
1591
1592/*
1593 * Description:
1594 * Enable default Key (KeyEntry[10]) by MISCFIFO
1595 *
1596 * Parameters:
1597 * In:
1598 * dwIoBase - Base Address for MAC
1599 *
1600 * Out:
1601 * none
1602 *
1603 * Return Value: none
1604 *
1605 */
1606/*
1607void MACvEnableDefaultKey (DWORD_PTR dwIoBase, BYTE byLocalID)
1608{
1609WORD wOffset;
1610DWORD dwData;
1611
1612
1613 if (byLocalID <= 1)
1614 return;
1615
1616 wOffset = MISCFIFO_KEYETRY0;
1617 wOffset += (10 * MISCFIFO_KEYENTRYSIZE);
1618
1619 dwData = 0xC0440000;
1620 VNSvOutPortW(dwIoBase + MAC_REG_MISCFFNDEX, wOffset);
1621 VNSvOutPortD(dwIoBase + MAC_REG_MISCFFDATA, dwData);
1622 VNSvOutPortW(dwIoBase + MAC_REG_MISCFFCTL, MISCFFCTL_WRITE);
1623 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"MACvEnableDefaultKey: wOffset: %d, Data: %lX\n", wOffset, dwData);
1624
1625}
1626*/
1627
1628/*
1629 * Description:
1630 * Disable default Key (KeyEntry[10]) by MISCFIFO
1631 *
1632 * Parameters:
1633 * In:
1634 * dwIoBase - Base Address for MAC
1635 *
1636 * Out:
1637 * none
1638 *
1639 * Return Value: none
1640 *
1641 */
1642void MACvDisableDefaultKey (DWORD_PTR dwIoBase)
1643{
1644WORD wOffset;
1645DWORD dwData;
1646
1647
1648 wOffset = MISCFIFO_KEYETRY0;
1649 wOffset += (10 * MISCFIFO_KEYENTRYSIZE);
1650
1651 dwData = 0x0;
1652 VNSvOutPortW(dwIoBase + MAC_REG_MISCFFNDEX, wOffset);
1653 VNSvOutPortD(dwIoBase + MAC_REG_MISCFFDATA, dwData);
1654 VNSvOutPortW(dwIoBase + MAC_REG_MISCFFCTL, MISCFFCTL_WRITE);
1655 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"MACvDisableDefaultKey: wOffset: %d, Data: %lX\n", wOffset, dwData);
1656}
1657
1658/*
1659 * Description:
1660 * Set the default TKIP Group Key (KeyEntry[10]) by MISCFIFO
1661 *
1662 * Parameters:
1663 * In:
1664 * dwIoBase - Base Address for MAC
1665 *
1666 * Out:
1667 * none
1668 *
1669 * Return Value: none
1670 *
1671 */
1672void MACvSetDefaultTKIPKeyEntry (DWORD_PTR dwIoBase, UINT uKeyLen, UINT uKeyIdx, PDWORD pdwKey, BYTE byLocalID)
1673{
1674WORD wOffset;
1675DWORD dwData;
1676int ii;
1677
1678 if (byLocalID <= 1)
1679 return;
1680
1681
1682 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"MACvSetDefaultTKIPKeyEntry\n");
1683 wOffset = MISCFIFO_KEYETRY0;
1684 // Kyle test : change offset from 10 -> 0
1685 wOffset += (10 * MISCFIFO_KEYENTRYSIZE);
1686
1687 dwData = 0xC0660000;
1688 VNSvOutPortW(dwIoBase + MAC_REG_MISCFFNDEX, wOffset);
1689 VNSvOutPortD(dwIoBase + MAC_REG_MISCFFDATA, dwData);
1690 VNSvOutPortW(dwIoBase + MAC_REG_MISCFFCTL, MISCFFCTL_WRITE);
1691 wOffset++;
1692
1693 dwData = 0;
1694 VNSvOutPortW(dwIoBase + MAC_REG_MISCFFNDEX, wOffset);
1695 VNSvOutPortD(dwIoBase + MAC_REG_MISCFFDATA, dwData);
1696 VNSvOutPortW(dwIoBase + MAC_REG_MISCFFCTL, MISCFFCTL_WRITE);
1697 wOffset++;
1698
1699 wOffset += (uKeyIdx * 4);
1700 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"1. wOffset: %d, Data: %lX, idx:%d\n", wOffset, *pdwKey, uKeyIdx);
1701 // alway push 128 bits
1702 for (ii=0; ii<4; ii++) {
1703 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"2.(%d) wOffset: %d, Data: %lX\n", ii, wOffset+ii, *pdwKey);
1704 VNSvOutPortW(dwIoBase + MAC_REG_MISCFFNDEX, wOffset+ii);
1705 VNSvOutPortD(dwIoBase + MAC_REG_MISCFFDATA, *pdwKey++);
1706 VNSvOutPortW(dwIoBase + MAC_REG_MISCFFCTL, MISCFFCTL_WRITE);
1707 }
1708
1709}
1710
1711
1712
1713/*
1714 * Description:
1715 * Set the Key Control by MISCFIFO
1716 *
1717 * Parameters:
1718 * In:
1719 * dwIoBase - Base Address for MAC
1720 *
1721 * Out:
1722 * none
1723 *
1724 * Return Value: none
1725 *
1726 */
1727
1728void MACvSetDefaultKeyCtl (DWORD_PTR dwIoBase, WORD wKeyCtl, UINT uEntryIdx, BYTE byLocalID)
1729{
1730WORD wOffset;
1731DWORD dwData;
1732
1733 if (byLocalID <= 1)
1734 return;
1735
1736
1737 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"MACvSetKeyEntry\n");
1738 wOffset = MISCFIFO_KEYETRY0;
1739 wOffset += (uEntryIdx * MISCFIFO_KEYENTRYSIZE);
1740
1741 dwData = 0;
1742 dwData |= wKeyCtl;
1743 dwData <<= 16;
1744 dwData |= 0xffff;
1745 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"1. wOffset: %d, Data: %lX, KeyCtl:%X\n", wOffset, dwData, wKeyCtl);
1746
1747 VNSvOutPortW(dwIoBase + MAC_REG_MISCFFNDEX, wOffset);
1748 VNSvOutPortD(dwIoBase + MAC_REG_MISCFFDATA, dwData);
1749 VNSvOutPortW(dwIoBase + MAC_REG_MISCFFCTL, MISCFFCTL_WRITE);
1750
1751}
1752
diff --git a/drivers/staging/vt6655/mac.h b/drivers/staging/vt6655/mac.h
new file mode 100644
index 000000000000..edb70965d4dc
--- /dev/null
+++ b/drivers/staging/vt6655/mac.h
@@ -0,0 +1,1166 @@
1/*
2 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
3 * All rights reserved.
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 *
20 * File: mac.h
21 *
22 * Purpose: MAC routines
23 *
24 * Author: Tevin Chen
25 *
26 * Date: May 21, 1996
27 * Revision History:
28 * 07-01-2003 Bryan YC Fan: Re-write codes to support VT3253 spec.
29 * 08-25-2003 Kyle Hsu: Porting MAC functions from sim53.
30 * 09-03-2003 Bryan YC Fan: Add MACvDisableProtectMD & MACvEnableProtectMD
31 *
32 */
33
34#ifndef __MAC_H__
35#define __MAC_H__
36
37
38
39#if !defined(__TTYPE_H__)
40#include "ttype.h"
41#endif
42#if !defined(__TMACRO_H__)
43#include "tmacro.h"
44#endif
45#if !defined(__UPC_H__)
46#include "upc.h"
47#endif
48
49/*--------------------- Export Definitions -------------------------*/
50//
51// Registers in the MAC
52//
53#define MAC_MAX_CONTEXT_SIZE_PAGE0 256
54#define MAC_MAX_CONTEXT_SIZE_PAGE1 128
55#define MAC_MAX_CONTEXT_SIZE MAC_MAX_CONTEXT_SIZE_PAGE0 + MAC_MAX_CONTEXT_SIZE_PAGE1
56
57// Registers not related to 802.11b
58#define MAC_REG_BCFG0 0x00
59#define MAC_REG_BCFG1 0x01
60#define MAC_REG_FCR0 0x02
61#define MAC_REG_FCR1 0x03
62#define MAC_REG_BISTCMD 0x04
63#define MAC_REG_BISTSR0 0x05
64#define MAC_REG_BISTSR1 0x06
65#define MAC_REG_BISTSR2 0x07
66#define MAC_REG_I2MCSR 0x08
67#define MAC_REG_I2MTGID 0x09
68#define MAC_REG_I2MTGAD 0x0A
69#define MAC_REG_I2MCFG 0x0B
70#define MAC_REG_I2MDIPT 0x0C
71#define MAC_REG_I2MDOPT 0x0E
72#define MAC_REG_PMC0 0x10
73#define MAC_REG_PMC1 0x11
74#define MAC_REG_STICKHW 0x12
75#define MAC_REG_LOCALID 0x14
76#define MAC_REG_TESTCFG 0x15
77#define MAC_REG_JUMPER0 0x16
78#define MAC_REG_JUMPER1 0x17
79#define MAC_REG_TMCTL0 0x18
80#define MAC_REG_TMCTL1 0x19
81#define MAC_REG_TMDATA0 0x1C
82// MAC Parameter related
83#define MAC_REG_LRT 0x20 //
84#define MAC_REG_SRT 0x21 //
85#define MAC_REG_SIFS 0x22 //
86#define MAC_REG_DIFS 0x23 //
87#define MAC_REG_EIFS 0x24 //
88#define MAC_REG_SLOT 0x25 //
89#define MAC_REG_BI 0x26 //
90#define MAC_REG_CWMAXMIN0 0x28 //
91#define MAC_REG_LINKOFFTOTM 0x2A
92#define MAC_REG_SWTMOT 0x2B
93#define MAC_REG_MIBCNTR 0x2C
94#define MAC_REG_RTSOKCNT 0x2C
95#define MAC_REG_RTSFAILCNT 0x2D
96#define MAC_REG_ACKFAILCNT 0x2E
97#define MAC_REG_FCSERRCNT 0x2F
98// TSF Related
99#define MAC_REG_TSFCNTR 0x30 //
100#define MAC_REG_NEXTTBTT 0x38 //
101#define MAC_REG_TSFOFST 0x40 //
102#define MAC_REG_TFTCTL 0x48 //
103// WMAC Control/Status Related
104#define MAC_REG_ENCFG 0x4C //
105#define MAC_REG_PAGE1SEL 0x4F //
106#define MAC_REG_CFG 0x50 //
107#define MAC_REG_TEST 0x52 //
108#define MAC_REG_HOSTCR 0x54 //
109#define MAC_REG_MACCR 0x55 //
110#define MAC_REG_RCR 0x56 //
111#define MAC_REG_TCR 0x57 //
112#define MAC_REG_IMR 0x58 //
113#define MAC_REG_ISR 0x5C
114// Power Saving Related
115#define MAC_REG_PSCFG 0x60 //
116#define MAC_REG_PSCTL 0x61 //
117#define MAC_REG_PSPWRSIG 0x62 //
118#define MAC_REG_BBCR13 0x63
119#define MAC_REG_AIDATIM 0x64
120#define MAC_REG_PWBT 0x66
121#define MAC_REG_WAKEOKTMR 0x68
122#define MAC_REG_CALTMR 0x69
123#define MAC_REG_SYNSPACCNT 0x6A
124#define MAC_REG_WAKSYNOPT 0x6B
125// Baseband/IF Control Group
126#define MAC_REG_BBREGCTL 0x6C //
127#define MAC_REG_CHANNEL 0x6D
128#define MAC_REG_BBREGADR 0x6E
129#define MAC_REG_BBREGDATA 0x6F
130#define MAC_REG_IFREGCTL 0x70 //
131#define MAC_REG_IFDATA 0x71 //
132#define MAC_REG_ITRTMSET 0x74 //
133#define MAC_REG_PAPEDELAY 0x77 //
134#define MAC_REG_SOFTPWRCTL 0x78 //
135#define MAC_REG_GPIOCTL0 0x7A //
136#define MAC_REG_GPIOCTL1 0x7B //
137
138// MAC DMA Related Group
139#define MAC_REG_TXDMACTL0 0x7C //
140#define MAC_REG_TXDMAPTR0 0x80 //
141#define MAC_REG_AC0DMACTL 0x84 //
142#define MAC_REG_AC0DMAPTR 0x88 //
143#define MAC_REG_BCNDMACTL 0x8C //
144#define MAC_REG_BCNDMAPTR 0x90 //
145#define MAC_REG_RXDMACTL0 0x94 //
146#define MAC_REG_RXDMAPTR0 0x98 //
147#define MAC_REG_RXDMACTL1 0x9C //
148#define MAC_REG_RXDMAPTR1 0xA0 //
149#define MAC_REG_SYNCDMACTL 0xA4 //
150#define MAC_REG_SYNCDMAPTR 0xA8
151#define MAC_REG_ATIMDMACTL 0xAC
152#define MAC_REG_ATIMDMAPTR 0xB0
153// MiscFF PIO related
154#define MAC_REG_MISCFFNDEX 0xB4
155#define MAC_REG_MISCFFCTL 0xB6
156#define MAC_REG_MISCFFDATA 0xB8
157// Extend SW Timer
158#define MAC_REG_TMDATA1 0xBC
159// WOW Related Group
160#define MAC_REG_WAKEUPEN0 0xC0
161#define MAC_REG_WAKEUPEN1 0xC1
162#define MAC_REG_WAKEUPSR0 0xC2
163#define MAC_REG_WAKEUPSR1 0xC3
164#define MAC_REG_WAKE128_0 0xC4
165#define MAC_REG_WAKE128_1 0xD4
166#define MAC_REG_WAKE128_2 0xE4
167#define MAC_REG_WAKE128_3 0xF4
168
169/////////////// Page 1 ///////////////////
170#define MAC_REG_CRC_128_0 0x04
171#define MAC_REG_CRC_128_1 0x06
172#define MAC_REG_CRC_128_2 0x08
173#define MAC_REG_CRC_128_3 0x0A
174// MAC Configuration Group
175#define MAC_REG_PAR0 0x0C
176#define MAC_REG_PAR4 0x10
177#define MAC_REG_BSSID0 0x14
178#define MAC_REG_BSSID4 0x18
179#define MAC_REG_MAR0 0x1C
180#define MAC_REG_MAR4 0x20
181// MAC RSPPKT INFO Group
182#define MAC_REG_RSPINF_B_1 0x24
183#define MAC_REG_RSPINF_B_2 0x28
184#define MAC_REG_RSPINF_B_5 0x2C
185#define MAC_REG_RSPINF_B_11 0x30
186#define MAC_REG_RSPINF_A_6 0x34
187#define MAC_REG_RSPINF_A_9 0x36
188#define MAC_REG_RSPINF_A_12 0x38
189#define MAC_REG_RSPINF_A_18 0x3A
190#define MAC_REG_RSPINF_A_24 0x3C
191#define MAC_REG_RSPINF_A_36 0x3E
192#define MAC_REG_RSPINF_A_48 0x40
193#define MAC_REG_RSPINF_A_54 0x42
194#define MAC_REG_RSPINF_A_72 0x44
195
196// 802.11h relative
197#define MAC_REG_QUIETINIT 0x60
198#define MAC_REG_QUIETGAP 0x62
199#define MAC_REG_QUIETDUR 0x64
200#define MAC_REG_MSRCTL 0x66
201#define MAC_REG_MSRBBSTS 0x67
202#define MAC_REG_MSRSTART 0x68
203#define MAC_REG_MSRDURATION 0x70
204#define MAC_REG_CCAFRACTION 0x72
205#define MAC_REG_PWRCCK 0x73
206#define MAC_REG_PWROFDM 0x7C
207
208
209//
210// Bits in the BCFG0 register
211//
212#define BCFG0_PERROFF 0x40
213#define BCFG0_MRDMDIS 0x20
214#define BCFG0_MRDLDIS 0x10
215#define BCFG0_MWMEN 0x08
216#define BCFG0_VSERREN 0x02
217#define BCFG0_LATMEN 0x01
218
219//
220// Bits in the BCFG1 register
221//
222#define BCFG1_CFUNOPT 0x80
223#define BCFG1_CREQOPT 0x40
224#define BCFG1_DMA8 0x10
225#define BCFG1_ARBITOPT 0x08
226#define BCFG1_PCIMEN 0x04
227#define BCFG1_MIOEN 0x02
228#define BCFG1_CISDLYEN 0x01
229
230// Bits in RAMBIST registers
231#define BISTCMD_TSTPAT5 0x00 //
232#define BISTCMD_TSTPATA 0x80 //
233#define BISTCMD_TSTERR 0x20 //
234#define BISTCMD_TSTPATF 0x18 //
235#define BISTCMD_TSTPAT0 0x10 //
236#define BISTCMD_TSTMODE 0x04 //
237#define BISTCMD_TSTITTX 0x03 //
238#define BISTCMD_TSTATRX 0x02 //
239#define BISTCMD_TSTATTX 0x01 //
240#define BISTCMD_TSTRX 0x00 //
241#define BISTSR0_BISTGO 0x01 //
242#define BISTSR1_TSTSR 0x01 //
243#define BISTSR2_CMDPRTEN 0x02 //
244#define BISTSR2_RAMTSTEN 0x01 //
245
246//
247// Bits in the I2MCFG EEPROM register
248//
249#define I2MCFG_BOUNDCTL 0x80
250#define I2MCFG_WAITCTL 0x20
251#define I2MCFG_SCLOECTL 0x10
252#define I2MCFG_WBUSYCTL 0x08
253#define I2MCFG_NORETRY 0x04
254#define I2MCFG_I2MLDSEQ 0x02
255#define I2MCFG_I2CMFAST 0x01
256
257//
258// Bits in the I2MCSR EEPROM register
259//
260#define I2MCSR_EEMW 0x80
261#define I2MCSR_EEMR 0x40
262#define I2MCSR_AUTOLD 0x08
263#define I2MCSR_NACK 0x02
264#define I2MCSR_DONE 0x01
265
266//
267// Bits in the PMC1 register
268//
269#define SPS_RST 0x80
270#define PCISTIKY 0x40
271#define PME_OVR 0x02
272
273//
274// Bits in the STICKYHW register
275//
276#define STICKHW_DS1_SHADOW 0x02
277#define STICKHW_DS0_SHADOW 0x01
278
279//
280// Bits in the TMCTL register
281//
282#define TMCTL_TSUSP 0x04
283#define TMCTL_TMD 0x02
284#define TMCTL_TE 0x01
285
286//
287// Bits in the TFTCTL register
288//
289#define TFTCTL_HWUTSF 0x80 //
290#define TFTCTL_TBTTSYNC 0x40
291#define TFTCTL_HWUTSFEN 0x20
292#define TFTCTL_TSFCNTRRD 0x10 //
293#define TFTCTL_TBTTSYNCEN 0x08 //
294#define TFTCTL_TSFSYNCEN 0x04 //
295#define TFTCTL_TSFCNTRST 0x02 //
296#define TFTCTL_TSFCNTREN 0x01 //
297
298//
299// Bits in the EnhanceCFG register
300//
301#define EnCFG_BarkerPream 0x00020000
302#define EnCFG_NXTBTTCFPSTR 0x00010000
303//#define EnCFG_TXLMT3UPDATE 0x00008000
304//#define EnCFG_TXLMT2UPDATE 0x00004000
305//#define EnCFG_TXLMT1UPDATE 0x00002000
306//#define EnCFG_TXLMT3EN 0x00001000
307//#define EnCFG_TXLMT2EN 0x00000800
308//#define EnCFG_TXLMT1EN 0x00000400
309#define EnCFG_BcnSusClr 0x00000200
310#define EnCFG_BcnSusInd 0x00000100
311//#define EnCFG_CWOFF1 0x00000080
312#define EnCFG_CFP_ProtectEn 0x00000040
313#define EnCFG_ProtectMd 0x00000020
314#define EnCFG_HwParCFP 0x00000010
315//#define EnCFG_QOS 0x00000008
316#define EnCFG_CFNULRSP 0x00000004
317#define EnCFG_BBType_MASK 0x00000003
318#define EnCFG_BBType_g 0x00000002
319#define EnCFG_BBType_b 0x00000001
320#define EnCFG_BBType_a 0x00000000
321
322//
323// Bits in the Page1Sel register
324//
325#define PAGE1_SEL 0x01
326
327//
328// Bits in the CFG register
329//
330#define CFG_TKIPOPT 0x80
331#define CFG_RXDMAOPT 0x40
332#define CFG_TMOT_SW 0x20
333#define CFG_TMOT_HWLONG 0x10
334#define CFG_TMOT_HW 0x00
335#define CFG_CFPENDOPT 0x08
336#define CFG_BCNSUSEN 0x04
337#define CFG_NOTXTIMEOUT 0x02
338#define CFG_NOBUFOPT 0x01
339
340//
341// Bits in the TEST register
342//
343#define TEST_LBEXT 0x80 //
344#define TEST_LBINT 0x40 //
345#define TEST_LBNONE 0x00 //
346#define TEST_SOFTINT 0x20 //
347#define TEST_CONTTX 0x10 //
348#define TEST_TXPE 0x08 //
349#define TEST_NAVDIS 0x04 //
350#define TEST_NOCTS 0x02 //
351#define TEST_NOACK 0x01 //
352
353//
354// Bits in the HOSTCR register
355//
356#define HOSTCR_TXONST 0x80 //
357#define HOSTCR_RXONST 0x40 //
358#define HOSTCR_ADHOC 0x20 // Network Type 1 = Ad-hoc
359#define HOSTCR_AP 0x10 // Port Type 1 = AP
360#define HOSTCR_TXON 0x08 //0000 1000
361#define HOSTCR_RXON 0x04 //0000 0100
362#define HOSTCR_MACEN 0x02 //0000 0010
363#define HOSTCR_SOFTRST 0x01 //0000 0001
364
365//
366// Bits in the MACCR register
367//
368#define MACCR_SYNCFLUSHOK 0x04 //
369#define MACCR_SYNCFLUSH 0x02 //
370#define MACCR_CLRNAV 0x01 //
371
372// Bits in the MAC_REG_GPIOCTL0 register
373//
374#define LED_ACTSET 0x01 //
375#define LED_RFOFF 0x02 //
376#define LED_NOCONNECT 0x04 //
377//
378// Bits in the RCR register
379//
380#define RCR_SSID 0x80
381#define RCR_RXALLTYPE 0x40 //
382#define RCR_UNICAST 0x20 //
383#define RCR_BROADCAST 0x10 //
384#define RCR_MULTICAST 0x08 //
385#define RCR_WPAERR 0x04 //
386#define RCR_ERRCRC 0x02 //
387#define RCR_BSSID 0x01 //
388
389//
390// Bits in the TCR register
391//
392#define TCR_SYNCDCFOPT 0x02 //
393#define TCR_AUTOBCNTX 0x01 // Beacon automatically transmit enable
394
395//
396// Bits in the IMR register
397//
398#define IMR_MEASURESTART 0x80000000 //
399#define IMR_QUIETSTART 0x20000000 //
400#define IMR_RADARDETECT 0x10000000 //
401#define IMR_MEASUREEND 0x08000000 //
402#define IMR_SOFTTIMER1 0x00200000 //
403//#define IMR_SYNCFLUSHOK 0x00100000 //
404//#define IMR_ATIMEND 0x00080000 //0000 1000 0000 0000 0000 0000
405//#define IMR_CFPEND 0x00040000 //0000 0100 0000 0000 0000 0000
406//#define IMR_AC3DMA 0x00020000 //0000 0010 0000 0000 0000 0000
407//#define IMR_AC2DMA 0x00010000 //0000 0001 0000 0000 0000 0000
408//#define IMR_AC1DMA 0x00008000 //0000 0000 1000 0000 0000 0000
409//#define IMR_SYNCTX 0x00004000 //0000 0000 0100 0000 0000 0000
410//#define IMR_ATIMTX 0x00002000 //0000 0000 0010 0000 0000 0000
411#define IMR_RXDMA1 0x00001000 //0000 0000 0001 0000 0000 0000
412#define IMR_RXNOBUF 0x00000800 //
413#define IMR_MIBNEARFULL 0x00000400 //
414#define IMR_SOFTINT 0x00000200 //
415#define IMR_FETALERR 0x00000100 //
416#define IMR_WATCHDOG 0x00000080 //
417#define IMR_SOFTTIMER 0x00000040 //
418#define IMR_GPIO 0x00000020 //
419#define IMR_TBTT 0x00000010 //
420#define IMR_RXDMA0 0x00000008 //
421#define IMR_BNTX 0x00000004 //
422#define IMR_AC0DMA 0x00000002 //
423#define IMR_TXDMA0 0x00000001 //
424
425
426//
427// Bits in the ISR register
428//
429
430#define ISR_MEASURESTART 0x80000000 //
431#define ISR_QUIETSTART 0x20000000 //
432#define ISR_RADARDETECT 0x10000000 //
433#define ISR_MEASUREEND 0x08000000 //
434#define ISR_SOFTTIMER1 0x00200000 //
435//#define ISR_SYNCFLUSHOK 0x00100000 //0001 0000 0000 0000 0000 0000
436//#define ISR_ATIMEND 0x00080000 //0000 1000 0000 0000 0000 0000
437//#define ISR_CFPEND 0x00040000 //0000 0100 0000 0000 0000 0000
438//#define ISR_AC3DMA 0x00020000 //0000 0010 0000 0000 0000 0000
439//#define ISR_AC2DMA 0x00010000 //0000 0001 0000 0000 0000 0000
440//#define ISR_AC1DMA 0x00008000 //0000 0000 1000 0000 0000 0000
441//#define ISR_SYNCTX 0x00004000 //0000 0000 0100 0000 0000 0000
442//#define ISR_ATIMTX 0x00002000 //0000 0000 0010 0000 0000 0000
443#define ISR_RXDMA1 0x00001000 //0000 0000 0001 0000 0000 0000
444#define ISR_RXNOBUF 0x00000800 //0000 0000 0000 1000 0000 0000
445#define ISR_MIBNEARFULL 0x00000400 //0000 0000 0000 0100 0000 0000
446#define ISR_SOFTINT 0x00000200 //
447#define ISR_FETALERR 0x00000100 //
448#define ISR_WATCHDOG 0x00000080 //
449#define ISR_SOFTTIMER 0x00000040 //
450#define ISR_GPIO 0x00000020 //
451#define ISR_TBTT 0x00000010 //
452#define ISR_RXDMA0 0x00000008 //
453#define ISR_BNTX 0x00000004 //
454#define ISR_AC0DMA 0x00000002 //
455#define ISR_TXDMA0 0x00000001 //
456
457
458//
459// Bits in the PSCFG register
460//
461#define PSCFG_PHILIPMD 0x40 //
462#define PSCFG_WAKECALEN 0x20 //
463#define PSCFG_WAKETMREN 0x10 //
464#define PSCFG_BBPSPROG 0x08 //
465#define PSCFG_WAKESYN 0x04 //
466#define PSCFG_SLEEPSYN 0x02 //
467#define PSCFG_AUTOSLEEP 0x01 //
468
469//
470// Bits in the PSCTL register
471//
472#define PSCTL_WAKEDONE 0x20 //
473#define PSCTL_PS 0x10 //
474#define PSCTL_GO2DOZE 0x08 //
475#define PSCTL_LNBCN 0x04 //
476#define PSCTL_ALBCN 0x02 //
477#define PSCTL_PSEN 0x01 //
478
479//
480// Bits in the PSPWSIG register
481//
482#define PSSIG_WPE3 0x80 //
483#define PSSIG_WPE2 0x40 //
484#define PSSIG_WPE1 0x20 //
485#define PSSIG_WRADIOPE 0x10 //
486#define PSSIG_SPE3 0x08 //
487#define PSSIG_SPE2 0x04 //
488#define PSSIG_SPE1 0x02 //
489#define PSSIG_SRADIOPE 0x01 //
490
491//
492// Bits in the BBREGCTL register
493//
494#define BBREGCTL_DONE 0x04 //
495#define BBREGCTL_REGR 0x02 //
496#define BBREGCTL_REGW 0x01 //
497
498//
499// Bits in the IFREGCTL register
500//
501#define IFREGCTL_DONE 0x04 //
502#define IFREGCTL_IFRF 0x02 //
503#define IFREGCTL_REGW 0x01 //
504
505//
506// Bits in the SOFTPWRCTL register
507//
508#define SOFTPWRCTL_RFLEOPT 0x0800 //
509#define SOFTPWRCTL_TXPEINV 0x0200 //
510#define SOFTPWRCTL_SWPECTI 0x0100 //
511#define SOFTPWRCTL_SWPAPE 0x0020 //
512#define SOFTPWRCTL_SWCALEN 0x0010 //
513#define SOFTPWRCTL_SWRADIO_PE 0x0008 //
514#define SOFTPWRCTL_SWPE2 0x0004 //
515#define SOFTPWRCTL_SWPE1 0x0002 //
516#define SOFTPWRCTL_SWPE3 0x0001 //
517
518//
519// Bits in the GPIOCTL1 register
520//
521#define GPIO1_DATA1 0x20 //
522#define GPIO1_MD1 0x10 //
523#define GPIO1_DATA0 0x02 //
524#define GPIO1_MD0 0x01 //
525
526//
527// Bits in the DMACTL register
528//
529#define DMACTL_CLRRUN 0x00080000 //
530#define DMACTL_RUN 0x00000008 //
531#define DMACTL_WAKE 0x00000004 //
532#define DMACTL_DEAD 0x00000002 //
533#define DMACTL_ACTIVE 0x00000001 //
534//
535// Bits in the RXDMACTL0 register
536//
537#define RX_PERPKT 0x00000100 //
538#define RX_PERPKTCLR 0x01000000 //
539//
540// Bits in the BCNDMACTL register
541//
542#define BEACON_READY 0x01 //
543//
544// Bits in the MISCFFCTL register
545//
546#define MISCFFCTL_WRITE 0x0001 //
547
548
549//
550// Bits in WAKEUPEN0
551//
552#define WAKEUPEN0_DIRPKT 0x10
553#define WAKEUPEN0_LINKOFF 0x08
554#define WAKEUPEN0_ATIMEN 0x04
555#define WAKEUPEN0_TIMEN 0x02
556#define WAKEUPEN0_MAGICEN 0x01
557
558//
559// Bits in WAKEUPEN1
560//
561#define WAKEUPEN1_128_3 0x08
562#define WAKEUPEN1_128_2 0x04
563#define WAKEUPEN1_128_1 0x02
564#define WAKEUPEN1_128_0 0x01
565
566//
567// Bits in WAKEUPSR0
568//
569#define WAKEUPSR0_DIRPKT 0x10
570#define WAKEUPSR0_LINKOFF 0x08
571#define WAKEUPSR0_ATIMEN 0x04
572#define WAKEUPSR0_TIMEN 0x02
573#define WAKEUPSR0_MAGICEN 0x01
574
575//
576// Bits in WAKEUPSR1
577//
578#define WAKEUPSR1_128_3 0x08
579#define WAKEUPSR1_128_2 0x04
580#define WAKEUPSR1_128_1 0x02
581#define WAKEUPSR1_128_0 0x01
582
583//
584// Bits in the MAC_REG_GPIOCTL register
585//
586#define GPIO0_MD 0x01 //
587#define GPIO0_DATA 0x02 //
588#define GPIO0_INTMD 0x04 //
589#define GPIO1_MD 0x10 //
590#define GPIO1_DATA 0x20 //
591
592
593//
594// Bits in the MSRCTL register
595//
596#define MSRCTL_FINISH 0x80
597#define MSRCTL_READY 0x40
598#define MSRCTL_RADARDETECT 0x20
599#define MSRCTL_EN 0x10
600#define MSRCTL_QUIETTXCHK 0x08
601#define MSRCTL_QUIETRPT 0x04
602#define MSRCTL_QUIETINT 0x02
603#define MSRCTL_QUIETEN 0x01
604//
605// Bits in the MSRCTL1 register
606//
607#define MSRCTL1_TXPWR 0x08
608#define MSRCTL1_CSAPAREN 0x04
609#define MSRCTL1_TXPAUSE 0x01
610
611
612// Loopback mode
613#define MAC_LB_EXT 0x02 //
614#define MAC_LB_INTERNAL 0x01 //
615#define MAC_LB_NONE 0x00 //
616
617// Ethernet address filter type
618#define PKT_TYPE_NONE 0x00 // turn off receiver
619#define PKT_TYPE_ALL_MULTICAST 0x80
620#define PKT_TYPE_PROMISCUOUS 0x40
621#define PKT_TYPE_DIRECTED 0x20 // obselete, directed address is always accepted
622#define PKT_TYPE_BROADCAST 0x10
623#define PKT_TYPE_MULTICAST 0x08
624#define PKT_TYPE_ERROR_WPA 0x04
625#define PKT_TYPE_ERROR_CRC 0x02
626#define PKT_TYPE_BSSID 0x01
627
628#define Default_BI 0x200
629
630
631// MiscFIFO Offset
632#define MISCFIFO_KEYETRY0 32
633#define MISCFIFO_KEYENTRYSIZE 22
634#define MISCFIFO_SYNINFO_IDX 10
635#define MISCFIFO_SYNDATA_IDX 11
636#define MISCFIFO_SYNDATASIZE 21
637
638// enabled mask value of irq
639#define IMR_MASK_VALUE (IMR_SOFTTIMER1 | \
640 IMR_RXDMA1 | \
641 IMR_RXNOBUF | \
642 IMR_MIBNEARFULL | \
643 IMR_SOFTINT | \
644 IMR_FETALERR | \
645 IMR_WATCHDOG | \
646 IMR_SOFTTIMER | \
647 IMR_GPIO | \
648 IMR_TBTT | \
649 IMR_RXDMA0 | \
650 IMR_BNTX | \
651 IMR_AC0DMA | \
652 IMR_TXDMA0)
653
654// max time out delay time
655#define W_MAX_TIMEOUT 0xFFF0U //
656
657// wait time within loop
658#define CB_DELAY_LOOP_WAIT 10 // 10ms
659
660//
661// revision id
662//
663#define REV_ID_VT3253_A0 0x00
664#define REV_ID_VT3253_A1 0x01
665#define REV_ID_VT3253_B0 0x08
666#define REV_ID_VT3253_B1 0x09
667
668/*--------------------- Export Types ------------------------------*/
669
670/*--------------------- Export Macros ------------------------------*/
671
672#define MACvRegBitsOn(dwIoBase, byRegOfs, byBits) \
673{ \
674 BYTE byData; \
675 VNSvInPortB(dwIoBase + byRegOfs, &byData); \
676 VNSvOutPortB(dwIoBase + byRegOfs, byData | (byBits)); \
677}
678
679#define MACvWordRegBitsOn(dwIoBase, byRegOfs, wBits) \
680{ \
681 WORD wData; \
682 VNSvInPortW(dwIoBase + byRegOfs, &wData); \
683 VNSvOutPortW(dwIoBase + byRegOfs, wData | (wBits)); \
684}
685
686#define MACvDWordRegBitsOn(dwIoBase, byRegOfs, dwBits) \
687{ \
688 DWORD dwData; \
689 VNSvInPortD(dwIoBase + byRegOfs, &dwData); \
690 VNSvOutPortD(dwIoBase + byRegOfs, dwData | (dwBits)); \
691}
692
693#define MACvRegBitsOnEx(dwIoBase, byRegOfs, byMask, byBits) \
694{ \
695 BYTE byData; \
696 VNSvInPortB(dwIoBase + byRegOfs, &byData); \
697 byData &= byMask; \
698 VNSvOutPortB(dwIoBase + byRegOfs, byData | (byBits)); \
699}
700
701#define MACvRegBitsOff(dwIoBase, byRegOfs, byBits) \
702{ \
703 BYTE byData; \
704 VNSvInPortB(dwIoBase + byRegOfs, &byData); \
705 VNSvOutPortB(dwIoBase + byRegOfs, byData & ~(byBits)); \
706}
707
708#define MACvWordRegBitsOff(dwIoBase, byRegOfs, wBits) \
709{ \
710 WORD wData; \
711 VNSvInPortW(dwIoBase + byRegOfs, &wData); \
712 VNSvOutPortW(dwIoBase + byRegOfs, wData & ~(wBits)); \
713}
714
715#define MACvDWordRegBitsOff(dwIoBase, byRegOfs, dwBits) \
716{ \
717 DWORD dwData; \
718 VNSvInPortD(dwIoBase + byRegOfs, &dwData); \
719 VNSvOutPortD(dwIoBase + byRegOfs, dwData & ~(dwBits)); \
720}
721
722#define MACvGetCurrRx0DescAddr(dwIoBase, pdwCurrDescAddr) \
723{ \
724 VNSvInPortD(dwIoBase + MAC_REG_RXDMAPTR0, \
725 (PDWORD)pdwCurrDescAddr); \
726}
727
728#define MACvGetCurrRx1DescAddr(dwIoBase, pdwCurrDescAddr) \
729{ \
730 VNSvInPortD(dwIoBase + MAC_REG_RXDMAPTR1, \
731 (PDWORD)pdwCurrDescAddr); \
732}
733
734#define MACvGetCurrTx0DescAddr(dwIoBase, pdwCurrDescAddr) \
735{ \
736 VNSvInPortD(dwIoBase + MAC_REG_TXDMAPTR0, \
737 (PDWORD)pdwCurrDescAddr); \
738}
739
740#define MACvGetCurrAC0DescAddr(dwIoBase, pdwCurrDescAddr) \
741{ \
742 VNSvInPortD(dwIoBase + MAC_REG_AC0DMAPTR, \
743 (PDWORD)pdwCurrDescAddr); \
744}
745
746#define MACvGetCurrSyncDescAddr(dwIoBase, pdwCurrDescAddr) \
747{ \
748 VNSvInPortD(dwIoBase + MAC_REG_SYNCDMAPTR, \
749 (PDWORD)pdwCurrDescAddr); \
750}
751
752#define MACvGetCurrATIMDescAddr(dwIoBase, pdwCurrDescAddr) \
753{ \
754 VNSvInPortD(dwIoBase + MAC_REG_ATIMDMAPTR, \
755 (PDWORD)pdwCurrDescAddr); \
756} \
757
758// set the chip with current BCN tx descriptor address
759#define MACvSetCurrBCNTxDescAddr(dwIoBase, dwCurrDescAddr) \
760{ \
761 VNSvOutPortD(dwIoBase + MAC_REG_BCNDMAPTR, \
762 dwCurrDescAddr); \
763}
764
765// set the chip with current BCN length
766#define MACvSetCurrBCNLength(dwIoBase, wCurrBCNLength) \
767{ \
768 VNSvOutPortW(dwIoBase + MAC_REG_BCNDMACTL+2, \
769 wCurrBCNLength); \
770}
771
772#define MACvReadBSSIDAddress(dwIoBase, pbyEtherAddr) \
773{ \
774 VNSvOutPortB(dwIoBase + MAC_REG_PAGE1SEL, 1); \
775 VNSvInPortB(dwIoBase + MAC_REG_BSSID0, \
776 (PBYTE)pbyEtherAddr); \
777 VNSvInPortB(dwIoBase + MAC_REG_BSSID0 + 1, \
778 pbyEtherAddr + 1); \
779 VNSvInPortB(dwIoBase + MAC_REG_BSSID0 + 2, \
780 pbyEtherAddr + 2); \
781 VNSvInPortB(dwIoBase + MAC_REG_BSSID0 + 3, \
782 pbyEtherAddr + 3); \
783 VNSvInPortB(dwIoBase + MAC_REG_BSSID0 + 4, \
784 pbyEtherAddr + 4); \
785 VNSvInPortB(dwIoBase + MAC_REG_BSSID0 + 5, \
786 pbyEtherAddr + 5); \
787 VNSvOutPortB(dwIoBase + MAC_REG_PAGE1SEL, 0); \
788}
789
790#define MACvWriteBSSIDAddress(dwIoBase, pbyEtherAddr) \
791{ \
792 VNSvOutPortB(dwIoBase + MAC_REG_PAGE1SEL, 1); \
793 VNSvOutPortB(dwIoBase + MAC_REG_BSSID0, \
794 *(pbyEtherAddr)); \
795 VNSvOutPortB(dwIoBase + MAC_REG_BSSID0 + 1, \
796 *(pbyEtherAddr + 1)); \
797 VNSvOutPortB(dwIoBase + MAC_REG_BSSID0 + 2, \
798 *(pbyEtherAddr + 2)); \
799 VNSvOutPortB(dwIoBase + MAC_REG_BSSID0 + 3, \
800 *(pbyEtherAddr + 3)); \
801 VNSvOutPortB(dwIoBase + MAC_REG_BSSID0 + 4, \
802 *(pbyEtherAddr + 4)); \
803 VNSvOutPortB(dwIoBase + MAC_REG_BSSID0 + 5, \
804 *(pbyEtherAddr + 5)); \
805 VNSvOutPortB(dwIoBase + MAC_REG_PAGE1SEL, 0); \
806}
807
808#define MACvReadEtherAddress(dwIoBase, pbyEtherAddr) \
809{ \
810 VNSvOutPortB(dwIoBase + MAC_REG_PAGE1SEL, 1); \
811 VNSvInPortB(dwIoBase + MAC_REG_PAR0, \
812 (PBYTE)pbyEtherAddr); \
813 VNSvInPortB(dwIoBase + MAC_REG_PAR0 + 1, \
814 pbyEtherAddr + 1); \
815 VNSvInPortB(dwIoBase + MAC_REG_PAR0 + 2, \
816 pbyEtherAddr + 2); \
817 VNSvInPortB(dwIoBase + MAC_REG_PAR0 + 3, \
818 pbyEtherAddr + 3); \
819 VNSvInPortB(dwIoBase + MAC_REG_PAR0 + 4, \
820 pbyEtherAddr + 4); \
821 VNSvInPortB(dwIoBase + MAC_REG_PAR0 + 5, \
822 pbyEtherAddr + 5); \
823 VNSvOutPortB(dwIoBase + MAC_REG_PAGE1SEL, 0); \
824}
825
826
827#define MACvWriteEtherAddress(dwIoBase, pbyEtherAddr) \
828{ \
829 VNSvOutPortB(dwIoBase + MAC_REG_PAGE1SEL, 1); \
830 VNSvOutPortB(dwIoBase + MAC_REG_PAR0, \
831 *pbyEtherAddr); \
832 VNSvOutPortB(dwIoBase + MAC_REG_PAR0 + 1, \
833 *(pbyEtherAddr + 1)); \
834 VNSvOutPortB(dwIoBase + MAC_REG_PAR0 + 2, \
835 *(pbyEtherAddr + 2)); \
836 VNSvOutPortB(dwIoBase + MAC_REG_PAR0 + 3, \
837 *(pbyEtherAddr + 3)); \
838 VNSvOutPortB(dwIoBase + MAC_REG_PAR0 + 4, \
839 *(pbyEtherAddr + 4)); \
840 VNSvOutPortB(dwIoBase + MAC_REG_PAR0 + 5, \
841 *(pbyEtherAddr + 5)); \
842 VNSvOutPortB(dwIoBase + MAC_REG_PAGE1SEL, 0); \
843}
844
845
846#define MACvClearISR(dwIoBase) \
847{ \
848 VNSvOutPortD(dwIoBase + MAC_REG_ISR, IMR_MASK_VALUE); \
849}
850
851#define MACvStart(dwIoBase) \
852{ \
853 VNSvOutPortB(dwIoBase + MAC_REG_HOSTCR, \
854 (HOSTCR_MACEN | HOSTCR_RXON | HOSTCR_TXON)); \
855}
856
857#define MACvRx0PerPktMode(dwIoBase) \
858{ \
859 VNSvOutPortD(dwIoBase + MAC_REG_RXDMACTL0, RX_PERPKT); \
860}
861
862#define MACvRx0BufferFillMode(dwIoBase) \
863{ \
864 VNSvOutPortD(dwIoBase + MAC_REG_RXDMACTL0, RX_PERPKTCLR); \
865}
866
867#define MACvRx1PerPktMode(dwIoBase) \
868{ \
869 VNSvOutPortD(dwIoBase + MAC_REG_RXDMACTL1, RX_PERPKT); \
870}
871
872#define MACvRx1BufferFillMode(dwIoBase) \
873{ \
874 VNSvOutPortD(dwIoBase + MAC_REG_RXDMACTL1, RX_PERPKTCLR); \
875}
876
877#define MACvRxOn(dwIoBase) \
878{ \
879 MACvRegBitsOn(dwIoBase, MAC_REG_HOSTCR, HOSTCR_RXON); \
880}
881
882#define MACvReceive0(dwIoBase) \
883{ \
884 DWORD dwData; \
885 VNSvInPortD(dwIoBase + MAC_REG_RXDMACTL0, &dwData); \
886 if (dwData & DMACTL_RUN) { \
887 VNSvOutPortD(dwIoBase + MAC_REG_RXDMACTL0, DMACTL_WAKE);\
888 } \
889 else { \
890 VNSvOutPortD(dwIoBase + MAC_REG_RXDMACTL0, DMACTL_RUN); \
891 } \
892}
893
894#define MACvReceive1(dwIoBase) \
895{ \
896 DWORD dwData; \
897 VNSvInPortD(dwIoBase + MAC_REG_RXDMACTL1, &dwData); \
898 if (dwData & DMACTL_RUN) { \
899 VNSvOutPortD(dwIoBase + MAC_REG_RXDMACTL1, DMACTL_WAKE);\
900 } \
901 else { \
902 VNSvOutPortD(dwIoBase + MAC_REG_RXDMACTL1, DMACTL_RUN); \
903 } \
904}
905
906#define MACvTxOn(dwIoBase) \
907{ \
908 MACvRegBitsOn(dwIoBase, MAC_REG_HOSTCR, HOSTCR_TXON); \
909}
910
911#define MACvTransmit0(dwIoBase) \
912{ \
913 DWORD dwData; \
914 VNSvInPortD(dwIoBase + MAC_REG_TXDMACTL0, &dwData); \
915 if (dwData & DMACTL_RUN) { \
916 VNSvOutPortD(dwIoBase + MAC_REG_TXDMACTL0, DMACTL_WAKE);\
917 } \
918 else { \
919 VNSvOutPortD(dwIoBase + MAC_REG_TXDMACTL0, DMACTL_RUN); \
920 } \
921}
922
923#define MACvTransmitAC0(dwIoBase) \
924{ \
925 DWORD dwData; \
926 VNSvInPortD(dwIoBase + MAC_REG_AC0DMACTL, &dwData); \
927 if (dwData & DMACTL_RUN) { \
928 VNSvOutPortD(dwIoBase + MAC_REG_AC0DMACTL, DMACTL_WAKE);\
929 } \
930 else { \
931 VNSvOutPortD(dwIoBase + MAC_REG_AC0DMACTL, DMACTL_RUN); \
932 } \
933}
934
935#define MACvTransmitSYNC(dwIoBase) \
936{ \
937 DWORD dwData; \
938 VNSvInPortD(dwIoBase + MAC_REG_SYNCDMACTL, &dwData); \
939 if (dwData & DMACTL_RUN) { \
940 VNSvOutPortD(dwIoBase + MAC_REG_SYNCDMACTL, DMACTL_WAKE);\
941 } \
942 else { \
943 VNSvOutPortD(dwIoBase + MAC_REG_SYNCDMACTL, DMACTL_RUN); \
944 } \
945}
946
947#define MACvTransmitATIM(dwIoBase) \
948{ \
949 DWORD dwData; \
950 VNSvInPortD(dwIoBase + MAC_REG_ATIMDMACTL, &dwData); \
951 if (dwData & DMACTL_RUN) { \
952 VNSvOutPortD(dwIoBase + MAC_REG_ATIMDMACTL, DMACTL_WAKE);\
953 } \
954 else { \
955 VNSvOutPortD(dwIoBase + MAC_REG_ATIMDMACTL, DMACTL_RUN); \
956 } \
957}
958
959#define MACvTransmitBCN(dwIoBase) \
960{ \
961 VNSvOutPortB(dwIoBase + MAC_REG_BCNDMACTL, BEACON_READY); \
962}
963
964#define MACvClearStckDS(dwIoBase) \
965{ \
966 BYTE byOrgValue; \
967 VNSvInPortB(dwIoBase + MAC_REG_STICKHW, &byOrgValue); \
968 byOrgValue = byOrgValue & 0xFC; \
969 VNSvOutPortB(dwIoBase + MAC_REG_STICKHW, byOrgValue); \
970}
971
972#define MACvReadISR(dwIoBase, pdwValue) \
973{ \
974 VNSvInPortD(dwIoBase + MAC_REG_ISR, pdwValue); \
975}
976
977#define MACvWriteISR(dwIoBase, dwValue) \
978{ \
979 VNSvOutPortD(dwIoBase + MAC_REG_ISR, dwValue); \
980}
981
982#define MACvIntEnable(dwIoBase, dwMask) \
983{ \
984 VNSvOutPortD(dwIoBase + MAC_REG_IMR, dwMask); \
985}
986
987#define MACvIntDisable(dwIoBase) \
988{ \
989 VNSvOutPortD(dwIoBase + MAC_REG_IMR, 0); \
990}
991
992#define MACvSelectPage0(dwIoBase) \
993{ \
994 VNSvOutPortB(dwIoBase + MAC_REG_PAGE1SEL, 0); \
995}
996#define MACvSelectPage1(dwIoBase) \
997{ \
998 VNSvOutPortB(dwIoBase + MAC_REG_PAGE1SEL, 1); \
999}
1000
1001#define MACvReadMIBCounter(dwIoBase, pdwCounter) \
1002{ \
1003 VNSvInPortD(dwIoBase + MAC_REG_MIBCNTR , pdwCounter); \
1004}
1005
1006#define MACvPwrEvntDisable(dwIoBase) \
1007{ \
1008 VNSvOutPortW(dwIoBase + MAC_REG_WAKEUPEN0, 0x0000); \
1009}
1010
1011#define MACvEnableProtectMD(dwIoBase) \
1012{ \
1013 DWORD dwOrgValue; \
1014 VNSvInPortD(dwIoBase + MAC_REG_ENCFG , &dwOrgValue); \
1015 dwOrgValue = dwOrgValue | EnCFG_ProtectMd; \
1016 VNSvOutPortD(dwIoBase + MAC_REG_ENCFG, dwOrgValue); \
1017}
1018
1019#define MACvDisableProtectMD(dwIoBase) \
1020{ \
1021 DWORD dwOrgValue; \
1022 VNSvInPortD(dwIoBase + MAC_REG_ENCFG , &dwOrgValue); \
1023 dwOrgValue = dwOrgValue & ~EnCFG_ProtectMd; \
1024 VNSvOutPortD(dwIoBase + MAC_REG_ENCFG, dwOrgValue); \
1025}
1026
1027#define MACvEnableBarkerPreambleMd(dwIoBase) \
1028{ \
1029 DWORD dwOrgValue; \
1030 VNSvInPortD(dwIoBase + MAC_REG_ENCFG , &dwOrgValue); \
1031 dwOrgValue = dwOrgValue | EnCFG_BarkerPream; \
1032 VNSvOutPortD(dwIoBase + MAC_REG_ENCFG, dwOrgValue); \
1033}
1034
1035#define MACvDisableBarkerPreambleMd(dwIoBase) \
1036{ \
1037 DWORD dwOrgValue; \
1038 VNSvInPortD(dwIoBase + MAC_REG_ENCFG , &dwOrgValue); \
1039 dwOrgValue = dwOrgValue & ~EnCFG_BarkerPream; \
1040 VNSvOutPortD(dwIoBase + MAC_REG_ENCFG, dwOrgValue); \
1041}
1042
1043#define MACvSetBBType(dwIoBase, byTyp) \
1044{ \
1045 DWORD dwOrgValue; \
1046 VNSvInPortD(dwIoBase + MAC_REG_ENCFG , &dwOrgValue); \
1047 dwOrgValue = dwOrgValue & ~EnCFG_BBType_MASK; \
1048 dwOrgValue = dwOrgValue | (DWORD) byTyp; \
1049 VNSvOutPortD(dwIoBase + MAC_REG_ENCFG, dwOrgValue); \
1050}
1051
1052#define MACvReadATIMW(dwIoBase, pwCounter) \
1053{ \
1054 VNSvInPortW(dwIoBase + MAC_REG_AIDATIM , pwCounter); \
1055}
1056
1057#define MACvWriteATIMW(dwIoBase, wCounter) \
1058{ \
1059 VNSvOutPortW(dwIoBase + MAC_REG_AIDATIM , wCounter); \
1060}
1061
1062#define MACvWriteCRC16_128(dwIoBase, byRegOfs, wCRC) \
1063{ \
1064 VNSvOutPortB(dwIoBase + MAC_REG_PAGE1SEL, 1); \
1065 VNSvOutPortW(dwIoBase + byRegOfs, wCRC); \
1066 VNSvOutPortB(dwIoBase + MAC_REG_PAGE1SEL, 0); \
1067}
1068
1069#define MACvGPIOIn(dwIoBase, pbyValue) \
1070{ \
1071 VNSvInPortB(dwIoBase + MAC_REG_GPIOCTL1, pbyValue); \
1072}
1073
1074#define MACvSetRFLE_LatchBase(dwIoBase) \
1075{ \
1076 MACvWordRegBitsOn(dwIoBase, MAC_REG_SOFTPWRCTL, SOFTPWRCTL_RFLEOPT); \
1077}
1078
1079/*--------------------- Export Classes ----------------------------*/
1080
1081/*--------------------- Export Variables --------------------------*/
1082
1083/*--------------------- Export Functions --------------------------*/
1084#ifdef __cplusplus
1085extern "C" { /* Assume C declarations for C++ */
1086#endif /* __cplusplus */
1087
1088extern WORD TxRate_iwconfig;//2008-5-8 <add> by chester
1089VOID MACvReadAllRegs(DWORD_PTR dwIoBase, PBYTE pbyMacRegs);
1090
1091BOOL MACbIsRegBitsOn(DWORD_PTR dwIoBase, BYTE byRegOfs, BYTE byTestBits);
1092BOOL MACbIsRegBitsOff(DWORD_PTR dwIoBase, BYTE byRegOfs, BYTE byTestBits);
1093
1094BOOL MACbIsIntDisable(DWORD_PTR dwIoBase);
1095
1096BYTE MACbyReadMultiAddr(DWORD_PTR dwIoBase, UINT uByteIdx);
1097VOID MACvWriteMultiAddr(DWORD_PTR dwIoBase, UINT uByteIdx, BYTE byData);
1098VOID MACvSetMultiAddrByHash(DWORD_PTR dwIoBase, BYTE byHashIdx);
1099VOID MACvResetMultiAddrByHash(DWORD_PTR dwIoBase, BYTE byHashIdx);
1100
1101VOID MACvSetRxThreshold(DWORD_PTR dwIoBase, BYTE byThreshold);
1102VOID MACvGetRxThreshold(DWORD_PTR dwIoBase, PBYTE pbyThreshold);
1103
1104VOID MACvSetTxThreshold(DWORD_PTR dwIoBase, BYTE byThreshold);
1105VOID MACvGetTxThreshold(DWORD_PTR dwIoBase, PBYTE pbyThreshold);
1106
1107VOID MACvSetDmaLength(DWORD_PTR dwIoBase, BYTE byDmaLength);
1108VOID MACvGetDmaLength(DWORD_PTR dwIoBase, PBYTE pbyDmaLength);
1109
1110VOID MACvSetShortRetryLimit(DWORD_PTR dwIoBase, BYTE byRetryLimit);
1111VOID MACvGetShortRetryLimit(DWORD_PTR dwIoBase, PBYTE pbyRetryLimit);
1112
1113VOID MACvSetLongRetryLimit(DWORD_PTR dwIoBase, BYTE byRetryLimit);
1114VOID MACvGetLongRetryLimit(DWORD_PTR dwIoBase, PBYTE pbyRetryLimit);
1115
1116VOID MACvSetLoopbackMode(DWORD_PTR dwIoBase, BYTE byLoopbackMode);
1117BOOL MACbIsInLoopbackMode(DWORD_PTR dwIoBase);
1118
1119VOID MACvSetPacketFilter(DWORD_PTR dwIoBase, WORD wFilterType);
1120
1121VOID MACvSaveContext(DWORD_PTR dwIoBase, PBYTE pbyCxtBuf);
1122VOID MACvRestoreContext(DWORD_PTR dwIoBase, PBYTE pbyCxtBuf);
1123BOOL MACbCompareContext(DWORD_PTR dwIoBase, PBYTE pbyCxtBuf);
1124
1125BOOL MACbSoftwareReset(DWORD_PTR dwIoBase);
1126BOOL MACbSafeSoftwareReset(DWORD_PTR dwIoBase);
1127BOOL MACbSafeRxOff(DWORD_PTR dwIoBase);
1128BOOL MACbSafeTxOff(DWORD_PTR dwIoBase);
1129BOOL MACbSafeStop(DWORD_PTR dwIoBase);
1130BOOL MACbShutdown(DWORD_PTR dwIoBase);
1131VOID MACvInitialize(DWORD_PTR dwIoBase);
1132VOID MACvSetCurrRx0DescAddr(DWORD_PTR dwIoBase, DWORD dwCurrDescAddr);
1133VOID MACvSetCurrRx1DescAddr(DWORD_PTR dwIoBase, DWORD dwCurrDescAddr);
1134VOID MACvSetCurrTXDescAddr(int iTxType, DWORD_PTR dwIoBase, DWORD dwCurrDescAddr);
1135VOID MACvSetCurrTx0DescAddrEx(DWORD_PTR dwIoBase, DWORD dwCurrDescAddr);
1136VOID MACvSetCurrAC0DescAddrEx(DWORD_PTR dwIoBase, DWORD dwCurrDescAddr);
1137VOID MACvSetCurrSyncDescAddrEx(DWORD_PTR dwIoBase, DWORD dwCurrDescAddr);
1138VOID MACvSetCurrATIMDescAddrEx(DWORD_PTR dwIoBase, DWORD dwCurrDescAddr);
1139void MACvTimer0MicroSDelay(DWORD_PTR dwIoBase, UINT uDelay);
1140void MACvOneShotTimer0MicroSec(DWORD_PTR dwIoBase, UINT uDelayTime);
1141void MACvOneShotTimer1MicroSec(DWORD_PTR dwIoBase, UINT uDelayTime);
1142
1143void MACvSetMISCFifo(DWORD_PTR dwIoBase, WORD wOffset, DWORD dwData);
1144
1145BOOL MACbTxDMAOff (DWORD_PTR dwIoBase, UINT idx);
1146
1147void MACvClearBusSusInd(DWORD_PTR dwIoBase);
1148void MACvEnableBusSusEn(DWORD_PTR dwIoBase);
1149
1150BOOL MACbFlushSYNCFifo(DWORD_PTR dwIoBase);
1151BOOL MACbPSWakeup(DWORD_PTR dwIoBase);
1152
1153void MACvSetKeyEntry(DWORD_PTR dwIoBase, WORD wKeyCtl, UINT uEntryIdx, UINT uKeyIdx, PBYTE pbyAddr, PDWORD pdwKey, BYTE byLocalID);
1154void MACvDisableKeyEntry(DWORD_PTR dwIoBase, UINT uEntryIdx);
1155void MACvSetDefaultKeyEntry(DWORD_PTR dwIoBase, UINT uKeyLen, UINT uKeyIdx, PDWORD pdwKey, BYTE byLocalID);
1156//void MACvEnableDefaultKey(DWORD_PTR dwIoBase, BYTE byLocalID);
1157void MACvDisableDefaultKey(DWORD_PTR dwIoBase);
1158void MACvSetDefaultTKIPKeyEntry(DWORD_PTR dwIoBase, UINT uKeyLen, UINT uKeyIdx, PDWORD pdwKey, BYTE byLocalID);
1159void MACvSetDefaultKeyCtl(DWORD_PTR dwIoBase, WORD wKeyCtl, UINT uEntryIdx, BYTE byLocalID);
1160
1161#ifdef __cplusplus
1162} /* End of extern "C" { */
1163#endif /* __cplusplus */
1164
1165#endif // __MAC_H__
1166
diff --git a/drivers/staging/vt6655/mib.c b/drivers/staging/vt6655/mib.c
new file mode 100644
index 000000000000..3f06de141a84
--- /dev/null
+++ b/drivers/staging/vt6655/mib.c
@@ -0,0 +1,616 @@
1/*
2 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
3 * All rights reserved.
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * File: mib.c
20 *
21 * Purpose: Implement MIB Data Structure
22 *
23 * Author: Tevin Chen
24 *
25 * Date: May 21, 1996
26 *
27 * Functions:
28 * STAvClearAllCounter - Clear All MIB Counter
29 * STAvUpdateIstStatCounter - Update ISR statistic counter
30 * STAvUpdateRDStatCounter - Update Rx statistic counter
31 * STAvUpdateRDStatCounterEx - Update Rx statistic counter and copy rcv data
32 * STAvUpdateTDStatCounter - Update Tx statistic counter
33 * STAvUpdateTDStatCounterEx - Update Tx statistic counter and copy tx data
34 * STAvUpdate802_11Counter - Update 802.11 mib counter
35 *
36 * Revision History:
37 *
38 */
39
40
41#if !defined(__UPC_H__)
42#include "upc.h"
43#endif
44#if !defined(__MAC_H__)
45#include "mac.h"
46#endif
47#if !defined(__TBIT_H__)
48#include "tbit.h"
49#endif
50#if !defined(__TETHER_H__)
51#include "tether.h"
52#endif
53#if !defined(__MIB_H__)
54#include "mib.h"
55#endif
56#if !defined(__WCTL_H__)
57#include "wctl.h"
58#endif
59#if !defined(__UMEM_H__)
60#include "umem.h"
61#endif
62#if !defined(__BASEBAND_H__)
63#include "baseband.h"
64#endif
65
66/*--------------------- Static Definitions -------------------------*/
67static int msglevel =MSG_LEVEL_INFO;
68/*--------------------- Static Classes ----------------------------*/
69
70/*--------------------- Static Variables --------------------------*/
71
72/*--------------------- Static Functions --------------------------*/
73
74/*--------------------- Export Variables --------------------------*/
75
76/*--------------------- Export Functions --------------------------*/
77
78
79
80/*
81 * Description: Clear All Statistic Counter
82 *
83 * Parameters:
84 * In:
85 * pStatistic - Pointer to Statistic Counter Data Structure
86 * Out:
87 * none
88 *
89 * Return Value: none
90 *
91 */
92void STAvClearAllCounter (PSStatCounter pStatistic)
93{
94 // set memory to zero
95 ZERO_MEMORY(pStatistic, sizeof(SStatCounter));
96}
97
98
99/*
100 * Description: Update Isr Statistic Counter
101 *
102 * Parameters:
103 * In:
104 * pStatistic - Pointer to Statistic Counter Data Structure
105 * wisr - Interrupt status
106 * Out:
107 * none
108 *
109 * Return Value: none
110 *
111 */
112void STAvUpdateIsrStatCounter (PSStatCounter pStatistic, DWORD dwIsr)
113{
114 /**********************/
115 /* ABNORMAL interrupt */
116 /**********************/
117 // not any IMR bit invoke irq
118
119 if (dwIsr == 0) {
120 pStatistic->ISRStat.dwIsrUnknown++;
121 return;
122 }
123
124//Added by Kyle
125 if (BITbIsBitOn(dwIsr, ISR_TXDMA0)) // ISR, bit0
126 pStatistic->ISRStat.dwIsrTx0OK++; // TXDMA0 successful
127
128 if (BITbIsBitOn(dwIsr, ISR_AC0DMA)) // ISR, bit1
129 pStatistic->ISRStat.dwIsrAC0TxOK++; // AC0DMA successful
130
131 if (BITbIsBitOn(dwIsr, ISR_BNTX)) // ISR, bit2
132 pStatistic->ISRStat.dwIsrBeaconTxOK++; // BeaconTx successful
133
134 if (BITbIsBitOn(dwIsr, ISR_RXDMA0)) // ISR, bit3
135 pStatistic->ISRStat.dwIsrRx0OK++; // Rx0 successful
136
137 if (BITbIsBitOn(dwIsr, ISR_TBTT)) // ISR, bit4
138 pStatistic->ISRStat.dwIsrTBTTInt++; // TBTT successful
139
140 if (BITbIsBitOn(dwIsr, ISR_SOFTTIMER)) // ISR, bit6
141 pStatistic->ISRStat.dwIsrSTIMERInt++;
142
143 if (BITbIsBitOn(dwIsr, ISR_WATCHDOG)) // ISR, bit7
144 pStatistic->ISRStat.dwIsrWatchDog++;
145
146 if (BITbIsBitOn(dwIsr, ISR_FETALERR)) // ISR, bit8
147 pStatistic->ISRStat.dwIsrUnrecoverableError++;
148
149 if (BITbIsBitOn(dwIsr, ISR_SOFTINT)) // ISR, bit9
150 pStatistic->ISRStat.dwIsrSoftInterrupt++; // software interrupt
151
152 if (BITbIsBitOn(dwIsr, ISR_MIBNEARFULL)) // ISR, bit10
153 pStatistic->ISRStat.dwIsrMIBNearfull++;
154
155 if (BITbIsBitOn(dwIsr, ISR_RXNOBUF)) // ISR, bit11
156 pStatistic->ISRStat.dwIsrRxNoBuf++; // Rx No Buff
157
158 if (BITbIsBitOn(dwIsr, ISR_RXDMA1)) // ISR, bit12
159 pStatistic->ISRStat.dwIsrRx1OK++; // Rx1 successful
160
161// if (BITbIsBitOn(dwIsr, ISR_ATIMTX)) // ISR, bit13
162// pStatistic->ISRStat.dwIsrATIMTxOK++; // ATIMTX successful
163
164// if (BITbIsBitOn(dwIsr, ISR_SYNCTX)) // ISR, bit14
165// pStatistic->ISRStat.dwIsrSYNCTxOK++; // SYNCTX successful
166
167// if (BITbIsBitOn(dwIsr, ISR_CFPEND)) // ISR, bit18
168// pStatistic->ISRStat.dwIsrCFPEnd++;
169
170// if (BITbIsBitOn(dwIsr, ISR_ATIMEND)) // ISR, bit19
171// pStatistic->ISRStat.dwIsrATIMEnd++;
172
173// if (BITbIsBitOn(dwIsr, ISR_SYNCFLUSHOK)) // ISR, bit20
174// pStatistic->ISRStat.dwIsrSYNCFlushOK++;
175
176 if (BITbIsBitOn(dwIsr, ISR_SOFTTIMER1)) // ISR, bit21
177 pStatistic->ISRStat.dwIsrSTIMER1Int++;
178
179}
180
181
182/*
183 * Description: Update Rx Statistic Counter
184 *
185 * Parameters:
186 * In:
187 * pStatistic - Pointer to Statistic Counter Data Structure
188 * byRSR - Rx Status
189 * byNewRSR - Rx Status
190 * pbyBuffer - Rx Buffer
191 * cbFrameLength - Rx Length
192 * Out:
193 * none
194 *
195 * Return Value: none
196 *
197 */
198void STAvUpdateRDStatCounter (PSStatCounter pStatistic,
199 BYTE byRSR, BYTE byNewRSR, BYTE byRxRate,
200 PBYTE pbyBuffer, UINT cbFrameLength)
201{
202 //need change
203 PS802_11Header pHeader = (PS802_11Header)pbyBuffer;
204
205 if (BITbIsBitOn(byRSR, RSR_ADDROK))
206 pStatistic->dwRsrADDROk++;
207 if (BITbIsBitOn(byRSR, RSR_CRCOK)) {
208 pStatistic->dwRsrCRCOk++;
209
210 pStatistic->ullRsrOK++;
211
212 if (cbFrameLength >= U_ETHER_ADDR_LEN) {
213 // update counters in case that successful transmit
214 if (BITbIsBitOn(byRSR, RSR_ADDRBROAD)) {
215 pStatistic->ullRxBroadcastFrames++;
216 pStatistic->ullRxBroadcastBytes += (ULONGLONG)cbFrameLength;
217 }
218 else if (BITbIsBitOn(byRSR, RSR_ADDRMULTI)) {
219 pStatistic->ullRxMulticastFrames++;
220 pStatistic->ullRxMulticastBytes += (ULONGLONG)cbFrameLength;
221 }
222 else {
223 pStatistic->ullRxDirectedFrames++;
224 pStatistic->ullRxDirectedBytes += (ULONGLONG)cbFrameLength;
225 }
226 }
227 }
228
229 if(byRxRate==22) {
230 pStatistic->CustomStat.ullRsr11M++;
231 if(BITbIsBitOn(byRSR, RSR_CRCOK)) {
232 pStatistic->CustomStat.ullRsr11MCRCOk++;
233 }
234 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"11M: ALL[%d], OK[%d]:[%02x]\n", (INT)pStatistic->CustomStat.ullRsr11M, (INT)pStatistic->CustomStat.ullRsr11MCRCOk, byRSR);
235 }
236 else if(byRxRate==11) {
237 pStatistic->CustomStat.ullRsr5M++;
238 if(BITbIsBitOn(byRSR, RSR_CRCOK)) {
239 pStatistic->CustomStat.ullRsr5MCRCOk++;
240 }
241 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO" 5M: ALL[%d], OK[%d]:[%02x]\n", (INT)pStatistic->CustomStat.ullRsr5M, (INT)pStatistic->CustomStat.ullRsr5MCRCOk, byRSR);
242 }
243 else if(byRxRate==4) {
244 pStatistic->CustomStat.ullRsr2M++;
245 if(BITbIsBitOn(byRSR, RSR_CRCOK)) {
246 pStatistic->CustomStat.ullRsr2MCRCOk++;
247 }
248 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO" 2M: ALL[%d], OK[%d]:[%02x]\n", (INT)pStatistic->CustomStat.ullRsr2M, (INT)pStatistic->CustomStat.ullRsr2MCRCOk, byRSR);
249 }
250 else if(byRxRate==2){
251 pStatistic->CustomStat.ullRsr1M++;
252 if(BITbIsBitOn(byRSR, RSR_CRCOK)) {
253 pStatistic->CustomStat.ullRsr1MCRCOk++;
254 }
255 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO" 1M: ALL[%d], OK[%d]:[%02x]\n", (INT)pStatistic->CustomStat.ullRsr1M, (INT)pStatistic->CustomStat.ullRsr1MCRCOk, byRSR);
256 }
257 else if(byRxRate==12){
258 pStatistic->CustomStat.ullRsr6M++;
259 if(BITbIsBitOn(byRSR, RSR_CRCOK)) {
260 pStatistic->CustomStat.ullRsr6MCRCOk++;
261 }
262 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO" 6M: ALL[%d], OK[%d]\n", (INT)pStatistic->CustomStat.ullRsr6M, (INT)pStatistic->CustomStat.ullRsr6MCRCOk);
263 }
264 else if(byRxRate==18){
265 pStatistic->CustomStat.ullRsr9M++;
266 if(BITbIsBitOn(byRSR, RSR_CRCOK)) {
267 pStatistic->CustomStat.ullRsr9MCRCOk++;
268 }
269 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO" 9M: ALL[%d], OK[%d]\n", (INT)pStatistic->CustomStat.ullRsr9M, (INT)pStatistic->CustomStat.ullRsr9MCRCOk);
270 }
271 else if(byRxRate==24){
272 pStatistic->CustomStat.ullRsr12M++;
273 if(BITbIsBitOn(byRSR, RSR_CRCOK)) {
274 pStatistic->CustomStat.ullRsr12MCRCOk++;
275 }
276 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"12M: ALL[%d], OK[%d]\n", (INT)pStatistic->CustomStat.ullRsr12M, (INT)pStatistic->CustomStat.ullRsr12MCRCOk);
277 }
278 else if(byRxRate==36){
279 pStatistic->CustomStat.ullRsr18M++;
280 if(BITbIsBitOn(byRSR, RSR_CRCOK)) {
281 pStatistic->CustomStat.ullRsr18MCRCOk++;
282 }
283 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"18M: ALL[%d], OK[%d]\n", (INT)pStatistic->CustomStat.ullRsr18M, (INT)pStatistic->CustomStat.ullRsr18MCRCOk);
284 }
285 else if(byRxRate==48){
286 pStatistic->CustomStat.ullRsr24M++;
287 if(BITbIsBitOn(byRSR, RSR_CRCOK)) {
288 pStatistic->CustomStat.ullRsr24MCRCOk++;
289 }
290 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"24M: ALL[%d], OK[%d]\n", (INT)pStatistic->CustomStat.ullRsr24M, (INT)pStatistic->CustomStat.ullRsr24MCRCOk);
291 }
292 else if(byRxRate==72){
293 pStatistic->CustomStat.ullRsr36M++;
294 if(BITbIsBitOn(byRSR, RSR_CRCOK)) {
295 pStatistic->CustomStat.ullRsr36MCRCOk++;
296 }
297 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"36M: ALL[%d], OK[%d]\n", (INT)pStatistic->CustomStat.ullRsr36M, (INT)pStatistic->CustomStat.ullRsr36MCRCOk);
298 }
299 else if(byRxRate==96){
300 pStatistic->CustomStat.ullRsr48M++;
301 if(BITbIsBitOn(byRSR, RSR_CRCOK)) {
302 pStatistic->CustomStat.ullRsr48MCRCOk++;
303 }
304 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"48M: ALL[%d], OK[%d]\n", (INT)pStatistic->CustomStat.ullRsr48M, (INT)pStatistic->CustomStat.ullRsr48MCRCOk);
305 }
306 else if(byRxRate==108){
307 pStatistic->CustomStat.ullRsr54M++;
308 if(BITbIsBitOn(byRSR, RSR_CRCOK)) {
309 pStatistic->CustomStat.ullRsr54MCRCOk++;
310 }
311 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"54M: ALL[%d], OK[%d]\n", (INT)pStatistic->CustomStat.ullRsr54M, (INT)pStatistic->CustomStat.ullRsr54MCRCOk);
312 }
313 else {
314 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Unknown: Total[%d], CRCOK[%d]\n", (INT)pStatistic->dwRsrRxPacket+1, (INT)pStatistic->dwRsrCRCOk);
315 }
316
317 if (BITbIsBitOn(byRSR, RSR_BSSIDOK))
318 pStatistic->dwRsrBSSIDOk++;
319
320 if (BITbIsBitOn(byRSR, RSR_BCNSSIDOK))
321 pStatistic->dwRsrBCNSSIDOk++;
322 if (BITbIsBitOn(byRSR, RSR_IVLDLEN)) //invalid len (> 2312 byte)
323 pStatistic->dwRsrLENErr++;
324 if (BITbIsBitOn(byRSR, RSR_IVLDTYP)) //invalid packet type
325 pStatistic->dwRsrTYPErr++;
326 if (BITbIsBitOn(byRSR, (RSR_IVLDTYP | RSR_IVLDLEN)))
327 pStatistic->dwRsrErr++;
328
329 if (BITbIsBitOn(byNewRSR, NEWRSR_DECRYPTOK))
330 pStatistic->dwNewRsrDECRYPTOK++;
331 if (BITbIsBitOn(byNewRSR, NEWRSR_CFPIND))
332 pStatistic->dwNewRsrCFP++;
333 if (BITbIsBitOn(byNewRSR, NEWRSR_HWUTSF))
334 pStatistic->dwNewRsrUTSF++;
335 if (BITbIsBitOn(byNewRSR, NEWRSR_BCNHITAID))
336 pStatistic->dwNewRsrHITAID++;
337 if (BITbIsBitOn(byNewRSR, NEWRSR_BCNHITAID0))
338 pStatistic->dwNewRsrHITAID0++;
339
340 // increase rx packet count
341 pStatistic->dwRsrRxPacket++;
342 pStatistic->dwRsrRxOctet += cbFrameLength;
343
344
345 if (IS_TYPE_DATA(pbyBuffer)) {
346 pStatistic->dwRsrRxData++;
347 } else if (IS_TYPE_MGMT(pbyBuffer)){
348 pStatistic->dwRsrRxManage++;
349 } else if (IS_TYPE_CONTROL(pbyBuffer)){
350 pStatistic->dwRsrRxControl++;
351 }
352
353 if (BITbIsBitOn(byRSR, RSR_ADDRBROAD))
354 pStatistic->dwRsrBroadcast++;
355 else if (BITbIsBitOn(byRSR, RSR_ADDRMULTI))
356 pStatistic->dwRsrMulticast++;
357 else
358 pStatistic->dwRsrDirected++;
359
360 if (WLAN_GET_FC_MOREFRAG(pHeader->wFrameCtl))
361 pStatistic->dwRsrRxFragment++;
362
363 if (cbFrameLength < MIN_PACKET_LEN + 4) {
364 pStatistic->dwRsrRunt++;
365 }
366 else if (cbFrameLength == MIN_PACKET_LEN + 4) {
367 pStatistic->dwRsrRxFrmLen64++;
368 }
369 else if ((65 <= cbFrameLength) && (cbFrameLength <= 127)) {
370 pStatistic->dwRsrRxFrmLen65_127++;
371 }
372 else if ((128 <= cbFrameLength) && (cbFrameLength <= 255)) {
373 pStatistic->dwRsrRxFrmLen128_255++;
374 }
375 else if ((256 <= cbFrameLength) && (cbFrameLength <= 511)) {
376 pStatistic->dwRsrRxFrmLen256_511++;
377 }
378 else if ((512 <= cbFrameLength) && (cbFrameLength <= 1023)) {
379 pStatistic->dwRsrRxFrmLen512_1023++;
380 }
381 else if ((1024 <= cbFrameLength) && (cbFrameLength <= MAX_PACKET_LEN + 4)) {
382 pStatistic->dwRsrRxFrmLen1024_1518++;
383 } else if (cbFrameLength > MAX_PACKET_LEN + 4) {
384 pStatistic->dwRsrLong++;
385 }
386
387}
388
389
390
391/*
392 * Description: Update Rx Statistic Counter and copy Rx buffer
393 *
394 * Parameters:
395 * In:
396 * pStatistic - Pointer to Statistic Counter Data Structure
397 * byRSR - Rx Status
398 * byNewRSR - Rx Status
399 * pbyBuffer - Rx Buffer
400 * cbFrameLength - Rx Length
401 * Out:
402 * none
403 *
404 * Return Value: none
405 *
406 */
407
408void
409STAvUpdateRDStatCounterEx (
410 PSStatCounter pStatistic,
411 BYTE byRSR,
412 BYTE byNewRSR,
413 BYTE byRxRate,
414 PBYTE pbyBuffer,
415 UINT cbFrameLength
416 )
417{
418 STAvUpdateRDStatCounter(
419 pStatistic,
420 byRSR,
421 byNewRSR,
422 byRxRate,
423 pbyBuffer,
424 cbFrameLength
425 );
426
427 // rx length
428 pStatistic->dwCntRxFrmLength = cbFrameLength;
429 // rx pattern, we just see 10 bytes for sample
430 MEMvCopy(pStatistic->abyCntRxPattern, (PBYTE)pbyBuffer, 10);
431}
432
433
434/*
435 * Description: Update Tx Statistic Counter
436 *
437 * Parameters:
438 * In:
439 * pStatistic - Pointer to Statistic Counter Data Structure
440 * byTSR0 - Tx Status
441 * byTSR1 - Tx Status
442 * pbyBuffer - Tx Buffer
443 * cbFrameLength - Tx Length
444 * uIdx - Index of Tx DMA
445 * Out:
446 * none
447 *
448 * Return Value: none
449 *
450 */
451void
452STAvUpdateTDStatCounter (
453 PSStatCounter pStatistic,
454 BYTE byTSR0,
455 BYTE byTSR1,
456 PBYTE pbyBuffer,
457 UINT cbFrameLength,
458 UINT uIdx
459 )
460{
461 PWLAN_80211HDR_A4 pHeader;
462 PBYTE pbyDestAddr;
463 BYTE byTSR0_NCR = byTSR0 & TSR0_NCR;
464
465
466
467 pHeader = (PWLAN_80211HDR_A4) pbyBuffer;
468 if (WLAN_GET_FC_TODS(pHeader->wFrameCtl) == 0) {
469 pbyDestAddr = &(pHeader->abyAddr1[0]);
470 }
471 else {
472 pbyDestAddr = &(pHeader->abyAddr3[0]);
473 }
474 // increase tx packet count
475 pStatistic->dwTsrTxPacket[uIdx]++;
476 pStatistic->dwTsrTxOctet[uIdx] += cbFrameLength;
477
478 if (byTSR0_NCR != 0) {
479 pStatistic->dwTsrRetry[uIdx]++;
480 pStatistic->dwTsrTotalRetry[uIdx] += byTSR0_NCR;
481
482 if (byTSR0_NCR == 1)
483 pStatistic->dwTsrOnceRetry[uIdx]++;
484 else
485 pStatistic->dwTsrMoreThanOnceRetry[uIdx]++;
486 }
487
488 if ((byTSR1&(TSR1_TERR|TSR1_RETRYTMO|TSR1_TMO|ACK_DATA)) == 0) {
489 pStatistic->ullTsrOK[uIdx]++;
490 pStatistic->CustomStat.ullTsrAllOK =
491 (pStatistic->ullTsrOK[TYPE_AC0DMA] + pStatistic->ullTsrOK[TYPE_TXDMA0]);
492 // update counters in case that successful transmit
493 if (IS_BROADCAST_ADDRESS(pbyDestAddr)) {
494 pStatistic->ullTxBroadcastFrames[uIdx]++;
495 pStatistic->ullTxBroadcastBytes[uIdx] += (ULONGLONG)cbFrameLength;
496 }
497 else if (IS_MULTICAST_ADDRESS(pbyDestAddr)) {
498 pStatistic->ullTxMulticastFrames[uIdx]++;
499 pStatistic->ullTxMulticastBytes[uIdx] += (ULONGLONG)cbFrameLength;
500 }
501 else {
502 pStatistic->ullTxDirectedFrames[uIdx]++;
503 pStatistic->ullTxDirectedBytes[uIdx] += (ULONGLONG)cbFrameLength;
504 }
505 }
506 else {
507 if (BITbIsBitOn(byTSR1, TSR1_TERR))
508 pStatistic->dwTsrErr[uIdx]++;
509 if (BITbIsBitOn(byTSR1, TSR1_RETRYTMO))
510 pStatistic->dwTsrRetryTimeout[uIdx]++;
511 if (BITbIsBitOn(byTSR1, TSR1_TMO))
512 pStatistic->dwTsrTransmitTimeout[uIdx]++;
513 if (BITbIsBitOn(byTSR1, ACK_DATA))
514 pStatistic->dwTsrACKData[uIdx]++;
515 }
516
517 if (IS_BROADCAST_ADDRESS(pbyDestAddr))
518 pStatistic->dwTsrBroadcast[uIdx]++;
519 else if (IS_MULTICAST_ADDRESS(pbyDestAddr))
520 pStatistic->dwTsrMulticast[uIdx]++;
521 else
522 pStatistic->dwTsrDirected[uIdx]++;
523
524}
525
526
527/*
528 * Description: Update Tx Statistic Counter and copy Tx buffer
529 *
530 * Parameters:
531 * In:
532 * pStatistic - Pointer to Statistic Counter Data Structure
533 * pbyBuffer - Tx Buffer
534 * cbFrameLength - Tx Length
535 * Out:
536 * none
537 *
538 * Return Value: none
539 *
540 */
541void
542STAvUpdateTDStatCounterEx (
543 PSStatCounter pStatistic,
544 PBYTE pbyBuffer,
545 DWORD cbFrameLength
546 )
547{
548 UINT uPktLength;
549
550 uPktLength = (UINT)cbFrameLength;
551
552 // tx length
553 pStatistic->dwCntTxBufLength = uPktLength;
554 // tx pattern, we just see 16 bytes for sample
555 MEMvCopy(pStatistic->abyCntTxPattern, pbyBuffer, 16);
556}
557
558
559/*
560 * Description: Update 802.11 mib counter
561 *
562 * Parameters:
563 * In:
564 * p802_11Counter - Pointer to 802.11 mib counter
565 * pStatistic - Pointer to Statistic Counter Data Structure
566 * dwCounter - hardware counter for 802.11 mib
567 * Out:
568 * none
569 *
570 * Return Value: none
571 *
572 */
573void
574STAvUpdate802_11Counter(
575 PSDot11Counters p802_11Counter,
576 PSStatCounter pStatistic,
577 DWORD dwCounter
578 )
579{
580 //p802_11Counter->TransmittedFragmentCount
581 p802_11Counter->MulticastTransmittedFrameCount = (ULONGLONG) (pStatistic->dwTsrBroadcast[TYPE_AC0DMA] +
582 pStatistic->dwTsrBroadcast[TYPE_TXDMA0] +
583 pStatistic->dwTsrMulticast[TYPE_AC0DMA] +
584 pStatistic->dwTsrMulticast[TYPE_TXDMA0]);
585 p802_11Counter->FailedCount = (ULONGLONG) (pStatistic->dwTsrErr[TYPE_AC0DMA] + pStatistic->dwTsrErr[TYPE_TXDMA0]);
586 p802_11Counter->RetryCount = (ULONGLONG) (pStatistic->dwTsrRetry[TYPE_AC0DMA] + pStatistic->dwTsrRetry[TYPE_TXDMA0]);
587 p802_11Counter->MultipleRetryCount = (ULONGLONG) (pStatistic->dwTsrMoreThanOnceRetry[TYPE_AC0DMA] +
588 pStatistic->dwTsrMoreThanOnceRetry[TYPE_TXDMA0]);
589 //p802_11Counter->FrameDuplicateCount
590 p802_11Counter->RTSSuccessCount += (ULONGLONG) (dwCounter & 0x000000ff);
591 p802_11Counter->RTSFailureCount += (ULONGLONG) ((dwCounter & 0x0000ff00) >> 8);
592 p802_11Counter->ACKFailureCount += (ULONGLONG) ((dwCounter & 0x00ff0000) >> 16);
593 p802_11Counter->FCSErrorCount += (ULONGLONG) ((dwCounter & 0xff000000) >> 24);
594 //p802_11Counter->ReceivedFragmentCount
595 p802_11Counter->MulticastReceivedFrameCount = (ULONGLONG) (pStatistic->dwRsrBroadcast +
596 pStatistic->dwRsrMulticast);
597}
598
599/*
600 * Description: Clear 802.11 mib counter
601 *
602 * Parameters:
603 * In:
604 * p802_11Counter - Pointer to 802.11 mib counter
605 * Out:
606 * none
607 *
608 * Return Value: none
609 *
610 */
611void
612STAvClear802_11Counter(PSDot11Counters p802_11Counter)
613{
614 // set memory to zero
615 ZERO_MEMORY(p802_11Counter, sizeof(SDot11Counters));
616}
diff --git a/drivers/staging/vt6655/mib.h b/drivers/staging/vt6655/mib.h
new file mode 100644
index 000000000000..b4e1c4a19a7d
--- /dev/null
+++ b/drivers/staging/vt6655/mib.h
@@ -0,0 +1,399 @@
1/*
2 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
3 * All rights reserved.
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * File: mib.h
20 *
21 * Purpose: Implement MIB Data Structure
22 *
23 * Author: Tevin Chen
24 *
25 * Date: May 21, 1996
26 *
27 */
28
29#ifndef __MIB_H__
30#define __MIB_H__
31
32#if !defined(__TTYPE_H__)
33#include "ttype.h"
34#endif
35#if !defined(__TETHER_H__)
36#include "tether.h"
37#endif
38#if !defined(__DESC_H__)
39#include "desc.h"
40#endif
41
42
43
44//#define ULONGLONG ULONG
45
46/*--------------------- Export Definitions -------------------------*/
47//
48// 802.11 counter
49//
50
51typedef struct tagSDot11Counters {
52 ULONG Length; // Length of structure
53 ULONGLONG TransmittedFragmentCount;
54 ULONGLONG MulticastTransmittedFrameCount;
55 ULONGLONG FailedCount;
56 ULONGLONG RetryCount;
57 ULONGLONG MultipleRetryCount;
58 ULONGLONG RTSSuccessCount;
59 ULONGLONG RTSFailureCount;
60 ULONGLONG ACKFailureCount;
61 ULONGLONG FrameDuplicateCount;
62 ULONGLONG ReceivedFragmentCount;
63 ULONGLONG MulticastReceivedFrameCount;
64 ULONGLONG FCSErrorCount;
65 ULONGLONG TKIPLocalMICFailures;
66 ULONGLONG TKIPRemoteMICFailures;
67 ULONGLONG TKIPICVErrors;
68 ULONGLONG TKIPCounterMeasuresInvoked;
69 ULONGLONG TKIPReplays;
70 ULONGLONG CCMPFormatErrors;
71 ULONGLONG CCMPReplays;
72 ULONGLONG CCMPDecryptErrors;
73 ULONGLONG FourWayHandshakeFailures;
74// ULONGLONG WEPUndecryptableCount;
75// ULONGLONG WEPICVErrorCount;
76// ULONGLONG DecryptSuccessCount;
77// ULONGLONG DecryptFailureCount;
78} SDot11Counters, DEF* PSDot11Counters;
79
80
81//
82// MIB2 counter
83//
84typedef struct tagSMib2Counter {
85 LONG ifIndex;
86 TCHAR ifDescr[256]; // max size 255 plus zero ending
87 // e.g. "interface 1"
88 LONG ifType;
89 LONG ifMtu;
90 DWORD ifSpeed;
91 BYTE ifPhysAddress[U_ETHER_ADDR_LEN];
92 LONG ifAdminStatus;
93 LONG ifOperStatus;
94 DWORD ifLastChange;
95 DWORD ifInOctets;
96 DWORD ifInUcastPkts;
97 DWORD ifInNUcastPkts;
98 DWORD ifInDiscards;
99 DWORD ifInErrors;
100 DWORD ifInUnknownProtos;
101 DWORD ifOutOctets;
102 DWORD ifOutUcastPkts;
103 DWORD ifOutNUcastPkts;
104 DWORD ifOutDiscards;
105 DWORD ifOutErrors;
106 DWORD ifOutQLen;
107 DWORD ifSpecific;
108} SMib2Counter, DEF* PSMib2Counter;
109
110// Value in the ifType entry
111//#define ETHERNETCSMACD 6 //
112#define WIRELESSLANIEEE80211b 6 //
113
114// Value in the ifAdminStatus/ifOperStatus entry
115#define UP 1 //
116#define DOWN 2 //
117#define TESTING 3 //
118
119
120//
121// RMON counter
122//
123typedef struct tagSRmonCounter {
124 LONG etherStatsIndex;
125 DWORD etherStatsDataSource;
126 DWORD etherStatsDropEvents;
127 DWORD etherStatsOctets;
128 DWORD etherStatsPkts;
129 DWORD etherStatsBroadcastPkts;
130 DWORD etherStatsMulticastPkts;
131 DWORD etherStatsCRCAlignErrors;
132 DWORD etherStatsUndersizePkts;
133 DWORD etherStatsOversizePkts;
134 DWORD etherStatsFragments;
135 DWORD etherStatsJabbers;
136 DWORD etherStatsCollisions;
137 DWORD etherStatsPkt64Octets;
138 DWORD etherStatsPkt65to127Octets;
139 DWORD etherStatsPkt128to255Octets;
140 DWORD etherStatsPkt256to511Octets;
141 DWORD etherStatsPkt512to1023Octets;
142 DWORD etherStatsPkt1024to1518Octets;
143 DWORD etherStatsOwners;
144 DWORD etherStatsStatus;
145} SRmonCounter, DEF* PSRmonCounter;
146
147//
148// Custom counter
149//
150typedef struct tagSCustomCounters {
151 ULONG Length;
152
153 ULONGLONG ullTsrAllOK;
154
155 ULONGLONG ullRsr11M;
156 ULONGLONG ullRsr5M;
157 ULONGLONG ullRsr2M;
158 ULONGLONG ullRsr1M;
159
160 ULONGLONG ullRsr11MCRCOk;
161 ULONGLONG ullRsr5MCRCOk;
162 ULONGLONG ullRsr2MCRCOk;
163 ULONGLONG ullRsr1MCRCOk;
164
165 ULONGLONG ullRsr54M;
166 ULONGLONG ullRsr48M;
167 ULONGLONG ullRsr36M;
168 ULONGLONG ullRsr24M;
169 ULONGLONG ullRsr18M;
170 ULONGLONG ullRsr12M;
171 ULONGLONG ullRsr9M;
172 ULONGLONG ullRsr6M;
173
174 ULONGLONG ullRsr54MCRCOk;
175 ULONGLONG ullRsr48MCRCOk;
176 ULONGLONG ullRsr36MCRCOk;
177 ULONGLONG ullRsr24MCRCOk;
178 ULONGLONG ullRsr18MCRCOk;
179 ULONGLONG ullRsr12MCRCOk;
180 ULONGLONG ullRsr9MCRCOk;
181 ULONGLONG ullRsr6MCRCOk;
182
183} SCustomCounters, DEF* PSCustomCounters;
184
185
186//
187// Custom counter
188//
189typedef struct tagSISRCounters {
190 ULONG Length;
191
192 DWORD dwIsrTx0OK;
193 DWORD dwIsrAC0TxOK;
194 DWORD dwIsrBeaconTxOK;
195 DWORD dwIsrRx0OK;
196 DWORD dwIsrTBTTInt;
197 DWORD dwIsrSTIMERInt;
198 DWORD dwIsrWatchDog;
199 DWORD dwIsrUnrecoverableError;
200 DWORD dwIsrSoftInterrupt;
201 DWORD dwIsrMIBNearfull;
202 DWORD dwIsrRxNoBuf;
203
204 DWORD dwIsrUnknown; // unknown interrupt count
205
206 DWORD dwIsrRx1OK;
207 DWORD dwIsrATIMTxOK;
208 DWORD dwIsrSYNCTxOK;
209 DWORD dwIsrCFPEnd;
210 DWORD dwIsrATIMEnd;
211 DWORD dwIsrSYNCFlushOK;
212 DWORD dwIsrSTIMER1Int;
213 /////////////////////////////////////
214} SISRCounters, DEF* PSISRCounters;
215
216
217// Value in the etherStatsStatus entry
218#define VALID 1 //
219#define CREATE_REQUEST 2 //
220#define UNDER_CREATION 3 //
221#define INVALID 4 //
222
223//#define MAX_RATE 12
224//
225// statistic counter
226//
227typedef struct tagSStatCounter {
228 //
229 // ISR status count
230 //
231
232
233 // RSR status count
234 //
235 DWORD dwRsrFrmAlgnErr;
236 DWORD dwRsrErr;
237 DWORD dwRsrCRCErr;
238 DWORD dwRsrCRCOk;
239 DWORD dwRsrBSSIDOk;
240 DWORD dwRsrADDROk;
241 DWORD dwRsrBCNSSIDOk;
242 DWORD dwRsrLENErr;
243 DWORD dwRsrTYPErr;
244
245 DWORD dwNewRsrDECRYPTOK;
246 DWORD dwNewRsrCFP;
247 DWORD dwNewRsrUTSF;
248 DWORD dwNewRsrHITAID;
249 DWORD dwNewRsrHITAID0;
250
251 DWORD dwRsrLong;
252 DWORD dwRsrRunt;
253
254 DWORD dwRsrRxControl;
255 DWORD dwRsrRxData;
256 DWORD dwRsrRxManage;
257
258 DWORD dwRsrRxPacket;
259 DWORD dwRsrRxOctet;
260 DWORD dwRsrBroadcast;
261 DWORD dwRsrMulticast;
262 DWORD dwRsrDirected;
263 // 64-bit OID
264 ULONGLONG ullRsrOK;
265
266 // for some optional OIDs (64 bits) and DMI support
267 ULONGLONG ullRxBroadcastBytes;
268 ULONGLONG ullRxMulticastBytes;
269 ULONGLONG ullRxDirectedBytes;
270 ULONGLONG ullRxBroadcastFrames;
271 ULONGLONG ullRxMulticastFrames;
272 ULONGLONG ullRxDirectedFrames;
273
274 DWORD dwRsrRxFragment;
275 DWORD dwRsrRxFrmLen64;
276 DWORD dwRsrRxFrmLen65_127;
277 DWORD dwRsrRxFrmLen128_255;
278 DWORD dwRsrRxFrmLen256_511;
279 DWORD dwRsrRxFrmLen512_1023;
280 DWORD dwRsrRxFrmLen1024_1518;
281
282 // TSR status count
283 //
284 DWORD dwTsrTotalRetry[TYPE_MAXTD]; // total collision retry count
285 DWORD dwTsrOnceRetry[TYPE_MAXTD]; // this packet only occur one collision
286 DWORD dwTsrMoreThanOnceRetry[TYPE_MAXTD]; // this packet occur more than one collision
287 DWORD dwTsrRetry[TYPE_MAXTD]; // this packet has ever occur collision,
288 // that is (dwTsrOnceCollision0 + dwTsrMoreThanOnceCollision0)
289 DWORD dwTsrACKData[TYPE_MAXTD];
290 DWORD dwTsrErr[TYPE_MAXTD];
291 DWORD dwAllTsrOK[TYPE_MAXTD];
292 DWORD dwTsrRetryTimeout[TYPE_MAXTD];
293 DWORD dwTsrTransmitTimeout[TYPE_MAXTD];
294
295 DWORD dwTsrTxPacket[TYPE_MAXTD];
296 DWORD dwTsrTxOctet[TYPE_MAXTD];
297 DWORD dwTsrBroadcast[TYPE_MAXTD];
298 DWORD dwTsrMulticast[TYPE_MAXTD];
299 DWORD dwTsrDirected[TYPE_MAXTD];
300
301 // RD/TD count
302 DWORD dwCntRxFrmLength;
303 DWORD dwCntTxBufLength;
304
305 BYTE abyCntRxPattern[16];
306 BYTE abyCntTxPattern[16];
307
308
309
310 // Software check....
311 DWORD dwCntRxDataErr; // rx buffer data software compare CRC err count
312 DWORD dwCntDecryptErr; // rx buffer data software compare CRC err count
313 DWORD dwCntRxICVErr; // rx buffer data software compare CRC err count
314 UINT idxRxErrorDesc[TYPE_MAXRD]; // index for rx data error RD
315
316 // 64-bit OID
317 ULONGLONG ullTsrOK[TYPE_MAXTD];
318
319 // for some optional OIDs (64 bits) and DMI support
320 ULONGLONG ullTxBroadcastFrames[TYPE_MAXTD];
321 ULONGLONG ullTxMulticastFrames[TYPE_MAXTD];
322 ULONGLONG ullTxDirectedFrames[TYPE_MAXTD];
323 ULONGLONG ullTxBroadcastBytes[TYPE_MAXTD];
324 ULONGLONG ullTxMulticastBytes[TYPE_MAXTD];
325 ULONGLONG ullTxDirectedBytes[TYPE_MAXTD];
326
327// DWORD dwTxRetryCount[8];
328 //
329 // ISR status count
330 //
331 SISRCounters ISRStat;
332
333 SCustomCounters CustomStat;
334
335 #ifdef Calcu_LinkQual
336 //Tx count:
337 ULONG TxNoRetryOkCount; //success tx no retry !
338 ULONG TxRetryOkCount; //sucess tx but retry !
339 ULONG TxFailCount; //fail tx ?
340 //Rx count:
341 ULONG RxOkCnt; //sucess rx !
342 ULONG RxFcsErrCnt; //fail rx ?
343 //statistic
344 ULONG SignalStren;
345 ULONG LinkQuality;
346 #endif
347} SStatCounter, DEF* PSStatCounter;
348
349/*--------------------- Export Classes ----------------------------*/
350
351/*--------------------- Export Variables --------------------------*/
352
353/*--------------------- Export Functions --------------------------*/
354#ifdef __cplusplus
355extern "C" { /* Assume C declarations for C++ */
356#endif /* __cplusplus */
357
358
359void STAvClearAllCounter(PSStatCounter pStatistic);
360
361void STAvUpdateIsrStatCounter(PSStatCounter pStatistic, DWORD dwIsr);
362
363void STAvUpdateRDStatCounter(PSStatCounter pStatistic,
364 BYTE byRSR, BYTE byNewRSR, BYTE byRxRate,
365 PBYTE pbyBuffer, UINT cbFrameLength);
366
367void STAvUpdateRDStatCounterEx(PSStatCounter pStatistic,
368 BYTE byRSR, BYTE byNewRsr, BYTE byRxRate,
369 PBYTE pbyBuffer, UINT cbFrameLength);
370
371void STAvUpdateTDStatCounter(PSStatCounter pStatistic,
372 BYTE byTSR0, BYTE byTSR1,
373 PBYTE pbyBuffer, UINT cbFrameLength, UINT uIdx );
374
375void STAvUpdateTDStatCounterEx(
376 PSStatCounter pStatistic,
377 PBYTE pbyBuffer,
378 DWORD cbFrameLength
379 );
380
381void STAvUpdate802_11Counter(
382 PSDot11Counters p802_11Counter,
383 PSStatCounter pStatistic,
384 DWORD dwCounter
385 );
386
387void STAvClear802_11Counter(PSDot11Counters p802_11Counter);
388
389#ifdef __cplusplus
390} /* End of extern "C" { */
391#endif /* __cplusplus */
392
393
394
395
396#endif // __MIB_H__
397
398
399
diff --git a/drivers/staging/vt6655/michael.c b/drivers/staging/vt6655/michael.c
new file mode 100644
index 000000000000..7bda4c19e903
--- /dev/null
+++ b/drivers/staging/vt6655/michael.c
@@ -0,0 +1,188 @@
1/*
2 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
3 * All rights reserved.
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 *
20 * File: michael.cpp
21 *
22 * Purpose: The implementation of LIST data structure.
23 *
24 * Author: Kyle Hsu
25 *
26 * Date: Sep 4, 2002
27 *
28 * Functions:
29 * s_dwGetUINT32 - Convert from BYTE[] to DWORD in a portable way
30 * s_vPutUINT32 - Convert from DWORD to BYTE[] in a portable way
31 * s_vClear - Reset the state to the empty message.
32 * s_vSetKey - Set the key.
33 * MIC_vInit - Set the key.
34 * s_vAppendByte - Append the byte to our word-sized buffer.
35 * MIC_vAppend - call s_vAppendByte.
36 * MIC_vGetMIC - Append the minimum padding and call s_vAppendByte.
37 *
38 * Revision History:
39 *
40 */
41
42#if !defined(__TMACRO_H__)
43#include "tmacro.h"
44#endif
45#if !defined(__TBIT_H__)
46#include "tbit.h"
47#endif
48#if !defined(__MICHAEL_H__)
49#include "michael.h"
50#endif
51
52/*--------------------- Static Definitions -------------------------*/
53
54/*--------------------- Static Variables --------------------------*/
55
56/*--------------------- Static Functions --------------------------*/
57/*
58static DWORD s_dwGetUINT32(BYTE * p); // Get DWORD from 4 bytes LSByte first
59static VOID s_vPutUINT32(BYTE* p, DWORD val); // Put DWORD into 4 bytes LSByte first
60*/
61static VOID s_vClear(void); // Clear the internal message,
62 // resets the object to the state just after construction.
63static VOID s_vSetKey(DWORD dwK0, DWORD dwK1);
64static VOID s_vAppendByte(BYTE b); // Add a single byte to the internal message
65
66/*--------------------- Export Variables --------------------------*/
67static DWORD L, R; // Current state
68
69static DWORD K0, K1; // Key
70static DWORD M; // Message accumulator (single word)
71static UINT nBytesInM; // # bytes in M
72
73/*--------------------- Export Functions --------------------------*/
74
75/*
76static DWORD s_dwGetUINT32 (BYTE * p)
77// Convert from BYTE[] to DWORD in a portable way
78{
79 DWORD res = 0;
80 UINT i;
81 for(i=0; i<4; i++ )
82 {
83 res |= (*p++) << (8*i);
84 }
85 return res;
86}
87
88static VOID s_vPutUINT32 (BYTE* p, DWORD val)
89// Convert from DWORD to BYTE[] in a portable way
90{
91 UINT i;
92 for(i=0; i<4; i++ )
93 {
94 *p++ = (BYTE) (val & 0xff);
95 val >>= 8;
96 }
97}
98*/
99
100static VOID s_vClear (void)
101{
102 // Reset the state to the empty message.
103 L = K0;
104 R = K1;
105 nBytesInM = 0;
106 M = 0;
107}
108
109static VOID s_vSetKey (DWORD dwK0, DWORD dwK1)
110{
111 // Set the key
112 K0 = dwK0;
113 K1 = dwK1;
114 // and reset the message
115 s_vClear();
116}
117
118static VOID s_vAppendByte (BYTE b)
119{
120 // Append the byte to our word-sized buffer
121 M |= b << (8*nBytesInM);
122 nBytesInM++;
123 // Process the word if it is full.
124 if( nBytesInM >= 4 )
125 {
126 L ^= M;
127 R ^= ROL32( L, 17 );
128 L += R;
129 R ^= ((L & 0xff00ff00) >> 8) | ((L & 0x00ff00ff) << 8);
130 L += R;
131 R ^= ROL32( L, 3 );
132 L += R;
133 R ^= ROR32( L, 2 );
134 L += R;
135 // Clear the buffer
136 M = 0;
137 nBytesInM = 0;
138 }
139}
140
141VOID MIC_vInit (DWORD dwK0, DWORD dwK1)
142{
143 // Set the key
144 s_vSetKey(dwK0, dwK1);
145}
146
147
148VOID MIC_vUnInit (void)
149{
150 // Wipe the key material
151 K0 = 0;
152 K1 = 0;
153
154 // And the other fields as well.
155 //Note that this sets (L,R) to (K0,K1) which is just fine.
156 s_vClear();
157}
158
159VOID MIC_vAppend (PBYTE src, UINT nBytes)
160{
161 // This is simple
162 while (nBytes > 0)
163 {
164 s_vAppendByte(*src++);
165 nBytes--;
166 }
167}
168
169VOID MIC_vGetMIC (PDWORD pdwL, PDWORD pdwR)
170{
171 // Append the minimum padding
172 s_vAppendByte(0x5a);
173 s_vAppendByte(0);
174 s_vAppendByte(0);
175 s_vAppendByte(0);
176 s_vAppendByte(0);
177 // and then zeroes until the length is a multiple of 4
178 while( nBytesInM != 0 )
179 {
180 s_vAppendByte(0);
181 }
182 // The s_vAppendByte function has already computed the result.
183 *pdwL = L;
184 *pdwR = R;
185 // Reset to the empty message.
186 s_vClear();
187}
188
diff --git a/drivers/staging/vt6655/michael.h b/drivers/staging/vt6655/michael.h
new file mode 100644
index 000000000000..62a24a6083aa
--- /dev/null
+++ b/drivers/staging/vt6655/michael.h
@@ -0,0 +1,62 @@
1/*
2 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
3 * All rights reserved.
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 *
20 * File: Michael.h
21 *
22 * Purpose: Reference implementation for Michael
23 * written by Niels Ferguson
24 *
25 * Author: Kyle Hsu
26 *
27 * Date: Jan 2, 2003
28 *
29 */
30
31
32#ifndef __MICHAEL_H__
33#define __MICHAEL_H__
34
35#if !defined(__UMEM_H__)
36#include "umem.h"
37#endif
38/*--------------------- Export Definitions -------------------------*/
39
40/*--------------------- Export Types ------------------------------*/
41
42VOID MIC_vInit(DWORD dwK0, DWORD dwK1);
43
44VOID MIC_vUnInit(void);
45
46// Append bytes to the message to be MICed
47VOID MIC_vAppend(PBYTE src, UINT nBytes);
48
49// Get the MIC result. Destination should accept 8 bytes of result.
50// This also resets the message to empty.
51VOID MIC_vGetMIC(PDWORD pdwL, PDWORD pdwR);
52
53/*--------------------- Export Macros ------------------------------*/
54
55// Rotation functions on 32 bit values
56#define ROL32( A, n ) \
57 ( ((A) << (n)) | ( ((A)>>(32-(n))) & ( (1UL << (n)) - 1 ) ) )
58#define ROR32( A, n ) ROL32( (A), 32-(n) )
59
60#endif //__MICHAEL_H__
61
62
diff --git a/drivers/staging/vt6655/power.c b/drivers/staging/vt6655/power.c
new file mode 100644
index 000000000000..edd8336712a2
--- /dev/null
+++ b/drivers/staging/vt6655/power.c
@@ -0,0 +1,441 @@
1/*
2 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
3 * All rights reserved.
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * File: power.c
20 *
21 * Purpose: Handles 802.11 power managment functions
22 *
23 * Author: Lyndon Chen
24 *
25 * Date: July 17, 2002
26 *
27 * Functions:
28 * PSvEnablePowerSaving - Enable Power Saving Mode
29 * PSvDiasblePowerSaving - Disable Power Saving Mode
30 * PSbConsiderPowerDown - Decide if we can Power Down
31 * PSvSendPSPOLL - Send PS-POLL packet
32 * PSbSendNullPacket - Send Null packet
33 * PSbIsNextTBTTWakeUp - Decide if we need to wake up at next Beacon
34 *
35 * Revision History:
36 *
37 */
38
39
40
41#if !defined(__TTYPE_H__)
42#include "ttype.h"
43#endif
44#if !defined(__TBIT_H__)
45#include "tbit.h"
46#endif
47#if !defined(__MAC_H__)
48#include "mac.h"
49#endif
50#if !defined(__DEVICE_H__)
51#include "device.h"
52#endif
53#if !defined(__WMGR_H__)
54#include "wmgr.h"
55#endif
56#if !defined(__POWER_H__)
57#include "power.h"
58#endif
59#if !defined(__WCMD_H__)
60#include "wcmd.h"
61#endif
62#if !defined(__TBIT_H__)
63#include "tbit.h"
64#endif
65#if !defined(__UMEM_H__)
66#include "umem.h"
67#endif
68#if !defined(__RXTX_H__)
69#include "rxtx.h"
70#endif
71#if !defined(__CARD_H__)
72#include "card.h"
73#endif
74
75
76
77
78/*--------------------- Static Definitions -------------------------*/
79
80
81
82
83/*--------------------- Static Classes ----------------------------*/
84
85/*--------------------- Static Variables --------------------------*/
86static int msglevel =MSG_LEVEL_INFO;
87/*--------------------- Static Functions --------------------------*/
88
89
90/*--------------------- Export Variables --------------------------*/
91
92
93/*--------------------- Export Functions --------------------------*/
94
95/*+
96 *
97 * Routine Description:
98 * Enable hw power saving functions
99 *
100 * Return Value:
101 * None.
102 *
103-*/
104
105
106VOID
107PSvEnablePowerSaving(
108 IN HANDLE hDeviceContext,
109 IN WORD wListenInterval
110 )
111{
112 PSDevice pDevice = (PSDevice)hDeviceContext;
113 PSMgmtObject pMgmt = pDevice->pMgmt;
114 WORD wAID = pMgmt->wCurrAID | BIT14 | BIT15;
115
116 // set period of power up before TBTT
117 VNSvOutPortW(pDevice->PortOffset + MAC_REG_PWBT, C_PWBT);
118 if (pDevice->eOPMode != OP_MODE_ADHOC) {
119 // set AID
120 VNSvOutPortW(pDevice->PortOffset + MAC_REG_AIDATIM, wAID);
121 } else {
122 // set ATIM Window
123 MACvWriteATIMW(pDevice->PortOffset, pMgmt->wCurrATIMWindow);
124 }
125 // Set AutoSleep
126 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_PSCFG, PSCFG_AUTOSLEEP);
127 // Set HWUTSF
128 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_TFTCTL, TFTCTL_HWUTSF);
129
130 if (wListenInterval >= 2) {
131 // clear always listen beacon
132 MACvRegBitsOff(pDevice->PortOffset, MAC_REG_PSCTL, PSCTL_ALBCN);
133 //pDevice->wCFG &= ~CFG_ALB;
134 // first time set listen next beacon
135 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_PSCTL, PSCTL_LNBCN);
136 pMgmt->wCountToWakeUp = wListenInterval;
137 }
138 else {
139 // always listen beacon
140 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_PSCTL, PSCTL_ALBCN);
141 //pDevice->wCFG |= CFG_ALB;
142 pMgmt->wCountToWakeUp = 0;
143 }
144
145 // enable power saving hw function
146 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_PSCTL, PSCTL_PSEN);
147 pDevice->bEnablePSMode = TRUE;
148
149 if (pDevice->eOPMode == OP_MODE_ADHOC) {
150// bMgrPrepareBeaconToSend((HANDLE)pDevice, pMgmt);
151 }
152 // We don't send null pkt in ad hoc mode since beacon will handle this.
153 else if (pDevice->eOPMode == OP_MODE_INFRASTRUCTURE) {
154 PSbSendNullPacket(pDevice);
155 }
156 pDevice->bPWBitOn = TRUE;
157 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "PS:Power Saving Mode Enable... \n");
158 return;
159}
160
161
162
163
164
165
166/*+
167 *
168 * Routine Description:
169 * Disable hw power saving functions
170 *
171 * Return Value:
172 * None.
173 *
174-*/
175
176VOID
177PSvDisablePowerSaving(
178 IN HANDLE hDeviceContext
179 )
180{
181 PSDevice pDevice = (PSDevice)hDeviceContext;
182// PSMgmtObject pMgmt = pDevice->pMgmt;
183
184 // disable power saving hw function
185 MACbPSWakeup(pDevice->PortOffset);
186 //clear AutoSleep
187 MACvRegBitsOff(pDevice->PortOffset, MAC_REG_PSCFG, PSCFG_AUTOSLEEP);
188 //clear HWUTSF
189 MACvRegBitsOff(pDevice->PortOffset, MAC_REG_TFTCTL, TFTCTL_HWUTSF);
190 // set always listen beacon
191 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_PSCTL, PSCTL_ALBCN);
192
193 pDevice->bEnablePSMode = FALSE;
194
195 if (pDevice->eOPMode == OP_MODE_INFRASTRUCTURE) {
196 PSbSendNullPacket(pDevice);
197 }
198 pDevice->bPWBitOn = FALSE;
199 return;
200}
201
202
203/*+
204 *
205 * Routine Description:
206 * Consider to power down when no more packets to tx or rx.
207 *
208 * Return Value:
209 * TRUE, if power down success
210 * FALSE, if fail
211-*/
212
213
214BOOL
215PSbConsiderPowerDown(
216 IN HANDLE hDeviceContext,
217 IN BOOL bCheckRxDMA,
218 IN BOOL bCheckCountToWakeUp
219 )
220{
221 PSDevice pDevice = (PSDevice)hDeviceContext;
222 PSMgmtObject pMgmt = pDevice->pMgmt;
223 UINT uIdx;
224
225 // check if already in Doze mode
226 if (MACbIsRegBitsOn(pDevice->PortOffset, MAC_REG_PSCTL, PSCTL_PS))
227 return TRUE;
228
229 if (pMgmt->eCurrMode != WMAC_MODE_IBSS_STA) {
230 // check if in TIM wake period
231 if (pMgmt->bInTIMWake)
232 return FALSE;
233 }
234
235 // check scan state
236 if (pDevice->bCmdRunning)
237 return FALSE;
238
239 // Froce PSEN on
240 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_PSCTL, PSCTL_PSEN);
241
242 // check if all TD are empty,
243 for (uIdx = 0; uIdx < TYPE_MAXTD; uIdx ++) {
244 if (pDevice->iTDUsed[uIdx] != 0)
245 return FALSE;
246 }
247
248 // check if rx isr is clear
249 if (bCheckRxDMA &&
250 ((pDevice->dwIsr& ISR_RXDMA0) != 0) &&
251 ((pDevice->dwIsr & ISR_RXDMA1) != 0)){
252 return FALSE;
253 };
254
255 if (pMgmt->eCurrMode != WMAC_MODE_IBSS_STA) {
256 if (bCheckCountToWakeUp &&
257 (pMgmt->wCountToWakeUp == 0 || pMgmt->wCountToWakeUp == 1)) {
258 return FALSE;
259 }
260 }
261
262 // no Tx, no Rx isr, now go to Doze
263 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_PSCTL, PSCTL_GO2DOZE);
264 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Go to Doze ZZZZZZZZZZZZZZZ\n");
265 return TRUE;
266}
267
268
269
270/*+
271 *
272 * Routine Description:
273 * Send PS-POLL packet
274 *
275 * Return Value:
276 * None.
277 *
278-*/
279
280
281
282VOID
283PSvSendPSPOLL(
284 IN HANDLE hDeviceContext
285 )
286{
287 PSDevice pDevice = (PSDevice)hDeviceContext;
288 PSMgmtObject pMgmt = pDevice->pMgmt;
289 PSTxMgmtPacket pTxPacket = NULL;
290
291
292 memset(pMgmt->pbyPSPacketPool, 0, sizeof(STxMgmtPacket) + WLAN_HDR_ADDR2_LEN);
293 pTxPacket = (PSTxMgmtPacket)pMgmt->pbyPSPacketPool;
294 pTxPacket->p80211Header = (PUWLAN_80211HDR)((PBYTE)pTxPacket + sizeof(STxMgmtPacket));
295 pTxPacket->p80211Header->sA2.wFrameCtl = cpu_to_le16(
296 (
297 WLAN_SET_FC_FTYPE(WLAN_TYPE_CTL) |
298 WLAN_SET_FC_FSTYPE(WLAN_FSTYPE_PSPOLL) |
299 WLAN_SET_FC_PWRMGT(0)
300 ));
301 pTxPacket->p80211Header->sA2.wDurationID = pMgmt->wCurrAID | BIT14 | BIT15;
302 memcpy(pTxPacket->p80211Header->sA2.abyAddr1, pMgmt->abyCurrBSSID, WLAN_ADDR_LEN);
303 memcpy(pTxPacket->p80211Header->sA2.abyAddr2, pMgmt->abyMACAddr, WLAN_ADDR_LEN);
304 pTxPacket->cbMPDULen = WLAN_HDR_ADDR2_LEN;
305 pTxPacket->cbPayloadLen = 0;
306 // send the frame
307 if (csMgmt_xmit(pDevice, pTxPacket) != CMD_STATUS_PENDING) {
308 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Send PS-Poll packet failed..\n");
309 }
310 else {
311// DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Send PS-Poll packet success..\n");
312 };
313
314 return;
315}
316
317
318
319/*+
320 *
321 * Routine Description:
322 * Send NULL packet to AP for notification power state of STA
323 *
324 * Return Value:
325 * None.
326 *
327-*/
328BOOL
329PSbSendNullPacket(
330 IN HANDLE hDeviceContext
331 )
332{
333 PSDevice pDevice = (PSDevice)hDeviceContext;
334 PSTxMgmtPacket pTxPacket = NULL;
335 PSMgmtObject pMgmt = pDevice->pMgmt;
336 UINT uIdx;
337
338
339 if (pDevice->bLinkPass == FALSE) {
340 return FALSE;
341 }
342 #ifdef TxInSleep
343 if ((pDevice->bEnablePSMode == FALSE) &&
344 (pDevice->fTxDataInSleep == FALSE)){
345 return FALSE;
346 }
347#else
348 if (pDevice->bEnablePSMode == FALSE) {
349 return FALSE;
350 }
351#endif
352 if (pDevice->bEnablePSMode) {
353 for (uIdx = 0; uIdx < TYPE_MAXTD; uIdx ++) {
354 if (pDevice->iTDUsed[uIdx] != 0)
355 return FALSE;
356 }
357 }
358
359 memset(pMgmt->pbyPSPacketPool, 0, sizeof(STxMgmtPacket) + WLAN_NULLDATA_FR_MAXLEN);
360 pTxPacket = (PSTxMgmtPacket)pMgmt->pbyPSPacketPool;
361 pTxPacket->p80211Header = (PUWLAN_80211HDR)((PBYTE)pTxPacket + sizeof(STxMgmtPacket));
362
363 if (pDevice->bEnablePSMode) {
364
365 pTxPacket->p80211Header->sA3.wFrameCtl = cpu_to_le16(
366 (
367 WLAN_SET_FC_FTYPE(WLAN_TYPE_DATA) |
368 WLAN_SET_FC_FSTYPE(WLAN_FSTYPE_NULL) |
369 WLAN_SET_FC_PWRMGT(1)
370 ));
371 }
372 else {
373 pTxPacket->p80211Header->sA3.wFrameCtl = cpu_to_le16(
374 (
375 WLAN_SET_FC_FTYPE(WLAN_TYPE_DATA) |
376 WLAN_SET_FC_FSTYPE(WLAN_FSTYPE_NULL) |
377 WLAN_SET_FC_PWRMGT(0)
378 ));
379 }
380
381 if(pMgmt->eCurrMode != WMAC_MODE_IBSS_STA) {
382 pTxPacket->p80211Header->sA3.wFrameCtl |= cpu_to_le16((WORD)WLAN_SET_FC_TODS(1));
383 }
384
385 memcpy(pTxPacket->p80211Header->sA3.abyAddr1, pMgmt->abyCurrBSSID, WLAN_ADDR_LEN);
386 memcpy(pTxPacket->p80211Header->sA3.abyAddr2, pMgmt->abyMACAddr, WLAN_ADDR_LEN);
387 memcpy(pTxPacket->p80211Header->sA3.abyAddr3, pMgmt->abyCurrBSSID, WLAN_BSSID_LEN);
388 pTxPacket->cbMPDULen = WLAN_HDR_ADDR3_LEN;
389 pTxPacket->cbPayloadLen = 0;
390 // send the frame
391 if (csMgmt_xmit(pDevice, pTxPacket) != CMD_STATUS_PENDING) {
392 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Send Null Packet failed !\n");
393 return FALSE;
394 }
395 else {
396
397// DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Send Null Packet success....\n");
398 }
399
400
401 return TRUE ;
402}
403
404/*+
405 *
406 * Routine Description:
407 * Check if Next TBTT must wake up
408 *
409 * Return Value:
410 * None.
411 *
412-*/
413
414BOOL
415PSbIsNextTBTTWakeUp(
416 IN HANDLE hDeviceContext
417 )
418{
419
420 PSDevice pDevice = (PSDevice)hDeviceContext;
421 PSMgmtObject pMgmt = pDevice->pMgmt;
422 BOOL bWakeUp = FALSE;
423
424 if (pMgmt->wListenInterval >= 2) {
425 if (pMgmt->wCountToWakeUp == 0) {
426 pMgmt->wCountToWakeUp = pMgmt->wListenInterval;
427 }
428
429 pMgmt->wCountToWakeUp --;
430
431 if (pMgmt->wCountToWakeUp == 1) {
432 // Turn on wake up to listen next beacon
433 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_PSCTL, PSCTL_LNBCN);
434 bWakeUp = TRUE;
435 }
436
437 }
438
439 return bWakeUp;
440}
441
diff --git a/drivers/staging/vt6655/power.h b/drivers/staging/vt6655/power.h
new file mode 100644
index 000000000000..a01e7e9aaf67
--- /dev/null
+++ b/drivers/staging/vt6655/power.h
@@ -0,0 +1,85 @@
1/*
2 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
3 * All rights reserved.
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 *
20 * File: power.h
21 *
22 * Purpose: Handles 802.11 power managment functions
23 *
24 * Author: Lyndon Chen
25 *
26 * Date: July 17, 2002
27 *
28 */
29
30#ifndef __POWER_H__
31#define __POWER_H__
32
33
34/*--------------------- Export Definitions -------------------------*/
35#define C_PWBT 1000 // micro sec. power up before TBTT
36#define PS_FAST_INTERVAL 1 // Fast power saving listen interval
37#define PS_MAX_INTERVAL 4 // MAX power saving listen interval
38
39/*--------------------- Export Classes ----------------------------*/
40
41/*--------------------- Export Variables --------------------------*/
42
43
44/*--------------------- Export Types ------------------------------*/
45
46
47/*--------------------- Export Functions --------------------------*/
48
49// IN PSDevice pDevice
50// IN PSDevice hDeviceContext
51
52BOOL
53PSbConsiderPowerDown(
54 IN HANDLE hDeviceContext,
55 IN BOOL bCheckRxDMA,
56 IN BOOL bCheckCountToWakeUp
57 );
58
59VOID
60PSvDisablePowerSaving(
61 IN HANDLE hDeviceContext
62 );
63
64VOID
65PSvEnablePowerSaving(
66 IN HANDLE hDeviceContext,
67 IN WORD wListenInterval
68 );
69
70VOID
71PSvSendPSPOLL(
72 IN HANDLE hDeviceContext
73 );
74
75BOOL
76PSbSendNullPacket(
77 IN HANDLE hDeviceContext
78 );
79
80BOOL
81PSbIsNextTBTTWakeUp(
82 IN HANDLE hDeviceContext
83 );
84
85#endif //__POWER_H__
diff --git a/drivers/staging/vt6655/rc4.c b/drivers/staging/vt6655/rc4.c
new file mode 100644
index 000000000000..0345e3247f4d
--- /dev/null
+++ b/drivers/staging/vt6655/rc4.c
@@ -0,0 +1,86 @@
1/*
2 * File: rc4.c
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17 *
18 * Purpose:
19 *
20 * Functions:
21 *
22 * Revision History:
23 *
24 * Author: Kyle Hsu
25 *
26 * Date: Sep 4, 2002
27 *
28 */
29
30#if !defined(__RC4_H__)
31#include "rc4.h"
32#endif
33
34VOID rc4_init(PRC4Ext pRC4, PBYTE pbyKey, UINT cbKey_len)
35{
36 UINT ust1, ust2;
37 UINT keyindex;
38 UINT stateindex;
39 PBYTE pbyst;
40 UINT idx;
41
42 pbyst = pRC4->abystate;
43 pRC4->ux = 0;
44 pRC4->uy = 0;
45 for (idx = 0; idx < 256; idx++)
46 pbyst[idx] = (BYTE)idx;
47 keyindex = 0;
48 stateindex = 0;
49 for (idx = 0; idx < 256; idx++) {
50 ust1 = pbyst[idx];
51 stateindex = (stateindex + pbyKey[keyindex] + ust1) & 0xff;
52 ust2 = pbyst[stateindex];
53 pbyst[stateindex] = (BYTE)ust1;
54 pbyst[idx] = (BYTE)ust2;
55 if (++keyindex >= cbKey_len)
56 keyindex = 0;
57 }
58}
59
60UINT rc4_byte(PRC4Ext pRC4)
61{
62 UINT ux;
63 UINT uy;
64 UINT ustx, usty;
65 PBYTE pbyst;
66
67 pbyst = pRC4->abystate;
68 ux = (pRC4->ux + 1) & 0xff;
69 ustx = pbyst[ux];
70 uy = (ustx + pRC4->uy) & 0xff;
71 usty = pbyst[uy];
72 pRC4->ux = ux;
73 pRC4->uy = uy;
74 pbyst[uy] = (BYTE)ustx;
75 pbyst[ux] = (BYTE)usty;
76
77 return pbyst[(ustx + usty) & 0xff];
78}
79
80VOID rc4_encrypt(PRC4Ext pRC4, PBYTE pbyDest,
81 PBYTE pbySrc, UINT cbData_len)
82{
83 UINT ii;
84 for (ii = 0; ii < cbData_len; ii++)
85 pbyDest[ii] = (BYTE)(pbySrc[ii] ^ rc4_byte(pRC4));
86}
diff --git a/drivers/staging/vt6655/rc4.h b/drivers/staging/vt6655/rc4.h
new file mode 100644
index 000000000000..4e3ccc559c8f
--- /dev/null
+++ b/drivers/staging/vt6655/rc4.h
@@ -0,0 +1,51 @@
1/*
2 * File: rc4.h
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17 *
18 * Purpose:
19 *
20 * Functions:
21 *
22 * Revision History:
23 *
24 * Author: Kyle Hsu
25 *
26 * Date: Sep 4, 2002
27 *
28 */
29
30#ifndef __RC4_H__
31#define __RC4_H__
32
33#if !defined(__TTYPE_H__)
34#include "ttype.h"
35#endif
36
37
38
39/*--------------------- Export Definitions -------------------------*/
40/*--------------------- Export Types ------------------------------*/
41typedef struct {
42 UINT ux;
43 UINT uy;
44 BYTE abystate[256];
45} RC4Ext, DEF* PRC4Ext;
46
47VOID rc4_init(PRC4Ext pRC4, PBYTE pbyKey, UINT cbKey_len);
48UINT rc4_byte(PRC4Ext pRC4);
49void rc4_encrypt(PRC4Ext pRC4, PBYTE pbyDest, PBYTE pbySrc, UINT cbData_len);
50
51#endif //__RC4_H__
diff --git a/drivers/staging/vt6655/rf.c b/drivers/staging/vt6655/rf.c
new file mode 100644
index 000000000000..9d4e3eb7c8e5
--- /dev/null
+++ b/drivers/staging/vt6655/rf.c
@@ -0,0 +1,1283 @@
1/*
2 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
3 * All rights reserved.
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 *
20 * File: rf.c
21 *
22 * Purpose: rf function code
23 *
24 * Author: Jerry Chen
25 *
26 * Date: Feb. 19, 2004
27 *
28 * Functions:
29 * IFRFbWriteEmbeded - Embeded write RF register via MAC
30 *
31 * Revision History:
32 *
33 */
34#if !defined(__MAC_H__)
35#include "mac.h"
36#endif
37#if !defined(__SROM_H__)
38#include "srom.h"
39#endif
40#if !defined(__TBIT_H__)
41#include "tbit.h"
42#endif
43#if !defined(__RF_H__)
44#include "rf.h"
45#endif
46#if !defined(__BASEBAND_H__)
47#include "baseband.h"
48#endif
49
50/*--------------------- Static Definitions -------------------------*/
51
52//static int msglevel =MSG_LEVEL_INFO;
53
54#define BY_RF2959_REG_LEN 23 //24bits
55#define CB_RF2959_INIT_SEQ 15
56#define SWITCH_CHANNEL_DELAY_RF2959 200 //us
57#define RF2959_PWR_IDX_LEN 32
58
59#define BY_MA2825_REG_LEN 23 //24bit
60#define CB_MA2825_INIT_SEQ 13
61#define SWITCH_CHANNEL_DELAY_MA2825 200 //us
62#define MA2825_PWR_IDX_LEN 31
63
64#define BY_AL2230_REG_LEN 23 //24bit
65#define CB_AL2230_INIT_SEQ 15
66#define SWITCH_CHANNEL_DELAY_AL2230 200 //us
67#define AL2230_PWR_IDX_LEN 64
68
69
70#define BY_UW2451_REG_LEN 23
71#define CB_UW2451_INIT_SEQ 6
72#define SWITCH_CHANNEL_DELAY_UW2451 200 //us
73#define UW2451_PWR_IDX_LEN 25
74
75//{{ RobertYu: 20041118
76#define BY_MA2829_REG_LEN 23 //24bit
77#define CB_MA2829_INIT_SEQ 13
78#define SWITCH_CHANNEL_DELAY_MA2829 200 //us
79#define MA2829_PWR_IDX_LEN 64
80//}} RobertYu
81
82//{{ RobertYu:20050103
83#define BY_AL7230_REG_LEN 23 //24bit
84#define CB_AL7230_INIT_SEQ 16
85#define SWITCH_CHANNEL_DELAY_AL7230 200 //us
86#define AL7230_PWR_IDX_LEN 64
87//}} RobertYu
88
89//{{ RobertYu: 20041210
90#define BY_UW2452_REG_LEN 23
91#define CB_UW2452_INIT_SEQ 5 //RoberYu:20050113, Rev0.2 Programming Guide(remove R3, so 6-->5)
92#define SWITCH_CHANNEL_DELAY_UW2452 100 //us
93#define UW2452_PWR_IDX_LEN 64
94//}} RobertYu
95
96#define BY_VT3226_REG_LEN 23
97#define CB_VT3226_INIT_SEQ 12
98#define SWITCH_CHANNEL_DELAY_VT3226 200 //us
99#define VT3226_PWR_IDX_LEN 16
100
101/*--------------------- Static Classes ----------------------------*/
102
103/*--------------------- Static Variables --------------------------*/
104
105
106
107const DWORD dwAL2230InitTable[CB_AL2230_INIT_SEQ] = {
108 0x03F79000+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW, //
109 0x03333100+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW, //
110 0x01A00200+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW, //
111 0x00FFF300+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW, //
112 0x0005A400+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW, //
113 0x0F4DC500+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW, //
114 0x0805B600+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW, //
115 0x0146C700+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW, //
116 0x00068800+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW, //
117 0x0403B900+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW, //
118 0x00DBBA00+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW, //
119 0x00099B00+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW, //
120 0x0BDFFC00+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW,
121 0x00000D00+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW,
122 0x00580F00+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW
123 };
124
125const DWORD dwAL2230ChannelTable0[CB_MAX_CHANNEL] = {
126 0x03F79000+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 1, Tf = 2412MHz
127 0x03F79000+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 2, Tf = 2417MHz
128 0x03E79000+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 3, Tf = 2422MHz
129 0x03E79000+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 4, Tf = 2427MHz
130 0x03F7A000+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 5, Tf = 2432MHz
131 0x03F7A000+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 6, Tf = 2437MHz
132 0x03E7A000+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 7, Tf = 2442MHz
133 0x03E7A000+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 8, Tf = 2447MHz
134 0x03F7B000+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 9, Tf = 2452MHz
135 0x03F7B000+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 10, Tf = 2457MHz
136 0x03E7B000+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 11, Tf = 2462MHz
137 0x03E7B000+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 12, Tf = 2467MHz
138 0x03F7C000+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 13, Tf = 2472MHz
139 0x03E7C000+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW // channel = 14, Tf = 2412M
140 };
141
142const DWORD dwAL2230ChannelTable1[CB_MAX_CHANNEL] = {
143 0x03333100+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 1, Tf = 2412MHz
144 0x0B333100+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 2, Tf = 2417MHz
145 0x03333100+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 3, Tf = 2422MHz
146 0x0B333100+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 4, Tf = 2427MHz
147 0x03333100+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 5, Tf = 2432MHz
148 0x0B333100+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 6, Tf = 2437MHz
149 0x03333100+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 7, Tf = 2442MHz
150 0x0B333100+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 8, Tf = 2447MHz
151 0x03333100+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 9, Tf = 2452MHz
152 0x0B333100+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 10, Tf = 2457MHz
153 0x03333100+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 11, Tf = 2462MHz
154 0x0B333100+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 12, Tf = 2467MHz
155 0x03333100+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 13, Tf = 2472MHz
156 0x06666100+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW // channel = 14, Tf = 2412M
157 };
158
159DWORD dwAL2230PowerTable[AL2230_PWR_IDX_LEN] = {
160 0x04040900+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW,
161 0x04041900+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW,
162 0x04042900+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW,
163 0x04043900+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW,
164 0x04044900+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW,
165 0x04045900+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW,
166 0x04046900+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW,
167 0x04047900+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW,
168 0x04048900+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW,
169 0x04049900+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW,
170 0x0404A900+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW,
171 0x0404B900+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW,
172 0x0404C900+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW,
173 0x0404D900+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW,
174 0x0404E900+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW,
175 0x0404F900+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW,
176 0x04050900+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW,
177 0x04051900+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW,
178 0x04052900+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW,
179 0x04053900+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW,
180 0x04054900+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW,
181 0x04055900+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW,
182 0x04056900+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW,
183 0x04057900+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW,
184 0x04058900+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW,
185 0x04059900+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW,
186 0x0405A900+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW,
187 0x0405B900+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW,
188 0x0405C900+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW,
189 0x0405D900+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW,
190 0x0405E900+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW,
191 0x0405F900+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW,
192 0x04060900+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW,
193 0x04061900+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW,
194 0x04062900+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW,
195 0x04063900+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW,
196 0x04064900+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW,
197 0x04065900+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW,
198 0x04066900+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW,
199 0x04067900+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW,
200 0x04068900+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW,
201 0x04069900+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW,
202 0x0406A900+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW,
203 0x0406B900+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW,
204 0x0406C900+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW,
205 0x0406D900+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW,
206 0x0406E900+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW,
207 0x0406F900+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW,
208 0x04070900+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW,
209 0x04071900+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW,
210 0x04072900+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW,
211 0x04073900+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW,
212 0x04074900+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW,
213 0x04075900+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW,
214 0x04076900+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW,
215 0x04077900+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW,
216 0x04078900+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW,
217 0x04079900+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW,
218 0x0407A900+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW,
219 0x0407B900+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW,
220 0x0407C900+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW,
221 0x0407D900+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW,
222 0x0407E900+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW,
223 0x0407F900+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW
224 };
225
226//{{ RobertYu:20050104
227// 40MHz reference frequency
228// Need to Pull PLLON(PE3) low when writing channel registers through 3-wire.
229const DWORD dwAL7230InitTable[CB_AL7230_INIT_SEQ] = {
230 0x00379000+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // Channel1 // Need modify for 11a
231 0x13333100+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // Channel1 // Need modify for 11a
232 0x841FF200+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // Need modify for 11a: 451FE2
233 0x3FDFA300+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // Need modify for 11a: 5FDFA3
234 0x7FD78400+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // 11b/g // Need modify for 11a
235 //0x802B4500+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // Need modify for 11a: 8D1B45
236 // RoberYu:20050113, Rev0.47 Regsiter Setting Guide
237 0x802B5500+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // Need modify for 11a: 8D1B55
238 0x56AF3600+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW,
239 0xCE020700+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // Need modify for 11a: 860207
240 0x6EBC0800+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW,
241 0x221BB900+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW,
242 0xE0000A00+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // Need modify for 11a: E0600A
243 0x08031B00+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // init 0x080B1B00 => 0x080F1B00 for 3 wire control TxGain(D10)
244 //0x00093C00+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // Need modify for 11a: 00143C
245 // RoberYu:20050113, Rev0.47 Regsiter Setting Guide
246 0x000A3C00+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // Need modify for 11a: 00143C
247 0xFFFFFD00+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW,
248 0x00000E00+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW,
249 0x1ABA8F00+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW // Need modify for 11a: 12BACF
250 };
251
252const DWORD dwAL7230InitTableAMode[CB_AL7230_INIT_SEQ] = {
253 0x0FF52000+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // Channel184 // Need modify for 11b/g
254 0x00000100+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // Channel184 // Need modify for 11b/g
255 0x451FE200+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // Need modify for 11b/g
256 0x5FDFA300+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // Need modify for 11b/g
257 0x67F78400+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // 11a // Need modify for 11b/g
258 0x853F5500+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // Need modify for 11b/g, RoberYu:20050113
259 0x56AF3600+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW,
260 0xCE020700+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // Need modify for 11b/g
261 0x6EBC0800+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW,
262 0x221BB900+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW,
263 0xE0600A00+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // Need modify for 11b/g
264 0x08031B00+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // init 0x080B1B00 => 0x080F1B00 for 3 wire control TxGain(D10)
265 0x00147C00+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // Need modify for 11b/g
266 0xFFFFFD00+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW,
267 0x00000E00+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW,
268 0x12BACF00+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW // Need modify for 11b/g
269 };
270
271
272const DWORD dwAL7230ChannelTable0[CB_MAX_CHANNEL] = {
273 0x00379000+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 1, Tf = 2412MHz
274 0x00379000+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 2, Tf = 2417MHz
275 0x00379000+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 3, Tf = 2422MHz
276 0x00379000+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 4, Tf = 2427MHz
277 0x0037A000+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 5, Tf = 2432MHz
278 0x0037A000+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 6, Tf = 2437MHz
279 0x0037A000+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 7, Tf = 2442MHz
280 0x0037A000+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 8, Tf = 2447MHz //RobertYu: 20050218, update for APNode 0.49
281 0x0037B000+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 9, Tf = 2452MHz //RobertYu: 20050218, update for APNode 0.49
282 0x0037B000+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 10, Tf = 2457MHz //RobertYu: 20050218, update for APNode 0.49
283 0x0037B000+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 11, Tf = 2462MHz //RobertYu: 20050218, update for APNode 0.49
284 0x0037B000+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 12, Tf = 2467MHz //RobertYu: 20050218, update for APNode 0.49
285 0x0037C000+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 13, Tf = 2472MHz //RobertYu: 20050218, update for APNode 0.49
286 0x0037C000+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 14, Tf = 2484MHz
287
288 // 4.9G => Ch 183, 184, 185, 187, 188, 189, 192, 196 (Value:15 ~ 22)
289 0x0FF52000+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 183, Tf = 4915MHz (15)
290 0x0FF52000+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 184, Tf = 4920MHz (16)
291 0x0FF52000+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 185, Tf = 4925MHz (17)
292 0x0FF52000+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 187, Tf = 4935MHz (18)
293 0x0FF52000+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 188, Tf = 4940MHz (19)
294 0x0FF52000+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 189, Tf = 4945MHz (20)
295 0x0FF53000+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 192, Tf = 4960MHz (21)
296 0x0FF53000+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 196, Tf = 4980MHz (22)
297
298 // 5G => Ch 7, 8, 9, 11, 12, 16, 34, 36, 38, 40, 42, 44, 46, 48, 52, 56, 60, 64,
299 // 100, 104, 108, 112, 116, 120, 124, 128, 132, 136, 140, 149, 153, 157, 161, 165 (Value 23 ~ 56)
300
301 0x0FF54000+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 7, Tf = 5035MHz (23)
302 0x0FF54000+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 8, Tf = 5040MHz (24)
303 0x0FF54000+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 9, Tf = 5045MHz (25)
304 0x0FF54000+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 11, Tf = 5055MHz (26)
305 0x0FF54000+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 12, Tf = 5060MHz (27)
306 0x0FF55000+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 16, Tf = 5080MHz (28)
307 0x0FF56000+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 34, Tf = 5170MHz (29)
308 0x0FF56000+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 36, Tf = 5180MHz (30)
309 0x0FF57000+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 38, Tf = 5190MHz (31) //RobertYu: 20050218, update for APNode 0.49
310 0x0FF57000+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 40, Tf = 5200MHz (32)
311 0x0FF57000+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 42, Tf = 5210MHz (33)
312 0x0FF57000+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 44, Tf = 5220MHz (34)
313 0x0FF57000+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 46, Tf = 5230MHz (35)
314 0x0FF57000+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 48, Tf = 5240MHz (36)
315 0x0FF58000+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 52, Tf = 5260MHz (37)
316 0x0FF58000+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 56, Tf = 5280MHz (38)
317 0x0FF58000+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 60, Tf = 5300MHz (39)
318 0x0FF59000+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 64, Tf = 5320MHz (40)
319
320 0x0FF5C000+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 100, Tf = 5500MHz (41)
321 0x0FF5C000+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 104, Tf = 5520MHz (42)
322 0x0FF5C000+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 108, Tf = 5540MHz (43)
323 0x0FF5D000+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 112, Tf = 5560MHz (44)
324 0x0FF5D000+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 116, Tf = 5580MHz (45)
325 0x0FF5D000+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 120, Tf = 5600MHz (46)
326 0x0FF5E000+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 124, Tf = 5620MHz (47)
327 0x0FF5E000+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 128, Tf = 5640MHz (48)
328 0x0FF5E000+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 132, Tf = 5660MHz (49)
329 0x0FF5F000+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 136, Tf = 5680MHz (50)
330 0x0FF5F000+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 140, Tf = 5700MHz (51)
331 0x0FF60000+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 149, Tf = 5745MHz (52)
332 0x0FF60000+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 153, Tf = 5765MHz (53)
333 0x0FF60000+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 157, Tf = 5785MHz (54)
334 0x0FF61000+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 161, Tf = 5805MHz (55)
335 0x0FF61000+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW // channel = 165, Tf = 5825MHz (56)
336 };
337
338const DWORD dwAL7230ChannelTable1[CB_MAX_CHANNEL] = {
339 0x13333100+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 1, Tf = 2412MHz
340 0x1B333100+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 2, Tf = 2417MHz
341 0x03333100+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 3, Tf = 2422MHz
342 0x0B333100+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 4, Tf = 2427MHz
343 0x13333100+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 5, Tf = 2432MHz
344 0x1B333100+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 6, Tf = 2437MHz
345 0x03333100+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 7, Tf = 2442MHz
346 0x0B333100+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 8, Tf = 2447MHz
347 0x13333100+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 9, Tf = 2452MHz
348 0x1B333100+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 10, Tf = 2457MHz
349 0x03333100+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 11, Tf = 2462MHz
350 0x0B333100+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 12, Tf = 2467MHz
351 0x13333100+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 13, Tf = 2472MHz
352 0x06666100+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 14, Tf = 2484MHz
353
354 // 4.9G => Ch 183, 184, 185, 187, 188, 189, 192, 196 (Value:15 ~ 22)
355 0x1D555100+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 183, Tf = 4915MHz (15)
356 0x00000100+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 184, Tf = 4920MHz (16)
357 0x02AAA100+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 185, Tf = 4925MHz (17)
358 0x08000100+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 187, Tf = 4935MHz (18)
359 0x0AAAA100+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 188, Tf = 4940MHz (19)
360 0x0D555100+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 189, Tf = 4945MHz (20)
361 0x15555100+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 192, Tf = 4960MHz (21)
362 0x00000100+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 196, Tf = 4980MHz (22)
363
364 // 5G => Ch 7, 8, 9, 11, 12, 16, 34, 36, 38, 40, 42, 44, 46, 48, 52, 56, 60, 64,
365 // 100, 104, 108, 112, 116, 120, 124, 128, 132, 136, 140, 149, 153, 157, 161, 165 (Value 23 ~ 56)
366 0x1D555100+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 7, Tf = 5035MHz (23)
367 0x00000100+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 8, Tf = 5040MHz (24)
368 0x02AAA100+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 9, Tf = 5045MHz (25)
369 0x08000100+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 11, Tf = 5055MHz (26)
370 0x0AAAA100+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 12, Tf = 5060MHz (27)
371 0x15555100+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 16, Tf = 5080MHz (28)
372 0x05555100+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 34, Tf = 5170MHz (29)
373 0x0AAAA100+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 36, Tf = 5180MHz (30)
374 0x10000100+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 38, Tf = 5190MHz (31)
375 0x15555100+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 40, Tf = 5200MHz (32)
376 0x1AAAA100+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 42, Tf = 5210MHz (33)
377 0x00000100+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 44, Tf = 5220MHz (34)
378 0x05555100+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 46, Tf = 5230MHz (35)
379 0x0AAAA100+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 48, Tf = 5240MHz (36)
380 0x15555100+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 52, Tf = 5260MHz (37)
381 0x00000100+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 56, Tf = 5280MHz (38)
382 0x0AAAA100+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 60, Tf = 5300MHz (39)
383 0x15555100+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 64, Tf = 5320MHz (40)
384 0x15555100+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 100, Tf = 5500MHz (41)
385 0x00000100+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 104, Tf = 5520MHz (42)
386 0x0AAAA100+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 108, Tf = 5540MHz (43)
387 0x15555100+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 112, Tf = 5560MHz (44)
388 0x00000100+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 116, Tf = 5580MHz (45)
389 0x0AAAA100+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 120, Tf = 5600MHz (46)
390 0x15555100+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 124, Tf = 5620MHz (47)
391 0x00000100+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 128, Tf = 5640MHz (48)
392 0x0AAAA100+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 132, Tf = 5660MHz (49)
393 0x15555100+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 136, Tf = 5680MHz (50)
394 0x00000100+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 140, Tf = 5700MHz (51)
395 0x18000100+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 149, Tf = 5745MHz (52)
396 0x02AAA100+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 153, Tf = 5765MHz (53)
397 0x0D555100+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 157, Tf = 5785MHz (54)
398 0x18000100+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 161, Tf = 5805MHz (55)
399 0x02AAA100+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW // channel = 165, Tf = 5825MHz (56)
400 };
401
402const DWORD dwAL7230ChannelTable2[CB_MAX_CHANNEL] = {
403 0x7FD78400+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 1, Tf = 2412MHz
404 0x7FD78400+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 2, Tf = 2417MHz
405 0x7FD78400+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 3, Tf = 2422MHz
406 0x7FD78400+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 4, Tf = 2427MHz
407 0x7FD78400+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 5, Tf = 2432MHz
408 0x7FD78400+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 6, Tf = 2437MHz
409 0x7FD78400+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 7, Tf = 2442MHz
410 0x7FD78400+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 8, Tf = 2447MHz
411 0x7FD78400+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 9, Tf = 2452MHz
412 0x7FD78400+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 10, Tf = 2457MHz
413 0x7FD78400+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 11, Tf = 2462MHz
414 0x7FD78400+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 12, Tf = 2467MHz
415 0x7FD78400+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 13, Tf = 2472MHz
416 0x7FD78400+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 14, Tf = 2484MHz
417
418 // 4.9G => Ch 183, 184, 185, 187, 188, 189, 192, 196 (Value:15 ~ 22)
419 0x77D78400+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 183, Tf = 4915MHz (15)
420 0x67D78400+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 184, Tf = 4920MHz (16)
421 0x77D78400+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 185, Tf = 4925MHz (17)
422 0x77D78400+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 187, Tf = 4935MHz (18)
423 0x77D78400+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 188, Tf = 4940MHz (19)
424 0x77D78400+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 189, Tf = 4945MHz (20)
425 0x77D78400+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 192, Tf = 4960MHz (21)
426 0x67D78400+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 196, Tf = 4980MHz (22)
427
428 // 5G => Ch 7, 8, 9, 11, 12, 16, 34, 36, 38, 40, 42, 44, 46, 48, 52, 56, 60, 64,
429 // 100, 104, 108, 112, 116, 120, 124, 128, 132, 136, 140, 149, 153, 157, 161, 165 (Value 23 ~ 56)
430 0x77D78400+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 7, Tf = 5035MHz (23)
431 0x67D78400+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 8, Tf = 5040MHz (24)
432 0x77D78400+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 9, Tf = 5045MHz (25)
433 0x77D78400+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 11, Tf = 5055MHz (26)
434 0x77D78400+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 12, Tf = 5060MHz (27)
435 0x77D78400+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 16, Tf = 5080MHz (28)
436 0x77D78400+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 34, Tf = 5170MHz (29)
437 0x77D78400+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 36, Tf = 5180MHz (30)
438 0x77D78400+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 38, Tf = 5190MHz (31)
439 0x77D78400+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 40, Tf = 5200MHz (32)
440 0x77D78400+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 42, Tf = 5210MHz (33)
441 0x67D78400+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 44, Tf = 5220MHz (34)
442 0x77D78400+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 46, Tf = 5230MHz (35)
443 0x77D78400+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 48, Tf = 5240MHz (36)
444 0x77D78400+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 52, Tf = 5260MHz (37)
445 0x67D78400+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 56, Tf = 5280MHz (38)
446 0x77D78400+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 60, Tf = 5300MHz (39)
447 0x77D78400+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 64, Tf = 5320MHz (40)
448 0x77D78400+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 100, Tf = 5500MHz (41)
449 0x67D78400+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 104, Tf = 5520MHz (42)
450 0x77D78400+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 108, Tf = 5540MHz (43)
451 0x77D78400+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 112, Tf = 5560MHz (44)
452 0x67D78400+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 116, Tf = 5580MHz (45)
453 0x77D78400+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 120, Tf = 5600MHz (46)
454 0x77D78400+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 124, Tf = 5620MHz (47)
455 0x67D78400+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 128, Tf = 5640MHz (48)
456 0x77D78400+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 132, Tf = 5660MHz (49)
457 0x77D78400+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 136, Tf = 5680MHz (50)
458 0x67D78400+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 140, Tf = 5700MHz (51)
459 0x77D78400+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 149, Tf = 5745MHz (52)
460 0x77D78400+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 153, Tf = 5765MHz (53)
461 0x77D78400+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 157, Tf = 5785MHz (54)
462 0x77D78400+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW, // channel = 161, Tf = 5805MHz (55)
463 0x77D78400+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW // channel = 165, Tf = 5825MHz (56)
464 };
465//}} RobertYu
466
467
468
469
470/*--------------------- Static Functions --------------------------*/
471
472
473
474
475/*
476 * Description: AIROHA IFRF chip init function
477 *
478 * Parameters:
479 * In:
480 * dwIoBase - I/O base address
481 * Out:
482 * none
483 *
484 * Return Value: TRUE if succeeded; FALSE if failed.
485 *
486 */
487BOOL s_bAL7230Init (DWORD_PTR dwIoBase)
488{
489 int ii;
490 BOOL bResult;
491
492 bResult = TRUE;
493
494 //3-wire control for normal mode
495 VNSvOutPortB(dwIoBase + MAC_REG_SOFTPWRCTL, 0);
496
497 MACvWordRegBitsOn(dwIoBase, MAC_REG_SOFTPWRCTL, (SOFTPWRCTL_SWPECTI |
498 SOFTPWRCTL_TXPEINV));
499 BBvPowerSaveModeOFF(dwIoBase); //RobertYu:20050106, have DC value for Calibration
500
501 for (ii = 0; ii < CB_AL7230_INIT_SEQ; ii++)
502 bResult &= IFRFbWriteEmbeded(dwIoBase, dwAL7230InitTable[ii]);
503
504 // PLL On
505 MACvWordRegBitsOn(dwIoBase, MAC_REG_SOFTPWRCTL, SOFTPWRCTL_SWPE3);
506
507 //Calibration
508 MACvTimer0MicroSDelay(dwIoBase, 150);//150us
509 bResult &= IFRFbWriteEmbeded(dwIoBase, (0x9ABA8F00+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW)); //TXDCOC:active, RCK:diable
510 MACvTimer0MicroSDelay(dwIoBase, 30);//30us
511 bResult &= IFRFbWriteEmbeded(dwIoBase, (0x3ABA8F00+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW)); //TXDCOC:diable, RCK:active
512 MACvTimer0MicroSDelay(dwIoBase, 30);//30us
513 bResult &= IFRFbWriteEmbeded(dwIoBase, dwAL7230InitTable[CB_AL7230_INIT_SEQ-1]); //TXDCOC:diable, RCK:diable
514
515 MACvWordRegBitsOn(dwIoBase, MAC_REG_SOFTPWRCTL, (SOFTPWRCTL_SWPE3 |
516 SOFTPWRCTL_SWPE2 |
517 SOFTPWRCTL_SWPECTI |
518 SOFTPWRCTL_TXPEINV));
519
520 BBvPowerSaveModeON(dwIoBase); // RobertYu:20050106
521
522 // PE1: TX_ON, PE2: RX_ON, PE3: PLLON
523 //3-wire control for power saving mode
524 VNSvOutPortB(dwIoBase + MAC_REG_PSPWRSIG, (PSSIG_WPE3 | PSSIG_WPE2)); //1100 0000
525
526 return bResult;
527}
528
529// Need to Pull PLLON low when writing channel registers through 3-wire interface
530BOOL s_bAL7230SelectChannel (DWORD_PTR dwIoBase, BYTE byChannel)
531{
532 BOOL bResult;
533
534 bResult = TRUE;
535
536 // PLLON Off
537 MACvWordRegBitsOff(dwIoBase, MAC_REG_SOFTPWRCTL, SOFTPWRCTL_SWPE3);
538
539 bResult &= IFRFbWriteEmbeded (dwIoBase, dwAL7230ChannelTable0[byChannel-1]); //Reg0
540 bResult &= IFRFbWriteEmbeded (dwIoBase, dwAL7230ChannelTable1[byChannel-1]); //Reg1
541 bResult &= IFRFbWriteEmbeded (dwIoBase, dwAL7230ChannelTable2[byChannel-1]); //Reg4
542
543 // PLLOn On
544 MACvWordRegBitsOn(dwIoBase, MAC_REG_SOFTPWRCTL, SOFTPWRCTL_SWPE3);
545
546 // Set Channel[7] = 0 to tell H/W channel is changing now.
547 VNSvOutPortB(dwIoBase + MAC_REG_CHANNEL, (byChannel & 0x7F));
548 MACvTimer0MicroSDelay(dwIoBase, SWITCH_CHANNEL_DELAY_AL7230);
549 // Set Channel[7] = 1 to tell H/W channel change is done.
550 VNSvOutPortB(dwIoBase + MAC_REG_CHANNEL, (byChannel | 0x80));
551
552 return bResult;
553}
554
555/*
556 * Description: Select channel with UW2452 chip
557 *
558 * Parameters:
559 * In:
560 * dwIoBase - I/O base address
561 * uChannel - Channel number
562 * Out:
563 * none
564 *
565 * Return Value: TRUE if succeeded; FALSE if failed.
566 *
567 */
568
569
570//{{ RobertYu: 20041210
571/*
572 * Description: UW2452 IFRF chip init function
573 *
574 * Parameters:
575 * In:
576 * dwIoBase - I/O base address
577 * Out:
578 * none
579 *
580 * Return Value: TRUE if succeeded; FALSE if failed.
581 *
582 */
583
584
585
586//}} RobertYu
587////////////////////////////////////////////////////////////////////////////////
588
589/*
590 * Description: VT3226 IFRF chip init function
591 *
592 * Parameters:
593 * In:
594 * dwIoBase - I/O base address
595 * Out:
596 * none
597 *
598 * Return Value: TRUE if succeeded; FALSE if failed.
599 *
600 */
601
602/*
603 * Description: Select channel with VT3226 chip
604 *
605 * Parameters:
606 * In:
607 * dwIoBase - I/O base address
608 * uChannel - Channel number
609 * Out:
610 * none
611 *
612 * Return Value: TRUE if succeeded; FALSE if failed.
613 *
614 */
615
616
617
618/*--------------------- Export Variables --------------------------*/
619
620/*--------------------- Export Functions --------------------------*/
621
622/*
623 * Description: Write to IF/RF, by embeded programming
624 *
625 * Parameters:
626 * In:
627 * dwIoBase - I/O base address
628 * dwData - data to write
629 * Out:
630 * none
631 *
632 * Return Value: TRUE if succeeded; FALSE if failed.
633 *
634 */
635BOOL IFRFbWriteEmbeded (DWORD_PTR dwIoBase, DWORD dwData)
636{
637 WORD ww;
638 DWORD dwValue;
639
640 VNSvOutPortD(dwIoBase + MAC_REG_IFREGCTL, dwData);
641
642 // W_MAX_TIMEOUT is the timeout period
643 for (ww = 0; ww < W_MAX_TIMEOUT; ww++) {
644 VNSvInPortD(dwIoBase + MAC_REG_IFREGCTL, &dwValue);
645 if (BITbIsBitOn(dwValue, IFREGCTL_DONE))
646 break;
647 }
648
649 if (ww == W_MAX_TIMEOUT) {
650// DBG_PORT80_ALWAYS(0x32);
651 return FALSE;
652 }
653 return TRUE;
654}
655
656
657
658/*
659 * Description: RFMD RF2959 IFRF chip init function
660 *
661 * Parameters:
662 * In:
663 * dwIoBase - I/O base address
664 * Out:
665 * none
666 *
667 * Return Value: TRUE if succeeded; FALSE if failed.
668 *
669 */
670
671/*
672 * Description: Select channel with RFMD 2959 chip
673 *
674 * Parameters:
675 * In:
676 * dwIoBase - I/O base address
677 * uChannel - Channel number
678 * Out:
679 * none
680 *
681 * Return Value: TRUE if succeeded; FALSE if failed.
682 *
683 */
684
685/*
686 * Description: AIROHA IFRF chip init function
687 *
688 * Parameters:
689 * In:
690 * dwIoBase - I/O base address
691 * Out:
692 * none
693 *
694 * Return Value: TRUE if succeeded; FALSE if failed.
695 *
696 */
697BOOL RFbAL2230Init (DWORD_PTR dwIoBase)
698{
699 int ii;
700 BOOL bResult;
701
702 bResult = TRUE;
703
704 //3-wire control for normal mode
705 VNSvOutPortB(dwIoBase + MAC_REG_SOFTPWRCTL, 0);
706
707 MACvWordRegBitsOn(dwIoBase, MAC_REG_SOFTPWRCTL, (SOFTPWRCTL_SWPECTI |
708 SOFTPWRCTL_TXPEINV));
709//2008-8-21 chester <add>
710 // PLL Off
711
712 MACvWordRegBitsOff(dwIoBase, MAC_REG_SOFTPWRCTL, SOFTPWRCTL_SWPE3);
713
714
715
716 //patch abnormal AL2230 frequency output
717//2008-8-21 chester <add>
718 IFRFbWriteEmbeded(dwIoBase, (0x07168700+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW));
719
720
721 for (ii = 0; ii < CB_AL2230_INIT_SEQ; ii++)
722 bResult &= IFRFbWriteEmbeded(dwIoBase, dwAL2230InitTable[ii]);
723//2008-8-21 chester <add>
724MACvTimer0MicroSDelay(dwIoBase, 30); //delay 30 us
725
726 // PLL On
727 MACvWordRegBitsOn(dwIoBase, MAC_REG_SOFTPWRCTL, SOFTPWRCTL_SWPE3);
728
729 MACvTimer0MicroSDelay(dwIoBase, 150);//150us
730 bResult &= IFRFbWriteEmbeded(dwIoBase, (0x00d80f00+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW));
731 MACvTimer0MicroSDelay(dwIoBase, 30);//30us
732 bResult &= IFRFbWriteEmbeded(dwIoBase, (0x00780f00+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW));
733 MACvTimer0MicroSDelay(dwIoBase, 30);//30us
734 bResult &= IFRFbWriteEmbeded(dwIoBase, dwAL2230InitTable[CB_AL2230_INIT_SEQ-1]);
735
736 MACvWordRegBitsOn(dwIoBase, MAC_REG_SOFTPWRCTL, (SOFTPWRCTL_SWPE3 |
737 SOFTPWRCTL_SWPE2 |
738 SOFTPWRCTL_SWPECTI |
739 SOFTPWRCTL_TXPEINV));
740
741 //3-wire control for power saving mode
742 VNSvOutPortB(dwIoBase + MAC_REG_PSPWRSIG, (PSSIG_WPE3 | PSSIG_WPE2)); //1100 0000
743
744 return bResult;
745}
746
747BOOL RFbAL2230SelectChannel (DWORD_PTR dwIoBase, BYTE byChannel)
748{
749 BOOL bResult;
750
751 bResult = TRUE;
752
753 bResult &= IFRFbWriteEmbeded (dwIoBase, dwAL2230ChannelTable0[byChannel-1]);
754 bResult &= IFRFbWriteEmbeded (dwIoBase, dwAL2230ChannelTable1[byChannel-1]);
755
756 // Set Channel[7] = 0 to tell H/W channel is changing now.
757 VNSvOutPortB(dwIoBase + MAC_REG_CHANNEL, (byChannel & 0x7F));
758 MACvTimer0MicroSDelay(dwIoBase, SWITCH_CHANNEL_DELAY_AL2230);
759 // Set Channel[7] = 1 to tell H/W channel change is done.
760 VNSvOutPortB(dwIoBase + MAC_REG_CHANNEL, (byChannel | 0x80));
761
762 return bResult;
763}
764
765/*
766 * Description: UW2451 IFRF chip init function
767 *
768 * Parameters:
769 * In:
770 * dwIoBase - I/O base address
771 * Out:
772 * none
773 *
774 * Return Value: TRUE if succeeded; FALSE if failed.
775 *
776 */
777
778
779/*
780 * Description: Select channel with UW2451 chip
781 *
782 * Parameters:
783 * In:
784 * dwIoBase - I/O base address
785 * uChannel - Channel number
786 * Out:
787 * none
788 *
789 * Return Value: TRUE if succeeded; FALSE if failed.
790 *
791 */
792
793/*
794 * Description: Set sleep mode to UW2451 chip
795 *
796 * Parameters:
797 * In:
798 * dwIoBase - I/O base address
799 * uChannel - Channel number
800 * Out:
801 * none
802 *
803 * Return Value: TRUE if succeeded; FALSE if failed.
804 *
805 */
806
807/*
808 * Description: RF init function
809 *
810 * Parameters:
811 * In:
812 * byBBType
813 * byRFType
814 * Out:
815 * none
816 *
817 * Return Value: TRUE if succeeded; FALSE if failed.
818 *
819 */
820BOOL RFbInit (
821 IN PSDevice pDevice
822 )
823{
824BOOL bResult = TRUE;
825 switch (pDevice->byRFType) {
826 case RF_AIROHA :
827 case RF_AL2230S:
828 pDevice->byMaxPwrLevel = AL2230_PWR_IDX_LEN;
829 bResult = RFbAL2230Init(pDevice->PortOffset);
830 break;
831 case RF_AIROHA7230 :
832 pDevice->byMaxPwrLevel = AL7230_PWR_IDX_LEN;
833 bResult = s_bAL7230Init(pDevice->PortOffset);
834 break;
835 case RF_NOTHING :
836 bResult = TRUE;
837 break;
838 default :
839 bResult = FALSE;
840 break;
841 }
842 return bResult;
843}
844
845/*
846 * Description: RF ShutDown function
847 *
848 * Parameters:
849 * In:
850 * byBBType
851 * byRFType
852 * Out:
853 * none
854 *
855 * Return Value: TRUE if succeeded; FALSE if failed.
856 *
857 */
858BOOL RFbShutDown (
859 IN PSDevice pDevice
860 )
861{
862BOOL bResult = TRUE;
863
864 switch (pDevice->byRFType) {
865 case RF_AIROHA7230 :
866 bResult = IFRFbWriteEmbeded (pDevice->PortOffset, 0x1ABAEF00+(BY_AL7230_REG_LEN<<3)+IFREGCTL_REGW);
867 break;
868 default :
869 bResult = TRUE;
870 break;
871 }
872 return bResult;
873}
874
875/*
876 * Description: Select channel
877 *
878 * Parameters:
879 * In:
880 * byRFType
881 * byChannel - Channel number
882 * Out:
883 * none
884 *
885 * Return Value: TRUE if succeeded; FALSE if failed.
886 *
887 */
888BOOL RFbSelectChannel (DWORD_PTR dwIoBase, BYTE byRFType, BYTE byChannel)
889{
890BOOL bResult = TRUE;
891 switch (byRFType) {
892
893 case RF_AIROHA :
894 case RF_AL2230S:
895 bResult = RFbAL2230SelectChannel(dwIoBase, byChannel);
896 break;
897 //{{ RobertYu: 20050104
898 case RF_AIROHA7230 :
899 bResult = s_bAL7230SelectChannel(dwIoBase, byChannel);
900 break;
901 //}} RobertYu
902 case RF_NOTHING :
903 bResult = TRUE;
904 break;
905 default:
906 bResult = FALSE;
907 break;
908 }
909 return bResult;
910}
911
912/*
913 * Description: Write WakeProgSyn
914 *
915 * Parameters:
916 * In:
917 * dwIoBase - I/O base address
918 * uChannel - channel number
919 * bySleepCnt - SleepProgSyn count
920 *
921 * Return Value: None.
922 *
923 */
924BOOL RFvWriteWakeProgSyn (DWORD_PTR dwIoBase, BYTE byRFType, UINT uChannel)
925{
926 int ii;
927 BYTE byInitCount = 0;
928 BYTE bySleepCount = 0;
929
930 VNSvOutPortW(dwIoBase + MAC_REG_MISCFFNDEX, 0);
931 switch (byRFType) {
932 case RF_AIROHA:
933 case RF_AL2230S:
934
935 if (uChannel > CB_MAX_CHANNEL_24G)
936 return FALSE;
937
938 byInitCount = CB_AL2230_INIT_SEQ + 2; // Init Reg + Channel Reg (2)
939 bySleepCount = 0;
940 if (byInitCount > (MISCFIFO_SYNDATASIZE - bySleepCount)) {
941 return FALSE;
942 }
943
944 for (ii = 0; ii < CB_AL2230_INIT_SEQ; ii++ ) {
945 MACvSetMISCFifo(dwIoBase, (WORD)(MISCFIFO_SYNDATA_IDX + ii), dwAL2230InitTable[ii]);
946 }
947 MACvSetMISCFifo(dwIoBase, (WORD)(MISCFIFO_SYNDATA_IDX + ii), dwAL2230ChannelTable0[uChannel-1]);
948 ii ++;
949 MACvSetMISCFifo(dwIoBase, (WORD)(MISCFIFO_SYNDATA_IDX + ii), dwAL2230ChannelTable1[uChannel-1]);
950 break;
951
952 //{{ RobertYu: 20050104
953 // Need to check, PLLON need to be low for channel setting
954 case RF_AIROHA7230:
955 byInitCount = CB_AL7230_INIT_SEQ + 3; // Init Reg + Channel Reg (3)
956 bySleepCount = 0;
957 if (byInitCount > (MISCFIFO_SYNDATASIZE - bySleepCount)) {
958 return FALSE;
959 }
960
961 if (uChannel <= CB_MAX_CHANNEL_24G)
962 {
963 for (ii = 0; ii < CB_AL7230_INIT_SEQ; ii++ ) {
964 MACvSetMISCFifo(dwIoBase, (WORD)(MISCFIFO_SYNDATA_IDX + ii), dwAL7230InitTable[ii]);
965 }
966 }
967 else
968 {
969 for (ii = 0; ii < CB_AL7230_INIT_SEQ; ii++ ) {
970 MACvSetMISCFifo(dwIoBase, (WORD)(MISCFIFO_SYNDATA_IDX + ii), dwAL7230InitTableAMode[ii]);
971 }
972 }
973
974 MACvSetMISCFifo(dwIoBase, (WORD)(MISCFIFO_SYNDATA_IDX + ii), dwAL7230ChannelTable0[uChannel-1]);
975 ii ++;
976 MACvSetMISCFifo(dwIoBase, (WORD)(MISCFIFO_SYNDATA_IDX + ii), dwAL7230ChannelTable1[uChannel-1]);
977 ii ++;
978 MACvSetMISCFifo(dwIoBase, (WORD)(MISCFIFO_SYNDATA_IDX + ii), dwAL7230ChannelTable2[uChannel-1]);
979 break;
980 //}} RobertYu
981
982 case RF_NOTHING :
983 return TRUE;
984 break;
985
986 default:
987 return FALSE;
988 break;
989 }
990
991 MACvSetMISCFifo(dwIoBase, MISCFIFO_SYNINFO_IDX, (DWORD)MAKEWORD(bySleepCount, byInitCount));
992
993 return TRUE;
994}
995
996/*
997 * Description: Set Tx power
998 *
999 * Parameters:
1000 * In:
1001 * dwIoBase - I/O base address
1002 * dwRFPowerTable - RF Tx Power Setting
1003 * Out:
1004 * none
1005 *
1006 * Return Value: TRUE if succeeded; FALSE if failed.
1007 *
1008 */
1009BOOL RFbSetPower (
1010 IN PSDevice pDevice,
1011 IN UINT uRATE,
1012 IN UINT uCH
1013 )
1014{
1015BOOL bResult = TRUE;
1016BYTE byPwr = 0;
1017BYTE byDec = 0;
1018BYTE byPwrdBm = 0;
1019
1020 if (pDevice->dwDiagRefCount != 0) {
1021 return TRUE;
1022 }
1023 if ((uCH < 1) || (uCH > CB_MAX_CHANNEL)) {
1024 return FALSE;
1025 }
1026
1027 switch (uRATE) {
1028 case RATE_1M:
1029 case RATE_2M:
1030 case RATE_5M:
1031 case RATE_11M:
1032 byPwr = pDevice->abyCCKPwrTbl[uCH];
1033 byPwrdBm = pDevice->abyCCKDefaultPwr[uCH];
1034//PLICE_DEBUG->
1035 //byPwr+=5;
1036//PLICE_DEBUG <-
1037
1038//printk("Rate <11:byPwr is %d\n",byPwr);
1039 break;
1040 case RATE_6M:
1041 case RATE_9M:
1042 case RATE_18M:
1043 byPwr = pDevice->abyOFDMPwrTbl[uCH];
1044 if (pDevice->byRFType == RF_UW2452) {
1045 byDec = byPwr + 14;
1046 } else {
1047 byDec = byPwr + 10;
1048 }
1049 if (byDec >= pDevice->byMaxPwrLevel) {
1050 byDec = pDevice->byMaxPwrLevel-1;
1051 }
1052 if (pDevice->byRFType == RF_UW2452) {
1053 byPwrdBm = byDec - byPwr;
1054 byPwrdBm /= 3;
1055 } else {
1056 byPwrdBm = byDec - byPwr;
1057 byPwrdBm >>= 1;
1058 }
1059 byPwrdBm += pDevice->abyOFDMDefaultPwr[uCH];
1060 byPwr = byDec;
1061//PLICE_DEBUG->
1062 //byPwr+=5;
1063//PLICE_DEBUG<-
1064
1065//printk("Rate <24:byPwr is %d\n",byPwr);
1066 break;
1067 case RATE_24M:
1068 case RATE_36M:
1069 case RATE_48M:
1070 case RATE_54M:
1071 byPwr = pDevice->abyOFDMPwrTbl[uCH];
1072 byPwrdBm = pDevice->abyOFDMDefaultPwr[uCH];
1073//PLICE_DEBUG->
1074 //byPwr+=5;
1075//PLICE_DEBUG<-
1076//printk("Rate < 54:byPwr is %d\n",byPwr);
1077 break;
1078 }
1079
1080#if 0
1081
1082 // 802.11h TPC
1083 if (pDevice->bLinkPass == TRUE) {
1084 // do not over local constraint
1085 if (byPwrdBm > pDevice->abyLocalPwr[uCH]) {
1086 pDevice->byCurPwrdBm = pDevice->abyLocalPwr[uCH];
1087 byDec = byPwrdBm - pDevice->abyLocalPwr[uCH];
1088 if (pDevice->byRFType == RF_UW2452) {
1089 byDec *= 3;
1090 } else {
1091 byDec <<= 1;
1092 }
1093 if (byPwr > byDec) {
1094 byPwr -= byDec;
1095 } else {
1096 byPwr = 0;
1097 }
1098 } else {
1099 pDevice->byCurPwrdBm = byPwrdBm;
1100 }
1101 } else {
1102 // do not over regulatory constraint
1103 if (byPwrdBm > pDevice->abyRegPwr[uCH]) {
1104 pDevice->byCurPwrdBm = pDevice->abyRegPwr[uCH];
1105 byDec = byPwrdBm - pDevice->abyRegPwr[uCH];
1106 if (pDevice->byRFType == RF_UW2452) {
1107 byDec *= 3;
1108 } else {
1109 byDec <<= 1;
1110 }
1111 if (byPwr > byDec) {
1112 byPwr -= byDec;
1113 } else {
1114 byPwr = 0;
1115 }
1116 } else {
1117 pDevice->byCurPwrdBm = byPwrdBm;
1118 }
1119 }
1120#endif
1121
1122// if (pDevice->byLocalID <= REV_ID_VT3253_B1) {
1123 if (pDevice->byCurPwr == byPwr) {
1124 return TRUE;
1125 }
1126 bResult = RFbRawSetPower(pDevice, byPwr, uRATE);
1127// }
1128 if (bResult == TRUE) {
1129 pDevice->byCurPwr = byPwr;
1130 }
1131 return bResult;
1132}
1133
1134/*
1135 * Description: Set Tx power
1136 *
1137 * Parameters:
1138 * In:
1139 * dwIoBase - I/O base address
1140 * dwRFPowerTable - RF Tx Power Setting
1141 * Out:
1142 * none
1143 *
1144 * Return Value: TRUE if succeeded; FALSE if failed.
1145 *
1146 */
1147
1148BOOL RFbRawSetPower (
1149 IN PSDevice pDevice,
1150 IN BYTE byPwr,
1151 IN UINT uRATE
1152 )
1153{
1154BOOL bResult = TRUE;
1155DWORD dwMax7230Pwr = 0;
1156
1157 if (byPwr >= pDevice->byMaxPwrLevel) {
1158 return (FALSE);
1159 }
1160 switch (pDevice->byRFType) {
1161
1162 case RF_AIROHA :
1163 bResult &= IFRFbWriteEmbeded(pDevice->PortOffset, dwAL2230PowerTable[byPwr]);
1164 if (uRATE <= RATE_11M) {
1165 bResult &= IFRFbWriteEmbeded(pDevice->PortOffset, 0x0001B400+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW);
1166 } else {
1167 bResult &= IFRFbWriteEmbeded(pDevice->PortOffset, 0x0005A400+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW);
1168 }
1169 break;
1170
1171
1172 case RF_AL2230S :
1173 bResult &= IFRFbWriteEmbeded(pDevice->PortOffset, dwAL2230PowerTable[byPwr]);
1174 if (uRATE <= RATE_11M) {
1175 bResult &= IFRFbWriteEmbeded(pDevice->PortOffset, 0x040C1400+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW);
1176 bResult &= IFRFbWriteEmbeded(pDevice->PortOffset, 0x00299B00+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW);
1177 }else {
1178 bResult &= IFRFbWriteEmbeded(pDevice->PortOffset, 0x0005A400+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW);
1179 bResult &= IFRFbWriteEmbeded(pDevice->PortOffset, 0x00099B00+(BY_AL2230_REG_LEN<<3)+IFREGCTL_REGW);
1180 }
1181
1182 break;
1183
1184 case RF_AIROHA7230:
1185 // 0x080F1B00 for 3 wire control TxGain(D10) and 0x31 as TX Gain value
1186 dwMax7230Pwr = 0x080C0B00 | ( (byPwr) << 12 ) |
1187 (BY_AL7230_REG_LEN << 3 ) | IFREGCTL_REGW;
1188
1189 bResult &= IFRFbWriteEmbeded(pDevice->PortOffset, dwMax7230Pwr);
1190 break;
1191
1192
1193 default :
1194 break;
1195 }
1196 return bResult;
1197}
1198
1199/*+
1200 *
1201 * Routine Description:
1202 * Translate RSSI to dBm
1203 *
1204 * Parameters:
1205 * In:
1206 * pDevice - The adapter to be translated
1207 * byCurrRSSI - RSSI to be translated
1208 * Out:
1209 * pdwdbm - Translated dbm number
1210 *
1211 * Return Value: none
1212 *
1213-*/
1214VOID
1215RFvRSSITodBm (
1216 IN PSDevice pDevice,
1217 IN BYTE byCurrRSSI,
1218 OUT PLONG pldBm
1219 )
1220{
1221 BYTE byIdx = (((byCurrRSSI & 0xC0) >> 6) & 0x03);
1222 LONG b = (byCurrRSSI & 0x3F);
1223 LONG a = 0;
1224 BYTE abyAIROHARF[4] = {0, 18, 0, 40};
1225
1226 switch (pDevice->byRFType) {
1227 case RF_AIROHA:
1228 case RF_AL2230S:
1229 case RF_AIROHA7230: //RobertYu: 20040104
1230 a = abyAIROHARF[byIdx];
1231 break;
1232 default:
1233 break;
1234 }
1235
1236 *pldBm = -1 * (a + b * 2);
1237}
1238
1239////////////////////////////////////////////////////////////////////////////////
1240//{{ RobertYu: 20050104
1241
1242
1243// Post processing for the 11b/g and 11a.
1244// for save time on changing Reg2,3,5,7,10,12,15
1245BOOL RFbAL7230SelectChannelPostProcess (DWORD_PTR dwIoBase, BYTE byOldChannel, BYTE byNewChannel)
1246{
1247 BOOL bResult;
1248
1249 bResult = TRUE;
1250
1251 // if change between 11 b/g and 11a need to update the following register
1252 // Channel Index 1~14
1253
1254 if( (byOldChannel <= CB_MAX_CHANNEL_24G) && (byNewChannel > CB_MAX_CHANNEL_24G) )
1255 {
1256 // Change from 2.4G to 5G
1257 bResult &= IFRFbWriteEmbeded(dwIoBase, dwAL7230InitTableAMode[2]); //Reg2
1258 bResult &= IFRFbWriteEmbeded(dwIoBase, dwAL7230InitTableAMode[3]); //Reg3
1259 bResult &= IFRFbWriteEmbeded(dwIoBase, dwAL7230InitTableAMode[5]); //Reg5
1260 bResult &= IFRFbWriteEmbeded(dwIoBase, dwAL7230InitTableAMode[7]); //Reg7
1261 bResult &= IFRFbWriteEmbeded(dwIoBase, dwAL7230InitTableAMode[10]);//Reg10
1262 bResult &= IFRFbWriteEmbeded(dwIoBase, dwAL7230InitTableAMode[12]);//Reg12
1263 bResult &= IFRFbWriteEmbeded(dwIoBase, dwAL7230InitTableAMode[15]);//Reg15
1264 }
1265 else if( (byOldChannel > CB_MAX_CHANNEL_24G) && (byNewChannel <= CB_MAX_CHANNEL_24G) )
1266 {
1267 // change from 5G to 2.4G
1268 bResult &= IFRFbWriteEmbeded(dwIoBase, dwAL7230InitTable[2]); //Reg2
1269 bResult &= IFRFbWriteEmbeded(dwIoBase, dwAL7230InitTable[3]); //Reg3
1270 bResult &= IFRFbWriteEmbeded(dwIoBase, dwAL7230InitTable[5]); //Reg5
1271 bResult &= IFRFbWriteEmbeded(dwIoBase, dwAL7230InitTable[7]); //Reg7
1272 bResult &= IFRFbWriteEmbeded(dwIoBase, dwAL7230InitTable[10]);//Reg10
1273 bResult &= IFRFbWriteEmbeded(dwIoBase, dwAL7230InitTable[12]);//Reg12
1274 bResult &= IFRFbWriteEmbeded(dwIoBase, dwAL7230InitTable[15]);//Reg15
1275 }
1276
1277 return bResult;
1278}
1279
1280
1281//}} RobertYu
1282////////////////////////////////////////////////////////////////////////////////
1283
diff --git a/drivers/staging/vt6655/rf.h b/drivers/staging/vt6655/rf.h
new file mode 100644
index 000000000000..05fe17b2cfb7
--- /dev/null
+++ b/drivers/staging/vt6655/rf.h
@@ -0,0 +1,118 @@
1/*
2 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
3 * All rights reserved.
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 *
20 * File: rf.h
21 *
22 * Purpose:
23 *
24 * Author: Jerry Chen
25 *
26 * Date: Feb. 19, 2004
27 *
28 */
29
30
31#ifndef __RF_H__
32#define __RF_H__
33
34#if !defined(__TTYPE_H__)
35#include "ttype.h"
36#endif
37#if !defined(__DEVICE_H__)
38#include "device.h"
39#endif
40/*--------------------- Export Definitions -------------------------*/
41//
42// Baseband RF pair definition in eeprom (Bits 6..0)
43//
44#define RF_RFMD2959 0x01
45#define RF_MAXIMAG 0x02
46#define RF_AIROHA 0x03
47
48//#define RF_GCT5103 0x04
49#define RF_UW2451 0x05
50#define RF_MAXIMG 0x06
51#define RF_MAXIM2829 0x07 // RobertYu: 20041118
52#define RF_UW2452 0x08 // RobertYu: 20041210
53#define RF_AIROHA7230 0x0a // RobertYu: 20050104
54#define RF_UW2453 0x0b
55
56#define RF_VT3226 0x09
57#define RF_AL2230S 0x0e
58
59#define RF_NOTHING 0x7E
60#define RF_EMU 0x80
61#define RF_MASK 0x7F
62
63#define ZONE_FCC 0
64#define ZONE_MKK1 1
65#define ZONE_ETSI 2
66#define ZONE_IC 3
67#define ZONE_SPAIN 4
68#define ZONE_FRANCE 5
69#define ZONE_MKK 6
70#define ZONE_ISRAEL 7
71
72//[20050104] CB_MAXIM2829_CHANNEL_5G_HIGH, CB_UW2452_CHANNEL_5G_HIGH: 40==>41
73#define CB_MAXIM2829_CHANNEL_5G_HIGH 41 //Index41: channel = 100, Tf = 5500MHz, set the (A3:A0=0101) D6=1
74#define CB_UW2452_CHANNEL_5G_HIGH 41 //[20041210] Index41: channel = 100, Tf = 5500MHz, change VCO2->VCO3
75
76
77/*--------------------- Export Classes ----------------------------*/
78
79/*--------------------- Export Variables --------------------------*/
80
81/*--------------------- Export Functions --------------------------*/
82#ifdef __cplusplus
83extern "C" { /* Assume C declarations for C++ */
84#endif /* __cplusplus */
85
86BOOL IFRFbWriteEmbeded(DWORD_PTR dwIoBase, DWORD dwData);
87BOOL RFbSelectChannel(DWORD_PTR dwIoBase, BYTE byRFType, BYTE byChannel);
88BOOL RFbInit (
89 IN PSDevice pDevice
90 );
91BOOL RFvWriteWakeProgSyn(DWORD_PTR dwIoBase, BYTE byRFType, UINT uChannel);
92BOOL RFbSetPower(PSDevice pDevice, UINT uRATE, UINT uCH);
93BOOL RFbRawSetPower(
94 IN PSDevice pDevice,
95 IN BYTE byPwr,
96 IN UINT uRATE
97 );
98
99VOID
100RFvRSSITodBm(
101 IN PSDevice pDevice,
102 IN BYTE byCurrRSSI,
103 OUT PLONG pldBm
104 );
105
106//{{ RobertYu: 20050104
107BOOL RFbAL7230SelectChannelPostProcess(DWORD_PTR dwIoBase, BYTE byOldChannel, BYTE byNewChannel);
108//}} RobertYu
109
110#ifdef __cplusplus
111} /* End of extern "C" { */
112#endif /* __cplusplus */
113
114
115#endif // __RF_H__
116
117
118
diff --git a/drivers/staging/vt6655/rxtx.c b/drivers/staging/vt6655/rxtx.c
new file mode 100644
index 000000000000..c8a4a5533c7e
--- /dev/null
+++ b/drivers/staging/vt6655/rxtx.c
@@ -0,0 +1,3269 @@
1/*
2 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
3 * All rights reserved.
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * File: rxtx.c
20 *
21 * Purpose: handle WMAC/802.3/802.11 rx & tx functions
22 *
23 * Author: Lyndon Chen
24 *
25 * Date: May 20, 2003
26 *
27 * Functions:
28 * s_vGenerateTxParameter - Generate tx dma requried parameter.
29 * vGenerateMACHeader - Translate 802.3 to 802.11 header
30 * cbGetFragCount - Caculate fragement number count
31 * csBeacon_xmit - beacon tx function
32 * csMgmt_xmit - management tx function
33 * s_cbFillTxBufHead - fulfill tx dma buffer header
34 * s_uGetDataDuration - get tx data required duration
35 * s_uFillDataHead- fulfill tx data duration header
36 * s_uGetRTSCTSDuration- get rtx/cts requried duration
37 * s_uGetRTSCTSRsvTime- get rts/cts reserved time
38 * s_uGetTxRsvTime- get frame reserved time
39 * s_vFillCTSHead- fulfill CTS ctl header
40 * s_vFillFragParameter- Set fragement ctl parameter.
41 * s_vFillRTSHead- fulfill RTS ctl header
42 * s_vFillTxKey- fulfill tx encrypt key
43 * s_vSWencryption- Software encrypt header
44 * vDMA0_tx_80211- tx 802.11 frame via dma0
45 * vGenerateFIFOHeader- Generate tx FIFO ctl header
46 *
47 * Revision History:
48 *
49 */
50
51
52#if !defined(__DEVICE_H__)
53#include "device.h"
54#endif
55#if !defined(__RXTX_H__)
56#include "rxtx.h"
57#endif
58#if !defined(__TETHER_H__)
59#include "tether.h"
60#endif
61#if !defined(__CARD_H__)
62#include "card.h"
63#endif
64#if !defined(__BSSDB_H__)
65#include "bssdb.h"
66#endif
67#if !defined(__MAC_H__)
68#include "mac.h"
69#endif
70#if !defined(__BASEBAND_H__)
71#include "baseband.h"
72#endif
73#if !defined(__UMEM_H__)
74#include "umem.h"
75#endif
76#if !defined(__MICHAEL_H__)
77#include "michael.h"
78#endif
79#if !defined(__TKIP_H__)
80#include "tkip.h"
81#endif
82#if !defined(__TCRC_H__)
83#include "tcrc.h"
84#endif
85#if !defined(__WCTL_H__)
86#include "wctl.h"
87#endif
88#if !defined(__WROUTE_H__)
89#include "wroute.h"
90#endif
91#if !defined(__TBIT_H__)
92#include "tbit.h"
93#endif
94#if !defined(__HOSTAP_H__)
95#include "hostap.h"
96#endif
97#if !defined(__RF_H__)
98#include "rf.h"
99#endif
100
101/*--------------------- Static Definitions -------------------------*/
102
103/*--------------------- Static Classes ----------------------------*/
104
105/*--------------------- Static Variables --------------------------*/
106//static int msglevel =MSG_LEVEL_DEBUG;
107static int msglevel =MSG_LEVEL_INFO;
108
109#define PLICE_DEBUG
110
111
112/*--------------------- Static Functions --------------------------*/
113
114/*--------------------- Static Definitions -------------------------*/
115#define CRITICAL_PACKET_LEN 256 // if packet size < 256 -> in-direct send
116 // packet size >= 256 -> direct send
117
118const WORD wTimeStampOff[2][MAX_RATE] = {
119 {384, 288, 226, 209, 54, 43, 37, 31, 28, 25, 24, 23}, // Long Preamble
120 {384, 192, 130, 113, 54, 43, 37, 31, 28, 25, 24, 23}, // Short Preamble
121 };
122
123const WORD wFB_Opt0[2][5] = {
124 {RATE_12M, RATE_18M, RATE_24M, RATE_36M, RATE_48M}, // fallback_rate0
125 {RATE_12M, RATE_12M, RATE_18M, RATE_24M, RATE_36M}, // fallback_rate1
126 };
127const WORD wFB_Opt1[2][5] = {
128 {RATE_12M, RATE_18M, RATE_24M, RATE_24M, RATE_36M}, // fallback_rate0
129 {RATE_6M , RATE_6M, RATE_12M, RATE_12M, RATE_18M}, // fallback_rate1
130 };
131
132
133#define RTSDUR_BB 0
134#define RTSDUR_BA 1
135#define RTSDUR_AA 2
136#define CTSDUR_BA 3
137#define RTSDUR_BA_F0 4
138#define RTSDUR_AA_F0 5
139#define RTSDUR_BA_F1 6
140#define RTSDUR_AA_F1 7
141#define CTSDUR_BA_F0 8
142#define CTSDUR_BA_F1 9
143#define DATADUR_B 10
144#define DATADUR_A 11
145#define DATADUR_A_F0 12
146#define DATADUR_A_F1 13
147
148/*--------------------- Static Functions --------------------------*/
149
150
151
152static
153VOID
154s_vFillTxKey(
155 IN PSDevice pDevice,
156 IN PBYTE pbyBuf,
157 IN PBYTE pbyIVHead,
158 IN PSKeyItem pTransmitKey,
159 IN PBYTE pbyHdrBuf,
160 IN WORD wPayloadLen,
161 OUT PBYTE pMICHDR
162 );
163
164
165
166static
167VOID
168s_vFillRTSHead(
169 IN PSDevice pDevice,
170 IN BYTE byPktTyp,
171 IN PVOID pvRTS,
172 IN UINT cbFrameLength,
173 IN BOOL bNeedAck,
174 IN BOOL bDisCRC,
175 IN PSEthernetHeader psEthHeader,
176 IN WORD wCurrentRate,
177 IN BYTE byFBOption
178 );
179
180static
181VOID
182s_vGenerateTxParameter(
183 IN PSDevice pDevice,
184 IN BYTE byPktTyp,
185 IN PVOID pTxBufHead,
186 IN PVOID pvRrvTime,
187 IN PVOID pvRTS,
188 IN PVOID pvCTS,
189 IN UINT cbFrameSize,
190 IN BOOL bNeedACK,
191 IN UINT uDMAIdx,
192 IN PSEthernetHeader psEthHeader,
193 IN WORD wCurrentRate
194 );
195
196
197
198static void s_vFillFragParameter(
199 IN PSDevice pDevice,
200 IN PBYTE pbyBuffer,
201 IN UINT uTxType,
202 IN PVOID pvtdCurr,
203 IN WORD wFragType,
204 IN UINT cbReqCount
205 );
206
207
208static
209UINT
210s_cbFillTxBufHead (
211 IN PSDevice pDevice,
212 IN BYTE byPktTyp,
213 IN PBYTE pbyTxBufferAddr,
214 IN UINT cbFrameBodySize,
215 IN UINT uDMAIdx,
216 IN PSTxDesc pHeadTD,
217 IN PSEthernetHeader psEthHeader,
218 IN PBYTE pPacket,
219 IN BOOL bNeedEncrypt,
220 IN PSKeyItem pTransmitKey,
221 IN UINT uNodeIndex,
222 OUT PUINT puMACfragNum
223 );
224
225
226static
227UINT
228s_uFillDataHead (
229 IN PSDevice pDevice,
230 IN BYTE byPktTyp,
231 IN PVOID pTxDataHead,
232 IN UINT cbFrameLength,
233 IN UINT uDMAIdx,
234 IN BOOL bNeedAck,
235 IN UINT uFragIdx,
236 IN UINT cbLastFragmentSize,
237 IN UINT uMACfragNum,
238 IN BYTE byFBOption,
239 IN WORD wCurrentRate
240 );
241
242
243/*--------------------- Export Variables --------------------------*/
244
245
246
247static
248VOID
249s_vFillTxKey (
250 IN PSDevice pDevice,
251 IN PBYTE pbyBuf,
252 IN PBYTE pbyIVHead,
253 IN PSKeyItem pTransmitKey,
254 IN PBYTE pbyHdrBuf,
255 IN WORD wPayloadLen,
256 OUT PBYTE pMICHDR
257 )
258{
259 PDWORD pdwIV = (PDWORD) pbyIVHead;
260 PDWORD pdwExtIV = (PDWORD) ((PBYTE)pbyIVHead+4);
261 WORD wValue;
262 PS802_11Header pMACHeader = (PS802_11Header)pbyHdrBuf;
263 DWORD dwRevIVCounter;
264 BYTE byKeyIndex = 0;
265
266
267
268 //Fill TXKEY
269 if (pTransmitKey == NULL)
270 return;
271
272 dwRevIVCounter = cpu_to_le32(pDevice->dwIVCounter);
273 *pdwIV = pDevice->dwIVCounter;
274 byKeyIndex = pTransmitKey->dwKeyIndex & 0xf;
275
276 if (pTransmitKey->byCipherSuite == KEY_CTL_WEP) {
277 if (pTransmitKey->uKeyLength == WLAN_WEP232_KEYLEN ){
278 MEMvCopy(pDevice->abyPRNG, (PBYTE)&(dwRevIVCounter), 3);
279 MEMvCopy(pDevice->abyPRNG+3, pTransmitKey->abyKey, pTransmitKey->uKeyLength);
280 } else {
281 MEMvCopy(pbyBuf, (PBYTE)&(dwRevIVCounter), 3);
282 MEMvCopy(pbyBuf+3, pTransmitKey->abyKey, pTransmitKey->uKeyLength);
283 if(pTransmitKey->uKeyLength == WLAN_WEP40_KEYLEN) {
284 MEMvCopy(pbyBuf+8, (PBYTE)&(dwRevIVCounter), 3);
285 MEMvCopy(pbyBuf+11, pTransmitKey->abyKey, pTransmitKey->uKeyLength);
286 }
287 MEMvCopy(pDevice->abyPRNG, pbyBuf, 16);
288 }
289 // Append IV after Mac Header
290 *pdwIV &= WEP_IV_MASK;//00000000 11111111 11111111 11111111
291 *pdwIV |= (byKeyIndex << 30);
292 *pdwIV = cpu_to_le32(*pdwIV);
293 pDevice->dwIVCounter++;
294 if (pDevice->dwIVCounter > WEP_IV_MASK) {
295 pDevice->dwIVCounter = 0;
296 }
297 } else if (pTransmitKey->byCipherSuite == KEY_CTL_TKIP) {
298 pTransmitKey->wTSC15_0++;
299 if (pTransmitKey->wTSC15_0 == 0) {
300 pTransmitKey->dwTSC47_16++;
301 }
302 TKIPvMixKey(pTransmitKey->abyKey, pDevice->abyCurrentNetAddr,
303 pTransmitKey->wTSC15_0, pTransmitKey->dwTSC47_16, pDevice->abyPRNG);
304 MEMvCopy(pbyBuf, pDevice->abyPRNG, 16);
305 // Make IV
306 MEMvCopy(pdwIV, pDevice->abyPRNG, 3);
307
308 *(pbyIVHead+3) = (BYTE)(((byKeyIndex << 6) & 0xc0) | 0x20); // 0x20 is ExtIV
309 // Append IV&ExtIV after Mac Header
310 *pdwExtIV = cpu_to_le32(pTransmitKey->dwTSC47_16);
311 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"vFillTxKey()---- pdwExtIV: %lx\n", *pdwExtIV);
312
313 } else if (pTransmitKey->byCipherSuite == KEY_CTL_CCMP) {
314 pTransmitKey->wTSC15_0++;
315 if (pTransmitKey->wTSC15_0 == 0) {
316 pTransmitKey->dwTSC47_16++;
317 }
318 MEMvCopy(pbyBuf, pTransmitKey->abyKey, 16);
319
320 // Make IV
321 *pdwIV = 0;
322 *(pbyIVHead+3) = (BYTE)(((byKeyIndex << 6) & 0xc0) | 0x20); // 0x20 is ExtIV
323 *pdwIV |= cpu_to_le16((WORD)(pTransmitKey->wTSC15_0));
324 //Append IV&ExtIV after Mac Header
325 *pdwExtIV = cpu_to_le32(pTransmitKey->dwTSC47_16);
326
327 //Fill MICHDR0
328 *pMICHDR = 0x59;
329 *((PBYTE)(pMICHDR+1)) = 0; // TxPriority
330 MEMvCopy(pMICHDR+2, &(pMACHeader->abyAddr2[0]), 6);
331 *((PBYTE)(pMICHDR+8)) = HIBYTE(HIWORD(pTransmitKey->dwTSC47_16));
332 *((PBYTE)(pMICHDR+9)) = LOBYTE(HIWORD(pTransmitKey->dwTSC47_16));
333 *((PBYTE)(pMICHDR+10)) = HIBYTE(LOWORD(pTransmitKey->dwTSC47_16));
334 *((PBYTE)(pMICHDR+11)) = LOBYTE(LOWORD(pTransmitKey->dwTSC47_16));
335 *((PBYTE)(pMICHDR+12)) = HIBYTE(pTransmitKey->wTSC15_0);
336 *((PBYTE)(pMICHDR+13)) = LOBYTE(pTransmitKey->wTSC15_0);
337 *((PBYTE)(pMICHDR+14)) = HIBYTE(wPayloadLen);
338 *((PBYTE)(pMICHDR+15)) = LOBYTE(wPayloadLen);
339
340 //Fill MICHDR1
341 *((PBYTE)(pMICHDR+16)) = 0; // HLEN[15:8]
342 if (pDevice->bLongHeader) {
343 *((PBYTE)(pMICHDR+17)) = 28; // HLEN[7:0]
344 } else {
345 *((PBYTE)(pMICHDR+17)) = 22; // HLEN[7:0]
346 }
347 wValue = cpu_to_le16(pMACHeader->wFrameCtl & 0xC78F);
348 MEMvCopy(pMICHDR+18, (PBYTE)&wValue, 2); // MSKFRACTL
349 MEMvCopy(pMICHDR+20, &(pMACHeader->abyAddr1[0]), 6);
350 MEMvCopy(pMICHDR+26, &(pMACHeader->abyAddr2[0]), 6);
351
352 //Fill MICHDR2
353 MEMvCopy(pMICHDR+32, &(pMACHeader->abyAddr3[0]), 6);
354 wValue = pMACHeader->wSeqCtl;
355 wValue &= 0x000F;
356 wValue = cpu_to_le16(wValue);
357 MEMvCopy(pMICHDR+38, (PBYTE)&wValue, 2); // MSKSEQCTL
358 if (pDevice->bLongHeader) {
359 MEMvCopy(pMICHDR+40, &(pMACHeader->abyAddr4[0]), 6);
360 }
361 }
362}
363
364
365static
366VOID
367s_vSWencryption (
368 IN PSDevice pDevice,
369 IN PSKeyItem pTransmitKey,
370 IN PBYTE pbyPayloadHead,
371 IN WORD wPayloadSize
372 )
373{
374 UINT cbICVlen = 4;
375 DWORD dwICV = 0xFFFFFFFFL;
376 PDWORD pdwICV;
377
378 if (pTransmitKey == NULL)
379 return;
380
381 if (pTransmitKey->byCipherSuite == KEY_CTL_WEP) {
382 //=======================================================================
383 // Append ICV after payload
384 dwICV = CRCdwGetCrc32Ex(pbyPayloadHead, wPayloadSize, dwICV);//ICV(Payload)
385 pdwICV = (PDWORD)(pbyPayloadHead + wPayloadSize);
386 // finally, we must invert dwCRC to get the correct answer
387 *pdwICV = cpu_to_le32(~dwICV);
388 // RC4 encryption
389 rc4_init(&pDevice->SBox, pDevice->abyPRNG, pTransmitKey->uKeyLength + 3);
390 rc4_encrypt(&pDevice->SBox, pbyPayloadHead, pbyPayloadHead, wPayloadSize+cbICVlen);
391 //=======================================================================
392 } else if (pTransmitKey->byCipherSuite == KEY_CTL_TKIP) {
393 //=======================================================================
394 //Append ICV after payload
395 dwICV = CRCdwGetCrc32Ex(pbyPayloadHead, wPayloadSize, dwICV);//ICV(Payload)
396 pdwICV = (PDWORD)(pbyPayloadHead + wPayloadSize);
397 // finally, we must invert dwCRC to get the correct answer
398 *pdwICV = cpu_to_le32(~dwICV);
399 // RC4 encryption
400 rc4_init(&pDevice->SBox, pDevice->abyPRNG, TKIP_KEY_LEN);
401 rc4_encrypt(&pDevice->SBox, pbyPayloadHead, pbyPayloadHead, wPayloadSize+cbICVlen);
402 //=======================================================================
403 }
404}
405
406
407
408
409/*byPktTyp : PK_TYPE_11A 0
410 PK_TYPE_11B 1
411 PK_TYPE_11GB 2
412 PK_TYPE_11GA 3
413*/
414static
415UINT
416s_uGetTxRsvTime (
417 IN PSDevice pDevice,
418 IN BYTE byPktTyp,
419 IN UINT cbFrameLength,
420 IN WORD wRate,
421 IN BOOL bNeedAck
422 )
423{
424 UINT uDataTime, uAckTime;
425
426 uDataTime = BBuGetFrameTime(pDevice->byPreambleType, byPktTyp, cbFrameLength, wRate);
427#ifdef PLICE_DEBUG
428 //printk("s_uGetTxRsvTime is %d\n",uDataTime);
429#endif
430 if (byPktTyp == PK_TYPE_11B) {//llb,CCK mode
431 uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktTyp, 14, (WORD)pDevice->byTopCCKBasicRate);
432 } else {//11g 2.4G OFDM mode & 11a 5G OFDM mode
433 uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktTyp, 14, (WORD)pDevice->byTopOFDMBasicRate);
434 }
435
436 if (bNeedAck) {
437 return (uDataTime + pDevice->uSIFS + uAckTime);
438 }
439 else {
440 return uDataTime;
441 }
442}
443
444//byFreqType: 0=>5GHZ 1=>2.4GHZ
445static
446UINT
447s_uGetRTSCTSRsvTime (
448 IN PSDevice pDevice,
449 IN BYTE byRTSRsvType,
450 IN BYTE byPktTyp,
451 IN UINT cbFrameLength,
452 IN WORD wCurrentRate
453 )
454{
455 UINT uRrvTime , uRTSTime, uCTSTime, uAckTime, uDataTime;
456
457 uRrvTime = uRTSTime = uCTSTime = uAckTime = uDataTime = 0;
458
459
460 uDataTime = BBuGetFrameTime(pDevice->byPreambleType, byPktTyp, cbFrameLength, wCurrentRate);
461 if (byRTSRsvType == 0) { //RTSTxRrvTime_bb
462 uRTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktTyp, 20, pDevice->byTopCCKBasicRate);
463 uCTSTime = uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktTyp, 14, pDevice->byTopCCKBasicRate);
464 }
465 else if (byRTSRsvType == 1){ //RTSTxRrvTime_ba, only in 2.4GHZ
466 uRTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktTyp, 20, pDevice->byTopCCKBasicRate);
467 uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktTyp, 14, pDevice->byTopCCKBasicRate);
468 uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktTyp, 14, pDevice->byTopOFDMBasicRate);
469 }
470 else if (byRTSRsvType == 2) { //RTSTxRrvTime_aa
471 uRTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktTyp, 20, pDevice->byTopOFDMBasicRate);
472 uCTSTime = uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktTyp, 14, pDevice->byTopOFDMBasicRate);
473 }
474 else if (byRTSRsvType == 3) { //CTSTxRrvTime_ba, only in 2.4GHZ
475 uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktTyp, 14, pDevice->byTopCCKBasicRate);
476 uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktTyp, 14, pDevice->byTopOFDMBasicRate);
477 uRrvTime = uCTSTime + uAckTime + uDataTime + 2*pDevice->uSIFS;
478 return uRrvTime;
479 }
480
481 //RTSRrvTime
482 uRrvTime = uRTSTime + uCTSTime + uAckTime + uDataTime + 3*pDevice->uSIFS;
483 return uRrvTime;
484}
485
486//byFreqType 0: 5GHz, 1:2.4Ghz
487static
488UINT
489s_uGetDataDuration (
490 IN PSDevice pDevice,
491 IN BYTE byDurType,
492 IN UINT cbFrameLength,
493 IN BYTE byPktType,
494 IN WORD wRate,
495 IN BOOL bNeedAck,
496 IN UINT uFragIdx,
497 IN UINT cbLastFragmentSize,
498 IN UINT uMACfragNum,
499 IN BYTE byFBOption
500 )
501{
502 BOOL bLastFrag = 0;
503 UINT uAckTime =0, uNextPktTime = 0;
504
505
506
507 if (uFragIdx == (uMACfragNum-1)) {
508 bLastFrag = 1;
509 }
510
511
512 switch (byDurType) {
513
514 case DATADUR_B: //DATADUR_B
515 if (((uMACfragNum == 1)) || (bLastFrag == 1)) {//Non Frag or Last Frag
516 if (bNeedAck) {
517 uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopCCKBasicRate);
518 return (pDevice->uSIFS + uAckTime);
519 } else {
520 return 0;
521 }
522 }
523 else {//First Frag or Mid Frag
524 if (uFragIdx == (uMACfragNum-2)) {
525 uNextPktTime = s_uGetTxRsvTime(pDevice, byPktType, cbLastFragmentSize, wRate, bNeedAck);
526 } else {
527 uNextPktTime = s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wRate, bNeedAck);
528 }
529 if (bNeedAck) {
530 uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopCCKBasicRate);
531 return (pDevice->uSIFS + uAckTime + uNextPktTime);
532 } else {
533 return (pDevice->uSIFS + uNextPktTime);
534 }
535 }
536 break;
537
538 case DATADUR_A: //DATADUR_A
539 if (((uMACfragNum==1)) || (bLastFrag==1)) {//Non Frag or Last Frag
540 if(bNeedAck){
541 uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
542 return (pDevice->uSIFS + uAckTime);
543 } else {
544 return 0;
545 }
546 }
547 else {//First Frag or Mid Frag
548 if(uFragIdx == (uMACfragNum-2)){
549 uNextPktTime = s_uGetTxRsvTime(pDevice, byPktType, cbLastFragmentSize, wRate, bNeedAck);
550 } else {
551 uNextPktTime = s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wRate, bNeedAck);
552 }
553 if(bNeedAck){
554 uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
555 return (pDevice->uSIFS + uAckTime + uNextPktTime);
556 } else {
557 return (pDevice->uSIFS + uNextPktTime);
558 }
559 }
560 break;
561
562 case DATADUR_A_F0: //DATADUR_A_F0
563 if (((uMACfragNum==1)) || (bLastFrag==1)) {//Non Frag or Last Frag
564 if(bNeedAck){
565 uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
566 return (pDevice->uSIFS + uAckTime);
567 } else {
568 return 0;
569 }
570 }
571 else { //First Frag or Mid Frag
572 if (byFBOption == AUTO_FB_0) {
573 if (wRate < RATE_18M)
574 wRate = RATE_18M;
575 else if (wRate > RATE_54M)
576 wRate = RATE_54M;
577
578 if(uFragIdx == (uMACfragNum-2)){
579 uNextPktTime = s_uGetTxRsvTime(pDevice, byPktType, cbLastFragmentSize, wFB_Opt0[FB_RATE0][wRate-RATE_18M], bNeedAck);
580 } else {
581 uNextPktTime = s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt0[FB_RATE0][wRate-RATE_18M], bNeedAck);
582 }
583 } else { // (byFBOption == AUTO_FB_1)
584 if (wRate < RATE_18M)
585 wRate = RATE_18M;
586 else if (wRate > RATE_54M)
587 wRate = RATE_54M;
588
589 if(uFragIdx == (uMACfragNum-2)){
590 uNextPktTime = s_uGetTxRsvTime(pDevice, byPktType, cbLastFragmentSize, wFB_Opt1[FB_RATE0][wRate-RATE_18M], bNeedAck);
591 } else {
592 uNextPktTime = s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt1[FB_RATE0][wRate-RATE_18M], bNeedAck);
593 }
594 }
595
596 if(bNeedAck){
597 uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
598 return (pDevice->uSIFS + uAckTime + uNextPktTime);
599 } else {
600 return (pDevice->uSIFS + uNextPktTime);
601 }
602 }
603 break;
604
605 case DATADUR_A_F1: //DATADUR_A_F1
606 if (((uMACfragNum==1)) || (bLastFrag==1)) {//Non Frag or Last Frag
607 if(bNeedAck){
608 uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
609 return (pDevice->uSIFS + uAckTime);
610 } else {
611 return 0;
612 }
613 }
614 else { //First Frag or Mid Frag
615 if (byFBOption == AUTO_FB_0) {
616 if (wRate < RATE_18M)
617 wRate = RATE_18M;
618 else if (wRate > RATE_54M)
619 wRate = RATE_54M;
620
621 if(uFragIdx == (uMACfragNum-2)){
622 uNextPktTime = s_uGetTxRsvTime(pDevice, byPktType, cbLastFragmentSize, wFB_Opt0[FB_RATE1][wRate-RATE_18M], bNeedAck);
623 } else {
624 uNextPktTime = s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt0[FB_RATE1][wRate-RATE_18M], bNeedAck);
625 }
626
627 } else { // (byFBOption == AUTO_FB_1)
628 if (wRate < RATE_18M)
629 wRate = RATE_18M;
630 else if (wRate > RATE_54M)
631 wRate = RATE_54M;
632
633 if(uFragIdx == (uMACfragNum-2)){
634 uNextPktTime = s_uGetTxRsvTime(pDevice, byPktType, cbLastFragmentSize, wFB_Opt1[FB_RATE1][wRate-RATE_18M], bNeedAck);
635 } else {
636 uNextPktTime = s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt1[FB_RATE1][wRate-RATE_18M], bNeedAck);
637 }
638 }
639 if(bNeedAck){
640 uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
641 return (pDevice->uSIFS + uAckTime + uNextPktTime);
642 } else {
643 return (pDevice->uSIFS + uNextPktTime);
644 }
645 }
646 break;
647
648 default:
649 break;
650 }
651
652 ASSERT(FALSE);
653 return 0;
654}
655
656
657//byFreqType: 0=>5GHZ 1=>2.4GHZ
658static
659UINT
660s_uGetRTSCTSDuration (
661 IN PSDevice pDevice,
662 IN BYTE byDurType,
663 IN UINT cbFrameLength,
664 IN BYTE byPktType,
665 IN WORD wRate,
666 IN BOOL bNeedAck,
667 IN BYTE byFBOption
668 )
669{
670 UINT uCTSTime = 0, uDurTime = 0;
671
672
673 switch (byDurType) {
674
675 case RTSDUR_BB: //RTSDuration_bb
676 uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopCCKBasicRate);
677 uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wRate, bNeedAck);
678 break;
679
680 case RTSDUR_BA: //RTSDuration_ba
681 uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopCCKBasicRate);
682 uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wRate, bNeedAck);
683 break;
684
685 case RTSDUR_AA: //RTSDuration_aa
686 uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
687 uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wRate, bNeedAck);
688 break;
689
690 case CTSDUR_BA: //CTSDuration_ba
691 uDurTime = pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wRate, bNeedAck);
692 break;
693
694 case RTSDUR_BA_F0: //RTSDuration_ba_f0
695 uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopCCKBasicRate);
696 if ((byFBOption == AUTO_FB_0) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
697 uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt0[FB_RATE0][wRate-RATE_18M], bNeedAck);
698 } else if ((byFBOption == AUTO_FB_1) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
699 uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt1[FB_RATE0][wRate-RATE_18M], bNeedAck);
700 }
701 break;
702
703 case RTSDUR_AA_F0: //RTSDuration_aa_f0
704 uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
705 if ((byFBOption == AUTO_FB_0) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
706 uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt0[FB_RATE0][wRate-RATE_18M], bNeedAck);
707 } else if ((byFBOption == AUTO_FB_1) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
708 uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt1[FB_RATE0][wRate-RATE_18M], bNeedAck);
709 }
710 break;
711
712 case RTSDUR_BA_F1: //RTSDuration_ba_f1
713 uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopCCKBasicRate);
714 if ((byFBOption == AUTO_FB_0) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
715 uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt0[FB_RATE1][wRate-RATE_18M], bNeedAck);
716 } else if ((byFBOption == AUTO_FB_1) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
717 uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt1[FB_RATE1][wRate-RATE_18M], bNeedAck);
718 }
719 break;
720
721 case RTSDUR_AA_F1: //RTSDuration_aa_f1
722 uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
723 if ((byFBOption == AUTO_FB_0) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
724 uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt0[FB_RATE1][wRate-RATE_18M], bNeedAck);
725 } else if ((byFBOption == AUTO_FB_1) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
726 uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt1[FB_RATE1][wRate-RATE_18M], bNeedAck);
727 }
728 break;
729
730 case CTSDUR_BA_F0: //CTSDuration_ba_f0
731 if ((byFBOption == AUTO_FB_0) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
732 uDurTime = pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt0[FB_RATE0][wRate-RATE_18M], bNeedAck);
733 } else if ((byFBOption == AUTO_FB_1) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
734 uDurTime = pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt1[FB_RATE0][wRate-RATE_18M], bNeedAck);
735 }
736 break;
737
738 case CTSDUR_BA_F1: //CTSDuration_ba_f1
739 if ((byFBOption == AUTO_FB_0) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
740 uDurTime = pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt0[FB_RATE1][wRate-RATE_18M], bNeedAck);
741 } else if ((byFBOption == AUTO_FB_1) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
742 uDurTime = pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt1[FB_RATE1][wRate-RATE_18M], bNeedAck);
743 }
744 break;
745
746 default:
747 break;
748 }
749
750 return uDurTime;
751
752}
753
754
755
756static
757UINT
758s_uFillDataHead (
759 IN PSDevice pDevice,
760 IN BYTE byPktTyp,
761 IN PVOID pTxDataHead,
762 IN UINT cbFrameLength,
763 IN UINT uDMAIdx,
764 IN BOOL bNeedAck,
765 IN UINT uFragIdx,
766 IN UINT cbLastFragmentSize,
767 IN UINT uMACfragNum,
768 IN BYTE byFBOption,
769 IN WORD wCurrentRate
770 )
771{
772 WORD wLen = 0x0000;
773
774 if (pTxDataHead == NULL) {
775 return 0;
776 }
777
778 if (byPktTyp == PK_TYPE_11GB || byPktTyp == PK_TYPE_11GA) {
779 if (byFBOption == AUTO_FB_NONE) {
780 PSTxDataHead_g pBuf = (PSTxDataHead_g)pTxDataHead;
781 //Get SignalField,ServiceField,Length
782 BBvCaculateParameter(pDevice, cbFrameLength, wCurrentRate, byPktTyp,
783 (PWORD)&(wLen), (PBYTE)&(pBuf->byServiceField_a), (PBYTE)&(pBuf->bySignalField_a)
784 );
785 pBuf->wTransmitLength_a = cpu_to_le16(wLen);
786 BBvCaculateParameter(pDevice, cbFrameLength, pDevice->byTopCCKBasicRate, PK_TYPE_11B,
787 (PWORD)&(wLen), (PBYTE)&(pBuf->byServiceField_b), (PBYTE)&(pBuf->bySignalField_b)
788 );
789 pBuf->wTransmitLength_b = cpu_to_le16(wLen);
790 //Get Duration and TimeStamp
791 pBuf->wDuration_a = cpu_to_le16((WORD)s_uGetDataDuration(pDevice, DATADUR_A, cbFrameLength,
792 byPktTyp, wCurrentRate, bNeedAck, uFragIdx,
793 cbLastFragmentSize, uMACfragNum,
794 byFBOption)); //1: 2.4GHz
795 pBuf->wDuration_b = cpu_to_le16((WORD)s_uGetDataDuration(pDevice, DATADUR_B, cbFrameLength,
796 PK_TYPE_11B, pDevice->byTopCCKBasicRate,
797 bNeedAck, uFragIdx, cbLastFragmentSize,
798 uMACfragNum, byFBOption)); //1: 2.4
799
800 pBuf->wTimeStampOff_a = cpu_to_le16(wTimeStampOff[pDevice->byPreambleType%2][wCurrentRate%MAX_RATE]);
801 pBuf->wTimeStampOff_b = cpu_to_le16(wTimeStampOff[pDevice->byPreambleType%2][pDevice->byTopCCKBasicRate%MAX_RATE]);
802
803 return (pBuf->wDuration_a);
804 } else {
805 // Auto Fallback
806 PSTxDataHead_g_FB pBuf = (PSTxDataHead_g_FB)pTxDataHead;
807 //Get SignalField,ServiceField,Length
808 BBvCaculateParameter(pDevice, cbFrameLength, wCurrentRate, byPktTyp,
809 (PWORD)&(wLen), (PBYTE)&(pBuf->byServiceField_a), (PBYTE)&(pBuf->bySignalField_a)
810 );
811 pBuf->wTransmitLength_a = cpu_to_le16(wLen);
812 BBvCaculateParameter(pDevice, cbFrameLength, pDevice->byTopCCKBasicRate, PK_TYPE_11B,
813 (PWORD)&(wLen), (PBYTE)&(pBuf->byServiceField_b), (PBYTE)&(pBuf->bySignalField_b)
814 );
815 pBuf->wTransmitLength_b = cpu_to_le16(wLen);
816 //Get Duration and TimeStamp
817 pBuf->wDuration_a = cpu_to_le16((WORD)s_uGetDataDuration(pDevice, DATADUR_A, cbFrameLength, byPktTyp,
818 wCurrentRate, bNeedAck, uFragIdx, cbLastFragmentSize, uMACfragNum, byFBOption)); //1: 2.4GHz
819 pBuf->wDuration_b = cpu_to_le16((WORD)s_uGetDataDuration(pDevice, DATADUR_B, cbFrameLength, PK_TYPE_11B,
820 pDevice->byTopCCKBasicRate, bNeedAck, uFragIdx, cbLastFragmentSize, uMACfragNum, byFBOption)); //1: 2.4GHz
821 pBuf->wDuration_a_f0 = cpu_to_le16((WORD)s_uGetDataDuration(pDevice, DATADUR_A_F0, cbFrameLength, byPktTyp,
822 wCurrentRate, bNeedAck, uFragIdx, cbLastFragmentSize, uMACfragNum, byFBOption)); //1: 2.4GHz
823 pBuf->wDuration_a_f1 = cpu_to_le16((WORD)s_uGetDataDuration(pDevice, DATADUR_A_F1, cbFrameLength, byPktTyp,
824 wCurrentRate, bNeedAck, uFragIdx, cbLastFragmentSize, uMACfragNum, byFBOption)); //1: 2.4GHz
825
826 pBuf->wTimeStampOff_a = cpu_to_le16(wTimeStampOff[pDevice->byPreambleType%2][wCurrentRate%MAX_RATE]);
827 pBuf->wTimeStampOff_b = cpu_to_le16(wTimeStampOff[pDevice->byPreambleType%2][pDevice->byTopCCKBasicRate%MAX_RATE]);
828
829 return (pBuf->wDuration_a);
830 } //if (byFBOption == AUTO_FB_NONE)
831 }
832 else if (byPktTyp == PK_TYPE_11A) {
833 if ((byFBOption != AUTO_FB_NONE)) {
834 // Auto Fallback
835 PSTxDataHead_a_FB pBuf = (PSTxDataHead_a_FB)pTxDataHead;
836 //Get SignalField,ServiceField,Length
837 BBvCaculateParameter(pDevice, cbFrameLength, wCurrentRate, byPktTyp,
838 (PWORD)&(wLen), (PBYTE)&(pBuf->byServiceField), (PBYTE)&(pBuf->bySignalField)
839 );
840 pBuf->wTransmitLength = cpu_to_le16(wLen);
841 //Get Duration and TimeStampOff
842
843 pBuf->wDuration = cpu_to_le16((WORD)s_uGetDataDuration(pDevice, DATADUR_A, cbFrameLength, byPktTyp,
844 wCurrentRate, bNeedAck, uFragIdx, cbLastFragmentSize, uMACfragNum, byFBOption)); //0: 5GHz
845 pBuf->wDuration_f0 = cpu_to_le16((WORD)s_uGetDataDuration(pDevice, DATADUR_A_F0, cbFrameLength, byPktTyp,
846 wCurrentRate, bNeedAck, uFragIdx, cbLastFragmentSize, uMACfragNum, byFBOption)); //0: 5GHz
847 pBuf->wDuration_f1 = cpu_to_le16((WORD)s_uGetDataDuration(pDevice, DATADUR_A_F1, cbFrameLength, byPktTyp,
848 wCurrentRate, bNeedAck, uFragIdx, cbLastFragmentSize, uMACfragNum, byFBOption)); //0: 5GHz
849 pBuf->wTimeStampOff = cpu_to_le16(wTimeStampOff[pDevice->byPreambleType%2][wCurrentRate%MAX_RATE]);
850 return (pBuf->wDuration);
851 } else {
852 PSTxDataHead_ab pBuf = (PSTxDataHead_ab)pTxDataHead;
853 //Get SignalField,ServiceField,Length
854 BBvCaculateParameter(pDevice, cbFrameLength, wCurrentRate, byPktTyp,
855 (PWORD)&(wLen), (PBYTE)&(pBuf->byServiceField), (PBYTE)&(pBuf->bySignalField)
856 );
857 pBuf->wTransmitLength = cpu_to_le16(wLen);
858 //Get Duration and TimeStampOff
859
860 pBuf->wDuration = cpu_to_le16((WORD)s_uGetDataDuration(pDevice, DATADUR_A, cbFrameLength, byPktTyp,
861 wCurrentRate, bNeedAck, uFragIdx,
862 cbLastFragmentSize, uMACfragNum,
863 byFBOption));
864
865 pBuf->wTimeStampOff = cpu_to_le16(wTimeStampOff[pDevice->byPreambleType%2][wCurrentRate%MAX_RATE]);
866 return (pBuf->wDuration);
867 }
868 }
869 else {
870 PSTxDataHead_ab pBuf = (PSTxDataHead_ab)pTxDataHead;
871 //Get SignalField,ServiceField,Length
872 BBvCaculateParameter(pDevice, cbFrameLength, wCurrentRate, byPktTyp,
873 (PWORD)&(wLen), (PBYTE)&(pBuf->byServiceField), (PBYTE)&(pBuf->bySignalField)
874 );
875 pBuf->wTransmitLength = cpu_to_le16(wLen);
876 //Get Duration and TimeStampOff
877 pBuf->wDuration = cpu_to_le16((WORD)s_uGetDataDuration(pDevice, DATADUR_B, cbFrameLength, byPktTyp,
878 wCurrentRate, bNeedAck, uFragIdx,
879 cbLastFragmentSize, uMACfragNum,
880 byFBOption));
881 pBuf->wTimeStampOff = cpu_to_le16(wTimeStampOff[pDevice->byPreambleType%2][wCurrentRate%MAX_RATE]);
882 return (pBuf->wDuration);
883 }
884 return 0;
885}
886
887
888static
889VOID
890s_vFillRTSHead (
891 IN PSDevice pDevice,
892 IN BYTE byPktTyp,
893 IN PVOID pvRTS,
894 IN UINT cbFrameLength,
895 IN BOOL bNeedAck,
896 IN BOOL bDisCRC,
897 IN PSEthernetHeader psEthHeader,
898 IN WORD wCurrentRate,
899 IN BYTE byFBOption
900 )
901{
902 UINT uRTSFrameLen = 20;
903 WORD wLen = 0x0000;
904
905 // dummy code, only to avoid compiler warning message
906 UNREFERENCED_PARAMETER(bNeedAck);
907
908 if (pvRTS == NULL)
909 return;
910
911 if (bDisCRC) {
912 // When CRCDIS bit is on, H/W forgot to generate FCS for RTS frame,
913 // in this case we need to decrease its length by 4.
914 uRTSFrameLen -= 4;
915 }
916
917 // Note: So far RTSHead dosen't appear in ATIM & Beacom DMA, so we don't need to take them into account.
918 // Otherwise, we need to modified codes for them.
919 if (byPktTyp == PK_TYPE_11GB || byPktTyp == PK_TYPE_11GA) {
920 if (byFBOption == AUTO_FB_NONE) {
921 PSRTS_g pBuf = (PSRTS_g)pvRTS;
922 //Get SignalField,ServiceField,Length
923 BBvCaculateParameter(pDevice, uRTSFrameLen, pDevice->byTopCCKBasicRate, PK_TYPE_11B,
924 (PWORD)&(wLen), (PBYTE)&(pBuf->byServiceField_b), (PBYTE)&(pBuf->bySignalField_b)
925 );
926 pBuf->wTransmitLength_b = cpu_to_le16(wLen);
927 BBvCaculateParameter(pDevice, uRTSFrameLen, pDevice->byTopOFDMBasicRate, byPktTyp,
928 (PWORD)&(wLen), (PBYTE)&(pBuf->byServiceField_a), (PBYTE)&(pBuf->bySignalField_a)
929 );
930 pBuf->wTransmitLength_a = cpu_to_le16(wLen);
931 //Get Duration
932 pBuf->wDuration_bb = cpu_to_le16((WORD)s_uGetRTSCTSDuration(pDevice, RTSDUR_BB, cbFrameLength, PK_TYPE_11B, pDevice->byTopCCKBasicRate, bNeedAck, byFBOption)); //0:RTSDuration_bb, 1:2.4G, 1:CCKData
933 pBuf->wDuration_aa = cpu_to_le16((WORD)s_uGetRTSCTSDuration(pDevice, RTSDUR_AA, cbFrameLength, byPktTyp, wCurrentRate, bNeedAck, byFBOption)); //2:RTSDuration_aa, 1:2.4G, 2,3: 2.4G OFDMData
934 pBuf->wDuration_ba = cpu_to_le16((WORD)s_uGetRTSCTSDuration(pDevice, RTSDUR_BA, cbFrameLength, byPktTyp, wCurrentRate, bNeedAck, byFBOption)); //1:RTSDuration_ba, 1:2.4G, 2,3:2.4G OFDM Data
935
936 pBuf->Data.wDurationID = pBuf->wDuration_aa;
937 //Get RTS Frame body
938 pBuf->Data.wFrameControl = TYPE_CTL_RTS;//0x00B4
939 if ((pDevice->eOPMode == OP_MODE_ADHOC) ||
940 (pDevice->eOPMode == OP_MODE_AP)) {
941 MEMvCopy(&(pBuf->Data.abyRA[0]), &(psEthHeader->abyDstAddr[0]), U_ETHER_ADDR_LEN);
942 }
943 else {
944 MEMvCopy(&(pBuf->Data.abyRA[0]), &(pDevice->abyBSSID[0]), U_ETHER_ADDR_LEN);
945 }
946 if (pDevice->eOPMode == OP_MODE_AP) {
947 MEMvCopy(&(pBuf->Data.abyTA[0]), &(pDevice->abyBSSID[0]), U_ETHER_ADDR_LEN);
948 }
949 else {
950 MEMvCopy(&(pBuf->Data.abyTA[0]), &(psEthHeader->abySrcAddr[0]), U_ETHER_ADDR_LEN);
951 }
952 }
953 else {
954 PSRTS_g_FB pBuf = (PSRTS_g_FB)pvRTS;
955 //Get SignalField,ServiceField,Length
956 BBvCaculateParameter(pDevice, uRTSFrameLen, pDevice->byTopCCKBasicRate, PK_TYPE_11B,
957 (PWORD)&(wLen), (PBYTE)&(pBuf->byServiceField_b), (PBYTE)&(pBuf->bySignalField_b)
958 );
959 pBuf->wTransmitLength_b = cpu_to_le16(wLen);
960 BBvCaculateParameter(pDevice, uRTSFrameLen, pDevice->byTopOFDMBasicRate, byPktTyp,
961 (PWORD)&(wLen), (PBYTE)&(pBuf->byServiceField_a), (PBYTE)&(pBuf->bySignalField_a)
962 );
963 pBuf->wTransmitLength_a = cpu_to_le16(wLen);
964
965 //Get Duration
966 pBuf->wDuration_bb = cpu_to_le16((WORD)s_uGetRTSCTSDuration(pDevice, RTSDUR_BB, cbFrameLength, PK_TYPE_11B, pDevice->byTopCCKBasicRate, bNeedAck, byFBOption)); //0:RTSDuration_bb, 1:2.4G, 1:CCKData
967 pBuf->wDuration_aa = cpu_to_le16((WORD)s_uGetRTSCTSDuration(pDevice, RTSDUR_AA, cbFrameLength, byPktTyp, wCurrentRate, bNeedAck, byFBOption)); //2:RTSDuration_aa, 1:2.4G, 2,3:2.4G OFDMData
968 pBuf->wDuration_ba = cpu_to_le16((WORD)s_uGetRTSCTSDuration(pDevice, RTSDUR_BA, cbFrameLength, byPktTyp, wCurrentRate, bNeedAck, byFBOption)); //1:RTSDuration_ba, 1:2.4G, 2,3:2.4G OFDMData
969 pBuf->wRTSDuration_ba_f0 = cpu_to_le16((WORD)s_uGetRTSCTSDuration(pDevice, RTSDUR_BA_F0, cbFrameLength, byPktTyp, wCurrentRate, bNeedAck, byFBOption)); //4:wRTSDuration_ba_f0, 1:2.4G, 1:CCKData
970 pBuf->wRTSDuration_aa_f0 = cpu_to_le16((WORD)s_uGetRTSCTSDuration(pDevice, RTSDUR_AA_F0, cbFrameLength, byPktTyp, wCurrentRate, bNeedAck, byFBOption)); //5:wRTSDuration_aa_f0, 1:2.4G, 1:CCKData
971 pBuf->wRTSDuration_ba_f1 = cpu_to_le16((WORD)s_uGetRTSCTSDuration(pDevice, RTSDUR_BA_F1, cbFrameLength, byPktTyp, wCurrentRate, bNeedAck, byFBOption)); //6:wRTSDuration_ba_f1, 1:2.4G, 1:CCKData
972 pBuf->wRTSDuration_aa_f1 = cpu_to_le16((WORD)s_uGetRTSCTSDuration(pDevice, RTSDUR_AA_F1, cbFrameLength, byPktTyp, wCurrentRate, bNeedAck, byFBOption)); //7:wRTSDuration_aa_f1, 1:2.4G, 1:CCKData
973 pBuf->Data.wDurationID = pBuf->wDuration_aa;
974 //Get RTS Frame body
975 pBuf->Data.wFrameControl = TYPE_CTL_RTS;//0x00B4
976
977 if ((pDevice->eOPMode == OP_MODE_ADHOC) ||
978 (pDevice->eOPMode == OP_MODE_AP)) {
979 MEMvCopy(&(pBuf->Data.abyRA[0]), &(psEthHeader->abyDstAddr[0]), U_ETHER_ADDR_LEN);
980 }
981 else {
982 MEMvCopy(&(pBuf->Data.abyRA[0]), &(pDevice->abyBSSID[0]), U_ETHER_ADDR_LEN);
983 }
984
985 if (pDevice->eOPMode == OP_MODE_AP) {
986 MEMvCopy(&(pBuf->Data.abyTA[0]), &(pDevice->abyBSSID[0]), U_ETHER_ADDR_LEN);
987 }
988 else {
989 MEMvCopy(&(pBuf->Data.abyTA[0]), &(psEthHeader->abySrcAddr[0]), U_ETHER_ADDR_LEN);
990 }
991
992 } // if (byFBOption == AUTO_FB_NONE)
993 }
994 else if (byPktTyp == PK_TYPE_11A) {
995 if (byFBOption == AUTO_FB_NONE) {
996 PSRTS_ab pBuf = (PSRTS_ab)pvRTS;
997 //Get SignalField,ServiceField,Length
998 BBvCaculateParameter(pDevice, uRTSFrameLen, pDevice->byTopOFDMBasicRate, byPktTyp,
999 (PWORD)&(wLen), (PBYTE)&(pBuf->byServiceField), (PBYTE)&(pBuf->bySignalField)
1000 );
1001 pBuf->wTransmitLength = cpu_to_le16(wLen);
1002 //Get Duration
1003 pBuf->wDuration = cpu_to_le16((WORD)s_uGetRTSCTSDuration(pDevice, RTSDUR_AA, cbFrameLength, byPktTyp, wCurrentRate, bNeedAck, byFBOption)); //0:RTSDuration_aa, 0:5G, 0: 5G OFDMData
1004 pBuf->Data.wDurationID = pBuf->wDuration;
1005 //Get RTS Frame body
1006 pBuf->Data.wFrameControl = TYPE_CTL_RTS;//0x00B4
1007
1008 if ((pDevice->eOPMode == OP_MODE_ADHOC) ||
1009 (pDevice->eOPMode == OP_MODE_AP)) {
1010 MEMvCopy(&(pBuf->Data.abyRA[0]), &(psEthHeader->abyDstAddr[0]), U_ETHER_ADDR_LEN);
1011 }
1012 else {
1013 MEMvCopy(&(pBuf->Data.abyRA[0]), &(pDevice->abyBSSID[0]), U_ETHER_ADDR_LEN);
1014 }
1015
1016 if (pDevice->eOPMode == OP_MODE_AP) {
1017 MEMvCopy(&(pBuf->Data.abyTA[0]), &(pDevice->abyBSSID[0]), U_ETHER_ADDR_LEN);
1018 }
1019 else {
1020 MEMvCopy(&(pBuf->Data.abyTA[0]), &(psEthHeader->abySrcAddr[0]), U_ETHER_ADDR_LEN);
1021 }
1022
1023 }
1024 else {
1025 PSRTS_a_FB pBuf = (PSRTS_a_FB)pvRTS;
1026 //Get SignalField,ServiceField,Length
1027 BBvCaculateParameter(pDevice, uRTSFrameLen, pDevice->byTopOFDMBasicRate, byPktTyp,
1028 (PWORD)&(wLen), (PBYTE)&(pBuf->byServiceField), (PBYTE)&(pBuf->bySignalField)
1029 );
1030 pBuf->wTransmitLength = cpu_to_le16(wLen);
1031 //Get Duration
1032 pBuf->wDuration = cpu_to_le16((WORD)s_uGetRTSCTSDuration(pDevice, RTSDUR_AA, cbFrameLength, byPktTyp, wCurrentRate, bNeedAck, byFBOption)); //0:RTSDuration_aa, 0:5G, 0: 5G OFDMData
1033 pBuf->wRTSDuration_f0 = cpu_to_le16((WORD)s_uGetRTSCTSDuration(pDevice, RTSDUR_AA_F0, cbFrameLength, byPktTyp, wCurrentRate, bNeedAck, byFBOption)); //5:RTSDuration_aa_f0, 0:5G, 0: 5G OFDMData
1034 pBuf->wRTSDuration_f1 = cpu_to_le16((WORD)s_uGetRTSCTSDuration(pDevice, RTSDUR_AA_F1, cbFrameLength, byPktTyp, wCurrentRate, bNeedAck, byFBOption)); //7:RTSDuration_aa_f1, 0:5G, 0:
1035 pBuf->Data.wDurationID = pBuf->wDuration;
1036 //Get RTS Frame body
1037 pBuf->Data.wFrameControl = TYPE_CTL_RTS;//0x00B4
1038
1039 if ((pDevice->eOPMode == OP_MODE_ADHOC) ||
1040 (pDevice->eOPMode == OP_MODE_AP)) {
1041 MEMvCopy(&(pBuf->Data.abyRA[0]), &(psEthHeader->abyDstAddr[0]), U_ETHER_ADDR_LEN);
1042 }
1043 else {
1044 MEMvCopy(&(pBuf->Data.abyRA[0]), &(pDevice->abyBSSID[0]), U_ETHER_ADDR_LEN);
1045 }
1046 if (pDevice->eOPMode == OP_MODE_AP) {
1047 MEMvCopy(&(pBuf->Data.abyTA[0]), &(pDevice->abyBSSID[0]), U_ETHER_ADDR_LEN);
1048 }
1049 else {
1050 MEMvCopy(&(pBuf->Data.abyTA[0]), &(psEthHeader->abySrcAddr[0]), U_ETHER_ADDR_LEN);
1051 }
1052 }
1053 }
1054 else if (byPktTyp == PK_TYPE_11B) {
1055 PSRTS_ab pBuf = (PSRTS_ab)pvRTS;
1056 //Get SignalField,ServiceField,Length
1057 BBvCaculateParameter(pDevice, uRTSFrameLen, pDevice->byTopCCKBasicRate, PK_TYPE_11B,
1058 (PWORD)&(wLen), (PBYTE)&(pBuf->byServiceField), (PBYTE)&(pBuf->bySignalField)
1059 );
1060 pBuf->wTransmitLength = cpu_to_le16(wLen);
1061 //Get Duration
1062 pBuf->wDuration = cpu_to_le16((WORD)s_uGetRTSCTSDuration(pDevice, RTSDUR_BB, cbFrameLength, byPktTyp, wCurrentRate, bNeedAck, byFBOption)); //0:RTSDuration_bb, 1:2.4G, 1:CCKData
1063 pBuf->Data.wDurationID = pBuf->wDuration;
1064 //Get RTS Frame body
1065 pBuf->Data.wFrameControl = TYPE_CTL_RTS;//0x00B4
1066
1067
1068 if ((pDevice->eOPMode == OP_MODE_ADHOC) ||
1069 (pDevice->eOPMode == OP_MODE_AP)) {
1070 MEMvCopy(&(pBuf->Data.abyRA[0]), &(psEthHeader->abyDstAddr[0]), U_ETHER_ADDR_LEN);
1071 }
1072 else {
1073 MEMvCopy(&(pBuf->Data.abyRA[0]), &(pDevice->abyBSSID[0]), U_ETHER_ADDR_LEN);
1074 }
1075
1076 if (pDevice->eOPMode == OP_MODE_AP) {
1077 MEMvCopy(&(pBuf->Data.abyTA[0]), &(pDevice->abyBSSID[0]), U_ETHER_ADDR_LEN);
1078 }
1079 else {
1080 MEMvCopy(&(pBuf->Data.abyTA[0]), &(psEthHeader->abySrcAddr[0]), U_ETHER_ADDR_LEN);
1081 }
1082 }
1083}
1084
1085static
1086VOID
1087s_vFillCTSHead (
1088 IN PSDevice pDevice,
1089 IN UINT uDMAIdx,
1090 IN BYTE byPktTyp,
1091 IN PVOID pvCTS,
1092 IN UINT cbFrameLength,
1093 IN BOOL bNeedAck,
1094 IN BOOL bDisCRC,
1095 IN WORD wCurrentRate,
1096 IN BYTE byFBOption
1097 )
1098{
1099 UINT uCTSFrameLen = 14;
1100 WORD wLen = 0x0000;
1101
1102 if (pvCTS == NULL) {
1103 return;
1104 }
1105
1106 if (bDisCRC) {
1107 // When CRCDIS bit is on, H/W forgot to generate FCS for CTS frame,
1108 // in this case we need to decrease its length by 4.
1109 uCTSFrameLen -= 4;
1110 }
1111
1112 if (byPktTyp == PK_TYPE_11GB || byPktTyp == PK_TYPE_11GA) {
1113 if (byFBOption != AUTO_FB_NONE && uDMAIdx != TYPE_ATIMDMA && uDMAIdx != TYPE_BEACONDMA) {
1114 // Auto Fall back
1115 PSCTS_FB pBuf = (PSCTS_FB)pvCTS;
1116 //Get SignalField,ServiceField,Length
1117 BBvCaculateParameter(pDevice, uCTSFrameLen, pDevice->byTopCCKBasicRate, PK_TYPE_11B,
1118 (PWORD)&(wLen), (PBYTE)&(pBuf->byServiceField_b), (PBYTE)&(pBuf->bySignalField_b)
1119 );
1120
1121
1122 pBuf->wTransmitLength_b = cpu_to_le16(wLen);
1123
1124 pBuf->wDuration_ba = (WORD)s_uGetRTSCTSDuration(pDevice, CTSDUR_BA, cbFrameLength, byPktTyp, wCurrentRate, bNeedAck, byFBOption); //3:CTSDuration_ba, 1:2.4G, 2,3:2.4G OFDM Data
1125 pBuf->wDuration_ba += pDevice->wCTSDuration;
1126 pBuf->wDuration_ba = cpu_to_le16(pBuf->wDuration_ba);
1127 //Get CTSDuration_ba_f0
1128 pBuf->wCTSDuration_ba_f0 = (WORD)s_uGetRTSCTSDuration(pDevice, CTSDUR_BA_F0, cbFrameLength, byPktTyp, wCurrentRate, bNeedAck, byFBOption); //8:CTSDuration_ba_f0, 1:2.4G, 2,3:2.4G OFDM Data
1129 pBuf->wCTSDuration_ba_f0 += pDevice->wCTSDuration;
1130 pBuf->wCTSDuration_ba_f0 = cpu_to_le16(pBuf->wCTSDuration_ba_f0);
1131 //Get CTSDuration_ba_f1
1132 pBuf->wCTSDuration_ba_f1 = (WORD)s_uGetRTSCTSDuration(pDevice, CTSDUR_BA_F1, cbFrameLength, byPktTyp, wCurrentRate, bNeedAck, byFBOption); //9:CTSDuration_ba_f1, 1:2.4G, 2,3:2.4G OFDM Data
1133 pBuf->wCTSDuration_ba_f1 += pDevice->wCTSDuration;
1134 pBuf->wCTSDuration_ba_f1 = cpu_to_le16(pBuf->wCTSDuration_ba_f1);
1135 //Get CTS Frame body
1136 pBuf->Data.wDurationID = pBuf->wDuration_ba;
1137 pBuf->Data.wFrameControl = TYPE_CTL_CTS;//0x00C4
1138 pBuf->Data.wReserved = 0x0000;
1139 MEMvCopy(&(pBuf->Data.abyRA[0]), &(pDevice->abyCurrentNetAddr[0]), U_ETHER_ADDR_LEN);
1140
1141 } else { //if (byFBOption != AUTO_FB_NONE && uDMAIdx != TYPE_ATIMDMA && uDMAIdx != TYPE_BEACONDMA)
1142 PSCTS pBuf = (PSCTS)pvCTS;
1143 //Get SignalField,ServiceField,Length
1144 BBvCaculateParameter(pDevice, uCTSFrameLen, pDevice->byTopCCKBasicRate, PK_TYPE_11B,
1145 (PWORD)&(wLen), (PBYTE)&(pBuf->byServiceField_b), (PBYTE)&(pBuf->bySignalField_b)
1146 );
1147 pBuf->wTransmitLength_b = cpu_to_le16(wLen);
1148 //Get CTSDuration_ba
1149 pBuf->wDuration_ba = cpu_to_le16((WORD)s_uGetRTSCTSDuration(pDevice, CTSDUR_BA, cbFrameLength, byPktTyp, wCurrentRate, bNeedAck, byFBOption)); //3:CTSDuration_ba, 1:2.4G, 2,3:2.4G OFDM Data
1150 pBuf->wDuration_ba += pDevice->wCTSDuration;
1151 pBuf->wDuration_ba = cpu_to_le16(pBuf->wDuration_ba);
1152
1153 //Get CTS Frame body
1154 pBuf->Data.wDurationID = pBuf->wDuration_ba;
1155 pBuf->Data.wFrameControl = TYPE_CTL_CTS;//0x00C4
1156 pBuf->Data.wReserved = 0x0000;
1157 MEMvCopy(&(pBuf->Data.abyRA[0]), &(pDevice->abyCurrentNetAddr[0]), U_ETHER_ADDR_LEN);
1158 }
1159 }
1160}
1161
1162
1163
1164
1165
1166
1167/*+
1168 *
1169 * Description:
1170 * Generate FIFO control for MAC & Baseband controller
1171 *
1172 * Parameters:
1173 * In:
1174 * pDevice - Pointer to adpater
1175 * pTxDataHead - Transmit Data Buffer
1176 * pTxBufHead - pTxBufHead
1177 * pvRrvTime - pvRrvTime
1178 * pvRTS - RTS Buffer
1179 * pCTS - CTS Buffer
1180 * cbFrameSize - Transmit Data Length (Hdr+Payload+FCS)
1181 * bNeedACK - If need ACK
1182 * uDescIdx - Desc Index
1183 * Out:
1184 * none
1185 *
1186 * Return Value: none
1187 *
1188-*/
1189// UINT cbFrameSize,//Hdr+Payload+FCS
1190static
1191VOID
1192s_vGenerateTxParameter (
1193 IN PSDevice pDevice,
1194 IN BYTE byPktTyp,
1195 IN PVOID pTxBufHead,
1196 IN PVOID pvRrvTime,
1197 IN PVOID pvRTS,
1198 IN PVOID pvCTS,
1199 IN UINT cbFrameSize,
1200 IN BOOL bNeedACK,
1201 IN UINT uDMAIdx,
1202 IN PSEthernetHeader psEthHeader,
1203 IN WORD wCurrentRate
1204 )
1205{
1206 UINT cbMACHdLen = WLAN_HDR_ADDR3_LEN; //24
1207 WORD wFifoCtl;
1208 BOOL bDisCRC = FALSE;
1209 BYTE byFBOption = AUTO_FB_NONE;
1210// WORD wCurrentRate = pDevice->wCurrentRate;
1211
1212 //DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"s_vGenerateTxParameter...\n");
1213 PSTxBufHead pFifoHead = (PSTxBufHead)pTxBufHead;
1214 pFifoHead->wReserved = wCurrentRate;
1215 wFifoCtl = pFifoHead->wFIFOCtl;
1216
1217 if (wFifoCtl & FIFOCTL_CRCDIS) {
1218 bDisCRC = TRUE;
1219 }
1220
1221 if (wFifoCtl & FIFOCTL_AUTO_FB_0) {
1222 byFBOption = AUTO_FB_0;
1223 }
1224 else if (wFifoCtl & FIFOCTL_AUTO_FB_1) {
1225 byFBOption = AUTO_FB_1;
1226 }
1227
1228 if (pDevice->bLongHeader)
1229 cbMACHdLen = WLAN_HDR_ADDR3_LEN + 6;
1230
1231 if (byPktTyp == PK_TYPE_11GB || byPktTyp == PK_TYPE_11GA) {
1232
1233 if (pvRTS != NULL) { //RTS_need
1234 //Fill RsvTime
1235 if (pvRrvTime) {
1236 PSRrvTime_gRTS pBuf = (PSRrvTime_gRTS)pvRrvTime;
1237 pBuf->wRTSTxRrvTime_aa = cpu_to_le16((WORD)s_uGetRTSCTSRsvTime(pDevice, 2, byPktTyp, cbFrameSize, wCurrentRate));//2:RTSTxRrvTime_aa, 1:2.4GHz
1238 pBuf->wRTSTxRrvTime_ba = cpu_to_le16((WORD)s_uGetRTSCTSRsvTime(pDevice, 1, byPktTyp, cbFrameSize, wCurrentRate));//1:RTSTxRrvTime_ba, 1:2.4GHz
1239 pBuf->wRTSTxRrvTime_bb = cpu_to_le16((WORD)s_uGetRTSCTSRsvTime(pDevice, 0, byPktTyp, cbFrameSize, wCurrentRate));//0:RTSTxRrvTime_bb, 1:2.4GHz
1240 pBuf->wTxRrvTime_a = cpu_to_le16((WORD) s_uGetTxRsvTime(pDevice, byPktTyp, cbFrameSize, wCurrentRate, bNeedACK));//2.4G OFDM
1241 pBuf->wTxRrvTime_b = cpu_to_le16((WORD) s_uGetTxRsvTime(pDevice, PK_TYPE_11B, cbFrameSize, pDevice->byTopCCKBasicRate, bNeedACK));//1:CCK
1242 }
1243 //Fill RTS
1244 s_vFillRTSHead(pDevice, byPktTyp, pvRTS, cbFrameSize, bNeedACK, bDisCRC, psEthHeader, wCurrentRate, byFBOption);
1245 }
1246 else {//RTS_needless, PCF mode
1247
1248 //Fill RsvTime
1249 if (pvRrvTime) {
1250 PSRrvTime_gCTS pBuf = (PSRrvTime_gCTS)pvRrvTime;
1251 pBuf->wTxRrvTime_a = cpu_to_le16((WORD)s_uGetTxRsvTime(pDevice, byPktTyp, cbFrameSize, wCurrentRate, bNeedACK));//2.4G OFDM
1252 pBuf->wTxRrvTime_b = cpu_to_le16((WORD)s_uGetTxRsvTime(pDevice, PK_TYPE_11B, cbFrameSize, pDevice->byTopCCKBasicRate, bNeedACK));//1:CCK
1253 pBuf->wCTSTxRrvTime_ba = cpu_to_le16((WORD)s_uGetRTSCTSRsvTime(pDevice, 3, byPktTyp, cbFrameSize, wCurrentRate));//3:CTSTxRrvTime_Ba, 1:2.4GHz
1254 }
1255
1256
1257 //Fill CTS
1258 s_vFillCTSHead(pDevice, uDMAIdx, byPktTyp, pvCTS, cbFrameSize, bNeedACK, bDisCRC, wCurrentRate, byFBOption);
1259 }
1260 }
1261 else if (byPktTyp == PK_TYPE_11A) {
1262
1263 if (pvRTS != NULL) {//RTS_need, non PCF mode
1264 //Fill RsvTime
1265 if (pvRrvTime) {
1266 PSRrvTime_ab pBuf = (PSRrvTime_ab)pvRrvTime;
1267 pBuf->wRTSTxRrvTime = cpu_to_le16((WORD)s_uGetRTSCTSRsvTime(pDevice, 2, byPktTyp, cbFrameSize, wCurrentRate));//2:RTSTxRrvTime_aa, 0:5GHz
1268 pBuf->wTxRrvTime = cpu_to_le16((WORD)s_uGetTxRsvTime(pDevice, byPktTyp, cbFrameSize, wCurrentRate, bNeedACK));//0:OFDM
1269 }
1270 //Fill RTS
1271 s_vFillRTSHead(pDevice, byPktTyp, pvRTS, cbFrameSize, bNeedACK, bDisCRC, psEthHeader, wCurrentRate, byFBOption);
1272 }
1273 else if (pvRTS == NULL) {//RTS_needless, non PCF mode
1274 //Fill RsvTime
1275 if (pvRrvTime) {
1276 PSRrvTime_ab pBuf = (PSRrvTime_ab)pvRrvTime;
1277 pBuf->wTxRrvTime = cpu_to_le16((WORD)s_uGetTxRsvTime(pDevice, PK_TYPE_11A, cbFrameSize, wCurrentRate, bNeedACK)); //0:OFDM
1278 }
1279 }
1280 }
1281 else if (byPktTyp == PK_TYPE_11B) {
1282
1283 if ((pvRTS != NULL)) {//RTS_need, non PCF mode
1284 //Fill RsvTime
1285 if (pvRrvTime) {
1286 PSRrvTime_ab pBuf = (PSRrvTime_ab)pvRrvTime;
1287 pBuf->wRTSTxRrvTime = cpu_to_le16((WORD)s_uGetRTSCTSRsvTime(pDevice, 0, byPktTyp, cbFrameSize, wCurrentRate));//0:RTSTxRrvTime_bb, 1:2.4GHz
1288 pBuf->wTxRrvTime = cpu_to_le16((WORD)s_uGetTxRsvTime(pDevice, PK_TYPE_11B, cbFrameSize, wCurrentRate, bNeedACK));//1:CCK
1289 }
1290 //Fill RTS
1291 s_vFillRTSHead(pDevice, byPktTyp, pvRTS, cbFrameSize, bNeedACK, bDisCRC, psEthHeader, wCurrentRate, byFBOption);
1292 }
1293 else { //RTS_needless, non PCF mode
1294 //Fill RsvTime
1295 if (pvRrvTime) {
1296 PSRrvTime_ab pBuf = (PSRrvTime_ab)pvRrvTime;
1297 pBuf->wTxRrvTime = cpu_to_le16((WORD)s_uGetTxRsvTime(pDevice, PK_TYPE_11B, cbFrameSize, wCurrentRate, bNeedACK)); //1:CCK
1298 }
1299 }
1300 }
1301 //DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"s_vGenerateTxParameter END.\n");
1302}
1303/*
1304 PBYTE pbyBuffer,//point to pTxBufHead
1305 WORD wFragType,//00:Non-Frag, 01:Start, 02:Mid, 03:Last
1306 UINT cbFragmentSize,//Hdr+payoad+FCS
1307*/
1308static
1309VOID
1310s_vFillFragParameter(
1311 IN PSDevice pDevice,
1312 IN PBYTE pbyBuffer,
1313 IN UINT uTxType,
1314 IN PVOID pvtdCurr,
1315 IN WORD wFragType,
1316 IN UINT cbReqCount
1317 )
1318{
1319 PSTxBufHead pTxBufHead = (PSTxBufHead) pbyBuffer;
1320 //DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"s_vFillFragParameter...\n");
1321
1322 if (uTxType == TYPE_SYNCDMA) {
1323 //PSTxSyncDesc ptdCurr = (PSTxSyncDesc)s_pvGetTxDescHead(pDevice, uTxType, uCurIdx);
1324 PSTxSyncDesc ptdCurr = (PSTxSyncDesc)pvtdCurr;
1325
1326 //Set FIFOCtl & TimeStamp in TxSyncDesc
1327 ptdCurr->m_wFIFOCtl = pTxBufHead->wFIFOCtl;
1328 ptdCurr->m_wTimeStamp = pTxBufHead->wTimeStamp;
1329 //Set TSR1 & ReqCount in TxDescHead
1330 ptdCurr->m_td1TD1.wReqCount = cpu_to_le16((WORD)(cbReqCount));
1331 if (wFragType == FRAGCTL_ENDFRAG) { //Last Fragmentation
1332 ptdCurr->m_td1TD1.byTCR |= (TCR_STP | TCR_EDP | EDMSDU);
1333 }
1334 else {
1335 ptdCurr->m_td1TD1.byTCR |= (TCR_STP | TCR_EDP);
1336 }
1337 }
1338 else {
1339 //PSTxDesc ptdCurr = (PSTxDesc)s_pvGetTxDescHead(pDevice, uTxType, uCurIdx);
1340 PSTxDesc ptdCurr = (PSTxDesc)pvtdCurr;
1341 //Set TSR1 & ReqCount in TxDescHead
1342 ptdCurr->m_td1TD1.wReqCount = cpu_to_le16((WORD)(cbReqCount));
1343 if (wFragType == FRAGCTL_ENDFRAG) { //Last Fragmentation
1344 ptdCurr->m_td1TD1.byTCR |= (TCR_STP | TCR_EDP | EDMSDU);
1345 }
1346 else {
1347 ptdCurr->m_td1TD1.byTCR |= (TCR_STP | TCR_EDP);
1348 }
1349 }
1350
1351 pTxBufHead->wFragCtl |= (WORD)wFragType;//0x0001; //0000 0000 0000 0001
1352
1353 //DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"s_vFillFragParameter END\n");
1354}
1355
1356static
1357UINT
1358s_cbFillTxBufHead (
1359 IN PSDevice pDevice,
1360 IN BYTE byPktTyp,
1361 IN PBYTE pbyTxBufferAddr,
1362 IN UINT cbFrameBodySize,
1363 IN UINT uDMAIdx,
1364 IN PSTxDesc pHeadTD,
1365 IN PSEthernetHeader psEthHeader,
1366 IN PBYTE pPacket,
1367 IN BOOL bNeedEncrypt,
1368 IN PSKeyItem pTransmitKey,
1369 IN UINT uNodeIndex,
1370 OUT PUINT puMACfragNum
1371 )
1372{
1373 UINT cbMACHdLen;
1374 UINT cbFrameSize;
1375 UINT cbFragmentSize; //Hdr+(IV)+payoad+(MIC)+(ICV)+FCS
1376 UINT cbFragPayloadSize;
1377 UINT cbLastFragmentSize; //Hdr+(IV)+payoad+(MIC)+(ICV)+FCS
1378 UINT cbLastFragPayloadSize;
1379 UINT uFragIdx;
1380 PBYTE pbyPayloadHead;
1381 PBYTE pbyIVHead;
1382 PBYTE pbyMacHdr;
1383 WORD wFragType; //00:Non-Frag, 01:Start, 10:Mid, 11:Last
1384 UINT uDuration;
1385 PBYTE pbyBuffer;
1386// UINT uKeyEntryIdx = NUM_KEY_ENTRY+1;
1387// BYTE byKeySel = 0xFF;
1388 UINT cbIVlen = 0;
1389 UINT cbICVlen = 0;
1390 UINT cbMIClen = 0;
1391 UINT cbFCSlen = 4;
1392 UINT cb802_1_H_len = 0;
1393 UINT uLength = 0;
1394 UINT uTmpLen = 0;
1395// BYTE abyTmp[8];
1396// DWORD dwCRC;
1397 UINT cbMICHDR = 0;
1398 DWORD dwMICKey0, dwMICKey1;
1399 DWORD dwMIC_Priority;
1400 PDWORD pdwMIC_L;
1401 PDWORD pdwMIC_R;
1402 DWORD dwSafeMIC_L, dwSafeMIC_R; //Fix "Last Frag Size" < "MIC length".
1403 BOOL bMIC2Frag = FALSE;
1404 UINT uMICFragLen = 0;
1405 UINT uMACfragNum = 1;
1406 UINT uPadding = 0;
1407 UINT cbReqCount = 0;
1408
1409 BOOL bNeedACK;
1410 BOOL bRTS;
1411 BOOL bIsAdhoc;
1412 PBYTE pbyType;
1413 PSTxDesc ptdCurr;
1414 PSTxBufHead psTxBufHd = (PSTxBufHead) pbyTxBufferAddr;
1415// UINT tmpDescIdx;
1416 UINT cbHeaderLength = 0;
1417 PVOID pvRrvTime;
1418 PSMICHDRHead pMICHDR;
1419 PVOID pvRTS;
1420 PVOID pvCTS;
1421 PVOID pvTxDataHd;
1422 WORD wTxBufSize; // FFinfo size
1423 UINT uTotalCopyLength = 0;
1424 BYTE byFBOption = AUTO_FB_NONE;
1425 BOOL bIsWEP256 = FALSE;
1426 PSMgmtObject pMgmt = pDevice->pMgmt;
1427
1428
1429 pvRrvTime = pMICHDR = pvRTS = pvCTS = pvTxDataHd = NULL;
1430
1431 //DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"s_cbFillTxBufHead...\n");
1432 if ((pDevice->eOPMode == OP_MODE_ADHOC) ||
1433 (pDevice->eOPMode == OP_MODE_AP)) {
1434
1435 if (IS_MULTICAST_ADDRESS(&(psEthHeader->abyDstAddr[0])) ||
1436 IS_BROADCAST_ADDRESS(&(psEthHeader->abyDstAddr[0]))) {
1437 bNeedACK = FALSE;
1438 }
1439 else {
1440 bNeedACK = TRUE;
1441 }
1442 bIsAdhoc = TRUE;
1443 }
1444 else {
1445 // MSDUs in Infra mode always need ACK
1446 bNeedACK = TRUE;
1447 bIsAdhoc = FALSE;
1448 }
1449
1450 if (pDevice->bLongHeader)
1451 cbMACHdLen = WLAN_HDR_ADDR3_LEN + 6;
1452 else
1453 cbMACHdLen = WLAN_HDR_ADDR3_LEN;
1454
1455
1456 if ((bNeedEncrypt == TRUE) && (pTransmitKey != NULL)) {
1457 if (pTransmitKey->byCipherSuite == KEY_CTL_WEP) {
1458 cbIVlen = 4;
1459 cbICVlen = 4;
1460 if (pTransmitKey->uKeyLength == WLAN_WEP232_KEYLEN) {
1461 bIsWEP256 = TRUE;
1462 }
1463 }
1464 if (pTransmitKey->byCipherSuite == KEY_CTL_TKIP) {
1465 cbIVlen = 8;//IV+ExtIV
1466 cbMIClen = 8;
1467 cbICVlen = 4;
1468 }
1469 if (pTransmitKey->byCipherSuite == KEY_CTL_CCMP) {
1470 cbIVlen = 8;//RSN Header
1471 cbICVlen = 8;//MIC
1472 cbMICHDR = sizeof(SMICHDRHead);
1473 }
1474 if (pDevice->byLocalID > REV_ID_VT3253_A1) {
1475 //MAC Header should be padding 0 to DW alignment.
1476 uPadding = 4 - (cbMACHdLen%4);
1477 uPadding %= 4;
1478 }
1479 }
1480
1481
1482 cbFrameSize = cbMACHdLen + cbIVlen + (cbFrameBodySize + cbMIClen) + cbICVlen + cbFCSlen;
1483
1484 if ((bNeedACK == FALSE) ||
1485 (cbFrameSize < pDevice->wRTSThreshold) ||
1486 ((cbFrameSize >= pDevice->wFragmentationThreshold) && (pDevice->wFragmentationThreshold <= pDevice->wRTSThreshold))
1487 ) {
1488 bRTS = FALSE;
1489 }
1490 else {
1491 bRTS = TRUE;
1492 psTxBufHd->wFIFOCtl |= (FIFOCTL_RTS | FIFOCTL_LRETRY);
1493 }
1494 //
1495 // Use for AUTO FALL BACK
1496 //
1497 if (psTxBufHd->wFIFOCtl & FIFOCTL_AUTO_FB_0) {
1498 byFBOption = AUTO_FB_0;
1499 }
1500 else if (psTxBufHd->wFIFOCtl & FIFOCTL_AUTO_FB_1) {
1501 byFBOption = AUTO_FB_1;
1502 }
1503
1504 //////////////////////////////////////////////////////
1505 //Set RrvTime/RTS/CTS Buffer
1506 wTxBufSize = sizeof(STxBufHead);
1507 if (byPktTyp == PK_TYPE_11GB || byPktTyp == PK_TYPE_11GA) {//802.11g packet
1508
1509 if (byFBOption == AUTO_FB_NONE) {
1510 if (bRTS == TRUE) {//RTS_need
1511 pvRrvTime = (PSRrvTime_gRTS) (pbyTxBufferAddr + wTxBufSize);
1512 pMICHDR = (PSMICHDRHead) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_gRTS));
1513 pvRTS = (PSRTS_g) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_gRTS) + cbMICHDR);
1514 pvCTS = NULL;
1515 pvTxDataHd = (PSTxDataHead_g) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_gRTS) + cbMICHDR + sizeof(SRTS_g));
1516 cbHeaderLength = wTxBufSize + sizeof(SRrvTime_gRTS) + cbMICHDR + sizeof(SRTS_g) + sizeof(STxDataHead_g);
1517 }
1518 else { //RTS_needless
1519 pvRrvTime = (PSRrvTime_gCTS) (pbyTxBufferAddr + wTxBufSize);
1520 pMICHDR = (PSMICHDRHead) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_gCTS));
1521 pvRTS = NULL;
1522 pvCTS = (PSCTS) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_gCTS) + cbMICHDR);
1523 pvTxDataHd = (PSTxDataHead_g) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_gCTS) + cbMICHDR + sizeof(SCTS));
1524 cbHeaderLength = wTxBufSize + sizeof(SRrvTime_gCTS) + cbMICHDR + sizeof(SCTS) + sizeof(STxDataHead_g);
1525 }
1526 } else {
1527 // Auto Fall Back
1528 if (bRTS == TRUE) {//RTS_need
1529 pvRrvTime = (PSRrvTime_gRTS) (pbyTxBufferAddr + wTxBufSize);
1530 pMICHDR = (PSMICHDRHead) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_gRTS));
1531 pvRTS = (PSRTS_g_FB) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_gRTS) + cbMICHDR);
1532 pvCTS = NULL;
1533 pvTxDataHd = (PSTxDataHead_g_FB) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_gRTS) + cbMICHDR + sizeof(SRTS_g_FB));
1534 cbHeaderLength = wTxBufSize + sizeof(SRrvTime_gRTS) + cbMICHDR + sizeof(SRTS_g_FB) + sizeof(STxDataHead_g_FB);
1535 }
1536 else { //RTS_needless
1537 pvRrvTime = (PSRrvTime_gCTS) (pbyTxBufferAddr + wTxBufSize);
1538 pMICHDR = (PSMICHDRHead) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_gCTS));
1539 pvRTS = NULL;
1540 pvCTS = (PSCTS_FB) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_gCTS) + cbMICHDR);
1541 pvTxDataHd = (PSTxDataHead_g_FB) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_gCTS) + cbMICHDR + sizeof(SCTS_FB));
1542 cbHeaderLength = wTxBufSize + sizeof(SRrvTime_gCTS) + cbMICHDR + sizeof(SCTS_FB) + sizeof(STxDataHead_g_FB);
1543 }
1544 } // Auto Fall Back
1545 }
1546 else {//802.11a/b packet
1547
1548 if (byFBOption == AUTO_FB_NONE) {
1549 if (bRTS == TRUE) {
1550 pvRrvTime = (PSRrvTime_ab) (pbyTxBufferAddr + wTxBufSize);
1551 pMICHDR = (PSMICHDRHead) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_ab));
1552 pvRTS = (PSRTS_ab) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_ab) + cbMICHDR);
1553 pvCTS = NULL;
1554 pvTxDataHd = (PSTxDataHead_ab) (pbyTxBufferAddr + wTxBufSize + sizeof(PSRrvTime_ab) + cbMICHDR + sizeof(SRTS_ab));
1555 cbHeaderLength = wTxBufSize + sizeof(PSRrvTime_ab) + cbMICHDR + sizeof(SRTS_ab) + sizeof(STxDataHead_ab);
1556 }
1557 else { //RTS_needless, need MICHDR
1558 pvRrvTime = (PSRrvTime_ab) (pbyTxBufferAddr + wTxBufSize);
1559 pMICHDR = (PSMICHDRHead) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_ab));
1560 pvRTS = NULL;
1561 pvCTS = NULL;
1562 pvTxDataHd = (PSTxDataHead_ab) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_ab) + cbMICHDR);
1563 cbHeaderLength = wTxBufSize + sizeof(SRrvTime_ab) + cbMICHDR + sizeof(STxDataHead_ab);
1564 }
1565 } else {
1566 // Auto Fall Back
1567 if (bRTS == TRUE) {//RTS_need
1568 pvRrvTime = (PSRrvTime_ab) (pbyTxBufferAddr + wTxBufSize);
1569 pMICHDR = (PSMICHDRHead) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_ab));
1570 pvRTS = (PSRTS_a_FB) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_ab) + cbMICHDR);
1571 pvCTS = NULL;
1572 pvTxDataHd = (PSTxDataHead_a_FB) (pbyTxBufferAddr + wTxBufSize + sizeof(PSRrvTime_ab) + cbMICHDR + sizeof(SRTS_a_FB));
1573 cbHeaderLength = wTxBufSize + sizeof(PSRrvTime_ab) + cbMICHDR + sizeof(SRTS_a_FB) + sizeof(STxDataHead_a_FB);
1574 }
1575 else { //RTS_needless
1576 pvRrvTime = (PSRrvTime_ab) (pbyTxBufferAddr + wTxBufSize);
1577 pMICHDR = (PSMICHDRHead) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_ab));
1578 pvRTS = NULL;
1579 pvCTS = NULL;
1580 pvTxDataHd = (PSTxDataHead_a_FB) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_ab) + cbMICHDR);
1581 cbHeaderLength = wTxBufSize + sizeof(SRrvTime_ab) + cbMICHDR + sizeof(STxDataHead_a_FB);
1582 }
1583 } // Auto Fall Back
1584 }
1585 ZERO_MEMORY((PVOID)(pbyTxBufferAddr + wTxBufSize), (cbHeaderLength - wTxBufSize));
1586
1587//////////////////////////////////////////////////////////////////
1588 if ((bNeedEncrypt == TRUE) && (pTransmitKey != NULL) && (pTransmitKey->byCipherSuite == KEY_CTL_TKIP)) {
1589 if (pDevice->pMgmt->eAuthenMode == WMAC_AUTH_WPANONE) {
1590 dwMICKey0 = *(PDWORD)(&pTransmitKey->abyKey[16]);
1591 dwMICKey1 = *(PDWORD)(&pTransmitKey->abyKey[20]);
1592 }
1593 else if ((pTransmitKey->dwKeyIndex & AUTHENTICATOR_KEY) != 0) {
1594 dwMICKey0 = *(PDWORD)(&pTransmitKey->abyKey[16]);
1595 dwMICKey1 = *(PDWORD)(&pTransmitKey->abyKey[20]);
1596 }
1597 else {
1598 dwMICKey0 = *(PDWORD)(&pTransmitKey->abyKey[24]);
1599 dwMICKey1 = *(PDWORD)(&pTransmitKey->abyKey[28]);
1600 }
1601 // DO Software Michael
1602 MIC_vInit(dwMICKey0, dwMICKey1);
1603 MIC_vAppend((PBYTE)&(psEthHeader->abyDstAddr[0]), 12);
1604 dwMIC_Priority = 0;
1605 MIC_vAppend((PBYTE)&dwMIC_Priority, 4);
1606 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"MIC KEY: %lX, %lX\n", dwMICKey0, dwMICKey1);
1607 }
1608
1609///////////////////////////////////////////////////////////////////
1610
1611 pbyMacHdr = (PBYTE)(pbyTxBufferAddr + cbHeaderLength);
1612 pbyPayloadHead = (PBYTE)(pbyMacHdr + cbMACHdLen + uPadding + cbIVlen);
1613 pbyIVHead = (PBYTE)(pbyMacHdr + cbMACHdLen + uPadding);
1614
1615 if ((cbFrameSize > pDevice->wFragmentationThreshold) && (bNeedACK == TRUE) && (bIsWEP256 == FALSE)) {
1616 // Fragmentation
1617 // FragThreshold = Fragment size(Hdr+(IV)+fragment payload+(MIC)+(ICV)+FCS)
1618 cbFragmentSize = pDevice->wFragmentationThreshold;
1619 cbFragPayloadSize = cbFragmentSize - cbMACHdLen - cbIVlen - cbICVlen - cbFCSlen;
1620 //FragNum = (FrameSize-(Hdr+FCS))/(Fragment Size -(Hrd+FCS)))
1621 uMACfragNum = (WORD) ((cbFrameBodySize + cbMIClen) / cbFragPayloadSize);
1622 cbLastFragPayloadSize = (cbFrameBodySize + cbMIClen) % cbFragPayloadSize;
1623 if (cbLastFragPayloadSize == 0) {
1624 cbLastFragPayloadSize = cbFragPayloadSize;
1625 } else {
1626 uMACfragNum++;
1627 }
1628 //[Hdr+(IV)+last fragment payload+(MIC)+(ICV)+FCS]
1629 cbLastFragmentSize = cbMACHdLen + cbLastFragPayloadSize + cbIVlen + cbICVlen + cbFCSlen;
1630
1631 for (uFragIdx = 0; uFragIdx < uMACfragNum; uFragIdx ++) {
1632 if (uFragIdx == 0) {
1633 //=========================
1634 // Start Fragmentation
1635 //=========================
1636 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Start Fragmentation...\n");
1637 wFragType = FRAGCTL_STAFRAG;
1638
1639
1640 //Fill FIFO,RrvTime,RTS,and CTS
1641 s_vGenerateTxParameter(pDevice, byPktTyp, (PVOID)psTxBufHd, pvRrvTime, pvRTS, pvCTS,
1642 cbFragmentSize, bNeedACK, uDMAIdx, psEthHeader, pDevice->wCurrentRate);
1643 //Fill DataHead
1644 uDuration = s_uFillDataHead(pDevice, byPktTyp, pvTxDataHd, cbFragmentSize, uDMAIdx, bNeedACK,
1645 uFragIdx, cbLastFragmentSize, uMACfragNum, byFBOption, pDevice->wCurrentRate);
1646 // Generate TX MAC Header
1647 vGenerateMACHeader(pDevice, pbyMacHdr, (WORD)uDuration, psEthHeader, bNeedEncrypt,
1648 wFragType, uDMAIdx, uFragIdx);
1649
1650 if (bNeedEncrypt == TRUE) {
1651 //Fill TXKEY
1652 s_vFillTxKey(pDevice, (PBYTE)(psTxBufHd->adwTxKey), pbyIVHead, pTransmitKey,
1653 pbyMacHdr, (WORD)cbFragPayloadSize, (PBYTE)pMICHDR);
1654 //Fill IV(ExtIV,RSNHDR)
1655 if (pDevice->bEnableHostWEP) {
1656 pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16 = pTransmitKey->dwTSC47_16;
1657 pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0 = pTransmitKey->wTSC15_0;
1658 }
1659 }
1660
1661
1662 // 802.1H
1663 if (ntohs(psEthHeader->wType) > MAX_DATA_LEN) {
1664 if ((psEthHeader->wType == TYPE_PKT_IPX) ||
1665 (psEthHeader->wType == cpu_to_le16(0xF380))) {
1666 MEMvCopy((PBYTE) (pbyPayloadHead), &pDevice->abySNAP_Bridgetunnel[0], 6);
1667 }
1668 else {
1669 MEMvCopy((PBYTE) (pbyPayloadHead), &pDevice->abySNAP_RFC1042[0], 6);
1670 }
1671 pbyType = (PBYTE) (pbyPayloadHead + 6);
1672 MEMvCopy(pbyType, &(psEthHeader->wType), sizeof(WORD));
1673 cb802_1_H_len = 8;
1674 }
1675
1676 cbReqCount = cbHeaderLength + cbMACHdLen + uPadding + cbIVlen + cbFragPayloadSize;
1677 //---------------------------
1678 // S/W or H/W Encryption
1679 //---------------------------
1680 //Fill MICHDR
1681 //if (pDevice->bAES) {
1682 // s_vFillMICHDR(pDevice, (PBYTE)pMICHDR, pbyMacHdr, (WORD)cbFragPayloadSize);
1683 //}
1684 //cbReqCount += s_uDoEncryption(pDevice, psEthHeader, (PVOID)psTxBufHd, byKeySel,
1685 // pbyPayloadHead, (WORD)cbFragPayloadSize, uDMAIdx);
1686
1687
1688
1689 //pbyBuffer = (PBYTE)pDevice->aamTxBuf[uDMAIdx][uDescIdx].pbyVAddr;
1690 pbyBuffer = (PBYTE)pHeadTD->pTDInfo->buf;
1691
1692 uLength = cbHeaderLength + cbMACHdLen + uPadding + cbIVlen + cb802_1_H_len;
1693 //copy TxBufferHeader + MacHeader to desc
1694 MEMvCopy(pbyBuffer, (PVOID)psTxBufHd, uLength);
1695
1696 // Copy the Packet into a tx Buffer
1697 MEMvCopy((pbyBuffer + uLength), (pPacket + 14), (cbFragPayloadSize - cb802_1_H_len));
1698
1699
1700 uTotalCopyLength += cbFragPayloadSize - cb802_1_H_len;
1701
1702 if ((bNeedEncrypt == TRUE) && (pTransmitKey != NULL) && (pTransmitKey->byCipherSuite == KEY_CTL_TKIP)) {
1703 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Start MIC: %d\n", cbFragPayloadSize);
1704 MIC_vAppend((pbyBuffer + uLength - cb802_1_H_len), cbFragPayloadSize);
1705
1706 }
1707
1708 //---------------------------
1709 // S/W Encryption
1710 //---------------------------
1711 if ((pDevice->byLocalID <= REV_ID_VT3253_A1)) {
1712 if (bNeedEncrypt) {
1713 s_vSWencryption(pDevice, pTransmitKey, (pbyBuffer + uLength - cb802_1_H_len), (WORD)cbFragPayloadSize);
1714 cbReqCount += cbICVlen;
1715 }
1716 }
1717
1718 ptdCurr = (PSTxDesc)pHeadTD;
1719 //--------------------
1720 //1.Set TSR1 & ReqCount in TxDescHead
1721 //2.Set FragCtl in TxBufferHead
1722 //3.Set Frame Control
1723 //4.Set Sequence Control
1724 //5.Get S/W generate FCS
1725 //--------------------
1726 s_vFillFragParameter(pDevice, pbyBuffer, uDMAIdx, (PVOID)ptdCurr, wFragType, cbReqCount);
1727
1728 ptdCurr->pTDInfo->dwReqCount = cbReqCount - uPadding;
1729 ptdCurr->pTDInfo->dwHeaderLength = cbHeaderLength;
1730 ptdCurr->pTDInfo->skb_dma = ptdCurr->pTDInfo->buf_dma;
1731 ptdCurr->buff_addr = cpu_to_le32(ptdCurr->pTDInfo->skb_dma);
1732 pDevice->iTDUsed[uDMAIdx]++;
1733 pHeadTD = ptdCurr->next;
1734 }
1735 else if (uFragIdx == (uMACfragNum-1)) {
1736 //=========================
1737 // Last Fragmentation
1738 //=========================
1739 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Last Fragmentation...\n");
1740 //tmpDescIdx = (uDescIdx + uFragIdx) % pDevice->cbTD[uDMAIdx];
1741
1742 wFragType = FRAGCTL_ENDFRAG;
1743
1744 //Fill FIFO,RrvTime,RTS,and CTS
1745 s_vGenerateTxParameter(pDevice, byPktTyp, (PVOID)psTxBufHd, pvRrvTime, pvRTS, pvCTS,
1746 cbLastFragmentSize, bNeedACK, uDMAIdx, psEthHeader, pDevice->wCurrentRate);
1747 //Fill DataHead
1748 uDuration = s_uFillDataHead(pDevice, byPktTyp, pvTxDataHd, cbLastFragmentSize, uDMAIdx, bNeedACK,
1749 uFragIdx, cbLastFragmentSize, uMACfragNum, byFBOption, pDevice->wCurrentRate);
1750
1751 // Generate TX MAC Header
1752 vGenerateMACHeader(pDevice, pbyMacHdr, (WORD)uDuration, psEthHeader, bNeedEncrypt,
1753 wFragType, uDMAIdx, uFragIdx);
1754
1755 if (bNeedEncrypt == TRUE) {
1756 //Fill TXKEY
1757 s_vFillTxKey(pDevice, (PBYTE)(psTxBufHd->adwTxKey), pbyIVHead, pTransmitKey,
1758 pbyMacHdr, (WORD)cbLastFragPayloadSize, (PBYTE)pMICHDR);
1759
1760 if (pDevice->bEnableHostWEP) {
1761 pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16 = pTransmitKey->dwTSC47_16;
1762 pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0 = pTransmitKey->wTSC15_0;
1763 }
1764
1765 }
1766
1767
1768 cbReqCount = cbHeaderLength + cbMACHdLen + uPadding + cbIVlen + cbLastFragPayloadSize;
1769 //---------------------------
1770 // S/W or H/W Encryption
1771 //---------------------------
1772
1773
1774
1775 pbyBuffer = (PBYTE)pHeadTD->pTDInfo->buf;
1776 //pbyBuffer = (PBYTE)pDevice->aamTxBuf[uDMAIdx][tmpDescIdx].pbyVAddr;
1777
1778 uLength = cbHeaderLength + cbMACHdLen + uPadding + cbIVlen;
1779
1780 //copy TxBufferHeader + MacHeader to desc
1781 MEMvCopy(pbyBuffer, (PVOID)psTxBufHd, uLength);
1782
1783 // Copy the Packet into a tx Buffer
1784 if (bMIC2Frag == FALSE) {
1785
1786 MEMvCopy((pbyBuffer + uLength),
1787 (pPacket + 14 + uTotalCopyLength),
1788 (cbLastFragPayloadSize - cbMIClen)
1789 );
1790 //TODO check uTmpLen !
1791 uTmpLen = cbLastFragPayloadSize - cbMIClen;
1792
1793 }
1794 if ((bNeedEncrypt == TRUE) && (pTransmitKey != NULL) && (pTransmitKey->byCipherSuite == KEY_CTL_TKIP)) {
1795 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"LAST: uMICFragLen:%d, cbLastFragPayloadSize:%d, uTmpLen:%d\n",
1796 uMICFragLen, cbLastFragPayloadSize, uTmpLen);
1797
1798 if (bMIC2Frag == FALSE) {
1799 if (uTmpLen != 0)
1800 MIC_vAppend((pbyBuffer + uLength), uTmpLen);
1801 pdwMIC_L = (PDWORD)(pbyBuffer + uLength + uTmpLen);
1802 pdwMIC_R = (PDWORD)(pbyBuffer + uLength + uTmpLen + 4);
1803 MIC_vGetMIC(pdwMIC_L, pdwMIC_R);
1804 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Last MIC:%lX, %lX\n", *pdwMIC_L, *pdwMIC_R);
1805 } else {
1806 if (uMICFragLen >= 4) {
1807 MEMvCopy((pbyBuffer + uLength), ((PBYTE)&dwSafeMIC_R + (uMICFragLen - 4)),
1808 (cbMIClen - uMICFragLen));
1809 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"LAST: uMICFragLen >= 4: %X, %d\n",
1810 *(PBYTE)((PBYTE)&dwSafeMIC_R + (uMICFragLen - 4)),
1811 (cbMIClen - uMICFragLen));
1812
1813 } else {
1814 MEMvCopy((pbyBuffer + uLength), ((PBYTE)&dwSafeMIC_L + uMICFragLen),
1815 (4 - uMICFragLen));
1816 MEMvCopy((pbyBuffer + uLength + (4 - uMICFragLen)), &dwSafeMIC_R, 4);
1817 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"LAST: uMICFragLen < 4: %X, %d\n",
1818 *(PBYTE)((PBYTE)&dwSafeMIC_R + uMICFragLen - 4),
1819 (cbMIClen - uMICFragLen));
1820 }
1821 /*
1822 for (ii = 0; ii < cbLastFragPayloadSize + 8 + 24; ii++) {
1823 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"%02x ", *((PBYTE)((pbyBuffer + uLength) + ii - 8 - 24)));
1824 }
1825 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"\n\n");
1826 */
1827 }
1828 MIC_vUnInit();
1829 } else {
1830 ASSERT(uTmpLen == (cbLastFragPayloadSize - cbMIClen));
1831 }
1832
1833
1834 //---------------------------
1835 // S/W Encryption
1836 //---------------------------
1837 if ((pDevice->byLocalID <= REV_ID_VT3253_A1)) {
1838 if (bNeedEncrypt) {
1839 s_vSWencryption(pDevice, pTransmitKey, (pbyBuffer + uLength), (WORD)cbLastFragPayloadSize);
1840 cbReqCount += cbICVlen;
1841 }
1842 }
1843
1844 ptdCurr = (PSTxDesc)pHeadTD;
1845
1846 //--------------------
1847 //1.Set TSR1 & ReqCount in TxDescHead
1848 //2.Set FragCtl in TxBufferHead
1849 //3.Set Frame Control
1850 //4.Set Sequence Control
1851 //5.Get S/W generate FCS
1852 //--------------------
1853
1854
1855 s_vFillFragParameter(pDevice, pbyBuffer, uDMAIdx, (PVOID)ptdCurr, wFragType, cbReqCount);
1856
1857 ptdCurr->pTDInfo->dwReqCount = cbReqCount - uPadding;
1858 ptdCurr->pTDInfo->dwHeaderLength = cbHeaderLength;
1859 ptdCurr->pTDInfo->skb_dma = ptdCurr->pTDInfo->buf_dma;
1860 ptdCurr->buff_addr = cpu_to_le32(ptdCurr->pTDInfo->skb_dma);
1861 pDevice->iTDUsed[uDMAIdx]++;
1862 pHeadTD = ptdCurr->next;
1863
1864 }
1865 else {
1866 //=========================
1867 // Middle Fragmentation
1868 //=========================
1869 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Middle Fragmentation...\n");
1870 //tmpDescIdx = (uDescIdx + uFragIdx) % pDevice->cbTD[uDMAIdx];
1871
1872 wFragType = FRAGCTL_MIDFRAG;
1873
1874 //Fill FIFO,RrvTime,RTS,and CTS
1875 s_vGenerateTxParameter(pDevice, byPktTyp, (PVOID)psTxBufHd, pvRrvTime, pvRTS, pvCTS,
1876 cbFragmentSize, bNeedACK, uDMAIdx, psEthHeader, pDevice->wCurrentRate);
1877 //Fill DataHead
1878 uDuration = s_uFillDataHead(pDevice, byPktTyp, pvTxDataHd, cbFragmentSize, uDMAIdx, bNeedACK,
1879 uFragIdx, cbLastFragmentSize, uMACfragNum, byFBOption, pDevice->wCurrentRate);
1880
1881 // Generate TX MAC Header
1882 vGenerateMACHeader(pDevice, pbyMacHdr, (WORD)uDuration, psEthHeader, bNeedEncrypt,
1883 wFragType, uDMAIdx, uFragIdx);
1884
1885
1886 if (bNeedEncrypt == TRUE) {
1887 //Fill TXKEY
1888 s_vFillTxKey(pDevice, (PBYTE)(psTxBufHd->adwTxKey), pbyIVHead, pTransmitKey,
1889 pbyMacHdr, (WORD)cbFragPayloadSize, (PBYTE)pMICHDR);
1890
1891 if (pDevice->bEnableHostWEP) {
1892 pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16 = pTransmitKey->dwTSC47_16;
1893 pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0 = pTransmitKey->wTSC15_0;
1894 }
1895 }
1896
1897 cbReqCount = cbHeaderLength + cbMACHdLen + uPadding + cbIVlen + cbFragPayloadSize;
1898 //---------------------------
1899 // S/W or H/W Encryption
1900 //---------------------------
1901 //Fill MICHDR
1902 //if (pDevice->bAES) {
1903 // s_vFillMICHDR(pDevice, (PBYTE)pMICHDR, pbyMacHdr, (WORD)cbFragPayloadSize);
1904 //}
1905 //cbReqCount += s_uDoEncryption(pDevice, psEthHeader, (PVOID)psTxBufHd, byKeySel,
1906 // pbyPayloadHead, (WORD)cbFragPayloadSize, uDMAIdx);
1907
1908
1909 pbyBuffer = (PBYTE)pHeadTD->pTDInfo->buf;
1910 //pbyBuffer = (PBYTE)pDevice->aamTxBuf[uDMAIdx][tmpDescIdx].pbyVAddr;
1911
1912
1913 uLength = cbHeaderLength + cbMACHdLen + uPadding + cbIVlen;
1914
1915 //copy TxBufferHeader + MacHeader to desc
1916 MEMvCopy(pbyBuffer, (PVOID)psTxBufHd, uLength);
1917
1918 // Copy the Packet into a tx Buffer
1919 MEMvCopy((pbyBuffer + uLength),
1920 (pPacket + 14 + uTotalCopyLength),
1921 cbFragPayloadSize
1922 );
1923 uTmpLen = cbFragPayloadSize;
1924
1925 uTotalCopyLength += uTmpLen;
1926
1927 if ((bNeedEncrypt == TRUE) && (pTransmitKey != NULL) && (pTransmitKey->byCipherSuite == KEY_CTL_TKIP)) {
1928
1929 MIC_vAppend((pbyBuffer + uLength), uTmpLen);
1930
1931 if (uTmpLen < cbFragPayloadSize) {
1932 bMIC2Frag = TRUE;
1933 uMICFragLen = cbFragPayloadSize - uTmpLen;
1934 ASSERT(uMICFragLen < cbMIClen);
1935
1936 pdwMIC_L = (PDWORD)(pbyBuffer + uLength + uTmpLen);
1937 pdwMIC_R = (PDWORD)(pbyBuffer + uLength + uTmpLen + 4);
1938 MIC_vGetMIC(pdwMIC_L, pdwMIC_R);
1939 dwSafeMIC_L = *pdwMIC_L;
1940 dwSafeMIC_R = *pdwMIC_R;
1941
1942 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"MIDDLE: uMICFragLen:%d, cbFragPayloadSize:%d, uTmpLen:%d\n",
1943 uMICFragLen, cbFragPayloadSize, uTmpLen);
1944 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Fill MIC in Middle frag [%d]\n", uMICFragLen);
1945 /*
1946 for (ii = 0; ii < uMICFragLen; ii++) {
1947 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"%02x ", *((PBYTE)((pbyBuffer + uLength + uTmpLen) + ii)));
1948 }
1949 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"\n");
1950 */
1951 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Get MIC:%lX, %lX\n", *pdwMIC_L, *pdwMIC_R);
1952 }
1953 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Middle frag len: %d\n", uTmpLen);
1954 /*
1955 for (ii = 0; ii < uTmpLen; ii++) {
1956 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"%02x ", *((PBYTE)((pbyBuffer + uLength) + ii)));
1957 }
1958 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"\n\n");
1959 */
1960
1961 } else {
1962 ASSERT(uTmpLen == (cbFragPayloadSize));
1963 }
1964
1965 if ((pDevice->byLocalID <= REV_ID_VT3253_A1)) {
1966 if (bNeedEncrypt) {
1967 s_vSWencryption(pDevice, pTransmitKey, (pbyBuffer + uLength), (WORD)cbFragPayloadSize);
1968 cbReqCount += cbICVlen;
1969 }
1970 }
1971
1972 ptdCurr = (PSTxDesc)pHeadTD;
1973
1974 //--------------------
1975 //1.Set TSR1 & ReqCount in TxDescHead
1976 //2.Set FragCtl in TxBufferHead
1977 //3.Set Frame Control
1978 //4.Set Sequence Control
1979 //5.Get S/W generate FCS
1980 //--------------------
1981
1982 s_vFillFragParameter(pDevice, pbyBuffer, uDMAIdx, (PVOID)ptdCurr, wFragType, cbReqCount);
1983
1984 ptdCurr->pTDInfo->dwReqCount = cbReqCount - uPadding;
1985 ptdCurr->pTDInfo->dwHeaderLength = cbHeaderLength;
1986 ptdCurr->pTDInfo->skb_dma = ptdCurr->pTDInfo->buf_dma;
1987 ptdCurr->buff_addr = cpu_to_le32(ptdCurr->pTDInfo->skb_dma);
1988 pDevice->iTDUsed[uDMAIdx]++;
1989 pHeadTD = ptdCurr->next;
1990 }
1991 } // for (uMACfragNum)
1992 }
1993 else {
1994 //=========================
1995 // No Fragmentation
1996 //=========================
1997 //DEVICE_PRTGRP03(("No Fragmentation...\n"));
1998 //DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"No Fragmentation...\n");
1999 wFragType = FRAGCTL_NONFRAG;
2000
2001 //Set FragCtl in TxBufferHead
2002 psTxBufHd->wFragCtl |= (WORD)wFragType;
2003
2004 //Fill FIFO,RrvTime,RTS,and CTS
2005 s_vGenerateTxParameter(pDevice, byPktTyp, (PVOID)psTxBufHd, pvRrvTime, pvRTS, pvCTS,
2006 cbFrameSize, bNeedACK, uDMAIdx, psEthHeader, pDevice->wCurrentRate);
2007 //Fill DataHead
2008 uDuration = s_uFillDataHead(pDevice, byPktTyp, pvTxDataHd, cbFrameSize, uDMAIdx, bNeedACK,
2009 0, 0, uMACfragNum, byFBOption, pDevice->wCurrentRate);
2010
2011 // Generate TX MAC Header
2012 vGenerateMACHeader(pDevice, pbyMacHdr, (WORD)uDuration, psEthHeader, bNeedEncrypt,
2013 wFragType, uDMAIdx, 0);
2014
2015 if (bNeedEncrypt == TRUE) {
2016 //Fill TXKEY
2017 s_vFillTxKey(pDevice, (PBYTE)(psTxBufHd->adwTxKey), pbyIVHead, pTransmitKey,
2018 pbyMacHdr, (WORD)cbFrameBodySize, (PBYTE)pMICHDR);
2019
2020 if (pDevice->bEnableHostWEP) {
2021 pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16 = pTransmitKey->dwTSC47_16;
2022 pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0 = pTransmitKey->wTSC15_0;
2023 }
2024 }
2025
2026 // 802.1H
2027 if (ntohs(psEthHeader->wType) > MAX_DATA_LEN) {
2028 if ((psEthHeader->wType == TYPE_PKT_IPX) ||
2029 (psEthHeader->wType == cpu_to_le16(0xF380))) {
2030 MEMvCopy((PBYTE) (pbyPayloadHead), &pDevice->abySNAP_Bridgetunnel[0], 6);
2031 }
2032 else {
2033 MEMvCopy((PBYTE) (pbyPayloadHead), &pDevice->abySNAP_RFC1042[0], 6);
2034 }
2035 pbyType = (PBYTE) (pbyPayloadHead + 6);
2036 MEMvCopy(pbyType, &(psEthHeader->wType), sizeof(WORD));
2037 cb802_1_H_len = 8;
2038 }
2039
2040 cbReqCount = cbHeaderLength + cbMACHdLen + uPadding + cbIVlen + (cbFrameBodySize + cbMIClen);
2041 //---------------------------
2042 // S/W or H/W Encryption
2043 //---------------------------
2044 //Fill MICHDR
2045 //if (pDevice->bAES) {
2046 // DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Fill MICHDR...\n");
2047 // s_vFillMICHDR(pDevice, (PBYTE)pMICHDR, pbyMacHdr, (WORD)cbFrameBodySize);
2048 //}
2049
2050 pbyBuffer = (PBYTE)pHeadTD->pTDInfo->buf;
2051 //pbyBuffer = (PBYTE)pDevice->aamTxBuf[uDMAIdx][uDescIdx].pbyVAddr;
2052
2053 uLength = cbHeaderLength + cbMACHdLen + uPadding + cbIVlen + cb802_1_H_len;
2054
2055 //copy TxBufferHeader + MacHeader to desc
2056 MEMvCopy(pbyBuffer, (PVOID)psTxBufHd, uLength);
2057
2058 // Copy the Packet into a tx Buffer
2059 MEMvCopy((pbyBuffer + uLength),
2060 (pPacket + 14),
2061 cbFrameBodySize - cb802_1_H_len
2062 );
2063
2064 if ((bNeedEncrypt == TRUE) && (pTransmitKey != NULL) && (pTransmitKey->byCipherSuite == KEY_CTL_TKIP)){
2065
2066 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Length:%d, %d\n", cbFrameBodySize - cb802_1_H_len, uLength);
2067 /*
2068 for (ii = 0; ii < (cbFrameBodySize - cb802_1_H_len); ii++) {
2069 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"%02x ", *((PBYTE)((pbyBuffer + uLength) + ii)));
2070 }
2071 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"\n");
2072 */
2073
2074 MIC_vAppend((pbyBuffer + uLength - cb802_1_H_len), cbFrameBodySize);
2075
2076 pdwMIC_L = (PDWORD)(pbyBuffer + uLength - cb802_1_H_len + cbFrameBodySize);
2077 pdwMIC_R = (PDWORD)(pbyBuffer + uLength - cb802_1_H_len + cbFrameBodySize + 4);
2078
2079 MIC_vGetMIC(pdwMIC_L, pdwMIC_R);
2080 MIC_vUnInit();
2081
2082
2083 if (pDevice->bTxMICFail == TRUE) {
2084 *pdwMIC_L = 0;
2085 *pdwMIC_R = 0;
2086 pDevice->bTxMICFail = FALSE;
2087 }
2088
2089 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"uLength: %d, %d\n", uLength, cbFrameBodySize);
2090 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"cbReqCount:%d, %d, %d, %d\n", cbReqCount, cbHeaderLength, uPadding, cbIVlen);
2091 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"MIC:%lx, %lx\n", *pdwMIC_L, *pdwMIC_R);
2092/*
2093 for (ii = 0; ii < 8; ii++) {
2094 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"%02x ", *(((PBYTE)(pdwMIC_L) + ii)));
2095 }
2096 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"\n");
2097*/
2098
2099 }
2100
2101
2102 if ((pDevice->byLocalID <= REV_ID_VT3253_A1)){
2103 if (bNeedEncrypt) {
2104 s_vSWencryption(pDevice, pTransmitKey, (pbyBuffer + uLength - cb802_1_H_len),
2105 (WORD)(cbFrameBodySize + cbMIClen));
2106 cbReqCount += cbICVlen;
2107 }
2108 }
2109
2110
2111 ptdCurr = (PSTxDesc)pHeadTD;
2112
2113 ptdCurr->pTDInfo->dwReqCount = cbReqCount - uPadding;
2114 ptdCurr->pTDInfo->dwHeaderLength = cbHeaderLength;
2115 ptdCurr->pTDInfo->skb_dma = ptdCurr->pTDInfo->buf_dma;
2116 ptdCurr->buff_addr = cpu_to_le32(ptdCurr->pTDInfo->skb_dma);
2117 //Set TSR1 & ReqCount in TxDescHead
2118 ptdCurr->m_td1TD1.byTCR |= (TCR_STP | TCR_EDP | EDMSDU);
2119 ptdCurr->m_td1TD1.wReqCount = cpu_to_le16((WORD)(cbReqCount));
2120
2121 pDevice->iTDUsed[uDMAIdx]++;
2122
2123
2124// DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO" ptdCurr->m_dwReserved0[%d] ptdCurr->m_dwReserved1[%d].\n", ptdCurr->pTDInfo->dwReqCount, ptdCurr->pTDInfo->dwHeaderLength);
2125// DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO" cbHeaderLength[%d]\n", cbHeaderLength);
2126
2127 }
2128 *puMACfragNum = uMACfragNum;
2129 //DEVICE_PRTGRP03(("s_cbFillTxBufHead END\n"));
2130 return cbHeaderLength;
2131}
2132
2133
2134VOID
2135vGenerateFIFOHeader (
2136 IN PSDevice pDevice,
2137 IN BYTE byPktTyp,
2138 IN PBYTE pbyTxBufferAddr,
2139 IN BOOL bNeedEncrypt,
2140 IN UINT cbPayloadSize,
2141 IN UINT uDMAIdx,
2142 IN PSTxDesc pHeadTD,
2143 IN PSEthernetHeader psEthHeader,
2144 IN PBYTE pPacket,
2145 IN PSKeyItem pTransmitKey,
2146 IN UINT uNodeIndex,
2147 OUT PUINT puMACfragNum,
2148 OUT PUINT pcbHeaderSize
2149 )
2150{
2151 UINT wTxBufSize; // FFinfo size
2152 BOOL bNeedACK;
2153 BOOL bIsAdhoc;
2154 WORD cbMacHdLen;
2155 PSTxBufHead pTxBufHead = (PSTxBufHead) pbyTxBufferAddr;
2156
2157 wTxBufSize = sizeof(STxBufHead);
2158
2159 ZERO_MEMORY(pTxBufHead, wTxBufSize);
2160 //Set FIFOCTL_NEEDACK
2161
2162 if ((pDevice->eOPMode == OP_MODE_ADHOC) ||
2163 (pDevice->eOPMode == OP_MODE_AP)) {
2164 if (IS_MULTICAST_ADDRESS(&(psEthHeader->abyDstAddr[0])) ||
2165 IS_BROADCAST_ADDRESS(&(psEthHeader->abyDstAddr[0]))) {
2166 bNeedACK = FALSE;
2167 pTxBufHead->wFIFOCtl = pTxBufHead->wFIFOCtl & (~FIFOCTL_NEEDACK);
2168 }
2169 else {
2170 bNeedACK = TRUE;
2171 pTxBufHead->wFIFOCtl |= FIFOCTL_NEEDACK;
2172 }
2173 bIsAdhoc = TRUE;
2174 }
2175 else {
2176 // MSDUs in Infra mode always need ACK
2177 bNeedACK = TRUE;
2178 pTxBufHead->wFIFOCtl |= FIFOCTL_NEEDACK;
2179 bIsAdhoc = FALSE;
2180 }
2181
2182
2183 pTxBufHead->wFIFOCtl |= FIFOCTL_TMOEN;
2184 pTxBufHead->wTimeStamp = cpu_to_le16(DEFAULT_MSDU_LIFETIME_RES_64us);
2185
2186 //Set FIFOCTL_LHEAD
2187 if (pDevice->bLongHeader)
2188 pTxBufHead->wFIFOCtl |= FIFOCTL_LHEAD;
2189
2190 //Set FIFOCTL_GENINT
2191
2192 pTxBufHead->wFIFOCtl |= FIFOCTL_GENINT;
2193
2194
2195 //Set FIFOCTL_ISDMA0
2196 if (TYPE_TXDMA0 == uDMAIdx) {
2197 pTxBufHead->wFIFOCtl |= FIFOCTL_ISDMA0;
2198 }
2199
2200 //Set FRAGCTL_MACHDCNT
2201 if (pDevice->bLongHeader) {
2202 cbMacHdLen = WLAN_HDR_ADDR3_LEN + 6;
2203 } else {
2204 cbMacHdLen = WLAN_HDR_ADDR3_LEN;
2205 }
2206 pTxBufHead->wFragCtl |= cpu_to_le16((WORD)(cbMacHdLen << 10));
2207
2208 //Set packet type
2209 if (byPktTyp == PK_TYPE_11A) {//0000 0000 0000 0000
2210 ;
2211 }
2212 else if (byPktTyp == PK_TYPE_11B) {//0000 0001 0000 0000
2213 pTxBufHead->wFIFOCtl |= FIFOCTL_11B;
2214 }
2215 else if (byPktTyp == PK_TYPE_11GB) {//0000 0010 0000 0000
2216 pTxBufHead->wFIFOCtl |= FIFOCTL_11GB;
2217 }
2218 else if (byPktTyp == PK_TYPE_11GA) {//0000 0011 0000 0000
2219 pTxBufHead->wFIFOCtl |= FIFOCTL_11GA;
2220 }
2221 //Set FIFOCTL_GrpAckPolicy
2222 if (pDevice->bGrpAckPolicy == TRUE) {//0000 0100 0000 0000
2223 pTxBufHead->wFIFOCtl |= FIFOCTL_GRPACK;
2224 }
2225
2226 //Set Auto Fallback Ctl
2227 if (pDevice->wCurrentRate >= RATE_18M) {
2228 if (pDevice->byAutoFBCtrl == AUTO_FB_0) {
2229 pTxBufHead->wFIFOCtl |= FIFOCTL_AUTO_FB_0;
2230 } else if (pDevice->byAutoFBCtrl == AUTO_FB_1) {
2231 pTxBufHead->wFIFOCtl |= FIFOCTL_AUTO_FB_1;
2232 }
2233 }
2234
2235 //Set FRAGCTL_WEPTYP
2236 pDevice->bAES = FALSE;
2237
2238 //Set FRAGCTL_WEPTYP
2239 if (pDevice->byLocalID > REV_ID_VT3253_A1) {
2240 if ((bNeedEncrypt) && (pTransmitKey != NULL)) { //WEP enabled
2241 if (pTransmitKey->byCipherSuite == KEY_CTL_TKIP) {
2242 pTxBufHead->wFragCtl |= FRAGCTL_TKIP;
2243 }
2244 else if (pTransmitKey->byCipherSuite == KEY_CTL_WEP) { //WEP40 or WEP104
2245 if (pTransmitKey->uKeyLength != WLAN_WEP232_KEYLEN)
2246 pTxBufHead->wFragCtl |= FRAGCTL_LEGACY;
2247 }
2248 else if (pTransmitKey->byCipherSuite == KEY_CTL_CCMP) { //CCMP
2249 pTxBufHead->wFragCtl |= FRAGCTL_AES;
2250 }
2251 }
2252 }
2253
2254#ifdef PLICE_DEBUG
2255 //printk("Func:vGenerateFIFOHeader:TxDataRate is %d,TxPower is %d\n",pDevice->wCurrentRate,pDevice->byCurPwr);
2256
2257 //if (pDevice->wCurrentRate <= 3)
2258 //{
2259 // RFbRawSetPower(pDevice,36,pDevice->wCurrentRate);
2260 //}
2261 //else
2262
2263 RFbSetPower(pDevice, pDevice->wCurrentRate, pDevice->byCurrentCh);
2264#endif
2265 //if (pDevice->wCurrentRate == 3)
2266 //pDevice->byCurPwr = 46;
2267 pTxBufHead->byTxPower = pDevice->byCurPwr;
2268
2269
2270
2271
2272/*
2273 if(pDevice->bEnableHostWEP)
2274 pTxBufHead->wFragCtl &= ~(FRAGCTL_TKIP | FRAGCTL_LEGACY |FRAGCTL_AES);
2275*/
2276 *pcbHeaderSize = s_cbFillTxBufHead(pDevice, byPktTyp, pbyTxBufferAddr, cbPayloadSize,
2277 uDMAIdx, pHeadTD, psEthHeader, pPacket, bNeedEncrypt,
2278 pTransmitKey, uNodeIndex, puMACfragNum);
2279
2280 return;
2281}
2282
2283
2284
2285
2286/*+
2287 *
2288 * Description:
2289 * Translate 802.3 to 802.11 header
2290 *
2291 * Parameters:
2292 * In:
2293 * pDevice - Pointer to adpater
2294 * dwTxBufferAddr - Transmit Buffer
2295 * pPacket - Packet from upper layer
2296 * cbPacketSize - Transmit Data Length
2297 * Out:
2298 * pcbHeadSize - Header size of MAC&Baseband control and 802.11 Header
2299 * pcbAppendPayload - size of append payload for 802.1H translation
2300 *
2301 * Return Value: none
2302 *
2303-*/
2304
2305VOID
2306vGenerateMACHeader (
2307 IN PSDevice pDevice,
2308 IN PBYTE pbyBufferAddr,
2309 IN WORD wDuration,
2310 IN PSEthernetHeader psEthHeader,
2311 IN BOOL bNeedEncrypt,
2312 IN WORD wFragType,
2313 IN UINT uDMAIdx,
2314 IN UINT uFragIdx
2315 )
2316{
2317 PS802_11Header pMACHeader = (PS802_11Header)pbyBufferAddr;
2318
2319 ZERO_MEMORY(pMACHeader, (sizeof(S802_11Header))); //- sizeof(pMACHeader->dwIV)));
2320
2321 if (uDMAIdx == TYPE_ATIMDMA) {
2322 pMACHeader->wFrameCtl = TYPE_802_11_ATIM;
2323 } else {
2324 pMACHeader->wFrameCtl = TYPE_802_11_DATA;
2325 }
2326
2327 if (pDevice->eOPMode == OP_MODE_AP) {
2328 MEMvCopy(&(pMACHeader->abyAddr1[0]), &(psEthHeader->abyDstAddr[0]), U_ETHER_ADDR_LEN);
2329 MEMvCopy(&(pMACHeader->abyAddr2[0]), &(pDevice->abyBSSID[0]), U_ETHER_ADDR_LEN);
2330 MEMvCopy(&(pMACHeader->abyAddr3[0]), &(psEthHeader->abySrcAddr[0]), U_ETHER_ADDR_LEN);
2331 pMACHeader->wFrameCtl |= FC_FROMDS;
2332 }
2333 else {
2334 if (pDevice->eOPMode == OP_MODE_ADHOC) {
2335 MEMvCopy(&(pMACHeader->abyAddr1[0]), &(psEthHeader->abyDstAddr[0]), U_ETHER_ADDR_LEN);
2336 MEMvCopy(&(pMACHeader->abyAddr2[0]), &(psEthHeader->abySrcAddr[0]), U_ETHER_ADDR_LEN);
2337 MEMvCopy(&(pMACHeader->abyAddr3[0]), &(pDevice->abyBSSID[0]), U_ETHER_ADDR_LEN);
2338 }
2339 else {
2340 MEMvCopy(&(pMACHeader->abyAddr3[0]), &(psEthHeader->abyDstAddr[0]), U_ETHER_ADDR_LEN);
2341 MEMvCopy(&(pMACHeader->abyAddr2[0]), &(psEthHeader->abySrcAddr[0]), U_ETHER_ADDR_LEN);
2342 MEMvCopy(&(pMACHeader->abyAddr1[0]), &(pDevice->abyBSSID[0]), U_ETHER_ADDR_LEN);
2343 pMACHeader->wFrameCtl |= FC_TODS;
2344 }
2345 }
2346
2347 if (bNeedEncrypt)
2348 pMACHeader->wFrameCtl |= cpu_to_le16((WORD)WLAN_SET_FC_ISWEP(1));
2349
2350 pMACHeader->wDurationID = cpu_to_le16(wDuration);
2351
2352 if (pDevice->bLongHeader) {
2353 PWLAN_80211HDR_A4 pMACA4Header = (PWLAN_80211HDR_A4) pbyBufferAddr;
2354 pMACHeader->wFrameCtl |= (FC_TODS | FC_FROMDS);
2355 MEMvCopy(pMACA4Header->abyAddr4, pDevice->abyBSSID, WLAN_ADDR_LEN);
2356 }
2357 pMACHeader->wSeqCtl = cpu_to_le16(pDevice->wSeqCounter << 4);
2358
2359 //Set FragNumber in Sequence Control
2360 pMACHeader->wSeqCtl |= cpu_to_le16((WORD)uFragIdx);
2361
2362 if ((wFragType == FRAGCTL_ENDFRAG) || (wFragType == FRAGCTL_NONFRAG)) {
2363 pDevice->wSeqCounter++;
2364 if (pDevice->wSeqCounter > 0x0fff)
2365 pDevice->wSeqCounter = 0;
2366 }
2367
2368 if ((wFragType == FRAGCTL_STAFRAG) || (wFragType == FRAGCTL_MIDFRAG)) { //StartFrag or MidFrag
2369 pMACHeader->wFrameCtl |= FC_MOREFRAG;
2370 }
2371}
2372
2373
2374
2375
2376
2377
2378CMD_STATUS csMgmt_xmit(PSDevice pDevice, PSTxMgmtPacket pPacket) {
2379
2380 PSTxDesc pFrstTD;
2381 BYTE byPktTyp;
2382 PBYTE pbyTxBufferAddr;
2383 PVOID pvRTS;
2384 PSCTS pCTS;
2385 PVOID pvTxDataHd;
2386 UINT uDuration;
2387 UINT cbReqCount;
2388 PS802_11Header pMACHeader;
2389 UINT cbHeaderSize;
2390 UINT cbFrameBodySize;
2391 BOOL bNeedACK;
2392 BOOL bIsPSPOLL = FALSE;
2393 PSTxBufHead pTxBufHead;
2394 UINT cbFrameSize;
2395 UINT cbIVlen = 0;
2396 UINT cbICVlen = 0;
2397 UINT cbMIClen = 0;
2398 UINT cbFCSlen = 4;
2399 UINT uPadding = 0;
2400 WORD wTxBufSize;
2401 UINT cbMacHdLen;
2402 SEthernetHeader sEthHeader;
2403 PVOID pvRrvTime;
2404 PVOID pMICHDR;
2405 PSMgmtObject pMgmt = pDevice->pMgmt;
2406 WORD wCurrentRate = RATE_1M;
2407
2408
2409 if (AVAIL_TD(pDevice, TYPE_TXDMA0) <= 0) {
2410 return CMD_STATUS_RESOURCES;
2411 }
2412
2413 pFrstTD = pDevice->apCurrTD[TYPE_TXDMA0];
2414 pbyTxBufferAddr = (PBYTE)pFrstTD->pTDInfo->buf;
2415 cbFrameBodySize = pPacket->cbPayloadLen;
2416 pTxBufHead = (PSTxBufHead) pbyTxBufferAddr;
2417 wTxBufSize = sizeof(STxBufHead);
2418 memset(pTxBufHead, 0, wTxBufSize);
2419
2420 if (pDevice->eCurrentPHYType == PHY_TYPE_11A) {
2421 wCurrentRate = RATE_6M;
2422 byPktTyp = PK_TYPE_11A;
2423 } else {
2424 wCurrentRate = RATE_1M;
2425 byPktTyp = PK_TYPE_11B;
2426 }
2427
2428 // SetPower will cause error power TX state for OFDM Date packet in TX buffer.
2429 // 2004.11.11 Kyle -- Using OFDM power to tx MngPkt will decrease the connection capability.
2430 // And cmd timer will wait data pkt TX finish before scanning so it's OK
2431 // to set power here.
2432 if (pDevice->pMgmt->eScanState != WMAC_NO_SCANNING) {
2433
2434 RFbSetPower(pDevice, wCurrentRate, pDevice->byCurrentCh);
2435 } else {
2436 RFbSetPower(pDevice, wCurrentRate, pMgmt->uCurrChannel);
2437 }
2438 pTxBufHead->byTxPower = pDevice->byCurPwr;
2439 //+++++++++++++++++++++ Patch VT3253 A1 performance +++++++++++++++++++++++++++
2440 if (pDevice->byFOETuning) {
2441 if ((pPacket->p80211Header->sA3.wFrameCtl & TYPE_DATE_NULL) == TYPE_DATE_NULL) {
2442 wCurrentRate = RATE_24M;
2443 byPktTyp = PK_TYPE_11GA;
2444 }
2445 }
2446
2447 //Set packet type
2448 if (byPktTyp == PK_TYPE_11A) {//0000 0000 0000 0000
2449 pTxBufHead->wFIFOCtl = 0;
2450 }
2451 else if (byPktTyp == PK_TYPE_11B) {//0000 0001 0000 0000
2452 pTxBufHead->wFIFOCtl |= FIFOCTL_11B;
2453 }
2454 else if (byPktTyp == PK_TYPE_11GB) {//0000 0010 0000 0000
2455 pTxBufHead->wFIFOCtl |= FIFOCTL_11GB;
2456 }
2457 else if (byPktTyp == PK_TYPE_11GA) {//0000 0011 0000 0000
2458 pTxBufHead->wFIFOCtl |= FIFOCTL_11GA;
2459 }
2460
2461 pTxBufHead->wFIFOCtl |= FIFOCTL_TMOEN;
2462 pTxBufHead->wTimeStamp = cpu_to_le16(DEFAULT_MGN_LIFETIME_RES_64us);
2463
2464
2465 if (IS_MULTICAST_ADDRESS(&(pPacket->p80211Header->sA3.abyAddr1[0])) ||
2466 IS_BROADCAST_ADDRESS(&(pPacket->p80211Header->sA3.abyAddr1[0]))) {
2467 bNeedACK = FALSE;
2468 }
2469 else {
2470 bNeedACK = TRUE;
2471 pTxBufHead->wFIFOCtl |= FIFOCTL_NEEDACK;
2472 };
2473
2474 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_AP) ||
2475 (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) ) {
2476
2477 pTxBufHead->wFIFOCtl |= FIFOCTL_LRETRY;
2478 //Set Preamble type always long
2479 //pDevice->byPreambleType = PREAMBLE_LONG;
2480 // probe-response don't retry
2481 //if ((pPacket->p80211Header->sA4.wFrameCtl & TYPE_SUBTYPE_MASK) == TYPE_MGMT_PROBE_RSP) {
2482 // bNeedACK = FALSE;
2483 // pTxBufHead->wFIFOCtl &= (~FIFOCTL_NEEDACK);
2484 //}
2485 }
2486
2487 pTxBufHead->wFIFOCtl |= (FIFOCTL_GENINT | FIFOCTL_ISDMA0);
2488
2489 if ((pPacket->p80211Header->sA4.wFrameCtl & TYPE_SUBTYPE_MASK) == TYPE_CTL_PSPOLL) {
2490 bIsPSPOLL = TRUE;
2491 cbMacHdLen = WLAN_HDR_ADDR2_LEN;
2492 } else {
2493 cbMacHdLen = WLAN_HDR_ADDR3_LEN;
2494 }
2495
2496 //Set FRAGCTL_MACHDCNT
2497 pTxBufHead->wFragCtl |= cpu_to_le16((WORD)(cbMacHdLen << 10));
2498
2499 // Notes:
2500 // Although spec says MMPDU can be fragmented; In most case,
2501 // no one will send a MMPDU under fragmentation. With RTS may occur.
2502 pDevice->bAES = FALSE; //Set FRAGCTL_WEPTYP
2503
2504 if (WLAN_GET_FC_ISWEP(pPacket->p80211Header->sA4.wFrameCtl) != 0) {
2505 if (pDevice->eEncryptionStatus == Ndis802_11Encryption1Enabled) {
2506 cbIVlen = 4;
2507 cbICVlen = 4;
2508 pTxBufHead->wFragCtl |= FRAGCTL_LEGACY;
2509 }
2510 else if (pDevice->eEncryptionStatus == Ndis802_11Encryption2Enabled) {
2511 cbIVlen = 8;//IV+ExtIV
2512 cbMIClen = 8;
2513 cbICVlen = 4;
2514 pTxBufHead->wFragCtl |= FRAGCTL_TKIP;
2515 //We need to get seed here for filling TxKey entry.
2516 //TKIPvMixKey(pTransmitKey->abyKey, pDevice->abyCurrentNetAddr,
2517 // pTransmitKey->wTSC15_0, pTransmitKey->dwTSC47_16, pDevice->abyPRNG);
2518 }
2519 else if (pDevice->eEncryptionStatus == Ndis802_11Encryption3Enabled) {
2520 cbIVlen = 8;//RSN Header
2521 cbICVlen = 8;//MIC
2522 pTxBufHead->wFragCtl |= FRAGCTL_AES;
2523 pDevice->bAES = TRUE;
2524 }
2525 //MAC Header should be padding 0 to DW alignment.
2526 uPadding = 4 - (cbMacHdLen%4);
2527 uPadding %= 4;
2528 }
2529
2530 cbFrameSize = cbMacHdLen + cbFrameBodySize + cbIVlen + cbMIClen + cbICVlen + cbFCSlen;
2531
2532 //Set FIFOCTL_GrpAckPolicy
2533 if (pDevice->bGrpAckPolicy == TRUE) {//0000 0100 0000 0000
2534 pTxBufHead->wFIFOCtl |= FIFOCTL_GRPACK;
2535 }
2536 //the rest of pTxBufHead->wFragCtl:FragTyp will be set later in s_vFillFragParameter()
2537
2538 //Set RrvTime/RTS/CTS Buffer
2539 if (byPktTyp == PK_TYPE_11GB || byPktTyp == PK_TYPE_11GA) {//802.11g packet
2540
2541 pvRrvTime = (PSRrvTime_gCTS) (pbyTxBufferAddr + wTxBufSize);
2542 pMICHDR = NULL;
2543 pvRTS = NULL;
2544 pCTS = (PSCTS) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_gCTS));
2545 pvTxDataHd = (PSTxDataHead_g) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_gCTS) + sizeof(SCTS));
2546 cbHeaderSize = wTxBufSize + sizeof(SRrvTime_gCTS) + sizeof(SCTS) + sizeof(STxDataHead_g);
2547 }
2548 else { // 802.11a/b packet
2549 pvRrvTime = (PSRrvTime_ab) (pbyTxBufferAddr + wTxBufSize);
2550 pMICHDR = NULL;
2551 pvRTS = NULL;
2552 pCTS = NULL;
2553 pvTxDataHd = (PSTxDataHead_ab) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_ab));
2554 cbHeaderSize = wTxBufSize + sizeof(SRrvTime_ab) + sizeof(STxDataHead_ab);
2555 }
2556
2557 ZERO_MEMORY((PVOID)(pbyTxBufferAddr + wTxBufSize), (cbHeaderSize - wTxBufSize));
2558
2559 MEMvCopy(&(sEthHeader.abyDstAddr[0]), &(pPacket->p80211Header->sA3.abyAddr1[0]), U_ETHER_ADDR_LEN);
2560 MEMvCopy(&(sEthHeader.abySrcAddr[0]), &(pPacket->p80211Header->sA3.abyAddr2[0]), U_ETHER_ADDR_LEN);
2561 //=========================
2562 // No Fragmentation
2563 //=========================
2564 pTxBufHead->wFragCtl |= (WORD)FRAGCTL_NONFRAG;
2565
2566
2567 //Fill FIFO,RrvTime,RTS,and CTS
2568 s_vGenerateTxParameter(pDevice, byPktTyp, pbyTxBufferAddr, pvRrvTime, pvRTS, pCTS,
2569 cbFrameSize, bNeedACK, TYPE_TXDMA0, &sEthHeader, wCurrentRate);
2570
2571 //Fill DataHead
2572 uDuration = s_uFillDataHead(pDevice, byPktTyp, pvTxDataHd, cbFrameSize, TYPE_TXDMA0, bNeedACK,
2573 0, 0, 1, AUTO_FB_NONE, wCurrentRate);
2574
2575 pMACHeader = (PS802_11Header) (pbyTxBufferAddr + cbHeaderSize);
2576
2577 cbReqCount = cbHeaderSize + cbMacHdLen + uPadding + cbIVlen + cbFrameBodySize;
2578
2579 if (WLAN_GET_FC_ISWEP(pPacket->p80211Header->sA4.wFrameCtl) != 0) {
2580 PBYTE pbyIVHead;
2581 PBYTE pbyPayloadHead;
2582 PBYTE pbyBSSID;
2583 PSKeyItem pTransmitKey = NULL;
2584
2585 pbyIVHead = (PBYTE)(pbyTxBufferAddr + cbHeaderSize + cbMacHdLen + uPadding);
2586 pbyPayloadHead = (PBYTE)(pbyTxBufferAddr + cbHeaderSize + cbMacHdLen + uPadding + cbIVlen);
2587
2588 //Fill TXKEY
2589 //Kyle: Need fix: TKIP and AES did't encryt Mnt Packet.
2590 //s_vFillTxKey(pDevice, (PBYTE)pTxBufHead->adwTxKey, NULL);
2591
2592 //Fill IV(ExtIV,RSNHDR)
2593 //s_vFillPrePayload(pDevice, pbyIVHead, NULL);
2594 //---------------------------
2595 // S/W or H/W Encryption
2596 //---------------------------
2597 //Fill MICHDR
2598 //if (pDevice->bAES) {
2599 // s_vFillMICHDR(pDevice, (PBYTE)pMICHDR, (PBYTE)pMACHeader, (WORD)cbFrameBodySize);
2600 //}
2601 do {
2602 if ((pDevice->eOPMode == OP_MODE_INFRASTRUCTURE) &&
2603 (pDevice->bLinkPass == TRUE)) {
2604 pbyBSSID = pDevice->abyBSSID;
2605 // get pairwise key
2606 if (KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, PAIRWISE_KEY, &pTransmitKey) == FALSE) {
2607 // get group key
2608 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == TRUE) {
2609 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Get GTK.\n");
2610 break;
2611 }
2612 } else {
2613 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Get PTK.\n");
2614 break;
2615 }
2616 }
2617 // get group key
2618 pbyBSSID = pDevice->abyBroadcastAddr;
2619 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == FALSE) {
2620 pTransmitKey = NULL;
2621 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"KEY is NULL. OP Mode[%d]\n", pDevice->eOPMode);
2622 } else {
2623 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Get GTK.\n");
2624 }
2625 } while(FALSE);
2626 //Fill TXKEY
2627 s_vFillTxKey(pDevice, (PBYTE)(pTxBufHead->adwTxKey), pbyIVHead, pTransmitKey,
2628 (PBYTE)pMACHeader, (WORD)cbFrameBodySize, NULL);
2629
2630 MEMvCopy(pMACHeader, pPacket->p80211Header, cbMacHdLen);
2631 MEMvCopy(pbyPayloadHead, ((PBYTE)(pPacket->p80211Header) + cbMacHdLen),
2632 cbFrameBodySize);
2633 }
2634 else {
2635 // Copy the Packet into a tx Buffer
2636 MEMvCopy(pMACHeader, pPacket->p80211Header, pPacket->cbMPDULen);
2637 }
2638
2639 pMACHeader->wSeqCtl = cpu_to_le16(pDevice->wSeqCounter << 4);
2640 pDevice->wSeqCounter++ ;
2641 if (pDevice->wSeqCounter > 0x0fff)
2642 pDevice->wSeqCounter = 0;
2643
2644 if (bIsPSPOLL) {
2645 // The MAC will automatically replace the Duration-field of MAC header by Duration-field
2646 // of FIFO control header.
2647 // This will cause AID-field of PS-POLL packet be incorrect (Because PS-POLL's AID field is
2648 // in the same place of other packet's Duration-field).
2649 // And it will cause Cisco-AP to issue Disassociation-packet
2650 if (byPktTyp == PK_TYPE_11GB || byPktTyp == PK_TYPE_11GA) {
2651 ((PSTxDataHead_g)pvTxDataHd)->wDuration_a = cpu_to_le16(pPacket->p80211Header->sA2.wDurationID);
2652 ((PSTxDataHead_g)pvTxDataHd)->wDuration_b = cpu_to_le16(pPacket->p80211Header->sA2.wDurationID);
2653 } else {
2654 ((PSTxDataHead_ab)pvTxDataHd)->wDuration = cpu_to_le16(pPacket->p80211Header->sA2.wDurationID);
2655 }
2656 }
2657
2658
2659 // first TD is the only TD
2660 //Set TSR1 & ReqCount in TxDescHead
2661 pFrstTD->m_td1TD1.byTCR = (TCR_STP | TCR_EDP | EDMSDU);
2662 pFrstTD->pTDInfo->skb_dma = pFrstTD->pTDInfo->buf_dma;
2663 pFrstTD->m_td1TD1.wReqCount = cpu_to_le16((WORD)(cbReqCount));
2664 pFrstTD->buff_addr = cpu_to_le32(pFrstTD->pTDInfo->skb_dma);
2665 pFrstTD->pTDInfo->byFlags = 0;
2666
2667 if (MACbIsRegBitsOn(pDevice->PortOffset, MAC_REG_PSCTL, PSCTL_PS)) {
2668 // Disable PS
2669 MACbPSWakeup(pDevice->PortOffset);
2670 }
2671 pDevice->bPWBitOn = FALSE;
2672
2673 wmb();
2674 pFrstTD->m_td0TD0.f1Owner = OWNED_BY_NIC;
2675 wmb();
2676
2677 pDevice->iTDUsed[TYPE_TXDMA0]++;
2678
2679 if (AVAIL_TD(pDevice, TYPE_TXDMA0) <= 1) {
2680 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO " available td0 <= 1\n");
2681 }
2682
2683 pDevice->apCurrTD[TYPE_TXDMA0] = pFrstTD->next;
2684#ifdef PLICE_DEBUG
2685 //printk("SCAN:CurrentRate is %d,TxPower is %d\n",wCurrentRate,pTxBufHead->byTxPower);
2686#endif
2687
2688#ifdef TxInSleep
2689 pDevice->nTxDataTimeCout=0; //2008-8-21 chester <add> for send null packet
2690 #endif
2691
2692 // Poll Transmit the adapter
2693 MACvTransmit0(pDevice->PortOffset);
2694
2695 return CMD_STATUS_PENDING;
2696
2697}
2698
2699
2700CMD_STATUS csBeacon_xmit(PSDevice pDevice, PSTxMgmtPacket pPacket) {
2701
2702 BYTE byPktTyp;
2703 PBYTE pbyBuffer = (PBYTE)pDevice->tx_beacon_bufs;
2704 UINT cbFrameSize = pPacket->cbMPDULen + WLAN_FCS_LEN;
2705 UINT cbHeaderSize = 0;
2706 WORD wTxBufSize = sizeof(STxShortBufHead);
2707 PSTxShortBufHead pTxBufHead = (PSTxShortBufHead) pbyBuffer;
2708 PSTxDataHead_ab pTxDataHead = (PSTxDataHead_ab) (pbyBuffer + wTxBufSize);
2709 PS802_11Header pMACHeader;
2710 WORD wCurrentRate;
2711 WORD wLen = 0x0000;
2712
2713
2714 memset(pTxBufHead, 0, wTxBufSize);
2715
2716 if (pDevice->eCurrentPHYType == PHY_TYPE_11A) {
2717 wCurrentRate = RATE_6M;
2718 byPktTyp = PK_TYPE_11A;
2719 } else {
2720 wCurrentRate = RATE_2M;
2721 byPktTyp = PK_TYPE_11B;
2722 }
2723
2724 //Set Preamble type always long
2725 pDevice->byPreambleType = PREAMBLE_LONG;
2726
2727 //Set FIFOCTL_GENINT
2728
2729 pTxBufHead->wFIFOCtl |= FIFOCTL_GENINT;
2730
2731
2732 //Set packet type & Get Duration
2733 if (byPktTyp == PK_TYPE_11A) {//0000 0000 0000 0000
2734 pTxDataHead->wDuration = cpu_to_le16((WORD)s_uGetDataDuration(pDevice, DATADUR_A, cbFrameSize, byPktTyp,
2735 wCurrentRate, FALSE, 0, 0, 1, AUTO_FB_NONE));
2736 }
2737 else if (byPktTyp == PK_TYPE_11B) {//0000 0001 0000 0000
2738 pTxBufHead->wFIFOCtl |= FIFOCTL_11B;
2739 pTxDataHead->wDuration = cpu_to_le16((WORD)s_uGetDataDuration(pDevice, DATADUR_B, cbFrameSize, byPktTyp,
2740 wCurrentRate, FALSE, 0, 0, 1, AUTO_FB_NONE));
2741 }
2742
2743 BBvCaculateParameter(pDevice, cbFrameSize, wCurrentRate, byPktTyp,
2744 (PWORD)&(wLen), (PBYTE)&(pTxDataHead->byServiceField), (PBYTE)&(pTxDataHead->bySignalField)
2745 );
2746 pTxDataHead->wTransmitLength = cpu_to_le16(wLen);
2747 //Get TimeStampOff
2748 pTxDataHead->wTimeStampOff = cpu_to_le16(wTimeStampOff[pDevice->byPreambleType%2][wCurrentRate%MAX_RATE]);
2749 cbHeaderSize = wTxBufSize + sizeof(STxDataHead_ab);
2750
2751 //Generate Beacon Header
2752 pMACHeader = (PS802_11Header)(pbyBuffer + cbHeaderSize);
2753 MEMvCopy(pMACHeader, pPacket->p80211Header, pPacket->cbMPDULen);
2754
2755 pMACHeader->wDurationID = 0;
2756 pMACHeader->wSeqCtl = cpu_to_le16(pDevice->wSeqCounter << 4);
2757 pDevice->wSeqCounter++ ;
2758 if (pDevice->wSeqCounter > 0x0fff)
2759 pDevice->wSeqCounter = 0;
2760
2761 // Set Beacon buffer length
2762 pDevice->wBCNBufLen = pPacket->cbMPDULen + cbHeaderSize;
2763
2764 MACvSetCurrBCNTxDescAddr(pDevice->PortOffset, (pDevice->tx_beacon_dma));
2765
2766 MACvSetCurrBCNLength(pDevice->PortOffset, pDevice->wBCNBufLen);
2767 // Set auto Transmit on
2768 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_TCR, TCR_AUTOBCNTX);
2769 // Poll Transmit the adapter
2770 MACvTransmitBCN(pDevice->PortOffset);
2771
2772 return CMD_STATUS_PENDING;
2773}
2774
2775
2776
2777UINT
2778cbGetFragCount (
2779 IN PSDevice pDevice,
2780 IN PSKeyItem pTransmitKey,
2781 IN UINT cbFrameBodySize,
2782 IN PSEthernetHeader psEthHeader
2783 )
2784{
2785 UINT cbMACHdLen;
2786 UINT cbFrameSize;
2787 UINT cbFragmentSize; //Hdr+(IV)+payoad+(MIC)+(ICV)+FCS
2788 UINT cbFragPayloadSize;
2789 UINT cbLastFragPayloadSize;
2790 UINT cbIVlen = 0;
2791 UINT cbICVlen = 0;
2792 UINT cbMIClen = 0;
2793 UINT cbFCSlen = 4;
2794 UINT uMACfragNum = 1;
2795 BOOL bNeedACK;
2796
2797
2798
2799 if ((pDevice->eOPMode == OP_MODE_ADHOC) ||
2800 (pDevice->eOPMode == OP_MODE_AP)) {
2801 if (IS_MULTICAST_ADDRESS(&(psEthHeader->abyDstAddr[0])) ||
2802 IS_BROADCAST_ADDRESS(&(psEthHeader->abyDstAddr[0]))) {
2803 bNeedACK = FALSE;
2804 }
2805 else {
2806 bNeedACK = TRUE;
2807 }
2808 }
2809 else {
2810 // MSDUs in Infra mode always need ACK
2811 bNeedACK = TRUE;
2812 }
2813
2814 if (pDevice->bLongHeader)
2815 cbMACHdLen = WLAN_HDR_ADDR3_LEN + 6;
2816 else
2817 cbMACHdLen = WLAN_HDR_ADDR3_LEN;
2818
2819
2820 if (pDevice->bEncryptionEnable == TRUE) {
2821
2822 if (pTransmitKey == NULL) {
2823 if ((pDevice->eEncryptionStatus == Ndis802_11Encryption1Enabled) ||
2824 (pDevice->pMgmt->eAuthenMode < WMAC_AUTH_WPA)) {
2825 cbIVlen = 4;
2826 cbICVlen = 4;
2827 } else if (pDevice->eEncryptionStatus == Ndis802_11Encryption2Enabled) {
2828 cbIVlen = 8;//IV+ExtIV
2829 cbMIClen = 8;
2830 cbICVlen = 4;
2831 } else if (pDevice->eEncryptionStatus == Ndis802_11Encryption3Enabled) {
2832 cbIVlen = 8;//RSN Header
2833 cbICVlen = 8;//MIC
2834 }
2835 } else if (pTransmitKey->byCipherSuite == KEY_CTL_WEP) {
2836 cbIVlen = 4;
2837 cbICVlen = 4;
2838 } else if (pTransmitKey->byCipherSuite == KEY_CTL_TKIP) {
2839 cbIVlen = 8;//IV+ExtIV
2840 cbMIClen = 8;
2841 cbICVlen = 4;
2842 } else if (pTransmitKey->byCipherSuite == KEY_CTL_CCMP) {
2843 cbIVlen = 8;//RSN Header
2844 cbICVlen = 8;//MIC
2845 }
2846 }
2847
2848 cbFrameSize = cbMACHdLen + cbIVlen + (cbFrameBodySize + cbMIClen) + cbICVlen + cbFCSlen;
2849
2850 if ((cbFrameSize > pDevice->wFragmentationThreshold) && (bNeedACK == TRUE)) {
2851 // Fragmentation
2852 cbFragmentSize = pDevice->wFragmentationThreshold;
2853 cbFragPayloadSize = cbFragmentSize - cbMACHdLen - cbIVlen - cbICVlen - cbFCSlen;
2854 uMACfragNum = (WORD) ((cbFrameBodySize + cbMIClen) / cbFragPayloadSize);
2855 cbLastFragPayloadSize = (cbFrameBodySize + cbMIClen) % cbFragPayloadSize;
2856 if (cbLastFragPayloadSize == 0) {
2857 cbLastFragPayloadSize = cbFragPayloadSize;
2858 } else {
2859 uMACfragNum++;
2860 }
2861 }
2862 return uMACfragNum;
2863}
2864
2865
2866VOID
2867vDMA0_tx_80211(PSDevice pDevice, struct sk_buff *skb, PBYTE pbMPDU, UINT cbMPDULen) {
2868
2869 PSTxDesc pFrstTD;
2870 BYTE byPktTyp;
2871 PBYTE pbyTxBufferAddr;
2872 PVOID pvRTS;
2873 PVOID pvCTS;
2874 PVOID pvTxDataHd;
2875 UINT uDuration;
2876 UINT cbReqCount;
2877 PS802_11Header pMACHeader;
2878 UINT cbHeaderSize;
2879 UINT cbFrameBodySize;
2880 BOOL bNeedACK;
2881 BOOL bIsPSPOLL = FALSE;
2882 PSTxBufHead pTxBufHead;
2883 UINT cbFrameSize;
2884 UINT cbIVlen = 0;
2885 UINT cbICVlen = 0;
2886 UINT cbMIClen = 0;
2887 UINT cbFCSlen = 4;
2888 UINT uPadding = 0;
2889 UINT cbMICHDR = 0;
2890 UINT uLength = 0;
2891 DWORD dwMICKey0, dwMICKey1;
2892 DWORD dwMIC_Priority;
2893 PDWORD pdwMIC_L;
2894 PDWORD pdwMIC_R;
2895 WORD wTxBufSize;
2896 UINT cbMacHdLen;
2897 SEthernetHeader sEthHeader;
2898 PVOID pvRrvTime;
2899 PVOID pMICHDR;
2900 PSMgmtObject pMgmt = pDevice->pMgmt;
2901 WORD wCurrentRate = RATE_1M;
2902 PUWLAN_80211HDR p80211Header;
2903 UINT uNodeIndex = 0;
2904 BOOL bNodeExist = FALSE;
2905 SKeyItem STempKey;
2906 PSKeyItem pTransmitKey = NULL;
2907 PBYTE pbyIVHead;
2908 PBYTE pbyPayloadHead;
2909 PBYTE pbyMacHdr;
2910
2911 UINT cbExtSuppRate = 0;
2912// PWLAN_IE pItem;
2913
2914
2915 pvRrvTime = pMICHDR = pvRTS = pvCTS = pvTxDataHd = NULL;
2916
2917 if(cbMPDULen <= WLAN_HDR_ADDR3_LEN) {
2918 cbFrameBodySize = 0;
2919 }
2920 else {
2921 cbFrameBodySize = cbMPDULen - WLAN_HDR_ADDR3_LEN;
2922 }
2923 p80211Header = (PUWLAN_80211HDR)pbMPDU;
2924
2925
2926 pFrstTD = pDevice->apCurrTD[TYPE_TXDMA0];
2927 pbyTxBufferAddr = (PBYTE)pFrstTD->pTDInfo->buf;
2928 pTxBufHead = (PSTxBufHead) pbyTxBufferAddr;
2929 wTxBufSize = sizeof(STxBufHead);
2930 memset(pTxBufHead, 0, wTxBufSize);
2931
2932 if (pDevice->eCurrentPHYType == PHY_TYPE_11A) {
2933 wCurrentRate = RATE_6M;
2934 byPktTyp = PK_TYPE_11A;
2935 } else {
2936 wCurrentRate = RATE_1M;
2937 byPktTyp = PK_TYPE_11B;
2938 }
2939
2940 // SetPower will cause error power TX state for OFDM Date packet in TX buffer.
2941 // 2004.11.11 Kyle -- Using OFDM power to tx MngPkt will decrease the connection capability.
2942 // And cmd timer will wait data pkt TX finish before scanning so it's OK
2943 // to set power here.
2944 if (pDevice->pMgmt->eScanState != WMAC_NO_SCANNING) {
2945 RFbSetPower(pDevice, wCurrentRate, pDevice->byCurrentCh);
2946 } else {
2947 RFbSetPower(pDevice, wCurrentRate, pMgmt->uCurrChannel);
2948 }
2949 pTxBufHead->byTxPower = pDevice->byCurPwr;
2950
2951 //+++++++++++++++++++++ Patch VT3253 A1 performance +++++++++++++++++++++++++++
2952 if (pDevice->byFOETuning) {
2953 if ((p80211Header->sA3.wFrameCtl & TYPE_DATE_NULL) == TYPE_DATE_NULL) {
2954 wCurrentRate = RATE_24M;
2955 byPktTyp = PK_TYPE_11GA;
2956 }
2957 }
2958
2959 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"vDMA0_tx_80211: p80211Header->sA3.wFrameCtl = %x \n", p80211Header->sA3.wFrameCtl);
2960
2961 //Set packet type
2962 if (byPktTyp == PK_TYPE_11A) {//0000 0000 0000 0000
2963 pTxBufHead->wFIFOCtl = 0;
2964 }
2965 else if (byPktTyp == PK_TYPE_11B) {//0000 0001 0000 0000
2966 pTxBufHead->wFIFOCtl |= FIFOCTL_11B;
2967 }
2968 else if (byPktTyp == PK_TYPE_11GB) {//0000 0010 0000 0000
2969 pTxBufHead->wFIFOCtl |= FIFOCTL_11GB;
2970 }
2971 else if (byPktTyp == PK_TYPE_11GA) {//0000 0011 0000 0000
2972 pTxBufHead->wFIFOCtl |= FIFOCTL_11GA;
2973 }
2974
2975 pTxBufHead->wFIFOCtl |= FIFOCTL_TMOEN;
2976 pTxBufHead->wTimeStamp = cpu_to_le16(DEFAULT_MGN_LIFETIME_RES_64us);
2977
2978
2979 if (IS_MULTICAST_ADDRESS(&(p80211Header->sA3.abyAddr1[0])) ||
2980 IS_BROADCAST_ADDRESS(&(p80211Header->sA3.abyAddr1[0]))) {
2981 bNeedACK = FALSE;
2982 if (pDevice->bEnableHostWEP) {
2983 uNodeIndex = 0;
2984 bNodeExist = TRUE;
2985 };
2986 }
2987 else {
2988 if (pDevice->bEnableHostWEP) {
2989 if (BSSDBbIsSTAInNodeDB(pDevice->pMgmt, (PBYTE)(p80211Header->sA3.abyAddr1), &uNodeIndex))
2990 bNodeExist = TRUE;
2991 };
2992 bNeedACK = TRUE;
2993 pTxBufHead->wFIFOCtl |= FIFOCTL_NEEDACK;
2994 };
2995
2996 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_AP) ||
2997 (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) ) {
2998
2999 pTxBufHead->wFIFOCtl |= FIFOCTL_LRETRY;
3000 //Set Preamble type always long
3001 //pDevice->byPreambleType = PREAMBLE_LONG;
3002
3003 // probe-response don't retry
3004 //if ((p80211Header->sA4.wFrameCtl & TYPE_SUBTYPE_MASK) == TYPE_MGMT_PROBE_RSP) {
3005 // bNeedACK = FALSE;
3006 // pTxBufHead->wFIFOCtl &= (~FIFOCTL_NEEDACK);
3007 //}
3008 }
3009
3010 pTxBufHead->wFIFOCtl |= (FIFOCTL_GENINT | FIFOCTL_ISDMA0);
3011
3012 if ((p80211Header->sA4.wFrameCtl & TYPE_SUBTYPE_MASK) == TYPE_CTL_PSPOLL) {
3013 bIsPSPOLL = TRUE;
3014 cbMacHdLen = WLAN_HDR_ADDR2_LEN;
3015 } else {
3016 cbMacHdLen = WLAN_HDR_ADDR3_LEN;
3017 }
3018
3019 // hostapd deamon ext support rate patch
3020 if (WLAN_GET_FC_FSTYPE(p80211Header->sA4.wFrameCtl) == WLAN_FSTYPE_ASSOCRESP) {
3021
3022 if (((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates)->len != 0) {
3023 cbExtSuppRate += ((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates)->len + WLAN_IEHDR_LEN;
3024 }
3025
3026 if (((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates)->len != 0) {
3027 cbExtSuppRate += ((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates)->len + WLAN_IEHDR_LEN;
3028 }
3029
3030 if (cbExtSuppRate >0) {
3031 cbFrameBodySize = WLAN_ASSOCRESP_OFF_SUPP_RATES;
3032 }
3033 }
3034
3035
3036 //Set FRAGCTL_MACHDCNT
3037 pTxBufHead->wFragCtl |= cpu_to_le16((WORD)cbMacHdLen << 10);
3038
3039 // Notes:
3040 // Although spec says MMPDU can be fragmented; In most case,
3041 // no one will send a MMPDU under fragmentation. With RTS may occur.
3042 pDevice->bAES = FALSE; //Set FRAGCTL_WEPTYP
3043
3044
3045 if (WLAN_GET_FC_ISWEP(p80211Header->sA4.wFrameCtl) != 0) {
3046 if (pDevice->eEncryptionStatus == Ndis802_11Encryption1Enabled) {
3047 cbIVlen = 4;
3048 cbICVlen = 4;
3049 pTxBufHead->wFragCtl |= FRAGCTL_LEGACY;
3050 }
3051 else if (pDevice->eEncryptionStatus == Ndis802_11Encryption2Enabled) {
3052 cbIVlen = 8;//IV+ExtIV
3053 cbMIClen = 8;
3054 cbICVlen = 4;
3055 pTxBufHead->wFragCtl |= FRAGCTL_TKIP;
3056 //We need to get seed here for filling TxKey entry.
3057 //TKIPvMixKey(pTransmitKey->abyKey, pDevice->abyCurrentNetAddr,
3058 // pTransmitKey->wTSC15_0, pTransmitKey->dwTSC47_16, pDevice->abyPRNG);
3059 }
3060 else if (pDevice->eEncryptionStatus == Ndis802_11Encryption3Enabled) {
3061 cbIVlen = 8;//RSN Header
3062 cbICVlen = 8;//MIC
3063 cbMICHDR = sizeof(SMICHDRHead);
3064 pTxBufHead->wFragCtl |= FRAGCTL_AES;
3065 pDevice->bAES = TRUE;
3066 }
3067 //MAC Header should be padding 0 to DW alignment.
3068 uPadding = 4 - (cbMacHdLen%4);
3069 uPadding %= 4;
3070 }
3071
3072 cbFrameSize = cbMacHdLen + cbFrameBodySize + cbIVlen + cbMIClen + cbICVlen + cbFCSlen + cbExtSuppRate;
3073
3074 //Set FIFOCTL_GrpAckPolicy
3075 if (pDevice->bGrpAckPolicy == TRUE) {//0000 0100 0000 0000
3076 pTxBufHead->wFIFOCtl |= FIFOCTL_GRPACK;
3077 }
3078 //the rest of pTxBufHead->wFragCtl:FragTyp will be set later in s_vFillFragParameter()
3079
3080
3081 if (byPktTyp == PK_TYPE_11GB || byPktTyp == PK_TYPE_11GA) {//802.11g packet
3082
3083 pvRrvTime = (PSRrvTime_gCTS) (pbyTxBufferAddr + wTxBufSize);
3084 pMICHDR = (PSMICHDRHead) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_gCTS));
3085 pvRTS = NULL;
3086 pvCTS = (PSCTS) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_gCTS) + cbMICHDR);
3087 pvTxDataHd = (PSTxDataHead_g) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_gCTS) + cbMICHDR + sizeof(SCTS));
3088 cbHeaderSize = wTxBufSize + sizeof(SRrvTime_gCTS) + cbMICHDR + sizeof(SCTS) + sizeof(STxDataHead_g);
3089
3090 }
3091 else {//802.11a/b packet
3092
3093 pvRrvTime = (PSRrvTime_ab) (pbyTxBufferAddr + wTxBufSize);
3094 pMICHDR = (PSMICHDRHead) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_ab));
3095 pvRTS = NULL;
3096 pvCTS = NULL;
3097 pvTxDataHd = (PSTxDataHead_ab) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_ab) + cbMICHDR);
3098 cbHeaderSize = wTxBufSize + sizeof(SRrvTime_ab) + cbMICHDR + sizeof(STxDataHead_ab);
3099
3100 }
3101
3102 ZERO_MEMORY((PVOID)(pbyTxBufferAddr + wTxBufSize), (cbHeaderSize - wTxBufSize));
3103 MEMvCopy(&(sEthHeader.abyDstAddr[0]), &(p80211Header->sA3.abyAddr1[0]), U_ETHER_ADDR_LEN);
3104 MEMvCopy(&(sEthHeader.abySrcAddr[0]), &(p80211Header->sA3.abyAddr2[0]), U_ETHER_ADDR_LEN);
3105 //=========================
3106 // No Fragmentation
3107 //=========================
3108 pTxBufHead->wFragCtl |= (WORD)FRAGCTL_NONFRAG;
3109
3110
3111 //Fill FIFO,RrvTime,RTS,and CTS
3112 s_vGenerateTxParameter(pDevice, byPktTyp, pbyTxBufferAddr, pvRrvTime, pvRTS, pvCTS,
3113 cbFrameSize, bNeedACK, TYPE_TXDMA0, &sEthHeader, wCurrentRate);
3114
3115 //Fill DataHead
3116 uDuration = s_uFillDataHead(pDevice, byPktTyp, pvTxDataHd, cbFrameSize, TYPE_TXDMA0, bNeedACK,
3117 0, 0, 1, AUTO_FB_NONE, wCurrentRate);
3118
3119 pMACHeader = (PS802_11Header) (pbyTxBufferAddr + cbHeaderSize);
3120
3121 cbReqCount = cbHeaderSize + cbMacHdLen + uPadding + cbIVlen + (cbFrameBodySize + cbMIClen) + cbExtSuppRate;
3122
3123 pbyMacHdr = (PBYTE)(pbyTxBufferAddr + cbHeaderSize);
3124 pbyPayloadHead = (PBYTE)(pbyMacHdr + cbMacHdLen + uPadding + cbIVlen);
3125 pbyIVHead = (PBYTE)(pbyMacHdr + cbMacHdLen + uPadding);
3126
3127 // Copy the Packet into a tx Buffer
3128 memcpy(pbyMacHdr, pbMPDU, cbMacHdLen);
3129
3130 // version set to 0, patch for hostapd deamon
3131 pMACHeader->wFrameCtl &= cpu_to_le16(0xfffc);
3132 memcpy(pbyPayloadHead, (pbMPDU + cbMacHdLen), cbFrameBodySize);
3133
3134 // replace support rate, patch for hostapd deamon( only support 11M)
3135 if (WLAN_GET_FC_FSTYPE(p80211Header->sA4.wFrameCtl) == WLAN_FSTYPE_ASSOCRESP) {
3136 if (cbExtSuppRate != 0) {
3137 if (((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates)->len != 0)
3138 memcpy((pbyPayloadHead + cbFrameBodySize),
3139 pMgmt->abyCurrSuppRates,
3140 ((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates)->len + WLAN_IEHDR_LEN
3141 );
3142 if (((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates)->len != 0)
3143 memcpy((pbyPayloadHead + cbFrameBodySize) + ((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates)->len + WLAN_IEHDR_LEN,
3144 pMgmt->abyCurrExtSuppRates,
3145 ((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates)->len + WLAN_IEHDR_LEN
3146 );
3147 }
3148 }
3149
3150 // Set wep
3151 if (WLAN_GET_FC_ISWEP(p80211Header->sA4.wFrameCtl) != 0) {
3152
3153 if (pDevice->bEnableHostWEP) {
3154 pTransmitKey = &STempKey;
3155 pTransmitKey->byCipherSuite = pMgmt->sNodeDBTable[uNodeIndex].byCipherSuite;
3156 pTransmitKey->dwKeyIndex = pMgmt->sNodeDBTable[uNodeIndex].dwKeyIndex;
3157 pTransmitKey->uKeyLength = pMgmt->sNodeDBTable[uNodeIndex].uWepKeyLength;
3158 pTransmitKey->dwTSC47_16 = pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16;
3159 pTransmitKey->wTSC15_0 = pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0;
3160 memcpy(pTransmitKey->abyKey,
3161 &pMgmt->sNodeDBTable[uNodeIndex].abyWepKey[0],
3162 pTransmitKey->uKeyLength
3163 );
3164 }
3165
3166 if ((pTransmitKey != NULL) && (pTransmitKey->byCipherSuite == KEY_CTL_TKIP)) {
3167
3168 dwMICKey0 = *(PDWORD)(&pTransmitKey->abyKey[16]);
3169 dwMICKey1 = *(PDWORD)(&pTransmitKey->abyKey[20]);
3170
3171 // DO Software Michael
3172 MIC_vInit(dwMICKey0, dwMICKey1);
3173 MIC_vAppend((PBYTE)&(sEthHeader.abyDstAddr[0]), 12);
3174 dwMIC_Priority = 0;
3175 MIC_vAppend((PBYTE)&dwMIC_Priority, 4);
3176 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"DMA0_tx_8021:MIC KEY: %lX, %lX\n", dwMICKey0, dwMICKey1);
3177
3178 uLength = cbHeaderSize + cbMacHdLen + uPadding + cbIVlen;
3179
3180 MIC_vAppend((pbyTxBufferAddr + uLength), cbFrameBodySize);
3181
3182 pdwMIC_L = (PDWORD)(pbyTxBufferAddr + uLength + cbFrameBodySize);
3183 pdwMIC_R = (PDWORD)(pbyTxBufferAddr + uLength + cbFrameBodySize + 4);
3184
3185 MIC_vGetMIC(pdwMIC_L, pdwMIC_R);
3186 MIC_vUnInit();
3187
3188 if (pDevice->bTxMICFail == TRUE) {
3189 *pdwMIC_L = 0;
3190 *pdwMIC_R = 0;
3191 pDevice->bTxMICFail = FALSE;
3192 }
3193
3194 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"uLength: %d, %d\n", uLength, cbFrameBodySize);
3195 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"cbReqCount:%d, %d, %d, %d\n", cbReqCount, cbHeaderSize, uPadding, cbIVlen);
3196 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"MIC:%lx, %lx\n", *pdwMIC_L, *pdwMIC_R);
3197
3198 }
3199
3200
3201 s_vFillTxKey(pDevice, (PBYTE)(pTxBufHead->adwTxKey), pbyIVHead, pTransmitKey,
3202 pbyMacHdr, (WORD)cbFrameBodySize, (PBYTE)pMICHDR);
3203
3204 if (pDevice->bEnableHostWEP) {
3205 pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16 = pTransmitKey->dwTSC47_16;
3206 pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0 = pTransmitKey->wTSC15_0;
3207 }
3208
3209 if ((pDevice->byLocalID <= REV_ID_VT3253_A1)) {
3210 s_vSWencryption(pDevice, pTransmitKey, pbyPayloadHead, (WORD)(cbFrameBodySize + cbMIClen));
3211 }
3212 }
3213
3214 pMACHeader->wSeqCtl = cpu_to_le16(pDevice->wSeqCounter << 4);
3215 pDevice->wSeqCounter++ ;
3216 if (pDevice->wSeqCounter > 0x0fff)
3217 pDevice->wSeqCounter = 0;
3218
3219
3220 if (bIsPSPOLL) {
3221 // The MAC will automatically replace the Duration-field of MAC header by Duration-field
3222 // of FIFO control header.
3223 // This will cause AID-field of PS-POLL packet be incorrect (Because PS-POLL's AID field is
3224 // in the same place of other packet's Duration-field).
3225 // And it will cause Cisco-AP to issue Disassociation-packet
3226 if (byPktTyp == PK_TYPE_11GB || byPktTyp == PK_TYPE_11GA) {
3227 ((PSTxDataHead_g)pvTxDataHd)->wDuration_a = cpu_to_le16(p80211Header->sA2.wDurationID);
3228 ((PSTxDataHead_g)pvTxDataHd)->wDuration_b = cpu_to_le16(p80211Header->sA2.wDurationID);
3229 } else {
3230 ((PSTxDataHead_ab)pvTxDataHd)->wDuration = cpu_to_le16(p80211Header->sA2.wDurationID);
3231 }
3232 }
3233
3234
3235 // first TD is the only TD
3236 //Set TSR1 & ReqCount in TxDescHead
3237 pFrstTD->pTDInfo->skb = skb;
3238 pFrstTD->m_td1TD1.byTCR = (TCR_STP | TCR_EDP | EDMSDU);
3239 pFrstTD->pTDInfo->skb_dma = pFrstTD->pTDInfo->buf_dma;
3240 pFrstTD->m_td1TD1.wReqCount = cpu_to_le16(cbReqCount);
3241 pFrstTD->buff_addr = cpu_to_le32(pFrstTD->pTDInfo->skb_dma);
3242 pFrstTD->pTDInfo->byFlags = 0;
3243 pFrstTD->pTDInfo->byFlags |= TD_FLAGS_PRIV_SKB;
3244
3245 if (MACbIsRegBitsOn(pDevice->PortOffset, MAC_REG_PSCTL, PSCTL_PS)) {
3246 // Disable PS
3247 MACbPSWakeup(pDevice->PortOffset);
3248 }
3249 pDevice->bPWBitOn = FALSE;
3250
3251 wmb();
3252 pFrstTD->m_td0TD0.f1Owner = OWNED_BY_NIC;
3253 wmb();
3254
3255 pDevice->iTDUsed[TYPE_TXDMA0]++;
3256
3257 if (AVAIL_TD(pDevice, TYPE_TXDMA0) <= 1) {
3258 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO " available td0 <= 1\n");
3259 }
3260
3261 pDevice->apCurrTD[TYPE_TXDMA0] = pFrstTD->next;
3262
3263 // Poll Transmit the adapter
3264 MACvTransmit0(pDevice->PortOffset);
3265
3266 return;
3267}
3268
3269
diff --git a/drivers/staging/vt6655/rxtx.h b/drivers/staging/vt6655/rxtx.h
new file mode 100644
index 000000000000..3e85264e2843
--- /dev/null
+++ b/drivers/staging/vt6655/rxtx.h
@@ -0,0 +1,132 @@
1/*
2 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
3 * All rights reserved.
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * File: whdr.h
20 *
21 * Purpose:
22 *
23 * Author: Jerry Chen
24 *
25 * Date: Jun. 27, 2002
26 *
27 */
28
29
30#ifndef __RXTX_H__
31#define __RXTX_H__
32
33#if !defined(__TTYPE_H__)
34#include "ttype.h"
35#endif
36#if !defined(__DEVICE_H__)
37#include "device.h"
38#endif
39#if !defined(__WCMD_H__)
40#include "wcmd.h"
41#endif
42
43
44/*--------------------- Export Definitions -------------------------*/
45
46/*--------------------- Export Classes ----------------------------*/
47
48/*--------------------- Export Variables --------------------------*/
49
50/*--------------------- Export Functions --------------------------*/
51
52
53#ifdef __cplusplus
54extern "C" { /* Assume C declarations for C++ */
55#endif /* __cplusplus */
56
57/*
58VOID vGenerateMACHeader(
59 IN PSDevice pDevice,
60 IN DWORD dwTxBufferAddr,
61 IN PBYTE pbySkbData,
62 IN UINT cbPacketSize,
63 IN BOOL bDMA0Used,
64 OUT PUINT pcbHeadSize,
65 OUT PUINT pcbAppendPayload
66 );
67
68VOID vProcessRxMACHeader (
69 IN PSDevice pDevice,
70 IN DWORD dwRxBufferAddr,
71 IN UINT cbPacketSize,
72 IN BOOL bIsWEP,
73 OUT PUINT pcbHeadSize
74 );
75*/
76
77
78VOID
79vGenerateMACHeader (
80 IN PSDevice pDevice,
81 IN PBYTE pbyBufferAddr,
82 IN WORD wDuration,
83 IN PSEthernetHeader psEthHeader,
84 IN BOOL bNeedEncrypt,
85 IN WORD wFragType,
86 IN UINT uDMAIdx,
87 IN UINT uFragIdx
88 );
89
90
91UINT
92cbGetFragCount(
93 IN PSDevice pDevice,
94 IN PSKeyItem pTransmitKey,
95 IN UINT cbFrameBodySize,
96 IN PSEthernetHeader psEthHeader
97 );
98
99
100VOID
101vGenerateFIFOHeader (
102 IN PSDevice pDevice,
103 IN BYTE byPktTyp,
104 IN PBYTE pbyTxBufferAddr,
105 IN BOOL bNeedEncrypt,
106 IN UINT cbPayloadSize,
107 IN UINT uDMAIdx,
108 IN PSTxDesc pHeadTD,
109 IN PSEthernetHeader psEthHeader,
110 IN PBYTE pPacket,
111 IN PSKeyItem pTransmitKey,
112 IN UINT uNodeIndex,
113 OUT PUINT puMACfragNum,
114 OUT PUINT pcbHeaderSize
115 );
116
117
118VOID vDMA0_tx_80211(PSDevice pDevice, struct sk_buff *skb, PBYTE pbMPDU, UINT cbMPDULen);
119CMD_STATUS csMgmt_xmit(PSDevice pDevice, PSTxMgmtPacket pPacket);
120CMD_STATUS csBeacon_xmit(PSDevice pDevice, PSTxMgmtPacket pPacket);
121
122#ifdef __cplusplus
123} /* End of extern "C" { */
124#endif /* __cplusplus */
125
126
127
128
129#endif // __RXTX_H__
130
131
132
diff --git a/drivers/staging/vt6655/srom.c b/drivers/staging/vt6655/srom.c
new file mode 100644
index 000000000000..655d68593701
--- /dev/null
+++ b/drivers/staging/vt6655/srom.c
@@ -0,0 +1,437 @@
1/*
2 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
3 * All rights reserved.
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * File: srom.c
20 *
21 * Purpose:Implement functions to access eeprom
22 *
23 * Author: Jerry Chen
24 *
25 * Date: Jan 29, 2003
26 *
27 * Functions:
28 * SROMbyReadEmbedded - Embedded read eeprom via MAC
29 * SROMbWriteEmbedded - Embedded write eeprom via MAC
30 * SROMvRegBitsOn - Set Bits On in eeprom
31 * SROMvRegBitsOff - Clear Bits Off in eeprom
32 * SROMbIsRegBitsOn - Test if Bits On in eeprom
33 * SROMbIsRegBitsOff - Test if Bits Off in eeprom
34 * SROMvReadAllContents - Read all contents in eeprom
35 * SROMvWriteAllContents - Write all contents in eeprom
36 * SROMvReadEtherAddress - Read Ethernet Address in eeprom
37 * SROMvWriteEtherAddress - Write Ethernet Address in eeprom
38 * SROMvReadSubSysVenId - Read Sub_VID and Sub_SysId in eeprom
39 * SROMbAutoLoad - Auto Load eeprom to MAC register
40 *
41 * Revision History:
42 *
43 */
44
45
46#if !defined(__UPC_H__)
47#include "upc.h"
48#endif
49#if !defined(__TMACRO_H__)
50#include "tmacro.h"
51#endif
52#if !defined(__TBIT_H__)
53#include "tbit.h"
54#endif
55#if !defined(__TETHER_H__)
56#include "tether.h"
57#endif
58#if !defined(__MAC_H__)
59#include "mac.h"
60#endif
61#if !defined(__SROM_H__)
62#include "srom.h"
63#endif
64
65
66
67
68/*--------------------- Static Definitions -------------------------*/
69
70/*--------------------- Static Classes ----------------------------*/
71
72/*--------------------- Static Variables --------------------------*/
73
74/*--------------------- Static Functions --------------------------*/
75
76/*--------------------- Export Variables --------------------------*/
77
78/*--------------------- Export Functions --------------------------*/
79
80
81
82
83/*
84 * Description: Read a byte from EEPROM, by MAC I2C
85 *
86 * Parameters:
87 * In:
88 * dwIoBase - I/O base address
89 * byContntOffset - address of EEPROM
90 * Out:
91 * none
92 *
93 * Return Value: data read
94 *
95 */
96BYTE SROMbyReadEmbedded(DWORD_PTR dwIoBase, BYTE byContntOffset)
97{
98 WORD wDelay, wNoACK;
99 BYTE byWait;
100 BYTE byData;
101 BYTE byOrg;
102
103 byData = 0xFF;
104 VNSvInPortB(dwIoBase + MAC_REG_I2MCFG, &byOrg);
105 // turn off hardware retry for getting NACK
106 VNSvOutPortB(dwIoBase + MAC_REG_I2MCFG, (byOrg & (~I2MCFG_NORETRY)));
107 for (wNoACK = 0; wNoACK < W_MAX_I2CRETRY; wNoACK++) {
108 VNSvOutPortB(dwIoBase + MAC_REG_I2MTGID, EEP_I2C_DEV_ID);
109 VNSvOutPortB(dwIoBase + MAC_REG_I2MTGAD, byContntOffset);
110
111 // issue read command
112 VNSvOutPortB(dwIoBase + MAC_REG_I2MCSR, I2MCSR_EEMR);
113 // wait DONE be set
114 for (wDelay = 0; wDelay < W_MAX_TIMEOUT; wDelay++) {
115 VNSvInPortB(dwIoBase + MAC_REG_I2MCSR, &byWait);
116 if (BITbIsAnyBitsOn(byWait, (I2MCSR_DONE | I2MCSR_NACK)))
117 break;
118 PCAvDelayByIO(CB_DELAY_LOOP_WAIT);
119 }
120 if ((wDelay < W_MAX_TIMEOUT) &&
121 (BITbIsBitOff(byWait, I2MCSR_NACK))) {
122 break;
123 }
124 }
125 VNSvInPortB(dwIoBase + MAC_REG_I2MDIPT, &byData);
126 VNSvOutPortB(dwIoBase + MAC_REG_I2MCFG, byOrg);
127 return byData;
128}
129
130
131/*
132 * Description: Write a byte to EEPROM, by MAC I2C
133 *
134 * Parameters:
135 * In:
136 * dwIoBase - I/O base address
137 * byContntOffset - address of EEPROM
138 * wData - data to write
139 * Out:
140 * none
141 *
142 * Return Value: TRUE if succeeded; FALSE if failed.
143 *
144 */
145BOOL SROMbWriteEmbedded (DWORD_PTR dwIoBase, BYTE byContntOffset, BYTE byData)
146{
147 WORD wDelay, wNoACK;
148 BYTE byWait;
149
150 BYTE byOrg;
151
152 VNSvInPortB(dwIoBase + MAC_REG_I2MCFG, &byOrg);
153 // turn off hardware retry for getting NACK
154 VNSvOutPortB(dwIoBase + MAC_REG_I2MCFG, (byOrg & (~I2MCFG_NORETRY)));
155 for (wNoACK = 0; wNoACK < W_MAX_I2CRETRY; wNoACK++) {
156 VNSvOutPortB(dwIoBase + MAC_REG_I2MTGID, EEP_I2C_DEV_ID);
157 VNSvOutPortB(dwIoBase + MAC_REG_I2MTGAD, byContntOffset);
158 VNSvOutPortB(dwIoBase + MAC_REG_I2MDOPT, byData);
159
160 // issue write command
161 VNSvOutPortB(dwIoBase + MAC_REG_I2MCSR, I2MCSR_EEMW);
162 // wait DONE be set
163 for (wDelay = 0; wDelay < W_MAX_TIMEOUT; wDelay++) {
164 VNSvInPortB(dwIoBase + MAC_REG_I2MCSR, &byWait);
165 if (BITbIsAnyBitsOn(byWait, (I2MCSR_DONE | I2MCSR_NACK)))
166 break;
167 PCAvDelayByIO(CB_DELAY_LOOP_WAIT);
168 }
169
170 if ((wDelay < W_MAX_TIMEOUT) &&
171 (BITbIsBitOff(byWait, I2MCSR_NACK))) {
172 break;
173 }
174 }
175 if (wNoACK == W_MAX_I2CRETRY) {
176 VNSvOutPortB(dwIoBase + MAC_REG_I2MCFG, byOrg);
177 return FALSE;
178 }
179 VNSvOutPortB(dwIoBase + MAC_REG_I2MCFG, byOrg);
180 return TRUE;
181}
182
183
184/*
185 * Description: Turn bits on in eeprom
186 *
187 * Parameters:
188 * In:
189 * dwIoBase - I/O base address
190 * byContntOffset - address of EEPROM
191 * byBits - bits to turn on
192 * Out:
193 * none
194 *
195 * Return Value: none
196 *
197 */
198void SROMvRegBitsOn (DWORD_PTR dwIoBase, BYTE byContntOffset, BYTE byBits)
199{
200 BYTE byOrgData;
201
202 byOrgData = SROMbyReadEmbedded(dwIoBase, byContntOffset);
203 SROMbWriteEmbedded(dwIoBase, byContntOffset,(BYTE)(byOrgData | byBits));
204}
205
206
207/*
208 * Description: Turn bits off in eeprom
209 *
210 * Parameters:
211 * In:
212 * dwIoBase - I/O base address
213 * byContntOffset - address of EEPROM
214 * byBits - bits to turn off
215 * Out:
216 * none
217 *
218 */
219void SROMvRegBitsOff (DWORD_PTR dwIoBase, BYTE byContntOffset, BYTE byBits)
220{
221 BYTE byOrgData;
222
223 byOrgData = SROMbyReadEmbedded(dwIoBase, byContntOffset);
224 SROMbWriteEmbedded(dwIoBase, byContntOffset,(BYTE)(byOrgData & (~byBits)));
225}
226
227
228/*
229 * Description: Test if bits on in eeprom
230 *
231 * Parameters:
232 * In:
233 * dwIoBase - I/O base address
234 * byContntOffset - address of EEPROM
235 * byTestBits - bits to test
236 * Out:
237 * none
238 *
239 * Return Value: TRUE if all test bits on; otherwise FALSE
240 *
241 */
242BOOL SROMbIsRegBitsOn (DWORD_PTR dwIoBase, BYTE byContntOffset, BYTE byTestBits)
243{
244 BYTE byOrgData;
245
246 byOrgData = SROMbyReadEmbedded(dwIoBase, byContntOffset);
247 return BITbIsAllBitsOn(byOrgData, byTestBits);
248}
249
250
251/*
252 * Description: Test if bits off in eeprom
253 *
254 * Parameters:
255 * In:
256 * dwIoBase - I/O base address
257 * byContntOffset - address of EEPROM
258 * byTestBits - bits to test
259 * Out:
260 * none
261 *
262 * Return Value: TRUE if all test bits off; otherwise FALSE
263 *
264 */
265BOOL SROMbIsRegBitsOff (DWORD_PTR dwIoBase, BYTE byContntOffset, BYTE byTestBits)
266{
267 BYTE byOrgData;
268
269 byOrgData = SROMbyReadEmbedded(dwIoBase, byContntOffset);
270 return BITbIsAllBitsOff(byOrgData, byTestBits);
271}
272
273
274/*
275 * Description: Read all contents of eeprom to buffer
276 *
277 * Parameters:
278 * In:
279 * dwIoBase - I/O base address
280 * Out:
281 * pbyEepromRegs - EEPROM content Buffer
282 *
283 * Return Value: none
284 *
285 */
286void SROMvReadAllContents (DWORD_PTR dwIoBase, PBYTE pbyEepromRegs)
287{
288 int ii;
289
290 // ii = Rom Address
291 for (ii = 0; ii < EEP_MAX_CONTEXT_SIZE; ii++) {
292 *pbyEepromRegs = SROMbyReadEmbedded(dwIoBase,(BYTE) ii);
293 pbyEepromRegs++;
294 }
295}
296
297
298/*
299 * Description: Write all contents of buffer to eeprom
300 *
301 * Parameters:
302 * In:
303 * dwIoBase - I/O base address
304 * pbyEepromRegs - EEPROM content Buffer
305 * Out:
306 * none
307 *
308 * Return Value: none
309 *
310 */
311void SROMvWriteAllContents (DWORD_PTR dwIoBase, PBYTE pbyEepromRegs)
312{
313 int ii;
314
315 // ii = Rom Address
316 for (ii = 0; ii < EEP_MAX_CONTEXT_SIZE; ii++) {
317 SROMbWriteEmbedded(dwIoBase,(BYTE) ii, *pbyEepromRegs);
318 pbyEepromRegs++;
319 }
320}
321
322
323/*
324 * Description: Read Ethernet Address from eeprom to buffer
325 *
326 * Parameters:
327 * In:
328 * dwIoBase - I/O base address
329 * Out:
330 * pbyEtherAddress - Ethernet Address buffer
331 *
332 * Return Value: none
333 *
334 */
335void SROMvReadEtherAddress (DWORD_PTR dwIoBase, PBYTE pbyEtherAddress)
336{
337 BYTE ii;
338
339 // ii = Rom Address
340 for (ii = 0; ii < U_ETHER_ADDR_LEN; ii++) {
341 *pbyEtherAddress = SROMbyReadEmbedded(dwIoBase, ii);
342 pbyEtherAddress++;
343 }
344}
345
346
347/*
348 * Description: Write Ethernet Address from buffer to eeprom
349 *
350 * Parameters:
351 * In:
352 * dwIoBase - I/O base address
353 * pbyEtherAddress - Ethernet Address buffer
354 * Out:
355 * none
356 *
357 * Return Value: none
358 *
359 */
360void SROMvWriteEtherAddress (DWORD_PTR dwIoBase, PBYTE pbyEtherAddress)
361{
362 BYTE ii;
363
364 // ii = Rom Address
365 for (ii = 0; ii < U_ETHER_ADDR_LEN; ii++) {
366 SROMbWriteEmbedded(dwIoBase, ii, *pbyEtherAddress);
367 pbyEtherAddress++;
368 }
369}
370
371
372/*
373 * Description: Read Sub_VID and Sub_SysId from eeprom to buffer
374 *
375 * Parameters:
376 * In:
377 * dwIoBase - I/O base address
378 * Out:
379 * pdwSubSysVenId - Sub_VID and Sub_SysId read
380 *
381 * Return Value: none
382 *
383 */
384void SROMvReadSubSysVenId (DWORD_PTR dwIoBase, PDWORD pdwSubSysVenId)
385{
386 PBYTE pbyData;
387
388 pbyData = (PBYTE)pdwSubSysVenId;
389 // sub vendor
390 *pbyData = SROMbyReadEmbedded(dwIoBase, 6);
391 *(pbyData+1) = SROMbyReadEmbedded(dwIoBase, 7);
392 // sub system
393 *(pbyData+2) = SROMbyReadEmbedded(dwIoBase, 8);
394 *(pbyData+3) = SROMbyReadEmbedded(dwIoBase, 9);
395}
396
397/*
398 * Description: Auto Load EEPROM to MAC register
399 *
400 * Parameters:
401 * In:
402 * dwIoBase - I/O base address
403 * Out:
404 * none
405 *
406 * Return Value: TRUE if success; otherwise FALSE
407 *
408 */
409BOOL SROMbAutoLoad (DWORD_PTR dwIoBase)
410{
411 BYTE byWait;
412 int ii;
413
414 BYTE byOrg;
415
416 VNSvInPortB(dwIoBase + MAC_REG_I2MCFG, &byOrg);
417 // turn on hardware retry
418 VNSvOutPortB(dwIoBase + MAC_REG_I2MCFG, (byOrg | I2MCFG_NORETRY));
419
420 MACvRegBitsOn(dwIoBase, MAC_REG_I2MCSR, I2MCSR_AUTOLD);
421
422 // ii = Rom Address
423 for (ii = 0; ii < EEP_MAX_CONTEXT_SIZE; ii++) {
424 MACvTimer0MicroSDelay(dwIoBase, CB_EEPROM_READBYTE_WAIT);
425 VNSvInPortB(dwIoBase + MAC_REG_I2MCSR, &byWait);
426 if (BITbIsBitOff(byWait, I2MCSR_AUTOLD))
427 break;
428 }
429
430 VNSvOutPortB(dwIoBase + MAC_REG_I2MCFG, byOrg);
431
432 if (ii == EEP_MAX_CONTEXT_SIZE)
433 return FALSE;
434 return TRUE;
435}
436
437
diff --git a/drivers/staging/vt6655/srom.h b/drivers/staging/vt6655/srom.h
new file mode 100644
index 000000000000..a4ca5f0b196d
--- /dev/null
+++ b/drivers/staging/vt6655/srom.h
@@ -0,0 +1,179 @@
1/*
2 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
3 * All rights reserved.
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 *
20 * File: srom.h
21 *
22 * Purpose: Implement functions to access eeprom
23 *
24 * Author: Jerry Chen
25 *
26 * Date: Jan 29, 2003
27 *
28 */
29
30
31#ifndef __SROM_H__
32#define __SROM_H__
33
34#if !defined(__TTYPE_H__)
35#include "ttype.h"
36#endif
37
38
39/*--------------------- Export Definitions -------------------------*/
40
41
42#define EEP_MAX_CONTEXT_SIZE 256
43
44#define CB_EEPROM_READBYTE_WAIT 900 //us
45
46#define W_MAX_I2CRETRY 0x0fff
47
48//
49// Contents in the EEPROM
50//
51
52#define EEP_OFS_PAR 0x00 // physical address
53#define EEP_OFS_ANTENNA 0x16
54#define EEP_OFS_RADIOCTL 0x17
55#define EEP_OFS_RFTYPE 0x1B // for select RF
56#define EEP_OFS_MINCHANNEL 0x1C // Min Channel #
57#define EEP_OFS_MAXCHANNEL 0x1D // Max Channel #
58#define EEP_OFS_SIGNATURE 0x1E //
59#define EEP_OFS_ZONETYPE 0x1F //
60#define EEP_OFS_RFTABLE 0x20 // RF POWER TABLE
61#define EEP_OFS_PWR_CCK 0x20
62#define EEP_OFS_SETPT_CCK 0x21
63#define EEP_OFS_PWR_OFDMG 0x23
64#define EEP_OFS_SETPT_OFDMG 0x24
65#define EEP_OFS_PWR_FORMULA_OST 0x26 //
66#define EEP_OFS_MAJOR_VER 0x2E
67#define EEP_OFS_MINOR_VER 0x2F
68#define EEP_OFS_CCK_PWR_TBL 0x30
69#define EEP_OFS_CCK_PWR_dBm 0x3F
70#define EEP_OFS_OFDM_PWR_TBL 0x40
71#define EEP_OFS_OFDM_PWR_dBm 0x4F
72//{{ RobertYu: 20041124
73#define EEP_OFS_SETPT_OFDMA 0x4E
74#define EEP_OFS_OFDMA_PWR_TBL 0x50
75//}}
76#define EEP_OFS_OFDMA_PWR_dBm 0xD2
77
78
79//----------need to remove --------------------
80#define EEP_OFS_BBTAB_LEN 0x70 // BB Table Length
81#define EEP_OFS_BBTAB_ADR 0x71 // BB Table Offset
82#define EEP_OFS_CHECKSUM 0xFF // reserved area for baseband 28h ~ 78h
83
84#define EEP_I2C_DEV_ID 0x50 // EEPROM device address on the I2C bus
85
86
87//
88// Bits in EEP_OFS_ANTENNA
89//
90#define EEP_ANTENNA_MAIN 0x01
91#define EEP_ANTENNA_AUX 0x02
92#define EEP_ANTINV 0x04
93
94//
95// Bits in EEP_OFS_RADIOCTL
96//
97#define EEP_RADIOCTL_ENABLE 0x80
98#define EEP_RADIOCTL_INV 0x01
99
100
101
102/*--------------------- Export Types ------------------------------*/
103
104// AT24C02 eeprom contents
105// 2048 bits = 256 bytes = 128 words
106//
107typedef struct tagSSromReg {
108 BYTE abyPAR[6]; // 0x00 (WORD)
109
110 WORD wSUB_VID; // 0x03 (WORD)
111 WORD wSUB_SID;
112
113 BYTE byBCFG0; // 0x05 (WORD)
114 BYTE byBCFG1;
115
116 BYTE byFCR0; // 0x06 (WORD)
117 BYTE byFCR1;
118 BYTE byPMC0; // 0x07 (WORD)
119 BYTE byPMC1;
120 BYTE byMAXLAT; // 0x08 (WORD)
121 BYTE byMINGNT;
122 BYTE byCFG0; // 0x09 (WORD)
123 BYTE byCFG1;
124 WORD wCISPTR; // 0x0A (WORD)
125 WORD wRsv0; // 0x0B (WORD)
126 WORD wRsv1; // 0x0C (WORD)
127 BYTE byBBPAIR; // 0x0D (WORD)
128 BYTE byRFTYPE;
129 BYTE byMinChannel; // 0x0E (WORD)
130 BYTE byMaxChannel;
131 BYTE bySignature; // 0x0F (WORD)
132 BYTE byCheckSum;
133
134 BYTE abyReserved0[96]; // 0x10 (WORD)
135 BYTE abyCIS[128]; // 0x80 (WORD)
136} SSromReg, DEF* PSSromReg;
137
138/*--------------------- Export Macros ------------------------------*/
139
140/*--------------------- Export Classes ----------------------------*/
141
142/*--------------------- Export Variables --------------------------*/
143
144/*--------------------- Export Functions --------------------------*/
145#ifdef __cplusplus
146extern "C" { /* Assume C declarations for C++ */
147#endif /* __cplusplus */
148
149
150BYTE SROMbyReadEmbedded(DWORD_PTR dwIoBase, BYTE byContntOffset);
151BOOL SROMbWriteEmbedded(DWORD_PTR dwIoBase, BYTE byContntOffset, BYTE byData);
152
153void SROMvRegBitsOn(DWORD_PTR dwIoBase, BYTE byContntOffset, BYTE byBits);
154void SROMvRegBitsOff(DWORD_PTR dwIoBase, BYTE byContntOffset, BYTE byBits);
155
156BOOL SROMbIsRegBitsOn(DWORD_PTR dwIoBase, BYTE byContntOffset, BYTE byTestBits);
157BOOL SROMbIsRegBitsOff(DWORD_PTR dwIoBase, BYTE byContntOffset, BYTE byTestBits);
158
159void SROMvReadAllContents(DWORD_PTR dwIoBase, PBYTE pbyEepromRegs);
160void SROMvWriteAllContents(DWORD_PTR dwIoBase, PBYTE pbyEepromRegs);
161
162void SROMvReadEtherAddress(DWORD_PTR dwIoBase, PBYTE pbyEtherAddress);
163void SROMvWriteEtherAddress(DWORD_PTR dwIoBase, PBYTE pbyEtherAddress);
164
165VOID SROMvReadSubSysVenId(DWORD_PTR dwIoBase, PDWORD pdwSubSysVenId);
166
167BOOL SROMbAutoLoad (DWORD_PTR dwIoBase);
168
169
170#ifdef __cplusplus
171} /* End of extern "C" { */
172#endif /* __cplusplus */
173
174
175
176
177#endif // __EEPROM_H__
178
179
diff --git a/drivers/staging/vt6655/tbit.h b/drivers/staging/vt6655/tbit.h
new file mode 100644
index 000000000000..7c3a82e9b608
--- /dev/null
+++ b/drivers/staging/vt6655/tbit.h
@@ -0,0 +1,78 @@
1/*
2 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
3 * All rights reserved.
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 *
20 * File: tbit.h
21 *
22 * Purpose: Bit routines
23 *
24 * Author: Tevin Chen
25 *
26 * Date: May 21, 1996
27 *
28 */
29
30
31#ifndef __TBIT_H__
32#define __TBIT_H__
33
34#if !defined(__TTYPE_H__)
35#include "ttype.h"
36#endif
37
38
39
40/*--------------------- Export Definitions -------------------------*/
41
42/*--------------------- Export Types ------------------------------*/
43
44/*--------------------- Export Macros ------------------------------*/
45
46// test single bit on
47#define BITbIsBitOn(tData, tTestBit) \
48 (((tData) & (tTestBit)) != 0)
49
50// test single bit off
51#define BITbIsBitOff(tData, tTestBit) \
52 (((tData) & (tTestBit)) == 0)
53
54
55#define BITbIsAllBitsOn(tData, tTestBit) \
56 (((tData) & (tTestBit)) == (tTestBit))
57
58#define BITbIsAllBitsOff(tData, tTestBit) \
59 (((tData) & (tTestBit)) == 0)
60
61#define BITbIsAnyBitsOn(tData, tTestBit) \
62 (((tData) & (tTestBit)) != 0)
63
64#define BITbIsAnyBitsOff(tData, tTestBit) \
65 (((tData) & (tTestBit)) != (tTestBit))
66
67/*--------------------- Export Classes ----------------------------*/
68
69/*--------------------- Export Variables --------------------------*/
70
71/*--------------------- Export Functions --------------------------*/
72
73
74
75#endif // __TBIT_H__
76
77
78
diff --git a/drivers/staging/vt6655/tcrc.c b/drivers/staging/vt6655/tcrc.c
new file mode 100644
index 000000000000..b70080c267c8
--- /dev/null
+++ b/drivers/staging/vt6655/tcrc.c
@@ -0,0 +1,207 @@
1/*
2 * Copyright (c) 2003 VIA Networking, Inc. All rights reserved.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17 *
18 *
19 * File: tcrc.c
20 *
21 * Purpose: Implement functions to caculate CRC
22 *
23 * Author: Tevin Chen
24 *
25 * Date: May 21, 1996
26 *
27 * Functions:
28 * CRCdwCrc32 -
29 * CRCdwGetCrc32 -
30 * CRCdwGetCrc32Ex -
31 *
32 * Revision History:
33 *
34 */
35
36
37#if !defined(__TBIT_H__)
38#include "tbit.h"
39#endif
40#if !defined(__TCRC_H__)
41#include "tcrc.h"
42#endif
43
44
45
46
47/*--------------------- Static Definitions -------------------------*/
48
49/*--------------------- Static Classes ----------------------------*/
50
51/*--------------------- Static Variables --------------------------*/
52
53// 32-bit CRC table
54static const DWORD s_adwCrc32Table[256] = {
55 0x00000000L, 0x77073096L, 0xEE0E612CL, 0x990951BAL,
56 0x076DC419L, 0x706AF48FL, 0xE963A535L, 0x9E6495A3L,
57 0x0EDB8832L, 0x79DCB8A4L, 0xE0D5E91EL, 0x97D2D988L,
58 0x09B64C2BL, 0x7EB17CBDL, 0xE7B82D07L, 0x90BF1D91L,
59 0x1DB71064L, 0x6AB020F2L, 0xF3B97148L, 0x84BE41DEL,
60 0x1ADAD47DL, 0x6DDDE4EBL, 0xF4D4B551L, 0x83D385C7L,
61 0x136C9856L, 0x646BA8C0L, 0xFD62F97AL, 0x8A65C9ECL,
62 0x14015C4FL, 0x63066CD9L, 0xFA0F3D63L, 0x8D080DF5L,
63 0x3B6E20C8L, 0x4C69105EL, 0xD56041E4L, 0xA2677172L,
64 0x3C03E4D1L, 0x4B04D447L, 0xD20D85FDL, 0xA50AB56BL,
65 0x35B5A8FAL, 0x42B2986CL, 0xDBBBC9D6L, 0xACBCF940L,
66 0x32D86CE3L, 0x45DF5C75L, 0xDCD60DCFL, 0xABD13D59L,
67 0x26D930ACL, 0x51DE003AL, 0xC8D75180L, 0xBFD06116L,
68 0x21B4F4B5L, 0x56B3C423L, 0xCFBA9599L, 0xB8BDA50FL,
69 0x2802B89EL, 0x5F058808L, 0xC60CD9B2L, 0xB10BE924L,
70 0x2F6F7C87L, 0x58684C11L, 0xC1611DABL, 0xB6662D3DL,
71 0x76DC4190L, 0x01DB7106L, 0x98D220BCL, 0xEFD5102AL,
72 0x71B18589L, 0x06B6B51FL, 0x9FBFE4A5L, 0xE8B8D433L,
73 0x7807C9A2L, 0x0F00F934L, 0x9609A88EL, 0xE10E9818L,
74 0x7F6A0DBBL, 0x086D3D2DL, 0x91646C97L, 0xE6635C01L,
75 0x6B6B51F4L, 0x1C6C6162L, 0x856530D8L, 0xF262004EL,
76 0x6C0695EDL, 0x1B01A57BL, 0x8208F4C1L, 0xF50FC457L,
77 0x65B0D9C6L, 0x12B7E950L, 0x8BBEB8EAL, 0xFCB9887CL,
78 0x62DD1DDFL, 0x15DA2D49L, 0x8CD37CF3L, 0xFBD44C65L,
79 0x4DB26158L, 0x3AB551CEL, 0xA3BC0074L, 0xD4BB30E2L,
80 0x4ADFA541L, 0x3DD895D7L, 0xA4D1C46DL, 0xD3D6F4FBL,
81 0x4369E96AL, 0x346ED9FCL, 0xAD678846L, 0xDA60B8D0L,
82 0x44042D73L, 0x33031DE5L, 0xAA0A4C5FL, 0xDD0D7CC9L,
83 0x5005713CL, 0x270241AAL, 0xBE0B1010L, 0xC90C2086L,
84 0x5768B525L, 0x206F85B3L, 0xB966D409L, 0xCE61E49FL,
85 0x5EDEF90EL, 0x29D9C998L, 0xB0D09822L, 0xC7D7A8B4L,
86 0x59B33D17L, 0x2EB40D81L, 0xB7BD5C3BL, 0xC0BA6CADL,
87 0xEDB88320L, 0x9ABFB3B6L, 0x03B6E20CL, 0x74B1D29AL,
88 0xEAD54739L, 0x9DD277AFL, 0x04DB2615L, 0x73DC1683L,
89 0xE3630B12L, 0x94643B84L, 0x0D6D6A3EL, 0x7A6A5AA8L,
90 0xE40ECF0BL, 0x9309FF9DL, 0x0A00AE27L, 0x7D079EB1L,
91 0xF00F9344L, 0x8708A3D2L, 0x1E01F268L, 0x6906C2FEL,
92 0xF762575DL, 0x806567CBL, 0x196C3671L, 0x6E6B06E7L,
93 0xFED41B76L, 0x89D32BE0L, 0x10DA7A5AL, 0x67DD4ACCL,
94 0xF9B9DF6FL, 0x8EBEEFF9L, 0x17B7BE43L, 0x60B08ED5L,
95 0xD6D6A3E8L, 0xA1D1937EL, 0x38D8C2C4L, 0x4FDFF252L,
96 0xD1BB67F1L, 0xA6BC5767L, 0x3FB506DDL, 0x48B2364BL,
97 0xD80D2BDAL, 0xAF0A1B4CL, 0x36034AF6L, 0x41047A60L,
98 0xDF60EFC3L, 0xA867DF55L, 0x316E8EEFL, 0x4669BE79L,
99 0xCB61B38CL, 0xBC66831AL, 0x256FD2A0L, 0x5268E236L,
100 0xCC0C7795L, 0xBB0B4703L, 0x220216B9L, 0x5505262FL,
101 0xC5BA3BBEL, 0xB2BD0B28L, 0x2BB45A92L, 0x5CB36A04L,
102 0xC2D7FFA7L, 0xB5D0CF31L, 0x2CD99E8BL, 0x5BDEAE1DL,
103 0x9B64C2B0L, 0xEC63F226L, 0x756AA39CL, 0x026D930AL,
104 0x9C0906A9L, 0xEB0E363FL, 0x72076785L, 0x05005713L,
105 0x95BF4A82L, 0xE2B87A14L, 0x7BB12BAEL, 0x0CB61B38L,
106 0x92D28E9BL, 0xE5D5BE0DL, 0x7CDCEFB7L, 0x0BDBDF21L,
107 0x86D3D2D4L, 0xF1D4E242L, 0x68DDB3F8L, 0x1FDA836EL,
108 0x81BE16CDL, 0xF6B9265BL, 0x6FB077E1L, 0x18B74777L,
109 0x88085AE6L, 0xFF0F6A70L, 0x66063BCAL, 0x11010B5CL,
110 0x8F659EFFL, 0xF862AE69L, 0x616BFFD3L, 0x166CCF45L,
111 0xA00AE278L, 0xD70DD2EEL, 0x4E048354L, 0x3903B3C2L,
112 0xA7672661L, 0xD06016F7L, 0x4969474DL, 0x3E6E77DBL,
113 0xAED16A4AL, 0xD9D65ADCL, 0x40DF0B66L, 0x37D83BF0L,
114 0xA9BCAE53L, 0xDEBB9EC5L, 0x47B2CF7FL, 0x30B5FFE9L,
115 0xBDBDF21CL, 0xCABAC28AL, 0x53B39330L, 0x24B4A3A6L,
116 0xBAD03605L, 0xCDD70693L, 0x54DE5729L, 0x23D967BFL,
117 0xB3667A2EL, 0xC4614AB8L, 0x5D681B02L, 0x2A6F2B94L,
118 0xB40BBE37L, 0xC30C8EA1L, 0x5A05DF1BL, 0x2D02EF8DL
119};
120
121/*--------------------- Static Functions --------------------------*/
122
123/*--------------------- Export Variables --------------------------*/
124
125
126
127
128/*+
129 *
130 * Description:
131 * Generate a CRC-32 from the data stream
132 *
133 * Parameters:
134 * In:
135 * pbyData - the data stream
136 * cbByte - the length of the stream
137 * dwCrcSeed - Seed for CRC32
138 * Out:
139 * none
140 *
141 * Return Value: CRC-32
142 *
143-*/
144DWORD CRCdwCrc32 (PBYTE pbyData, UINT cbByte, DWORD dwCrcSeed)
145{
146 DWORD dwCrc;
147
148 dwCrc = dwCrcSeed;
149 while (cbByte--) {
150 dwCrc = s_adwCrc32Table[(BYTE)((dwCrc ^ (*pbyData)) & 0xFF)] ^ (dwCrc >> 8);
151 pbyData++;
152 }
153
154 return dwCrc;
155}
156
157
158/*+
159 *
160 * Description:
161 * To test CRC generator, input 8 bytes packet
162 * -- 0xff 0xff 0xff 0xff 0x00 0x00 0x00 0x00
163 * the generated CRC should be
164 * -- 0xff 0xff 0xff 0xff
165 *
166 * Parameters:
167 * In:
168 * pbyData - the data stream
169 * cbByte - the length of the stream
170 * Out:
171 * none
172 *
173 * Return Value: CRC-32
174 *
175-*/
176DWORD CRCdwGetCrc32 (PBYTE pbyData, UINT cbByte)
177{
178 return ~CRCdwCrc32(pbyData, cbByte, 0xFFFFFFFFL);
179}
180
181
182/*+
183 *
184 * Description:
185 *
186 * NOTE.... Because CRCdwGetCrc32Ex() is an iteration function,
187 * this means we will use the output of CRCdwGetCrc32Ex()
188 * to be a new argument to do next CRCdwGetCrc32Ex() calculation.
189 * Thus, the final result must be inverted to be the
190 * correct answer.
191 *
192 * Parameters:
193 * In:
194 * pbyData - the data stream
195 * cbByte - the length of the stream
196 * Out:
197 * none
198 *
199 * Return Value: CRC-32
200 *
201-*/
202DWORD CRCdwGetCrc32Ex(PBYTE pbyData, UINT cbByte, DWORD dwPreCRC)
203{
204 return CRCdwCrc32(pbyData, cbByte, dwPreCRC);
205}
206
207
diff --git a/drivers/staging/vt6655/tcrc.h b/drivers/staging/vt6655/tcrc.h
new file mode 100644
index 000000000000..ebea22ed2da6
--- /dev/null
+++ b/drivers/staging/vt6655/tcrc.h
@@ -0,0 +1,71 @@
1/*
2 * Copyright (c) 2003 VIA Networking, Inc. All rights reserved.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17 *
18 *
19 * File: tcrc.h
20 *
21 * Purpose: Implement functions to caculate CRC
22 *
23 * Author: Tevin Chen
24 *
25 * Date: Jan. 28, 1997
26 *
27 */
28
29
30#ifndef __TCRC_H__
31#define __TCRC_H__
32
33#if !defined(__TTYPE_H__)
34#include "ttype.h"
35#endif
36
37
38
39
40/*--------------------- Export Definitions -------------------------*/
41
42/*--------------------- Export Types ------------------------------*/
43
44/*--------------------- Export Macros ------------------------------*/
45
46/*--------------------- Export Classes ----------------------------*/
47
48/*--------------------- Export Variables --------------------------*/
49
50/*--------------------- Export Functions --------------------------*/
51#ifdef __cplusplus
52extern "C" { /* Assume C declarations for C++ */
53#endif /* __cplusplus */
54
55
56DWORD CRCdwCrc32(PBYTE pbyData, UINT cbByte, DWORD dwCrcSeed);
57DWORD CRCdwGetCrc32(PBYTE pbyData, UINT cbByte);
58DWORD CRCdwGetCrc32Ex(PBYTE pbyData, UINT cbByte, DWORD dwPreCRC);
59
60
61#ifdef __cplusplus
62} /* End of extern "C" { */
63#endif /* __cplusplus */
64
65
66
67
68#endif // __TCRC_H__
69
70
71
diff --git a/drivers/staging/vt6655/test b/drivers/staging/vt6655/test
new file mode 100644
index 000000000000..039f7d71c537
--- /dev/null
+++ b/drivers/staging/vt6655/test
@@ -0,0 +1,9 @@
1KSP := /lib/modules/$(shell uname -r)/build \
2 /usr/src/linux-$(shell uname -r) \
3 /usr/src/linux-$(shell uname -r | sed 's/-.*//') \
4# /usr/src/kernel-headers-$(shell uname -r) \
5# /usr/src/kernel-source-$(shell uname -r) \
6# /usr/src/linux-$(shell uname -r | sed 's/\([0-9]*\.[0-9]*\)\..*/\1/') \
7# /usr/src/linux /home/plice
8test_dir = $(shell [ -e $(dir)/include/linux ] && echo $(dir))
9KSP := $(foreach dir, $(KSP), $(test_dir)) \ No newline at end of file
diff --git a/drivers/staging/vt6655/tether.c b/drivers/staging/vt6655/tether.c
new file mode 100644
index 000000000000..fd69423fe14b
--- /dev/null
+++ b/drivers/staging/vt6655/tether.c
@@ -0,0 +1,123 @@
1/*
2 * Copyright (c) 2003 VIA Networking, Inc. All rights reserved.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17 *
18 *
19 * File: tether.c
20 *
21 * Purpose:
22 *
23 * Author: Tevin Chen
24 *
25 * Date: May 21, 1996
26 *
27 * Functions:
28 * ETHbyGetHashIndexByCrc32 - Caculate multicast hash value by CRC32
29 * ETHbIsBufferCrc32Ok - Check CRC value of the buffer if Ok or not
30 *
31 * Revision History:
32 *
33 */
34
35#if !defined(__DEVICE_H__)
36#include "device.h"
37#endif
38#if !defined(__TMACRO_H__)
39#include "tmacro.h"
40#endif
41#if !defined(__TBIT_H__)
42#include "tbit.h"
43#endif
44#if !defined(__TCRC_H__)
45#include "tcrc.h"
46#endif
47#if !defined(__TETHER_H__)
48#include "tether.h"
49#endif
50
51
52
53
54/*--------------------- Static Definitions -------------------------*/
55
56/*--------------------- Static Classes ----------------------------*/
57
58/*--------------------- Static Variables --------------------------*/
59
60/*--------------------- Static Functions --------------------------*/
61
62/*--------------------- Export Variables --------------------------*/
63
64
65
66/*
67 * Description: Caculate multicast hash value by CRC32
68 *
69 * Parameters:
70 * In:
71 * pbyMultiAddr - Multicast Address
72 * Out:
73 * none
74 *
75 * Return Value: Hash value
76 *
77 */
78BYTE ETHbyGetHashIndexByCrc32 (PBYTE pbyMultiAddr)
79{
80 int ii;
81 BYTE byTmpHash;
82 BYTE byHash = 0;
83
84 // get the least 6-bits from CRC generator
85 byTmpHash = (BYTE)(CRCdwCrc32(pbyMultiAddr, U_ETHER_ADDR_LEN,
86 0xFFFFFFFFL) & 0x3F);
87 // reverse most bit to least bit
88 for (ii = 0; ii < (sizeof(byTmpHash) * 8); ii++) {
89 byHash <<= 1;
90 if (BITbIsBitOn(byTmpHash, 0x01))
91 byHash |= 1;
92 byTmpHash >>= 1;
93 }
94
95 // adjust 6-bits to the right most
96 return (byHash >> 2);
97}
98
99
100/*
101 * Description: Check CRC value of the buffer if Ok or not
102 *
103 * Parameters:
104 * In:
105 * pbyBuffer - pointer of buffer (normally is rx buffer)
106 * cbFrameLength - length of buffer, including CRC portion
107 * Out:
108 * none
109 *
110 * Return Value: TRUE if ok; FALSE if error.
111 *
112 */
113BOOL ETHbIsBufferCrc32Ok (PBYTE pbyBuffer, UINT cbFrameLength)
114{
115 DWORD dwCRC;
116
117 dwCRC = CRCdwGetCrc32(pbyBuffer, cbFrameLength - 4);
118 if (cpu_to_le32(*((PDWORD)(pbyBuffer + cbFrameLength - 4))) != dwCRC) {
119 return FALSE;
120 }
121 return TRUE;
122}
123
diff --git a/drivers/staging/vt6655/tether.h b/drivers/staging/vt6655/tether.h
new file mode 100644
index 000000000000..920a8bb68356
--- /dev/null
+++ b/drivers/staging/vt6655/tether.h
@@ -0,0 +1,256 @@
1/*
2 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
3 * All rights reserved.
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * File: tether.h
20 *
21 * Purpose:
22 *
23 * Author: Tevin Chen
24 *
25 * Date: Jan. 28, 1997
26 *
27 */
28
29
30
31#ifndef __TETHER_H__
32#define __TETHER_H__
33
34
35#if !defined(__TTYPE_H__)
36#include "ttype.h"
37#endif
38
39
40
41
42/*--------------------- Export Definitions -------------------------*/
43//
44// constants
45//
46#define U_ETHER_ADDR_LEN 6 // Ethernet address length
47#define U_TYPE_LEN 2 //
48#define U_CRC_LEN 4 //
49#define U_HEADER_LEN (U_ETHER_ADDR_LEN * 2 + U_TYPE_LEN)
50#define U_ETHER_ADDR_STR_LEN (U_ETHER_ADDR_LEN * 2 + 1)
51 // Ethernet address string length
52
53#define MIN_DATA_LEN 46 // min data length
54#define MAX_DATA_LEN 1500 // max data length
55
56#define MIN_PACKET_LEN (MIN_DATA_LEN + U_HEADER_LEN)
57 // 60
58 // min total packet length (tx)
59#define MAX_PACKET_LEN (MAX_DATA_LEN + U_HEADER_LEN)
60 // 1514
61 // max total packet length (tx)
62
63#define MAX_LOOKAHEAD_SIZE MAX_PACKET_LEN
64
65#define U_MULTI_ADDR_LEN 8 // multicast address length
66
67
68#ifdef __BIG_ENDIAN
69
70#define TYPE_PKT_IP 0x0800 //
71#define TYPE_PKT_ARP 0x0806 //
72#define TYPE_PKT_RARP 0x8035 //
73#define TYPE_PKT_IPX 0x8137 //
74#define TYPE_PKT_802_1x 0x888e
75#define TYPE_PKT_PreAuth 0x88C7
76
77#define TYPE_PKT_PING_M_REQ 0x8011 // master reguest
78#define TYPE_PKT_PING_S_GNT 0x8022 // slave grant
79#define TYPE_PKT_PING_M 0x8077 // pingpong master packet
80#define TYPE_PKT_PING_S 0x8088 // pingpong slave packet
81#define TYPE_PKT_WOL_M_REQ 0x8033 // WOL waker request
82#define TYPE_PKT_WOL_S_GNT 0x8044 // WOL sleeper grant
83#define TYPE_MGMT_PROBE_RSP 0x5000
84#define TYPE_PKT_VNT_DIAG 0x8011 // Diag Pkt
85#define TYPE_PKT_VNT_PER 0x8888 // Diag PER Pkt
86//
87// wFrameCtl field in the S802_11Header
88//
89// NOTE....
90// in network byte order, high byte is going first
91#define FC_TODS 0x0001
92#define FC_FROMDS 0x0002
93#define FC_MOREFRAG 0x0004
94#define FC_RETRY 0x0008
95#define FC_POWERMGT 0x0010
96#define FC_MOREDATA 0x0020
97#define FC_WEP 0x0040
98#define TYPE_802_11_ATIM 0x9000
99
100#define TYPE_802_11_DATA 0x0800
101#define TYPE_802_11_CTL 0x0400
102#define TYPE_802_11_MGMT 0x0000
103#define TYPE_802_11_MASK 0x0C00
104#define TYPE_SUBTYPE_MASK 0xFC00
105#define TYPE_802_11_NODATA 0x4000
106#define TYPE_DATE_NULL 0x4800
107
108#define TYPE_CTL_PSPOLL 0xa400
109#define TYPE_CTL_RTS 0xb400
110#define TYPE_CTL_CTS 0xc400
111#define TYPE_CTL_ACK 0xd400
112
113
114//#define WEP_IV_MASK 0xFFFFFF00
115
116#else //if LITTLE_ENDIAN
117//
118// wType field in the SEthernetHeader
119//
120// NOTE....
121// in network byte order, high byte is going first
122#define TYPE_PKT_IP 0x0008 //
123#define TYPE_PKT_ARP 0x0608 //
124#define TYPE_PKT_RARP 0x3580 //
125#define TYPE_PKT_IPX 0x3781 //
126
127#define TYPE_PKT_802_1x 0x8e88
128#define TYPE_PKT_PreAuth 0xC788
129
130#define TYPE_PKT_PING_M_REQ 0x1180 // master reguest
131#define TYPE_PKT_PING_S_GNT 0x2280 // slave grant
132#define TYPE_PKT_PING_M 0x7780 // pingpong master packet
133#define TYPE_PKT_PING_S 0x8880 // pingpong slave packet
134#define TYPE_PKT_WOL_M_REQ 0x3380 // WOL waker request
135#define TYPE_PKT_WOL_S_GNT 0x4480 // WOL sleeper grant
136#define TYPE_MGMT_PROBE_RSP 0x0050
137#define TYPE_PKT_VNT_DIAG 0x1180 // Diag Pkt
138#define TYPE_PKT_VNT_PER 0x8888 // Diag PER Pkt
139//
140// wFrameCtl field in the S802_11Header
141//
142// NOTE....
143// in network byte order, high byte is going first
144#define FC_TODS 0x0100
145#define FC_FROMDS 0x0200
146#define FC_MOREFRAG 0x0400
147#define FC_RETRY 0x0800
148#define FC_POWERMGT 0x1000
149#define FC_MOREDATA 0x2000
150#define FC_WEP 0x4000
151#define TYPE_802_11_ATIM 0x0090
152
153#define TYPE_802_11_DATA 0x0008
154#define TYPE_802_11_CTL 0x0004
155#define TYPE_802_11_MGMT 0x0000
156#define TYPE_802_11_MASK 0x000C
157#define TYPE_SUBTYPE_MASK 0x00FC
158#define TYPE_802_11_NODATA 0x0040
159#define TYPE_DATE_NULL 0x0048
160
161#define TYPE_CTL_PSPOLL 0x00a4
162#define TYPE_CTL_RTS 0x00b4
163#define TYPE_CTL_CTS 0x00c4
164#define TYPE_CTL_ACK 0x00d4
165
166
167//#define WEP_IV_MASK 0x00FFFFFF
168
169#endif //#ifdef __BIG_ENDIAN
170
171#define WEP_IV_MASK 0x00FFFFFF
172
173/*--------------------- Export Types ------------------------------*/
174//
175// Ethernet packet
176//
177typedef struct tagSEthernetHeader {
178 BYTE abyDstAddr[U_ETHER_ADDR_LEN];
179 BYTE abySrcAddr[U_ETHER_ADDR_LEN];
180 WORD wType;
181}__attribute__ ((__packed__))
182SEthernetHeader, DEF* PSEthernetHeader;
183
184
185//
186// 802_3 packet
187//
188typedef struct tagS802_3Header {
189 BYTE abyDstAddr[U_ETHER_ADDR_LEN];
190 BYTE abySrcAddr[U_ETHER_ADDR_LEN];
191 WORD wLen;
192}__attribute__ ((__packed__))
193S802_3Header, DEF* PS802_3Header;
194
195//
196// 802_11 packet
197//
198typedef struct tagS802_11Header {
199 WORD wFrameCtl;
200 WORD wDurationID;
201 BYTE abyAddr1[U_ETHER_ADDR_LEN];
202 BYTE abyAddr2[U_ETHER_ADDR_LEN];
203 BYTE abyAddr3[U_ETHER_ADDR_LEN];
204 WORD wSeqCtl;
205 BYTE abyAddr4[U_ETHER_ADDR_LEN];
206}__attribute__ ((__packed__))
207S802_11Header, DEF* PS802_11Header;
208
209/*--------------------- Export Macros ------------------------------*/
210// Frame type macro
211
212#define IS_MULTICAST_ADDRESS(pbyEtherAddr) \
213 ((*(PBYTE)(pbyEtherAddr) & 0x01) == 1)
214
215#define IS_BROADCAST_ADDRESS(pbyEtherAddr) ( \
216 (*(PDWORD)(pbyEtherAddr) == 0xFFFFFFFFL) && \
217 (*(PWORD)((PBYTE)(pbyEtherAddr) + 4) == 0xFFFF) \
218)
219
220#define IS_NULL_ADDRESS(pbyEtherAddr) ( \
221 (*(PDWORD)(pbyEtherAddr) == 0L) && \
222 (*(PWORD)((PBYTE)(pbyEtherAddr) + 4) == 0) \
223)
224
225#define IS_ETH_ADDRESS_EQUAL(pbyAddr1, pbyAddr2) ( \
226 (*(PDWORD)(pbyAddr1) == *(PDWORD)(pbyAddr2)) && \
227 (*(PWORD)((PBYTE)(pbyAddr1) + 4) == \
228 *(PWORD)((PBYTE)(pbyAddr2) + 4)) \
229)
230
231/*--------------------- Export Classes ----------------------------*/
232
233/*--------------------- Export Variables --------------------------*/
234
235/*--------------------- Export Functions --------------------------*/
236#ifdef __cplusplus
237extern "C" { /* Assume C declarations for C++ */
238#endif /* __cplusplus */
239
240
241BYTE ETHbyGetHashIndexByCrc32(PBYTE pbyMultiAddr);
242//BYTE ETHbyGetHashIndexByCrc(PBYTE pbyMultiAddr);
243BOOL ETHbIsBufferCrc32Ok(PBYTE pbyBuffer, UINT cbFrameLength);
244
245
246#ifdef __cplusplus
247} /* End of extern "C" { */
248#endif /* __cplusplus */
249
250
251
252
253#endif // __TETHER_H__
254
255
256
diff --git a/drivers/staging/vt6655/tkip.c b/drivers/staging/vt6655/tkip.c
new file mode 100644
index 000000000000..2ded8420c390
--- /dev/null
+++ b/drivers/staging/vt6655/tkip.c
@@ -0,0 +1,284 @@
1/*
2 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
3 * All rights reserved.
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 *
20 * File: tkip.c
21 *
22 * Purpose: Implement functions for 802.11i TKIP
23 *
24 * Author: Jerry Chen
25 *
26 * Date: Mar. 11, 2003
27 *
28 * Functions:
29 * TKIPvMixKey - Get TKIP RC4 Key from TK,TA, and TSC
30 *
31 * Revision History:
32 *
33 */
34
35
36#if !defined(__TMACRO_H__)
37#include "tmacro.h"
38#endif
39#if !defined(__TBIT_H__)
40#include "tbit.h"
41#endif
42#if !defined(__TKIP_H__)
43#include "tkip.h"
44#endif
45#if !defined(__UMEM_H__)
46#include "umem.h"
47#endif
48
49
50/*--------------------- Static Definitions -------------------------*/
51
52/*--------------------- Static Classes ----------------------------*/
53
54/*--------------------- Static Variables --------------------------*/
55
56/*--------------------- Static Functions --------------------------*/
57
58/*--------------------- Export Variables --------------------------*/
59
60/*--------------------- Static Definitions -------------------------*/
61
62/*--------------------- Static Classes ----------------------------*/
63
64/*--------------------- Static Variables --------------------------*/
65
66/* The Sbox is reduced to 2 16-bit wide tables, each with 256 entries. */
67/* The 2nd table is the same as the 1st but with the upper and lower */
68/* bytes swapped. To allow an endian tolerant implementation, the byte */
69/* halves have been expressed independently here. */
70const BYTE TKIP_Sbox_Lower[256] = {
71 0xA5,0x84,0x99,0x8D,0x0D,0xBD,0xB1,0x54,
72 0x50,0x03,0xA9,0x7D,0x19,0x62,0xE6,0x9A,
73 0x45,0x9D,0x40,0x87,0x15,0xEB,0xC9,0x0B,
74 0xEC,0x67,0xFD,0xEA,0xBF,0xF7,0x96,0x5B,
75 0xC2,0x1C,0xAE,0x6A,0x5A,0x41,0x02,0x4F,
76 0x5C,0xF4,0x34,0x08,0x93,0x73,0x53,0x3F,
77 0x0C,0x52,0x65,0x5E,0x28,0xA1,0x0F,0xB5,
78 0x09,0x36,0x9B,0x3D,0x26,0x69,0xCD,0x9F,
79 0x1B,0x9E,0x74,0x2E,0x2D,0xB2,0xEE,0xFB,
80 0xF6,0x4D,0x61,0xCE,0x7B,0x3E,0x71,0x97,
81 0xF5,0x68,0x00,0x2C,0x60,0x1F,0xC8,0xED,
82 0xBE,0x46,0xD9,0x4B,0xDE,0xD4,0xE8,0x4A,
83 0x6B,0x2A,0xE5,0x16,0xC5,0xD7,0x55,0x94,
84 0xCF,0x10,0x06,0x81,0xF0,0x44,0xBA,0xE3,
85 0xF3,0xFE,0xC0,0x8A,0xAD,0xBC,0x48,0x04,
86 0xDF,0xC1,0x75,0x63,0x30,0x1A,0x0E,0x6D,
87 0x4C,0x14,0x35,0x2F,0xE1,0xA2,0xCC,0x39,
88 0x57,0xF2,0x82,0x47,0xAC,0xE7,0x2B,0x95,
89 0xA0,0x98,0xD1,0x7F,0x66,0x7E,0xAB,0x83,
90 0xCA,0x29,0xD3,0x3C,0x79,0xE2,0x1D,0x76,
91 0x3B,0x56,0x4E,0x1E,0xDB,0x0A,0x6C,0xE4,
92 0x5D,0x6E,0xEF,0xA6,0xA8,0xA4,0x37,0x8B,
93 0x32,0x43,0x59,0xB7,0x8C,0x64,0xD2,0xE0,
94 0xB4,0xFA,0x07,0x25,0xAF,0x8E,0xE9,0x18,
95 0xD5,0x88,0x6F,0x72,0x24,0xF1,0xC7,0x51,
96 0x23,0x7C,0x9C,0x21,0xDD,0xDC,0x86,0x85,
97 0x90,0x42,0xC4,0xAA,0xD8,0x05,0x01,0x12,
98 0xA3,0x5F,0xF9,0xD0,0x91,0x58,0x27,0xB9,
99 0x38,0x13,0xB3,0x33,0xBB,0x70,0x89,0xA7,
100 0xB6,0x22,0x92,0x20,0x49,0xFF,0x78,0x7A,
101 0x8F,0xF8,0x80,0x17,0xDA,0x31,0xC6,0xB8,
102 0xC3,0xB0,0x77,0x11,0xCB,0xFC,0xD6,0x3A
103};
104
105const BYTE TKIP_Sbox_Upper[256] = {
106 0xC6,0xF8,0xEE,0xF6,0xFF,0xD6,0xDE,0x91,
107 0x60,0x02,0xCE,0x56,0xE7,0xB5,0x4D,0xEC,
108 0x8F,0x1F,0x89,0xFA,0xEF,0xB2,0x8E,0xFB,
109 0x41,0xB3,0x5F,0x45,0x23,0x53,0xE4,0x9B,
110 0x75,0xE1,0x3D,0x4C,0x6C,0x7E,0xF5,0x83,
111 0x68,0x51,0xD1,0xF9,0xE2,0xAB,0x62,0x2A,
112 0x08,0x95,0x46,0x9D,0x30,0x37,0x0A,0x2F,
113 0x0E,0x24,0x1B,0xDF,0xCD,0x4E,0x7F,0xEA,
114 0x12,0x1D,0x58,0x34,0x36,0xDC,0xB4,0x5B,
115 0xA4,0x76,0xB7,0x7D,0x52,0xDD,0x5E,0x13,
116 0xA6,0xB9,0x00,0xC1,0x40,0xE3,0x79,0xB6,
117 0xD4,0x8D,0x67,0x72,0x94,0x98,0xB0,0x85,
118 0xBB,0xC5,0x4F,0xED,0x86,0x9A,0x66,0x11,
119 0x8A,0xE9,0x04,0xFE,0xA0,0x78,0x25,0x4B,
120 0xA2,0x5D,0x80,0x05,0x3F,0x21,0x70,0xF1,
121 0x63,0x77,0xAF,0x42,0x20,0xE5,0xFD,0xBF,
122 0x81,0x18,0x26,0xC3,0xBE,0x35,0x88,0x2E,
123 0x93,0x55,0xFC,0x7A,0xC8,0xBA,0x32,0xE6,
124 0xC0,0x19,0x9E,0xA3,0x44,0x54,0x3B,0x0B,
125 0x8C,0xC7,0x6B,0x28,0xA7,0xBC,0x16,0xAD,
126 0xDB,0x64,0x74,0x14,0x92,0x0C,0x48,0xB8,
127 0x9F,0xBD,0x43,0xC4,0x39,0x31,0xD3,0xF2,
128 0xD5,0x8B,0x6E,0xDA,0x01,0xB1,0x9C,0x49,
129 0xD8,0xAC,0xF3,0xCF,0xCA,0xF4,0x47,0x10,
130 0x6F,0xF0,0x4A,0x5C,0x38,0x57,0x73,0x97,
131 0xCB,0xA1,0xE8,0x3E,0x96,0x61,0x0D,0x0F,
132 0xE0,0x7C,0x71,0xCC,0x90,0x06,0xF7,0x1C,
133 0xC2,0x6A,0xAE,0x69,0x17,0x99,0x3A,0x27,
134 0xD9,0xEB,0x2B,0x22,0xD2,0xA9,0x07,0x33,
135 0x2D,0x3C,0x15,0xC9,0x87,0xAA,0x50,0xA5,
136 0x03,0x59,0x09,0x1A,0x65,0xD7,0x84,0xD0,
137 0x82,0x29,0x5A,0x1E,0x7B,0xA8,0x6D,0x2C
138};
139
140
141//STKIPKeyManagement sTKIPKeyTable[MAX_TKIP_KEY];
142
143/*--------------------- Static Functions --------------------------*/
144unsigned int tkip_sbox(unsigned int index);
145unsigned int rotr1(unsigned int a);
146
147/*--------------------- Export Variables --------------------------*/
148
149/************************************************************/
150/* tkip_sbox() */
151/* Returns a 16 bit value from a 64K entry table. The Table */
152/* is synthesized from two 256 entry byte wide tables. */
153/************************************************************/
154unsigned int tkip_sbox(unsigned int index)
155{
156 unsigned int index_low;
157 unsigned int index_high;
158 unsigned int left, right;
159
160 index_low = (index % 256);
161 index_high = ((index >> 8) % 256);
162
163 left = TKIP_Sbox_Lower[index_low] + (TKIP_Sbox_Upper[index_low] * 256);
164 right = TKIP_Sbox_Upper[index_high] + (TKIP_Sbox_Lower[index_high] * 256);
165
166 return (left ^ right);
167};
168
169
170unsigned int rotr1(unsigned int a)
171{
172 unsigned int b;
173
174 if ((a & 0x01) == 0x01) {
175 b = (a >> 1) | 0x8000;
176 } else {
177 b = (a >> 1) & 0x7fff;
178 }
179 b = b % 65536;
180 return b;
181}
182
183
184/*
185 * Description: Caculate RC4Key fom TK, TA, and TSC
186 *
187 * Parameters:
188 * In:
189 * pbyTKey - TKey
190 * pbyTA - TA
191 * dwTSC - TSC
192 * Out:
193 * pbyRC4Key - RC4Key
194 *
195 * Return Value: none
196 *
197 */
198VOID TKIPvMixKey(
199 PBYTE pbyTKey,
200 PBYTE pbyTA,
201 WORD wTSC15_0,
202 DWORD dwTSC47_16,
203 PBYTE pbyRC4Key
204 )
205{
206 unsigned int p1k[5];
207// unsigned int ttak0, ttak1, ttak2, ttak3, ttak4;
208 unsigned int tsc0, tsc1, tsc2;
209 unsigned int ppk0, ppk1, ppk2, ppk3, ppk4, ppk5;
210 unsigned long int pnl,pnh;
211
212 int i, j;
213
214 pnl = wTSC15_0;
215 pnh = dwTSC47_16;
216
217 tsc0 = (unsigned int)((pnh >> 16) % 65536); /* msb */
218 tsc1 = (unsigned int)(pnh % 65536);
219 tsc2 = (unsigned int)(pnl % 65536); /* lsb */
220
221 /* Phase 1, step 1 */
222 p1k[0] = tsc1;
223 p1k[1] = tsc0;
224 p1k[2] = (unsigned int)(pbyTA[0] + (pbyTA[1]*256));
225 p1k[3] = (unsigned int)(pbyTA[2] + (pbyTA[3]*256));
226 p1k[4] = (unsigned int)(pbyTA[4] + (pbyTA[5]*256));
227
228 /* Phase 1, step 2 */
229 for (i=0; i<8; i++) {
230 j = 2*(i & 1);
231 p1k[0] = (p1k[0] + tkip_sbox( (p1k[4] ^ ((256*pbyTKey[1+j]) + pbyTKey[j])) % 65536 )) % 65536;
232 p1k[1] = (p1k[1] + tkip_sbox( (p1k[0] ^ ((256*pbyTKey[5+j]) + pbyTKey[4+j])) % 65536 )) % 65536;
233 p1k[2] = (p1k[2] + tkip_sbox( (p1k[1] ^ ((256*pbyTKey[9+j]) + pbyTKey[8+j])) % 65536 )) % 65536;
234 p1k[3] = (p1k[3] + tkip_sbox( (p1k[2] ^ ((256*pbyTKey[13+j]) + pbyTKey[12+j])) % 65536 )) % 65536;
235 p1k[4] = (p1k[4] + tkip_sbox( (p1k[3] ^ (((256*pbyTKey[1+j]) + pbyTKey[j]))) % 65536 )) % 65536;
236 p1k[4] = (p1k[4] + i) % 65536;
237 }
238 /* Phase 2, Step 1 */
239 ppk0 = p1k[0];
240 ppk1 = p1k[1];
241 ppk2 = p1k[2];
242 ppk3 = p1k[3];
243 ppk4 = p1k[4];
244 ppk5 = (p1k[4] + tsc2) % 65536;
245
246 /* Phase2, Step 2 */
247 ppk0 = ppk0 + tkip_sbox( (ppk5 ^ ((256*pbyTKey[1]) + pbyTKey[0])) % 65536);
248 ppk1 = ppk1 + tkip_sbox( (ppk0 ^ ((256*pbyTKey[3]) + pbyTKey[2])) % 65536);
249 ppk2 = ppk2 + tkip_sbox( (ppk1 ^ ((256*pbyTKey[5]) + pbyTKey[4])) % 65536);
250 ppk3 = ppk3 + tkip_sbox( (ppk2 ^ ((256*pbyTKey[7]) + pbyTKey[6])) % 65536);
251 ppk4 = ppk4 + tkip_sbox( (ppk3 ^ ((256*pbyTKey[9]) + pbyTKey[8])) % 65536);
252 ppk5 = ppk5 + tkip_sbox( (ppk4 ^ ((256*pbyTKey[11]) + pbyTKey[10])) % 65536);
253
254 ppk0 = ppk0 + rotr1(ppk5 ^ ((256*pbyTKey[13]) + pbyTKey[12]));
255 ppk1 = ppk1 + rotr1(ppk0 ^ ((256*pbyTKey[15]) + pbyTKey[14]));
256 ppk2 = ppk2 + rotr1(ppk1);
257 ppk3 = ppk3 + rotr1(ppk2);
258 ppk4 = ppk4 + rotr1(ppk3);
259 ppk5 = ppk5 + rotr1(ppk4);
260
261 /* Phase 2, Step 3 */
262 pbyRC4Key[0] = (tsc2 >> 8) % 256;
263 pbyRC4Key[1] = (((tsc2 >> 8) % 256) | 0x20) & 0x7f;
264 pbyRC4Key[2] = tsc2 % 256;
265 pbyRC4Key[3] = ((ppk5 ^ ((256*pbyTKey[1]) + pbyTKey[0])) >> 1) % 256;
266
267 pbyRC4Key[4] = ppk0 % 256;
268 pbyRC4Key[5] = (ppk0 >> 8) % 256;
269
270 pbyRC4Key[6] = ppk1 % 256;
271 pbyRC4Key[7] = (ppk1 >> 8) % 256;
272
273 pbyRC4Key[8] = ppk2 % 256;
274 pbyRC4Key[9] = (ppk2 >> 8) % 256;
275
276 pbyRC4Key[10] = ppk3 % 256;
277 pbyRC4Key[11] = (ppk3 >> 8) % 256;
278
279 pbyRC4Key[12] = ppk4 % 256;
280 pbyRC4Key[13] = (ppk4 >> 8) % 256;
281
282 pbyRC4Key[14] = ppk5 % 256;
283 pbyRC4Key[15] = (ppk5 >> 8) % 256;
284}
diff --git a/drivers/staging/vt6655/tkip.h b/drivers/staging/vt6655/tkip.h
new file mode 100644
index 000000000000..dc8382b67019
--- /dev/null
+++ b/drivers/staging/vt6655/tkip.h
@@ -0,0 +1,76 @@
1/*
2 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
3 * All rights reserved.
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 *
20 * File: tkip.h
21 *
22 * Purpose: Implement functions for 802.11i TKIP
23 *
24 * Author: Jerry Chen
25 *
26 * Date: Mar. 11, 2003
27 *
28 */
29
30
31#ifndef __TKIP_H__
32#define __TKIP_H__
33
34#if !defined(__TTYPE_H__)
35#include "ttype.h"
36#endif
37
38#if !defined(__TETHER_H__)
39#include "tether.h"
40#endif
41
42
43
44/*--------------------- Export Definitions -------------------------*/
45#define TKIP_KEY_LEN 16
46
47/*--------------------- Export Types ------------------------------*/
48
49/*--------------------- Export Macros ------------------------------*/
50
51/*--------------------- Export Classes ----------------------------*/
52
53/*--------------------- Export Variables --------------------------*/
54
55/*--------------------- Export Functions --------------------------*/
56#ifdef __cplusplus
57extern "C" { /* Assume C declarations for C++ */
58#endif /* __cplusplus */
59
60VOID TKIPvMixKey(
61 PBYTE pbyTKey,
62 PBYTE pbyTA,
63 WORD wTSC15_0,
64 DWORD dwTSC47_16,
65 PBYTE pbyRC4Key
66 );
67
68#ifdef __cplusplus
69} /* End of extern "C" { */
70#endif /* __cplusplus */
71
72
73#endif // __TKIP_H__
74
75
76
diff --git a/drivers/staging/vt6655/tmacro.h b/drivers/staging/vt6655/tmacro.h
new file mode 100644
index 000000000000..3d932a258dd1
--- /dev/null
+++ b/drivers/staging/vt6655/tmacro.h
@@ -0,0 +1,152 @@
1/*
2 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
3 * All rights reserved.
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * File: tmacro.h
20 *
21 * Purpose: define basic common types and macros
22 *
23 * Author: Tevin Chen
24 *
25 * Date: May 21, 1996
26 *
27 */
28
29
30#ifndef __TMACRO_H__
31#define __TMACRO_H__
32
33
34#if !defined(__TTYPE_H__)
35#include "ttype.h"
36#endif
37
38
39
40
41/****** Common helper macros ***********************************************/
42
43#if !defined(LONIBBLE)
44#define LONIBBLE(b) ((BYTE)(b) & 0x0F)
45#endif
46#if !defined(HINIBBLE)
47#define HINIBBLE(b) ((BYTE)(((WORD)(b) >> 4) & 0x0F))
48#endif
49
50#if !defined(LOBYTE)
51#define LOBYTE(w) ((BYTE)(w))
52#endif
53#if !defined(HIBYTE)
54#define HIBYTE(w) ((BYTE)(((WORD)(w) >> 8) & 0xFF))
55#endif
56
57#if !defined(LOWORD)
58#define LOWORD(d) ((WORD)(d))
59#endif
60#if !defined(HIWORD)
61#define HIWORD(d) ((WORD)((((DWORD)(d)) >> 16) & 0xFFFF))
62#endif
63
64#define LODWORD(q) ((q).u.dwLowDword)
65#define HIDWORD(q) ((q).u.dwHighDword)
66
67
68
69#if !defined(MAKEBYTE)
70#define MAKEBYTE(ln, hn) ((BYTE)(((BYTE)(ln) & 0x0F) | ((BYTE)(hn) << 4)))
71#endif
72#if !defined(MAKEWORD)
73#define MAKEWORD(lb, hb) ((WORD)(((BYTE)(lb)) | (((WORD)((BYTE)(hb))) << 8)))
74#endif
75#if !defined(MAKEDWORD)
76#define MAKEDWORD(lw, hw) ((DWORD)(((WORD)(lw)) | (((DWORD)((WORD)(hw))) << 16)))
77#endif
78#if !defined(MAKEQWORD)
79#define MAKEQWORD(ld, hd, pq) {pq->u.dwLowDword = ld; pq->u.dwHighDword = hd;}
80#endif
81
82#if !defined(MAKELONG)
83#define MAKELONG(low, high) ((LONG)(((WORD)(low)) | (((DWORD)((WORD)(high))) << 16)))
84#endif
85
86
87
88// Bytes Reverse: big endian to little endian convert
89#if !defined(REVWORD)
90#define REVWORD(w) ((WORD)( ((WORD)(w) >> 8) | ((WORD)(w) << 8) ))
91#endif
92#if !defined(REVDWORD)
93#define REVDWORD(d) (MAKEDWORD(MAKEWORD(HIBYTE(HIWORD(d)),LOBYTE(HIWORD(d))),MAKEWORD(HIBYTE(LOWORD(d)),LOBYTE(LOWORD(d)))))
94#endif
95
96/* map to known network names */
97/*
98#define ntohs(x) REVWORD(x)
99#define ntohl(x) REVDWORD(x)
100#define htons(x) REVWORD(x)
101#define htonl(x) REVDWORD(x)
102*/
103
104
105/*
106#ifndef NOMINMAX
107#ifndef max
108#define max(a,b) (((a) > (b)) ? (a) : (b))
109#endif
110#ifndef min
111#define min(a,b) (((a) < (b)) ? (a) : (b))
112#endif
113#endif // NOMINMAX
114*/
115
116
117
118/****** Misc macros ********************************************************/
119
120// get the field offset in the type(struct, class, ...)
121#define OFFSET(type, field) ((int)(&((type NEAR*)1)->field)-1)
122
123
124/* string equality shorthand */
125#define STR_EQ(x, y) (strcmp(x, y) == 0)
126#define STR_NE(x, y) (strcmp(x, y) != 0)
127
128
129// calculate element # of array
130#define ELEMENT_NUM(array) (sizeof(array) / sizeof(array[0]))
131//#define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0]))
132
133
134// null statement
135#define NULL_FUNC()
136
137
138/* Since not all compilers support structure assignment, the ASSIGN()
139 * macro is used. This controls how it's actually implemented.
140 */
141#ifdef NOSTRUCTASSIGN /* Version for old compilers that don't support it */
142#define ASSIGN(a,b) memcpy((char *)&(a),(char *)&(b),sizeof(b);
143#else /* Version for compilers that do */
144#define ASSIGN(a,b) ((a) = (b))
145#endif
146
147
148
149
150#endif // __TMACRO_H__
151
152
diff --git a/drivers/staging/vt6655/tpci.h b/drivers/staging/vt6655/tpci.h
new file mode 100644
index 000000000000..4a1c8ed75ca6
--- /dev/null
+++ b/drivers/staging/vt6655/tpci.h
@@ -0,0 +1,117 @@
1/*
2 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
3 * All rights reserved.
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 *
20 * File: tpci.h
21 *
22 * Purpose: PCI routines
23 *
24 * Author: Tevin Chen
25 *
26 * Date: May 21, 1996
27 *
28 */
29
30
31#ifndef __TPCI_H__
32#define __TPCI_H__
33
34#if !defined(__TTYPE_H__)
35#include "ttype.h"
36#endif
37
38
39
40
41/*--------------------- Export Definitions -------------------------*/
42#define MAX_PCI_BUS 4 // max. # of PCI bus that we support
43#define MAX_PCI_DEVICE 32 // max. # of PCI devices
44
45
46//
47// Registers in the PCI configuration space
48//
49#define PCI_REG_VENDOR_ID 0x00 //
50#define PCI_REG_DEVICE_ID 0x02 //
51#define PCI_REG_COMMAND 0x04 //
52#define PCI_REG_STATUS 0x06 //
53#define PCI_REG_REV_ID 0x08 //
54#define PCI_REG_CLASS_CODE 0x09 //
55#define PCI_REG_CACHELINE_SIZE 0x0C //
56#define PCI_REG_LAT_TIMER 0x0D //
57#define PCI_REG_HDR_TYPE 0x0E //
58#define PCI_REG_BIST 0x0F //
59
60#define PCI_REG_BAR0 0x10 //
61#define PCI_REG_BAR1 0x14 //
62#define PCI_REG_BAR2 0x18 //
63#define PCI_REG_CARDBUS_CIS_PTR 0x28 //
64
65#define PCI_REG_SUB_VEN_ID 0x2C //
66#define PCI_REG_SUB_SYS_ID 0x2E //
67#define PCI_REG_EXP_ROM_BAR 0x30 //
68#define PCI_REG_CAP 0x34 //
69
70#define PCI_REG_INT_LINE 0x3C //
71#define PCI_REG_INT_PIN 0x3D //
72#define PCI_REG_MIN_GNT 0x3E //
73#define PCI_REG_MAX_LAT 0x3F //
74
75#define PCI_REG_MAX_SIZE 0x100 // maximun total PCI registers
76
77
78//
79// Bits in the COMMAND register
80//
81#define COMMAND_BUSM 0x04 //
82#define COMMAND_WAIT 0x80 //
83
84/*--------------------- Export Types ------------------------------*/
85
86/*--------------------- Export Macros ------------------------------*/
87
88// macro MAKE Bus Dev Fun ID into WORD
89#define MAKE_BDF_TO_WORD(byBusId, byDevId, byFunId) \
90 MAKEWORD( \
91 ((((BYTE)(byDevId)) & 0x1F) << 3) + \
92 (((BYTE)(byFunId)) & 0x07), \
93 (byBusId) \
94 )
95
96#define GET_BUSID(wBusDevFunId) \
97 HIBYTE(wBusDevFunId)
98
99#define GET_DEVID(wBusDevFunId) \
100 (LOBYTE(wBusDevFunId) >> 3)
101
102#define GET_FUNID(wBusDevFunId) \
103 (LOBYTE(wBusDevFunId) & 0x07)
104
105
106/*--------------------- Export Classes ----------------------------*/
107
108/*--------------------- Export Variables --------------------------*/
109
110/*--------------------- Export Functions --------------------------*/
111
112
113
114
115#endif // __TPCI_H__
116
117
diff --git a/drivers/staging/vt6655/umem.h b/drivers/staging/vt6655/umem.h
new file mode 100644
index 000000000000..2c3eafa038e7
--- /dev/null
+++ b/drivers/staging/vt6655/umem.h
@@ -0,0 +1,75 @@
1/*
2 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
3 * All rights reserved.
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 *
20 * File: umem.h
21 *
22 * Purpose: Define Memory macros
23 *
24 * Author: Tevin Chen
25 *
26 * Date: Mar 17, 1997
27 *
28 */
29
30
31#ifndef __UMEM_H__
32#define __UMEM_H__
33
34#if !defined(__TTYPE_H__)
35#include "ttype.h"
36#endif
37
38
39
40/*--------------------- Export Definitions -------------------------*/
41// 4-byte memory tag
42#define MEM_TAG 'mTEW'
43
44// Macros used for memory allocation and deallocation.
45
46
47
48#define ZERO_MEMORY(Destination,Length) { \
49 memset((PVOID)(Destination), \
50 0, \
51 (ULONG)(Length) \
52 ); \
53}
54
55#define MEMvCopy(pvDest, pvSource, uCount) { \
56 memcpy((PVOID)(pvDest), \
57 (PVOID)(pvSource), \
58 (ULONG)(uCount) \
59 ); \
60}
61
62
63#define MEMEqualMemory(Destination,Source,Length) (!memcmp((Destination),(Source),(Length)))
64/*--------------------- Export Classes ----------------------------*/
65
66/*--------------------- Export Variables --------------------------*/
67
68/*--------------------- Export Functions --------------------------*/
69
70
71
72
73#endif // __UMEM_H__
74
75
diff --git a/drivers/staging/vt6655/upc.h b/drivers/staging/vt6655/upc.h
new file mode 100644
index 000000000000..113fc2c88c11
--- /dev/null
+++ b/drivers/staging/vt6655/upc.h
@@ -0,0 +1,171 @@
1/*
2 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
3 * All rights reserved.
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * File: upc.h
20 *
21 * Purpose: Macros to access device
22 *
23 * Author: Tevin Chen
24 *
25 * Date: Mar 17, 1997
26 *
27 */
28
29
30#ifndef __UPC_H__
31#define __UPC_H__
32
33#if !defined(DEVICE_H)
34#include "device.h"
35#endif
36#if !defined(__TTYPE_H__)
37#include "ttype.h"
38#endif
39
40/*--------------------- Export Definitions -------------------------*/
41
42
43//
44// For IO mapped
45//
46
47#ifdef IO_MAP
48
49#define VNSvInPortB(dwIOAddress, pbyData) { \
50 *(pbyData) = inb(dwIOAddress); \
51}
52
53
54#define VNSvInPortW(dwIOAddress, pwData) { \
55 *(pwData) = inw(dwIOAddress); \
56}
57
58#define VNSvInPortD(dwIOAddress, pdwData) { \
59 *(pdwData) = inl(dwIOAddress); \
60}
61
62
63#define VNSvOutPortB(dwIOAddress, byData) { \
64 outb(byData, dwIOAddress); \
65}
66
67
68#define VNSvOutPortW(dwIOAddress, wData) { \
69 outw(wData, dwIOAddress); \
70}
71
72#define VNSvOutPortD(dwIOAddress, dwData) { \
73 outl(dwData, dwIOAddress); \
74}
75
76#else
77
78//
79// For memory mapped IO
80//
81
82
83#define VNSvInPortB(dwIOAddress, pbyData) { \
84 volatile BYTE* pbyAddr = ((PBYTE)(dwIOAddress)); \
85 *(pbyData) = readb(pbyAddr); \
86}
87
88
89#define VNSvInPortW(dwIOAddress, pwData) { \
90 volatile WORD* pwAddr = ((PWORD)(dwIOAddress)); \
91 *(pwData) = readw(pwAddr); \
92}
93
94#define VNSvInPortD(dwIOAddress, pdwData) { \
95 volatile DWORD* pdwAddr = ((PDWORD)(dwIOAddress)); \
96 *(pdwData) = readl(pdwAddr); \
97}
98
99
100#define VNSvOutPortB(dwIOAddress, byData) { \
101 volatile BYTE* pbyAddr = ((PBYTE)(dwIOAddress)); \
102 writeb((BYTE)byData, pbyAddr); \
103}
104
105
106#define VNSvOutPortW(dwIOAddress, wData) { \
107 volatile WORD* pwAddr = ((PWORD)(dwIOAddress)); \
108 writew((WORD)wData, pwAddr); \
109}
110
111#define VNSvOutPortD(dwIOAddress, dwData) { \
112 volatile DWORD* pdwAddr = ((PDWORD)(dwIOAddress)); \
113 writel((DWORD)dwData, pdwAddr); \
114}
115
116#endif
117
118
119//
120// ALWAYS IO-Mapped IO when in 16-bit/32-bit environment
121//
122#define PCBvInPortB(dwIOAddress, pbyData) { \
123 *(pbyData) = inb(dwIOAddress); \
124}
125
126#define PCBvInPortW(dwIOAddress, pwData) { \
127 *(pwData) = inw(dwIOAddress); \
128}
129
130#define PCBvInPortD(dwIOAddress, pdwData) { \
131 *(pdwData) = inl(dwIOAddress); \
132}
133
134#define PCBvOutPortB(dwIOAddress, byData) { \
135 outb(byData, dwIOAddress); \
136}
137
138#define PCBvOutPortW(dwIOAddress, wData) { \
139 outw(wData, dwIOAddress); \
140}
141
142#define PCBvOutPortD(dwIOAddress, dwData) { \
143 outl(dwData, dwIOAddress); \
144}
145
146
147#define PCAvDelayByIO(uDelayUnit) { \
148 BYTE byData; \
149 ULONG ii; \
150 \
151 if (uDelayUnit <= 50) { \
152 udelay(uDelayUnit); \
153 } \
154 else { \
155 for (ii = 0; ii < (uDelayUnit); ii++) \
156 byData = inb(0x61); \
157 } \
158}
159
160
161/*--------------------- Export Classes ----------------------------*/
162
163/*--------------------- Export Variables --------------------------*/
164
165/*--------------------- Export Functions --------------------------*/
166
167
168
169
170#endif // __UPC_H__
171
diff --git a/drivers/staging/vt6655/vntconfiguration.dat b/drivers/staging/vt6655/vntconfiguration.dat
new file mode 100644
index 000000000000..0064ddce7c11
--- /dev/null
+++ b/drivers/staging/vt6655/vntconfiguration.dat
@@ -0,0 +1 @@
ZONETYPE=EUROPE \ No newline at end of file
diff --git a/drivers/staging/vt6655/vntwifi.c b/drivers/staging/vt6655/vntwifi.c
new file mode 100644
index 000000000000..58a1ba0eac07
--- /dev/null
+++ b/drivers/staging/vt6655/vntwifi.c
@@ -0,0 +1,832 @@
1/*
2 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
3 * All rights reserved.
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 *
20 * File: vntwifi.c
21 *
22 * Purpose: export functions for vntwifi lib
23 *
24 * Functions:
25 *
26 * Revision History:
27 *
28 * Author: Yiching Chen
29 *
30 * Date: feb. 2, 2005
31 *
32 */
33
34#if !defined(__VNTWIFI_H__)
35#include "vntwifi.h"
36#endif
37#if !defined(__UMEM_H__)
38#include "umem.h"
39#endif
40
41
42#if !defined(__TBIT_H__)
43#include "tbit.h"
44#endif
45#if !defined(__IEEE11h_H__)
46#include "IEEE11h.h"
47#endif
48#if !defined(__COUNTRY_H__)
49#include "country.h"
50#endif
51#if !defined(__DEVICE_H__)
52#include "device.h"
53#endif
54#if !defined(__WMGR_H__)
55#include "wmgr.h"
56#endif
57#if !defined(__DATARATE_H__)
58#include "datarate.h"
59#endif
60//#define PLICE_DEBUG
61
62/*--------------------- Static Definitions -------------------------*/
63//static int msglevel =MSG_LEVEL_DEBUG;
64//static int msglevel =MSG_LEVEL_INFO;
65
66/*--------------------- Static Classes ----------------------------*/
67
68/*--------------------- Static Variables --------------------------*/
69
70/*--------------------- Static Functions --------------------------*/
71
72/*--------------------- Export Variables --------------------------*/
73
74/*--------------------- Export Functions --------------------------*/
75
76/*+
77 *
78 * Description:
79 * Set Operation Mode
80 *
81 * Parameters:
82 * In:
83 * pMgmtHandle - pointer to management object
84 * eOPMode - Opreation Mode
85 * Out:
86 * none
87 *
88 * Return Value: none
89 *
90-*/
91VOID
92VNTWIFIvSetOPMode (
93 IN PVOID pMgmtHandle,
94 IN WMAC_CONFIG_MODE eOPMode
95 )
96{
97 PSMgmtObject pMgmt = (PSMgmtObject)pMgmtHandle;
98
99 pMgmt->eConfigMode = eOPMode;
100}
101
102
103/*+
104 *
105 * Description:
106 * Set Operation Mode
107 *
108 * Parameters:
109 * In:
110 * pMgmtHandle - pointer to management object
111 * wBeaconPeriod - Beacon Period
112 * wATIMWindow - ATIM window
113 * uChannel - channel number
114 * Out:
115 * none
116 *
117 * Return Value: none
118 *
119-*/
120VOID
121VNTWIFIvSetIBSSParameter (
122 IN PVOID pMgmtHandle,
123 IN WORD wBeaconPeriod,
124 IN WORD wATIMWindow,
125 IN UINT uChannel
126 )
127{
128 PSMgmtObject pMgmt = (PSMgmtObject)pMgmtHandle;
129
130 pMgmt->wIBSSBeaconPeriod = wBeaconPeriod;
131 pMgmt->wIBSSATIMWindow = wATIMWindow;
132 pMgmt->uIBSSChannel = uChannel;
133}
134
135/*+
136 *
137 * Description:
138 * Get current SSID
139 *
140 * Parameters:
141 * In:
142 * pMgmtHandle - pointer to management object
143 * Out:
144 * none
145 *
146 * Return Value: current SSID pointer.
147 *
148-*/
149PWLAN_IE_SSID
150VNTWIFIpGetCurrentSSID (
151 IN PVOID pMgmtHandle
152 )
153{
154 PSMgmtObject pMgmt = (PSMgmtObject)pMgmtHandle;
155 return((PWLAN_IE_SSID) pMgmt->abyCurrSSID);
156}
157
158/*+
159 *
160 * Description:
161 * Get current link channel
162 *
163 * Parameters:
164 * In:
165 * pMgmtHandle - pointer to management object
166 * Out:
167 * none
168 *
169 * Return Value: current Channel.
170 *
171-*/
172UINT
173VNTWIFIpGetCurrentChannel (
174 IN PVOID pMgmtHandle
175 )
176{
177 PSMgmtObject pMgmt = (PSMgmtObject)pMgmtHandle;
178 if (pMgmtHandle != NULL) {
179 return (pMgmt->uCurrChannel);
180 }
181 return 0;
182}
183
184/*+
185 *
186 * Description:
187 * Get current Assoc ID
188 *
189 * Parameters:
190 * In:
191 * pMgmtHandle - pointer to management object
192 * Out:
193 * none
194 *
195 * Return Value: current Assoc ID
196 *
197-*/
198WORD
199VNTWIFIwGetAssocID (
200 IN PVOID pMgmtHandle
201 )
202{
203 PSMgmtObject pMgmt = (PSMgmtObject)pMgmtHandle;
204 return(pMgmt->wCurrAID);
205}
206
207
208
209/*+
210 *
211 * Description:
212 * This routine return max support rate of IES
213 *
214 * Parameters:
215 * In:
216 * pSupportRateIEs
217 * pExtSupportRateIEs
218 *
219 * Out:
220 *
221 * Return Value: max support rate
222 *
223-*/
224BYTE
225VNTWIFIbyGetMaxSupportRate (
226 IN PWLAN_IE_SUPP_RATES pSupportRateIEs,
227 IN PWLAN_IE_SUPP_RATES pExtSupportRateIEs
228 )
229{
230 BYTE byMaxSupportRate = RATE_1M;
231 BYTE bySupportRate = RATE_1M;
232 UINT ii = 0;
233
234 if (pSupportRateIEs) {
235 for (ii = 0; ii < pSupportRateIEs->len; ii++) {
236 bySupportRate = DATARATEbyGetRateIdx(pSupportRateIEs->abyRates[ii]);
237 if (bySupportRate > byMaxSupportRate) {
238 byMaxSupportRate = bySupportRate;
239 }
240 }
241 }
242 if (pExtSupportRateIEs) {
243 for (ii = 0; ii < pExtSupportRateIEs->len; ii++) {
244 bySupportRate = DATARATEbyGetRateIdx(pExtSupportRateIEs->abyRates[ii]);
245 if (bySupportRate > byMaxSupportRate) {
246 byMaxSupportRate = bySupportRate;
247 }
248 }
249 }
250
251 return byMaxSupportRate;
252}
253
254/*+
255 *
256 * Description:
257 * This routine return data rate of ACK packtet
258 *
259 * Parameters:
260 * In:
261 * byRxDataRate
262 * pSupportRateIEs
263 * pExtSupportRateIEs
264 *
265 * Out:
266 *
267 * Return Value: max support rate
268 *
269-*/
270BYTE
271VNTWIFIbyGetACKTxRate (
272 IN BYTE byRxDataRate,
273 IN PWLAN_IE_SUPP_RATES pSupportRateIEs,
274 IN PWLAN_IE_SUPP_RATES pExtSupportRateIEs
275 )
276{
277 BYTE byMaxAckRate;
278 BYTE byBasicRate;
279 UINT ii;
280
281 if (byRxDataRate <= RATE_11M) {
282 byMaxAckRate = RATE_1M;
283 } else {
284 // 24M is mandatory for 802.11a and 802.11g
285 byMaxAckRate = RATE_24M;
286 }
287 if (pSupportRateIEs) {
288 for (ii = 0; ii < pSupportRateIEs->len; ii++) {
289 if (pSupportRateIEs->abyRates[ii] & 0x80) {
290 byBasicRate = DATARATEbyGetRateIdx(pSupportRateIEs->abyRates[ii]);
291 if ((byBasicRate <= byRxDataRate) &&
292 (byBasicRate > byMaxAckRate)) {
293 byMaxAckRate = byBasicRate;
294 }
295 }
296 }
297 }
298 if (pExtSupportRateIEs) {
299 for (ii = 0; ii < pExtSupportRateIEs->len; ii++) {
300 if (pExtSupportRateIEs->abyRates[ii] & 0x80) {
301 byBasicRate = DATARATEbyGetRateIdx(pExtSupportRateIEs->abyRates[ii]);
302 if ((byBasicRate <= byRxDataRate) &&
303 (byBasicRate > byMaxAckRate)) {
304 byMaxAckRate = byBasicRate;
305 }
306 }
307 }
308 }
309
310 return byMaxAckRate;
311}
312
313/*+
314 *
315 * Description:
316 * Set Authentication Mode
317 *
318 * Parameters:
319 * In:
320 * pMgmtHandle - pointer to management object
321 * eAuthMode - Authentication mode
322 * Out:
323 * none
324 *
325 * Return Value: none
326 *
327-*/
328VOID
329VNTWIFIvSetAuthenticationMode (
330 IN PVOID pMgmtHandle,
331 IN WMAC_AUTHENTICATION_MODE eAuthMode
332 )
333{
334 PSMgmtObject pMgmt = (PSMgmtObject)pMgmtHandle;
335
336 pMgmt->eAuthenMode = eAuthMode;
337 if ((eAuthMode == WMAC_AUTH_SHAREKEY) ||
338 (eAuthMode == WMAC_AUTH_AUTO)) {
339 pMgmt->bShareKeyAlgorithm = TRUE;
340 } else {
341 pMgmt->bShareKeyAlgorithm = FALSE;
342 }
343}
344
345/*+
346 *
347 * Description:
348 * Set Encryption Mode
349 *
350 * Parameters:
351 * In:
352 * pMgmtHandle - pointer to management object
353 * eAuthMode - Authentication mode
354 * Out:
355 * none
356 *
357 * Return Value: none
358 *
359-*/
360VOID
361VNTWIFIvSetEncryptionMode (
362 IN PVOID pMgmtHandle,
363 IN WMAC_ENCRYPTION_MODE eEncryptionMode
364 )
365{
366 PSMgmtObject pMgmt = (PSMgmtObject)pMgmtHandle;
367
368 pMgmt->eEncryptionMode = eEncryptionMode;
369 if ((eEncryptionMode == WMAC_ENCRYPTION_WEPEnabled) ||
370 (eEncryptionMode == WMAC_ENCRYPTION_TKIPEnabled) ||
371 (eEncryptionMode == WMAC_ENCRYPTION_AESEnabled) ) {
372 pMgmt->bPrivacyInvoked = TRUE;
373 } else {
374 pMgmt->bPrivacyInvoked = FALSE;
375 }
376}
377
378
379
380BOOL
381VNTWIFIbConfigPhyMode (
382 IN PVOID pMgmtHandle,
383 IN CARD_PHY_TYPE ePhyType
384 )
385{
386 PSMgmtObject pMgmt = (PSMgmtObject)pMgmtHandle;
387
388 if ((ePhyType != PHY_TYPE_AUTO) &&
389 (ePhyType != pMgmt->eCurrentPHYMode)) {
390 if (CARDbSetPhyParameter(pMgmt->pAdapter, ePhyType, 0, 0, NULL, NULL)==TRUE) {
391 pMgmt->eCurrentPHYMode = ePhyType;
392 } else {
393 return(FALSE);
394 }
395 }
396 pMgmt->eConfigPHYMode = ePhyType;
397 return(TRUE);
398}
399
400
401VOID
402VNTWIFIbGetConfigPhyMode (
403 IN PVOID pMgmtHandle,
404 OUT PVOID pePhyType
405 )
406{
407 PSMgmtObject pMgmt = (PSMgmtObject)pMgmtHandle;
408
409 if ((pMgmt != NULL) && (pePhyType != NULL)) {
410 *(PCARD_PHY_TYPE)pePhyType = pMgmt->eConfigPHYMode;
411 }
412}
413
414/*+
415 *
416 * Description:
417 * Clear BSS List Database except current assoc BSS
418 *
419 * Parameters:
420 * In:
421 * pMgmtHandle - Management Object structure
422 * bLinkPass - Current Link status
423 * Out:
424 *
425 * Return Value: None.
426 *
427-*/
428
429
430/*+
431 *
432 * Description:
433 * Query BSS List in management database
434 *
435 * Parameters:
436 * In:
437 * pMgmtHandle - Management Object structure
438 * Out:
439 * puBSSCount - BSS count
440 * pvFirstBSS - pointer to first BSS
441 *
442 * Return Value: None.
443 *
444-*/
445
446VOID
447VNTWIFIvQueryBSSList (
448 IN PVOID pMgmtHandle,
449 OUT PUINT puBSSCount,
450 OUT PVOID *pvFirstBSS
451 )
452{
453 UINT ii = 0;
454 PSMgmtObject pMgmt = (PSMgmtObject)pMgmtHandle;
455 PKnownBSS pBSS = NULL;
456 UINT uCount = 0;
457
458 *pvFirstBSS = NULL;
459
460 for (ii = 0; ii < MAX_BSS_NUM; ii++) {
461 pBSS = &(pMgmt->sBSSList[ii]);
462 if (!pBSS->bActive) {
463 continue;
464 }
465 if (*pvFirstBSS == NULL) {
466 *pvFirstBSS = &(pMgmt->sBSSList[ii]);
467 }
468 uCount++;
469 }
470 *puBSSCount = uCount;
471}
472
473
474
475
476VOID
477VNTWIFIvGetNextBSS (
478 IN PVOID pMgmtHandle,
479 IN PVOID pvCurrentBSS,
480 OUT PVOID *pvNextBSS
481 )
482{
483 PKnownBSS pBSS = (PKnownBSS) pvCurrentBSS;
484 PSMgmtObject pMgmt = (PSMgmtObject)pMgmtHandle;
485
486 *pvNextBSS = NULL;
487
488 while (*pvNextBSS == NULL) {
489 pBSS++;
490 if (pBSS > &(pMgmt->sBSSList[MAX_BSS_NUM])) {
491 return;
492 }
493 if (pBSS->bActive == TRUE) {
494 *pvNextBSS = pBSS;
495 return;
496 }
497 }
498}
499
500
501
502
503
504/*+
505 *
506 * Description:
507 * Update Tx attemps, Tx failure counter in Node DB
508 *
509 * In:
510 * Out:
511 * none
512 *
513 * Return Value: none
514 *
515-*/
516VOID
517VNTWIFIvUpdateNodeTxCounter(
518 IN PVOID pMgmtHandle,
519 IN PBYTE pbyDestAddress,
520 IN BOOL bTxOk,
521 IN WORD wRate,
522 IN PBYTE pbyTxFailCount
523 )
524{
525 PSMgmtObject pMgmt = (PSMgmtObject)pMgmtHandle;
526 UINT uNodeIndex = 0;
527 UINT ii;
528
529 if ((pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) ||
530 (pMgmt->eCurrMode == WMAC_MODE_ESS_AP)) {
531 if (BSSDBbIsSTAInNodeDB(pMgmt, pbyDestAddress, &uNodeIndex) == FALSE) {
532 return;
533 }
534 }
535 pMgmt->sNodeDBTable[uNodeIndex].uTxAttempts++;
536 if (bTxOk == TRUE) {
537 // transmit success, TxAttempts at least plus one
538 pMgmt->sNodeDBTable[uNodeIndex].uTxOk[MAX_RATE]++;
539 pMgmt->sNodeDBTable[uNodeIndex].uTxOk[wRate]++;
540 } else {
541 pMgmt->sNodeDBTable[uNodeIndex].uTxFailures++;
542 }
543 pMgmt->sNodeDBTable[uNodeIndex].uTxRetry += pbyTxFailCount[MAX_RATE];
544 for(ii=0;ii<MAX_RATE;ii++) {
545 pMgmt->sNodeDBTable[uNodeIndex].uTxFail[ii] += pbyTxFailCount[ii];
546 }
547 return;
548}
549
550
551VOID
552VNTWIFIvGetTxRate(
553 IN PVOID pMgmtHandle,
554 IN PBYTE pbyDestAddress,
555 OUT PWORD pwTxDataRate,
556 OUT PBYTE pbyACKRate,
557 OUT PBYTE pbyCCKBasicRate,
558 OUT PBYTE pbyOFDMBasicRate
559 )
560{
561 PSMgmtObject pMgmt = (PSMgmtObject)pMgmtHandle;
562 UINT uNodeIndex = 0;
563 WORD wTxDataRate = RATE_1M;
564 BYTE byACKRate = RATE_1M;
565 BYTE byCCKBasicRate = RATE_1M;
566 BYTE byOFDMBasicRate = RATE_24M;
567 PWLAN_IE_SUPP_RATES pSupportRateIEs = NULL;
568 PWLAN_IE_SUPP_RATES pExtSupportRateIEs = NULL;
569
570
571 if ((pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) ||
572 (pMgmt->eCurrMode == WMAC_MODE_ESS_AP)) {
573 // Adhoc Tx rate decided from node DB
574 if(BSSDBbIsSTAInNodeDB(pMgmt, pbyDestAddress, &uNodeIndex)) {
575 wTxDataRate = (pMgmt->sNodeDBTable[uNodeIndex].wTxDataRate);
576 pSupportRateIEs = (PWLAN_IE_SUPP_RATES) (pMgmt->sNodeDBTable[uNodeIndex].abyCurrSuppRates);
577 pExtSupportRateIEs = (PWLAN_IE_SUPP_RATES) (pMgmt->sNodeDBTable[uNodeIndex].abyCurrExtSuppRates);
578 } else {
579 if (pMgmt->eCurrentPHYMode != PHY_TYPE_11A) {
580 wTxDataRate = RATE_2M;
581 } else {
582 wTxDataRate = RATE_24M;
583 }
584 pSupportRateIEs = (PWLAN_IE_SUPP_RATES) pMgmt->abyCurrSuppRates;
585 pExtSupportRateIEs = (PWLAN_IE_SUPP_RATES) pMgmt->abyCurrExtSuppRates;
586 }
587 } else { // Infrastructure: rate decided from AP Node, index = 0
588
589 wTxDataRate = (pMgmt->sNodeDBTable[0].wTxDataRate);
590#ifdef PLICE_DEBUG
591 printk("GetTxRate:AP MAC is %02x:%02x:%02x:%02x:%02x:%02x,TxRate is %d\n",
592 pMgmt->sNodeDBTable[0].abyMACAddr[0],pMgmt->sNodeDBTable[0].abyMACAddr[1],
593 pMgmt->sNodeDBTable[0].abyMACAddr[2],pMgmt->sNodeDBTable[0].abyMACAddr[3],
594 pMgmt->sNodeDBTable[0].abyMACAddr[4],pMgmt->sNodeDBTable[0].abyMACAddr[5],wTxDataRate);
595#endif
596
597
598 pSupportRateIEs = (PWLAN_IE_SUPP_RATES) pMgmt->abyCurrSuppRates;
599 pExtSupportRateIEs = (PWLAN_IE_SUPP_RATES) pMgmt->abyCurrExtSuppRates;
600 }
601 byACKRate = VNTWIFIbyGetACKTxRate( (BYTE) wTxDataRate,
602 pSupportRateIEs,
603 pExtSupportRateIEs
604 );
605 if (byACKRate > (BYTE) wTxDataRate) {
606 byACKRate = (BYTE) wTxDataRate;
607 }
608 byCCKBasicRate = VNTWIFIbyGetACKTxRate( RATE_11M,
609 pSupportRateIEs,
610 pExtSupportRateIEs
611 );
612 byOFDMBasicRate = VNTWIFIbyGetACKTxRate(RATE_54M,
613 pSupportRateIEs,
614 pExtSupportRateIEs
615 );
616 *pwTxDataRate = wTxDataRate;
617 *pbyACKRate = byACKRate;
618 *pbyCCKBasicRate = byCCKBasicRate;
619 *pbyOFDMBasicRate = byOFDMBasicRate;
620 return;
621}
622
623BYTE
624VNTWIFIbyGetKeyCypher(
625 IN PVOID pMgmtHandle,
626 IN BOOL bGroupKey
627 )
628{
629 PSMgmtObject pMgmt = (PSMgmtObject)pMgmtHandle;
630
631 if (bGroupKey == TRUE) {
632 return (pMgmt->byCSSGK);
633 } else {
634 return (pMgmt->byCSSPK);
635 }
636}
637
638
639/*
640BOOL
641VNTWIFIbInit(
642 IN PVOID pAdapterHandler,
643 OUT PVOID *pMgmtHandler
644 )
645{
646
647 PSMgmtObject pMgmt = NULL;
648 UINT ii;
649
650
651 pMgmt = (PSMgmtObject)kmalloc(sizeof(SMgmtObject), (int)GFP_ATOMIC);
652 if (pMgmt == NULL) {
653 *pMgmtHandler = NULL;
654 return FALSE;
655 }
656
657 memset(pMgmt, 0, sizeof(SMgmtObject));
658 pMgmt->pAdapter = (PVOID) pAdapterHandler;
659
660 // should initial MAC address abyMACAddr
661 for(ii=0;ii<WLAN_BSSID_LEN;ii++) {
662 pMgmt->abyDesireBSSID[ii] = 0xFF;
663 }
664 pMgmt->pbyPSPacketPool = &pMgmt->byPSPacketPool[0];
665 pMgmt->pbyMgmtPacketPool = &pMgmt->byMgmtPacketPool[0];
666 pMgmt->byCSSPK = KEY_CTL_NONE;
667 pMgmt->byCSSGK = KEY_CTL_NONE;
668 pMgmt->wIBSSBeaconPeriod = DEFAULT_IBSS_BI;
669
670 pMgmt->cbFreeCmdQueue = CMD_Q_SIZE;
671 pMgmt->uCmdDequeueIdx = 0;
672 pMgmt->uCmdEnqueueIdx = 0;
673 pMgmt->eCommandState = WLAN_CMD_STATE_IDLE;
674 pMgmt->bCmdStop = FALSE;
675 pMgmt->bCmdRunning = FALSE;
676
677 *pMgmtHandler = pMgmt;
678 return TRUE;
679}
680*/
681
682
683
684BOOL
685VNTWIFIbSetPMKIDCache (
686 IN PVOID pMgmtObject,
687 IN ULONG ulCount,
688 IN PVOID pPMKIDInfo
689 )
690{
691 PSMgmtObject pMgmt = (PSMgmtObject) pMgmtObject;
692
693 if (ulCount > MAX_PMKID_CACHE) {
694 return (FALSE);
695 }
696 pMgmt->gsPMKIDCache.BSSIDInfoCount = ulCount;
697 MEMvCopy(pMgmt->gsPMKIDCache.BSSIDInfo, pPMKIDInfo, (ulCount*sizeof(PMKIDInfo)));
698 return (TRUE);
699}
700
701
702
703WORD
704VNTWIFIwGetMaxSupportRate(
705 IN PVOID pMgmtObject
706 )
707{
708 WORD wRate = RATE_54M;
709 PSMgmtObject pMgmt = (PSMgmtObject) pMgmtObject;
710
711 for(wRate = RATE_54M; wRate > RATE_1M; wRate--) {
712 if (BITbIsBitOn(pMgmt->sNodeDBTable[0].wSuppRate, (1<<wRate))) {
713 return (wRate);
714 }
715 }
716 if (pMgmt->eCurrentPHYMode == PHY_TYPE_11A) {
717 return (RATE_6M);
718 } else {
719 return (RATE_1M);
720 }
721}
722
723
724VOID
725VNTWIFIvSet11h (
726 IN PVOID pMgmtObject,
727 IN BOOL b11hEnable
728 )
729{
730 PSMgmtObject pMgmt = (PSMgmtObject) pMgmtObject;
731
732 pMgmt->b11hEnable = b11hEnable;
733}
734
735BOOL
736VNTWIFIbMeasureReport(
737 IN PVOID pMgmtObject,
738 IN BOOL bEndOfReport,
739 IN PVOID pvMeasureEID,
740 IN BYTE byReportMode,
741 IN BYTE byBasicMap,
742 IN BYTE byCCAFraction,
743 IN PBYTE pbyRPIs
744 )
745{
746 PSMgmtObject pMgmt = (PSMgmtObject) pMgmtObject;
747 PBYTE pbyCurrentEID = (PBYTE) (pMgmt->pCurrMeasureEIDRep);
748
749 //spin_lock_irq(&pDevice->lock);
750 if ((pvMeasureEID != NULL) &&
751 (pMgmt->uLengthOfRepEIDs < (WLAN_A3FR_MAXLEN - sizeof(MEASEURE_REP) - sizeof(WLAN_80211HDR_A3) - 3))
752 ) {
753 pMgmt->pCurrMeasureEIDRep->byElementID = WLAN_EID_MEASURE_REP;
754 pMgmt->pCurrMeasureEIDRep->len = 3;
755 pMgmt->pCurrMeasureEIDRep->byToken = ((PWLAN_IE_MEASURE_REQ) pvMeasureEID)->byToken;
756 pMgmt->pCurrMeasureEIDRep->byMode = byReportMode;
757 pMgmt->pCurrMeasureEIDRep->byType = ((PWLAN_IE_MEASURE_REQ) pvMeasureEID)->byType;
758 switch (pMgmt->pCurrMeasureEIDRep->byType) {
759 case MEASURE_TYPE_BASIC :
760 pMgmt->pCurrMeasureEIDRep->len += sizeof(MEASEURE_REP_BASIC);
761 MEMvCopy( &(pMgmt->pCurrMeasureEIDRep->sRep.sBasic),
762 &(((PWLAN_IE_MEASURE_REQ) pvMeasureEID)->sReq),
763 sizeof(MEASEURE_REQ));
764 pMgmt->pCurrMeasureEIDRep->sRep.sBasic.byMap = byBasicMap;
765 break;
766 case MEASURE_TYPE_CCA :
767 pMgmt->pCurrMeasureEIDRep->len += sizeof(MEASEURE_REP_CCA);
768 MEMvCopy( &(pMgmt->pCurrMeasureEIDRep->sRep.sCCA),
769 &(((PWLAN_IE_MEASURE_REQ) pvMeasureEID)->sReq),
770 sizeof(MEASEURE_REQ));
771 pMgmt->pCurrMeasureEIDRep->sRep.sCCA.byCCABusyFraction = byCCAFraction;
772 break;
773 case MEASURE_TYPE_RPI :
774 pMgmt->pCurrMeasureEIDRep->len += sizeof(MEASEURE_REP_RPI);
775 MEMvCopy( &(pMgmt->pCurrMeasureEIDRep->sRep.sRPI),
776 &(((PWLAN_IE_MEASURE_REQ) pvMeasureEID)->sReq),
777 sizeof(MEASEURE_REQ));
778 MEMvCopy(pMgmt->pCurrMeasureEIDRep->sRep.sRPI.abyRPIdensity, pbyRPIs, 8);
779 break;
780 default :
781 break;
782 }
783 pbyCurrentEID += (2 + pMgmt->pCurrMeasureEIDRep->len);
784 pMgmt->uLengthOfRepEIDs += (2 + pMgmt->pCurrMeasureEIDRep->len);
785 pMgmt->pCurrMeasureEIDRep = (PWLAN_IE_MEASURE_REP) pbyCurrentEID;
786 }
787 if (bEndOfReport == TRUE) {
788 IEEE11hbMSRRepTx(pMgmt);
789 }
790 //spin_unlock_irq(&pDevice->lock);
791 return (TRUE);
792}
793
794
795BOOL
796VNTWIFIbChannelSwitch(
797 IN PVOID pMgmtObject,
798 IN BYTE byNewChannel
799 )
800{
801 PSMgmtObject pMgmt = (PSMgmtObject) pMgmtObject;
802
803 //spin_lock_irq(&pDevice->lock);
804 pMgmt->uCurrChannel = byNewChannel;
805 pMgmt->bSwitchChannel = FALSE;
806 //spin_unlock_irq(&pDevice->lock);
807 return TRUE;
808}
809
810/*
811BOOL
812VNTWIFIbRadarPresent(
813 IN PVOID pMgmtObject,
814 IN BYTE byChannel
815 )
816{
817 PSMgmtObject pMgmt = (PSMgmtObject) pMgmtObject;
818 if ((pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) &&
819 (byChannel == (BYTE) pMgmt->uCurrChannel) &&
820 (pMgmt->bSwitchChannel != TRUE) &&
821 (pMgmt->b11hEnable == TRUE)) {
822 if (IS_ETH_ADDRESS_EQUAL(pMgmt->abyIBSSDFSOwner, CARDpGetCurrentAddress(pMgmt->pAdapter))) {
823 pMgmt->byNewChannel = CARDbyAutoChannelSelect(pMgmt->pAdapter,(BYTE) pMgmt->uCurrChannel);
824 pMgmt->bSwitchChannel = TRUE;
825 }
826 BEACONbSendBeacon(pMgmt);
827 CARDbChannelSwitch(pMgmt->pAdapter, 0, pMgmt->byNewChannel, 10);
828 }
829 return TRUE;
830}
831*/
832
diff --git a/drivers/staging/vt6655/vntwifi.h b/drivers/staging/vt6655/vntwifi.h
new file mode 100644
index 000000000000..3e620a726212
--- /dev/null
+++ b/drivers/staging/vt6655/vntwifi.h
@@ -0,0 +1,330 @@
1/*
2 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
3 * All rights reserved.
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 *
20 * File: vntwifi.h
21 *
22 * Purpose: export VNT Host WiFi library function
23 *
24 * Author: Yiching Chen
25 *
26 * Date: Jan 7, 2004
27 *
28 */
29
30#ifndef __VNTWIFI_H__
31#define __VNTWIFI_H__
32
33#if !defined(__TTYPE_H__)
34#include "ttype.h"
35#endif
36#if !defined(__80211MGR_H__)
37#include "80211mgr.h"
38#endif
39#if !defined(__CARD_H__)
40#include "card.h"
41#endif
42
43/*--------------------- Export Definitions -------------------------*/
44#define RATE_1M 0
45#define RATE_2M 1
46#define RATE_5M 2
47#define RATE_11M 3
48#define RATE_6M 4
49#define RATE_9M 5
50#define RATE_12M 6
51#define RATE_18M 7
52#define RATE_24M 8
53#define RATE_36M 9
54#define RATE_48M 10
55#define RATE_54M 11
56#define RATE_AUTO 12
57#define MAX_RATE 12
58
59// key CipherSuite
60#define KEY_CTL_WEP 0x00
61#define KEY_CTL_NONE 0x01
62#define KEY_CTL_TKIP 0x02
63#define KEY_CTL_CCMP 0x03
64#define KEY_CTL_INVALID 0xFF
65
66#define CHANNEL_MAX_24G 14
67
68#define MAX_BSS_NUM 42
69
70#define MAX_PMKID_CACHE 16
71
72// Pre-configured Authenticaiton Mode (from XP)
73typedef enum tagWMAC_AUTHENTICATION_MODE {
74
75 WMAC_AUTH_OPEN,
76 WMAC_AUTH_SHAREKEY,
77 WMAC_AUTH_AUTO,
78 WMAC_AUTH_WPA,
79 WMAC_AUTH_WPAPSK,
80 WMAC_AUTH_WPANONE,
81 WMAC_AUTH_WPA2,
82 WMAC_AUTH_WPA2PSK,
83 WMAC_AUTH_MAX // Not a real mode, defined as upper bound
84
85} WMAC_AUTHENTICATION_MODE, *PWMAC_AUTHENTICATION_MODE;
86
87typedef enum tagWMAC_ENCRYPTION_MODE {
88
89 WMAC_ENCRYPTION_WEPEnabled,
90 WMAC_ENCRYPTION_WEPDisabled,
91 WMAC_ENCRYPTION_WEPKeyAbsent,
92 WMAC_ENCRYPTION_WEPNotSupported,
93 WMAC_ENCRYPTION_TKIPEnabled,
94 WMAC_ENCRYPTION_TKIPKeyAbsent,
95 WMAC_ENCRYPTION_AESEnabled,
96 WMAC_ENCRYPTION_AESKeyAbsent
97
98} WMAC_ENCRYPTION_MODE, *PWMAC_ENCRYPTION_MODE;
99
100// Pre-configured Mode (from XP)
101
102typedef enum tagWMAC_CONFIG_MODE {
103
104 WMAC_CONFIG_ESS_STA = 0,
105 WMAC_CONFIG_IBSS_STA,
106 WMAC_CONFIG_AUTO,
107 WMAC_CONFIG_AP
108
109} WMAC_CONFIG_MODE, *PWMAC_CONFIG_MODE;
110
111
112
113typedef enum tagWMAC_POWER_MODE {
114
115 WMAC_POWER_CAM,
116 WMAC_POWER_FAST,
117 WMAC_POWER_MAX
118
119} WMAC_POWER_MODE, *PWMAC_POWER_MODE;
120
121#define VNTWIFIbIsShortSlotTime(wCapInfo) \
122 WLAN_GET_CAP_INFO_SHORTSLOTTIME(wCapInfo) \
123
124#define VNTWIFIbIsProtectMode(byERP) \
125 ((byERP & WLAN_EID_ERP_USE_PROTECTION) != 0) \
126
127#define VNTWIFIbIsBarkerMode(byERP) \
128 ((byERP & WLAN_EID_ERP_BARKER_MODE) != 0) \
129
130#define VNTWIFIbIsShortPreamble(wCapInfo) \
131 WLAN_GET_CAP_INFO_SHORTPREAMBLE(wCapInfo) \
132
133#define VNTWIFIbIsEncryption(wCapInfo) \
134 WLAN_GET_CAP_INFO_PRIVACY(wCapInfo) \
135
136#define VNTWIFIbIsESS(wCapInfo) \
137 WLAN_GET_CAP_INFO_ESS(wCapInfo) \
138
139
140/*--------------------- Export Classes ----------------------------*/
141
142/*--------------------- Export Variables --------------------------*/
143
144
145/*--------------------- Export Types ------------------------------*/
146
147
148/*--------------------- Export Functions --------------------------*/
149
150#ifdef __cplusplus
151extern "C" { /* Assume C declarations for C++ */
152#endif /* __cplusplus */
153
154
155VOID
156VNTWIFIvSetIBSSParameter (
157 IN PVOID pMgmtHandle,
158 IN WORD wBeaconPeriod,
159 IN WORD wATIMWindow,
160 IN UINT uChannel
161 );
162
163VOID
164VNTWIFIvSetOPMode (
165 IN PVOID pMgmtHandle,
166 IN WMAC_CONFIG_MODE eOPMode
167 );
168
169PWLAN_IE_SSID
170VNTWIFIpGetCurrentSSID(
171 IN PVOID pMgmtHandle
172 );
173
174UINT
175VNTWIFIpGetCurrentChannel(
176 IN PVOID pMgmtHandle
177 );
178
179WORD
180VNTWIFIwGetAssocID (
181 IN PVOID pMgmtHandle
182 );
183
184BYTE
185VNTWIFIbyGetMaxSupportRate (
186 IN PWLAN_IE_SUPP_RATES pSupportRateIEs,
187 IN PWLAN_IE_SUPP_RATES pExtSupportRateIEs
188 );
189
190BYTE
191VNTWIFIbyGetACKTxRate (
192 IN BYTE byRxDataRate,
193 IN PWLAN_IE_SUPP_RATES pSupportRateIEs,
194 IN PWLAN_IE_SUPP_RATES pExtSupportRateIEs
195 );
196
197VOID
198VNTWIFIvSetAuthenticationMode (
199 IN PVOID pMgmtHandle,
200 IN WMAC_AUTHENTICATION_MODE eAuthMode
201 );
202
203VOID
204VNTWIFIvSetEncryptionMode (
205 IN PVOID pMgmtHandle,
206 IN WMAC_ENCRYPTION_MODE eEncryptionMode
207 );
208
209
210BOOL
211VNTWIFIbConfigPhyMode(
212 IN PVOID pMgmtHandle,
213 IN CARD_PHY_TYPE ePhyType
214 );
215
216VOID
217VNTWIFIbGetConfigPhyMode(
218 IN PVOID pMgmtHandle,
219 OUT PVOID pePhyType
220 );
221
222VOID
223VNTWIFIvQueryBSSList(
224 IN PVOID pMgmtHandle,
225 OUT PUINT puBSSCount,
226 OUT PVOID *pvFirstBSS
227 );
228
229
230
231
232VOID
233VNTWIFIvGetNextBSS (
234 IN PVOID pMgmtHandle,
235 IN PVOID pvCurrentBSS,
236 OUT PVOID *pvNextBSS
237 );
238
239
240
241VOID
242VNTWIFIvUpdateNodeTxCounter(
243 IN PVOID pMgmtHandle,
244 IN PBYTE pbyDestAddress,
245 IN BOOL bTxOk,
246 IN WORD wRate,
247 IN PBYTE pbyTxFailCount
248 );
249
250
251VOID
252VNTWIFIvGetTxRate(
253 IN PVOID pMgmtHandle,
254 IN PBYTE pbyDestAddress,
255 OUT PWORD pwTxDataRate,
256 OUT PBYTE pbyACKRate,
257 OUT PBYTE pbyCCKBasicRate,
258 OUT PBYTE pbyOFDMBasicRate
259 );
260/*
261BOOL
262VNTWIFIbInit(
263 IN PVOID pAdapterHandler,
264 OUT PVOID *pMgmtHandler
265 );
266*/
267
268BYTE
269VNTWIFIbyGetKeyCypher(
270 IN PVOID pMgmtHandle,
271 IN BOOL bGroupKey
272 );
273
274
275
276
277BOOL
278VNTWIFIbSetPMKIDCache (
279 IN PVOID pMgmtObject,
280 IN ULONG ulCount,
281 IN PVOID pPMKIDInfo
282 );
283
284BOOL
285VNTWIFIbCommandRunning (
286 IN PVOID pMgmtObject
287 );
288
289WORD
290VNTWIFIwGetMaxSupportRate(
291 IN PVOID pMgmtObject
292 );
293
294// for 802.11h
295VOID
296VNTWIFIvSet11h (
297 IN PVOID pMgmtObject,
298 IN BOOL b11hEnable
299 );
300
301BOOL
302VNTWIFIbMeasureReport(
303 IN PVOID pMgmtObject,
304 IN BOOL bEndOfReport,
305 IN PVOID pvMeasureEID,
306 IN BYTE byReportMode,
307 IN BYTE byBasicMap,
308 IN BYTE byCCAFraction,
309 IN PBYTE pbyRPIs
310 );
311
312BOOL
313VNTWIFIbChannelSwitch(
314 IN PVOID pMgmtObject,
315 IN BYTE byNewChannel
316 );
317/*
318BOOL
319VNTWIFIbRadarPresent(
320 IN PVOID pMgmtObject,
321 IN BYTE byChannel
322 );
323*/
324
325#ifdef __cplusplus
326} /* End of extern "C" { */
327#endif /* __cplusplus */
328
329
330#endif //__VNTWIFI_H__
diff --git a/drivers/staging/vt6655/wcmd.c b/drivers/staging/vt6655/wcmd.c
new file mode 100644
index 000000000000..92563bd011b2
--- /dev/null
+++ b/drivers/staging/vt6655/wcmd.c
@@ -0,0 +1,1178 @@
1 /*
2 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
3 * All rights reserved.
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 *
20 * File: wcmd.c
21 *
22 * Purpose: Handles the management command interface functions
23 *
24 * Author: Lyndon Chen
25 *
26 * Date: May 8, 2003
27 *
28 * Functions:
29 * s_vProbeChannel - Active scan channel
30 * s_MgrMakeProbeRequest - Make ProbeRequest packet
31 * CommandTimer - Timer function to handle command
32 * s_bCommandComplete - Command Complete function
33 * bScheduleCommand - Push Command and wait Command Scheduler to do
34 * vCommandTimer- Command call back functions
35 * vCommandTimerWait- Call back timer
36 * bClearBSSID_SCAN- Clear BSSID_SCAN cmd in CMD Queue
37 *
38 * Revision History:
39 *
40 */
41
42
43
44
45#if !defined(__TTYPE_H__)
46#include "ttype.h"
47#endif
48#if !defined(__TMACRO_H__)
49#include "tmacro.h"
50#endif
51#if !defined(__DEVICE_H__)
52#include "device.h"
53#endif
54#if !defined(__MAC_H__)
55#include "mac.h"
56#endif
57#if !defined(__CARD_H__)
58#include "card.h"
59#endif
60#if !defined(__80211HDR_H__)
61#include "80211hdr.h"
62#endif
63#if !defined(__WCMD_H__)
64#include "wcmd.h"
65#endif
66#if !defined(__WMGR_H__)
67#include "wmgr.h"
68#endif
69#if !defined(__POWER_H__)
70#include "power.h"
71#endif
72#if !defined(__WCTL_H__)
73#include "wctl.h"
74#endif
75#if !defined(__CARD_H__)
76#include "card.h"
77#endif
78#if !defined(__BASEBAND_H__)
79#include "baseband.h"
80#endif
81#if !defined(__UMEM_H__)
82#include "umem.h"
83#endif
84#if !defined(__RXTX_H__)
85#include "rxtx.h"
86#endif
87#if !defined(__RF_H__)
88#include "rf.h"
89#endif
90//DavidWang
91#if !defined(__IOWPA_H__)
92#include "iowpa.h"
93#endif
94
95/*--------------------- Static Definitions -------------------------*/
96
97
98
99
100/*--------------------- Static Classes ----------------------------*/
101
102/*--------------------- Static Variables --------------------------*/
103static int msglevel =MSG_LEVEL_INFO;
104//static int msglevel =MSG_LEVEL_DEBUG;
105/*--------------------- Static Functions --------------------------*/
106
107static
108VOID
109s_vProbeChannel(
110 IN PSDevice pDevice
111 );
112
113
114static
115PSTxMgmtPacket
116s_MgrMakeProbeRequest(
117 IN PSDevice pDevice,
118 IN PSMgmtObject pMgmt,
119 IN PBYTE pScanBSSID,
120 IN PWLAN_IE_SSID pSSID,
121 IN PWLAN_IE_SUPP_RATES pCurrRates,
122 IN PWLAN_IE_SUPP_RATES pCurrExtSuppRates
123 );
124
125static
126BOOL
127s_bCommandComplete (
128 PSDevice pDevice
129 );
130
131/*--------------------- Export Variables --------------------------*/
132
133
134/*--------------------- Export Functions --------------------------*/
135
136
137/*
138 * Description:
139 * Stop AdHoc beacon during scan process
140 *
141 * Parameters:
142 * In:
143 * pDevice - Pointer to the adapter
144 * Out:
145 * none
146 *
147 * Return Value: none
148 *
149 */
150static
151void
152vAdHocBeaconStop(PSDevice pDevice)
153{
154
155 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
156 BOOL bStop;
157
158 /*
159 * temporarily stop Beacon packet for AdHoc Server
160 * if all of the following coditions are met:
161 * (1) STA is in AdHoc mode
162 * (2) VT3253 is programmed as automatic Beacon Transmitting
163 * (3) One of the following conditions is met
164 * (3.1) AdHoc channel is in B/G band and the
165 * current scan channel is in A band
166 * or
167 * (3.2) AdHoc channel is in A mode
168 */
169 bStop = FALSE;
170 if ((pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) &&
171 (pMgmt->eCurrState >= WMAC_STATE_STARTED))
172 {
173 if ((pMgmt->uIBSSChannel <= CB_MAX_CHANNEL_24G) &&
174 (pMgmt->uScanChannel > CB_MAX_CHANNEL_24G))
175 {
176 bStop = TRUE;
177 }
178 if (pMgmt->uIBSSChannel > CB_MAX_CHANNEL_24G)
179 {
180 bStop = TRUE;
181 }
182 }
183
184 if (bStop)
185 {
186 MACvRegBitsOff(pDevice->PortOffset, MAC_REG_TCR, TCR_AUTOBCNTX);
187 }
188
189}
190
191/*
192 * Description:
193 * Restart AdHoc beacon after scan process complete
194 *
195 * Parameters:
196 * In:
197 * pDevice - Pointer to the adapter
198 * Out:
199 * none
200 *
201 * Return Value: none
202 *
203 */
204static
205void
206vAdHocBeaconRestart(PSDevice pDevice)
207{
208 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
209
210 /*
211 * Restart Beacon packet for AdHoc Server
212 * if all of the following coditions are met:
213 * (1) STA is in AdHoc mode
214 * (2) VT3253 is programmed as automatic Beacon Transmitting
215 */
216 if ((pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) &&
217 (pMgmt->eCurrState >= WMAC_STATE_STARTED))
218 {
219 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_TCR, TCR_AUTOBCNTX);
220 }
221
222}
223
224
225
226
227/*+
228 *
229 * Routine Description:
230 * Prepare and send probe request management frames.
231 *
232 *
233 * Return Value:
234 * none.
235 *
236-*/
237
238static
239VOID
240s_vProbeChannel(
241 IN PSDevice pDevice
242 )
243{
244 //1M, 2M, 5M, 11M, 18M, 24M, 36M, 54M
245 BYTE abyCurrSuppRatesG[] = {WLAN_EID_SUPP_RATES, 8, 0x02, 0x04, 0x0B, 0x16, 0x24, 0x30, 0x48, 0x6C};
246 BYTE abyCurrExtSuppRatesG[] = {WLAN_EID_EXTSUPP_RATES, 4, 0x0C, 0x12, 0x18, 0x60};
247 //6M, 9M, 12M, 48M
248 BYTE abyCurrSuppRatesA[] = {WLAN_EID_SUPP_RATES, 8, 0x0C, 0x12, 0x18, 0x24, 0x30, 0x48, 0x60, 0x6C};
249 BYTE abyCurrSuppRatesB[] = {WLAN_EID_SUPP_RATES, 4, 0x02, 0x04, 0x0B, 0x16};
250 PBYTE pbyRate;
251 PSTxMgmtPacket pTxPacket;
252 PSMgmtObject pMgmt = pDevice->pMgmt;
253 UINT ii;
254
255
256 if (pDevice->eCurrentPHYType == PHY_TYPE_11A) {
257 pbyRate = &abyCurrSuppRatesA[0];
258 } else if (pDevice->eCurrentPHYType == PHY_TYPE_11B) {
259 pbyRate = &abyCurrSuppRatesB[0];
260 } else {
261 pbyRate = &abyCurrSuppRatesG[0];
262 }
263 // build an assocreq frame and send it
264 pTxPacket = s_MgrMakeProbeRequest
265 (
266 pDevice,
267 pMgmt,
268 pMgmt->abyScanBSSID,
269 (PWLAN_IE_SSID)pMgmt->abyScanSSID,
270 (PWLAN_IE_SUPP_RATES)pbyRate,
271 (PWLAN_IE_SUPP_RATES)abyCurrExtSuppRatesG
272 );
273
274 if (pTxPacket != NULL ){
275 for (ii = 0; ii < 2 ; ii++) {
276 if (csMgmt_xmit(pDevice, pTxPacket) != CMD_STATUS_PENDING) {
277 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Probe request sending fail.. \n");
278 }
279 else {
280 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Probe request is sending.. \n");
281 }
282 }
283 }
284
285}
286
287
288
289
290/*+
291 *
292 * Routine Description:
293 * Constructs an probe request frame
294 *
295 *
296 * Return Value:
297 * A ptr to Tx frame or NULL on allocation failue
298 *
299-*/
300
301
302PSTxMgmtPacket
303s_MgrMakeProbeRequest(
304 IN PSDevice pDevice,
305 IN PSMgmtObject pMgmt,
306 IN PBYTE pScanBSSID,
307 IN PWLAN_IE_SSID pSSID,
308 IN PWLAN_IE_SUPP_RATES pCurrRates,
309 IN PWLAN_IE_SUPP_RATES pCurrExtSuppRates
310
311 )
312{
313 PSTxMgmtPacket pTxPacket = NULL;
314 WLAN_FR_PROBEREQ sFrame;
315
316
317 pTxPacket = (PSTxMgmtPacket)pMgmt->pbyMgmtPacketPool;
318 memset(pTxPacket, 0, sizeof(STxMgmtPacket) + WLAN_PROBEREQ_FR_MAXLEN);
319 pTxPacket->p80211Header = (PUWLAN_80211HDR)((PBYTE)pTxPacket + sizeof(STxMgmtPacket));
320 sFrame.pBuf = (PBYTE)pTxPacket->p80211Header;
321 sFrame.len = WLAN_PROBEREQ_FR_MAXLEN;
322 vMgrEncodeProbeRequest(&sFrame);
323 sFrame.pHdr->sA3.wFrameCtl = cpu_to_le16(
324 (
325 WLAN_SET_FC_FTYPE(WLAN_TYPE_MGR) |
326 WLAN_SET_FC_FSTYPE(WLAN_FSTYPE_PROBEREQ)
327 ));
328 memcpy( sFrame.pHdr->sA3.abyAddr1, pScanBSSID, WLAN_ADDR_LEN);
329 memcpy( sFrame.pHdr->sA3.abyAddr2, pMgmt->abyMACAddr, WLAN_ADDR_LEN);
330 memcpy( sFrame.pHdr->sA3.abyAddr3, pScanBSSID, WLAN_BSSID_LEN);
331 // Copy the SSID, pSSID->len=0 indicate broadcast SSID
332 sFrame.pSSID = (PWLAN_IE_SSID)(sFrame.pBuf + sFrame.len);
333 sFrame.len += pSSID->len + WLAN_IEHDR_LEN;
334 memcpy(sFrame.pSSID, pSSID, pSSID->len + WLAN_IEHDR_LEN);
335 sFrame.pSuppRates = (PWLAN_IE_SUPP_RATES)(sFrame.pBuf + sFrame.len);
336 sFrame.len += pCurrRates->len + WLAN_IEHDR_LEN;
337 memcpy(sFrame.pSuppRates, pCurrRates, pCurrRates->len + WLAN_IEHDR_LEN);
338 // Copy the extension rate set
339 if (pDevice->eCurrentPHYType == PHY_TYPE_11G) {
340 sFrame.pExtSuppRates = (PWLAN_IE_SUPP_RATES)(sFrame.pBuf + sFrame.len);
341 sFrame.len += pCurrExtSuppRates->len + WLAN_IEHDR_LEN;
342 memcpy(sFrame.pExtSuppRates, pCurrExtSuppRates, pCurrExtSuppRates->len + WLAN_IEHDR_LEN);
343 }
344 pTxPacket->cbMPDULen = sFrame.len;
345 pTxPacket->cbPayloadLen = sFrame.len - WLAN_HDR_ADDR3_LEN;
346
347 return pTxPacket;
348}
349
350
351
352
353VOID
354vCommandTimerWait(
355 IN HANDLE hDeviceContext,
356 IN UINT MSecond
357 )
358{
359 PSDevice pDevice = (PSDevice)hDeviceContext;
360
361 init_timer(&pDevice->sTimerCommand);
362 pDevice->sTimerCommand.data = (ULONG)pDevice;
363 pDevice->sTimerCommand.function = (TimerFunction)vCommandTimer;
364 // RUN_AT :1 msec ~= (HZ/1024)
365 pDevice->sTimerCommand.expires = (UINT)RUN_AT((MSecond * HZ) >> 10);
366 add_timer(&pDevice->sTimerCommand);
367 return;
368}
369
370
371
372VOID
373vCommandTimer (
374 IN HANDLE hDeviceContext
375 )
376{
377 PSDevice pDevice = (PSDevice)hDeviceContext;
378 PSMgmtObject pMgmt = pDevice->pMgmt;
379 PWLAN_IE_SSID pItemSSID;
380 PWLAN_IE_SSID pItemSSIDCurr;
381 CMD_STATUS Status;
382 UINT ii;
383 BYTE byMask[8] = {1, 2, 4, 8, 0x10, 0x20, 0x40, 0x80};
384 struct sk_buff *skb;
385
386
387 if (pDevice->dwDiagRefCount != 0)
388 return;
389 if (pDevice->bCmdRunning != TRUE)
390 return;
391
392 spin_lock_irq(&pDevice->lock);
393
394 switch ( pDevice->eCommandState ) {
395
396 case WLAN_CMD_SCAN_START:
397
398 pDevice->byReAssocCount = 0;
399 if (pDevice->bRadioOff == TRUE) {
400 s_bCommandComplete(pDevice);
401 spin_unlock_irq(&pDevice->lock);
402 return;
403 }
404
405 if (pMgmt->eCurrMode == WMAC_MODE_ESS_AP) {
406 s_bCommandComplete(pDevice);
407 CARDbSetBSSID(pMgmt->pAdapter, pMgmt->abyCurrBSSID, OP_MODE_AP);
408 spin_unlock_irq(&pDevice->lock);
409 return;
410 }
411
412 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"eCommandState= WLAN_CMD_SCAN_START\n");
413 pItemSSID = (PWLAN_IE_SSID)pMgmt->abyScanSSID;
414 // wait all Data TD complete
415 if (pDevice->iTDUsed[TYPE_AC0DMA] != 0){
416 spin_unlock_irq(&pDevice->lock);
417 vCommandTimerWait((HANDLE)pDevice, 10);
418 return;
419 };
420
421 if (pMgmt->uScanChannel == 0 ) {
422 pMgmt->uScanChannel = pDevice->byMinChannel;
423 // Set Baseband to be more sensitive.
424
425 }
426 if (pMgmt->uScanChannel > pDevice->byMaxChannel) {
427 pMgmt->eScanState = WMAC_NO_SCANNING;
428
429 // Set Baseband's sensitivity back.
430 // Set channel back
431 CARDbSetChannel(pMgmt->pAdapter, pMgmt->uCurrChannel);
432 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Scanning, set back to channel: [%d]\n", pMgmt->uCurrChannel);
433 if (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) {
434 CARDbSetBSSID(pMgmt->pAdapter, pMgmt->abyCurrBSSID, OP_MODE_ADHOC);
435 } else {
436 CARDbSetBSSID(pMgmt->pAdapter, pMgmt->abyCurrBSSID, OP_MODE_INFRASTRUCTURE);
437 }
438 vAdHocBeaconRestart(pDevice);
439 s_bCommandComplete(pDevice);
440
441 } else {
442//2008-8-4 <add> by chester
443 if (!ChannelValid(pDevice->byZoneType, pMgmt->uScanChannel)) {
444 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Invalid channel pMgmt->uScanChannel = %d \n",pMgmt->uScanChannel);
445 s_bCommandComplete(pDevice);
446 return;
447 }
448//printk("chester-pMgmt->uScanChannel=%d,pDevice->byMaxChannel=%d\n",pMgmt->uScanChannel,pDevice->byMaxChannel);
449 if (pMgmt->uScanChannel == pDevice->byMinChannel) {
450 //pMgmt->eScanType = WMAC_SCAN_ACTIVE;
451 pMgmt->abyScanBSSID[0] = 0xFF;
452 pMgmt->abyScanBSSID[1] = 0xFF;
453 pMgmt->abyScanBSSID[2] = 0xFF;
454 pMgmt->abyScanBSSID[3] = 0xFF;
455 pMgmt->abyScanBSSID[4] = 0xFF;
456 pMgmt->abyScanBSSID[5] = 0xFF;
457 pItemSSID->byElementID = WLAN_EID_SSID;
458 // clear bssid list
459 // BSSvClearBSSList((HANDLE)pDevice, pDevice->bLinkPass);
460 pMgmt->eScanState = WMAC_IS_SCANNING;
461
462 }
463
464 vAdHocBeaconStop(pDevice);
465
466 if (CARDbSetChannel(pMgmt->pAdapter, pMgmt->uScanChannel) == TRUE) {
467 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"SCAN Channel: %d\n", pMgmt->uScanChannel);
468 } else {
469 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"SET SCAN Channel Fail: %d\n", pMgmt->uScanChannel);
470 }
471 CARDbSetBSSID(pMgmt->pAdapter, pMgmt->abyCurrBSSID, OP_MODE_UNKNOWN);
472// printk("chester-mxch=%d\n",pDevice->byMaxChannel);
473 // printk("chester-ch=%d\n",pMgmt->uScanChannel);
474 pMgmt->uScanChannel++;
475//2008-8-4 <modify> by chester
476 if (!ChannelValid(pDevice->byZoneType, pMgmt->uScanChannel) &&
477 pMgmt->uScanChannel <= pDevice->byMaxChannel ){
478 pMgmt->uScanChannel=pDevice->byMaxChannel+1;
479 pMgmt->eCommandState = WLAN_CMD_SCAN_END;
480
481 }
482
483
484 if ((pMgmt->b11hEnable == FALSE) ||
485 (pMgmt->uScanChannel < CB_MAX_CHANNEL_24G)) {
486 s_vProbeChannel(pDevice);
487 spin_unlock_irq(&pDevice->lock);
488 vCommandTimerWait((HANDLE)pDevice, WCMD_ACTIVE_SCAN_TIME);
489 return;
490 } else {
491 spin_unlock_irq(&pDevice->lock);
492 vCommandTimerWait((HANDLE)pDevice, WCMD_PASSIVE_SCAN_TIME);
493 return;
494 }
495
496 }
497
498 break;
499
500 case WLAN_CMD_SCAN_END:
501
502 // Set Baseband's sensitivity back.
503 // Set channel back
504 CARDbSetChannel(pMgmt->pAdapter, pMgmt->uCurrChannel);
505 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Scanning, set back to channel: [%d]\n", pMgmt->uCurrChannel);
506 if (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) {
507 CARDbSetBSSID(pMgmt->pAdapter, pMgmt->abyCurrBSSID, OP_MODE_ADHOC);
508 } else {
509 CARDbSetBSSID(pMgmt->pAdapter, pMgmt->abyCurrBSSID, OP_MODE_INFRASTRUCTURE);
510 }
511
512 pMgmt->eScanState = WMAC_NO_SCANNING;
513 vAdHocBeaconRestart(pDevice);
514//2008-0409-07, <Add> by Einsn Liu
515#ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
516 if(pMgmt->eScanType == WMAC_SCAN_PASSIVE)
517 {//send scan event to wpa_Supplicant
518 union iwreq_data wrqu;
519 memset(&wrqu, 0, sizeof(wrqu));
520 wireless_send_event(pDevice->dev, SIOCGIWSCAN, &wrqu, NULL);
521 }
522#endif
523 s_bCommandComplete(pDevice);
524 break;
525
526 case WLAN_CMD_DISASSOCIATE_START :
527 pDevice->byReAssocCount = 0;
528 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_STA) &&
529 (pMgmt->eCurrState != WMAC_STATE_ASSOC)) {
530 s_bCommandComplete(pDevice);
531 spin_unlock_irq(&pDevice->lock);
532 return;
533 } else {
534 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Send Disassociation Packet..\n");
535 // reason = 8 : disassoc because sta has left
536 vMgrDisassocBeginSta((HANDLE)pDevice, pMgmt, pMgmt->abyCurrBSSID, (8), &Status);
537 pDevice->bLinkPass = FALSE;
538 // unlock command busy
539 pItemSSID = (PWLAN_IE_SSID)pMgmt->abyCurrSSID;
540 pItemSSID->len = 0;
541 memset(pItemSSID->abySSID, 0, WLAN_SSID_MAXLEN);
542 pMgmt->eCurrState = WMAC_STATE_IDLE;
543 pMgmt->sNodeDBTable[0].bActive = FALSE;
544// pDevice->bBeaconBufReady = FALSE;
545 }
546 netif_stop_queue(pDevice->dev);
547 pDevice->eCommandState = WLAN_DISASSOCIATE_WAIT;
548 // wait all Control TD complete
549 if (pDevice->iTDUsed[TYPE_TXDMA0] != 0){
550 vCommandTimerWait((HANDLE)pDevice, 10);
551 spin_unlock_irq(&pDevice->lock);
552 return;
553 };
554 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO" CARDbRadioPowerOff\n");
555 //2008-09-02 <mark> by chester
556 // CARDbRadioPowerOff(pDevice);
557 s_bCommandComplete(pDevice);
558 break;
559
560 case WLAN_DISASSOCIATE_WAIT :
561 // wait all Control TD complete
562 if (pDevice->iTDUsed[TYPE_TXDMA0] != 0){
563 vCommandTimerWait((HANDLE)pDevice, 10);
564 spin_unlock_irq(&pDevice->lock);
565 return;
566 };
567//2008-09-02 <mark> by chester
568 // CARDbRadioPowerOff(pDevice);
569 s_bCommandComplete(pDevice);
570 break;
571
572 case WLAN_CMD_SSID_START:
573 pDevice->byReAssocCount = 0;
574 if (pDevice->bRadioOff == TRUE) {
575 s_bCommandComplete(pDevice);
576 spin_unlock_irq(&pDevice->lock);
577 return;
578 }
579//printk("chester-currmode=%d\n",pMgmt->eCurrMode);
580printk("chester-abyDesireSSID=%s\n",((PWLAN_IE_SSID)pMgmt->abyDesireSSID)->abySSID);
581 //memcpy(pMgmt->abyAdHocSSID,pMgmt->abyDesireSSID,
582 //((PWLAN_IE_SSID)pMgmt->abyDesireSSID)->len + WLAN_IEHDR_LEN);
583 pItemSSID = (PWLAN_IE_SSID)pMgmt->abyDesireSSID;
584 pItemSSIDCurr = (PWLAN_IE_SSID)pMgmt->abyCurrSSID;
585 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO" cmd: desire ssid = %s\n", pItemSSID->abySSID);
586 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO" cmd: curr ssid = %s\n", pItemSSIDCurr->abySSID);
587
588 if (pMgmt->eCurrState == WMAC_STATE_ASSOC) {
589 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO" Cmd pMgmt->eCurrState == WMAC_STATE_ASSOC\n");
590 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO" pItemSSID->len =%d\n",pItemSSID->len);
591 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO" pItemSSIDCurr->len = %d\n",pItemSSIDCurr->len);
592 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO" desire ssid = %s\n", pItemSSID->abySSID);
593 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO" curr ssid = %s\n", pItemSSIDCurr->abySSID);
594 }
595
596 if ((pMgmt->eCurrState == WMAC_STATE_ASSOC) ||
597 ((pMgmt->eCurrMode == WMAC_MODE_IBSS_STA)&& (pMgmt->eCurrState == WMAC_STATE_JOINTED))) {
598
599 if (pItemSSID->len == pItemSSIDCurr->len) {
600 if (memcmp(pItemSSID->abySSID, pItemSSIDCurr->abySSID, pItemSSID->len) == 0) {
601 s_bCommandComplete(pDevice);
602 spin_unlock_irq(&pDevice->lock);
603 return;
604 }
605 }
606
607 netif_stop_queue(pDevice->dev);
608 pDevice->bLinkPass = FALSE;
609 }
610 // set initial state
611 pMgmt->eCurrState = WMAC_STATE_IDLE;
612 pMgmt->eCurrMode = WMAC_MODE_STANDBY;
613 PSvDisablePowerSaving((HANDLE)pDevice);
614 BSSvClearNodeDBTable(pDevice, 0);
615
616 vMgrJoinBSSBegin((HANDLE)pDevice, &Status);
617 // if Infra mode
618 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_STA) && (pMgmt->eCurrState == WMAC_STATE_JOINTED)) {
619
620 // Call mgr to begin the deauthentication
621 // reason = (3) beacuse sta has left ESS
622 if (pMgmt->eCurrState>= WMAC_STATE_AUTH) {
623 vMgrDeAuthenBeginSta((HANDLE)pDevice, pMgmt, pMgmt->abyCurrBSSID, (3), &Status);
624 }
625 // Call mgr to begin the authentication
626 vMgrAuthenBeginSta((HANDLE)pDevice, pMgmt, &Status);
627 if (Status == CMD_STATUS_SUCCESS) {
628 pDevice->byLinkWaitCount = 0;
629 pDevice->eCommandState = WLAN_AUTHENTICATE_WAIT;
630 vCommandTimerWait((HANDLE)pDevice, AUTHENTICATE_TIMEOUT);
631 spin_unlock_irq(&pDevice->lock);
632 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO" Set eCommandState = WLAN_AUTHENTICATE_WAIT\n");
633 return;
634 }
635 }
636 // if Adhoc mode
637 else if (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) {
638 if (pMgmt->eCurrState == WMAC_STATE_JOINTED) {
639 if (netif_queue_stopped(pDevice->dev)){
640 netif_wake_queue(pDevice->dev);
641 }
642 pDevice->bLinkPass = TRUE;
643
644 pMgmt->sNodeDBTable[0].bActive = TRUE;
645 pMgmt->sNodeDBTable[0].uInActiveCount = 0;
646 bClearBSSID_SCAN(pDevice);
647 }
648 else {
649 // start own IBSS
650 vMgrCreateOwnIBSS((HANDLE)pDevice, &Status);
651 if (Status != CMD_STATUS_SUCCESS){
652 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO " WLAN_CMD_IBSS_CREATE fail ! \n");
653 };
654 BSSvAddMulticastNode(pDevice);
655 }
656 }
657 // if SSID not found
658 else if (pMgmt->eCurrMode == WMAC_MODE_STANDBY) {
659 if (pMgmt->eConfigMode == WMAC_CONFIG_IBSS_STA ||
660 pMgmt->eConfigMode == WMAC_CONFIG_AUTO) {
661 // start own IBSS
662 vMgrCreateOwnIBSS((HANDLE)pDevice, &Status);
663 if (Status != CMD_STATUS_SUCCESS){
664 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO" WLAN_CMD_IBSS_CREATE fail ! \n");
665 };
666 BSSvAddMulticastNode(pDevice);
667 if (netif_queue_stopped(pDevice->dev)){
668 netif_wake_queue(pDevice->dev);
669 }
670 pDevice->bLinkPass = TRUE;
671 }
672 else {
673 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Disconnect SSID none\n");
674 #ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
675 // if(pDevice->bWPASuppWextEnabled == TRUE)
676 {
677 union iwreq_data wrqu;
678 memset(&wrqu, 0, sizeof (wrqu));
679 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
680 printk("wireless_send_event--->SIOCGIWAP(disassociated:vMgrJoinBSSBegin Fail !!)\n");
681 wireless_send_event(pDevice->dev, SIOCGIWAP, &wrqu, NULL);
682 }
683 #endif
684
685 }
686 }
687 s_bCommandComplete(pDevice);
688 break;
689
690 case WLAN_AUTHENTICATE_WAIT :
691 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"eCommandState == WLAN_AUTHENTICATE_WAIT\n");
692 if (pMgmt->eCurrState == WMAC_STATE_AUTH) {
693 // Call mgr to begin the association
694 pDevice->byLinkWaitCount = 0;
695 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"eCurrState == WMAC_STATE_AUTH\n");
696 vMgrAssocBeginSta((HANDLE)pDevice, pMgmt, &Status);
697 if (Status == CMD_STATUS_SUCCESS) {
698 pDevice->byLinkWaitCount = 0;
699 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"eCommandState = WLAN_ASSOCIATE_WAIT\n");
700 pDevice->eCommandState = WLAN_ASSOCIATE_WAIT;
701 vCommandTimerWait((HANDLE)pDevice, ASSOCIATE_TIMEOUT);
702 spin_unlock_irq(&pDevice->lock);
703 return;
704 }
705 }
706
707 else if(pMgmt->eCurrState < WMAC_STATE_AUTHPENDING) {
708 printk("WLAN_AUTHENTICATE_WAIT:Authen Fail???\n");
709 }
710 else if(pDevice->byLinkWaitCount <= 4){ //mike add:wait another 2 sec if authenticated_frame delay!
711 pDevice->byLinkWaitCount ++;
712 printk("WLAN_AUTHENTICATE_WAIT:wait %d times!!\n",pDevice->byLinkWaitCount);
713 spin_unlock_irq(&pDevice->lock);
714 vCommandTimerWait((HANDLE)pDevice, AUTHENTICATE_TIMEOUT/2);
715 return;
716 }
717 pDevice->byLinkWaitCount = 0;
718 #if 0
719 #ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
720 // if(pDevice->bWPASuppWextEnabled == TRUE)
721 {
722 union iwreq_data wrqu;
723 memset(&wrqu, 0, sizeof (wrqu));
724 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
725 printk("wireless_send_event--->SIOCGIWAP(disassociated:AUTHENTICATE_WAIT_timeout)\n");
726 wireless_send_event(pDevice->dev, SIOCGIWAP, &wrqu, NULL);
727 }
728 #endif
729 #endif
730 s_bCommandComplete(pDevice);
731 break;
732
733 case WLAN_ASSOCIATE_WAIT :
734 if (pMgmt->eCurrState == WMAC_STATE_ASSOC) {
735 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"eCurrState == WMAC_STATE_ASSOC\n");
736 if (pDevice->ePSMode != WMAC_POWER_CAM) {
737 PSvEnablePowerSaving((HANDLE)pDevice, pMgmt->wListenInterval);
738 }
739 if (pMgmt->eAuthenMode >= WMAC_AUTH_WPA) {
740 KeybRemoveAllKey(&(pDevice->sKey), pDevice->abyBSSID, pDevice->PortOffset);
741 }
742 pDevice->bLinkPass = TRUE;
743 pDevice->byLinkWaitCount = 0;
744 pDevice->byReAssocCount = 0;
745 bClearBSSID_SCAN(pDevice);
746 if (pDevice->byFOETuning) {
747 BBvSetFOE(pDevice->PortOffset);
748 PSbSendNullPacket(pDevice);
749 }
750 if (netif_queue_stopped(pDevice->dev)){
751 netif_wake_queue(pDevice->dev);
752 }
753 #ifdef TxInSleep
754 if(pDevice->IsTxDataTrigger != FALSE) { //TxDataTimer is not triggered at the first time
755 // printk("Re-initial TxDataTimer****\n");
756 del_timer(&pDevice->sTimerTxData);
757 init_timer(&pDevice->sTimerTxData);
758 pDevice->sTimerTxData.data = (ULONG)pDevice;
759 pDevice->sTimerTxData.function = (TimerFunction)BSSvSecondTxData;
760 pDevice->sTimerTxData.expires = RUN_AT(10*HZ); //10s callback
761 pDevice->fTxDataInSleep = FALSE;
762 pDevice->nTxDataTimeCout = 0;
763 }
764 else {
765 // printk("mike:-->First time triger TimerTxData InSleep\n");
766 }
767 pDevice->IsTxDataTrigger = TRUE;
768 add_timer(&pDevice->sTimerTxData);
769 #endif
770 }
771 else if(pMgmt->eCurrState < WMAC_STATE_ASSOCPENDING) {
772 printk("WLAN_ASSOCIATE_WAIT:Association Fail???\n");
773 }
774 else if(pDevice->byLinkWaitCount <= 4){ //mike add:wait another 2 sec if associated_frame delay!
775 pDevice->byLinkWaitCount ++;
776 printk("WLAN_ASSOCIATE_WAIT:wait %d times!!\n",pDevice->byLinkWaitCount);
777 spin_unlock_irq(&pDevice->lock);
778 vCommandTimerWait((HANDLE)pDevice, ASSOCIATE_TIMEOUT/2);
779 return;
780 }
781 pDevice->byLinkWaitCount = 0;
782 #if 0
783 #ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
784 // if(pDevice->bWPASuppWextEnabled == TRUE)
785 {
786 union iwreq_data wrqu;
787 memset(&wrqu, 0, sizeof (wrqu));
788 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
789 printk("wireless_send_event--->SIOCGIWAP(disassociated:ASSOCIATE_WAIT_timeout)\n");
790 wireless_send_event(pDevice->dev, SIOCGIWAP, &wrqu, NULL);
791 }
792 #endif
793 #endif
794
795 s_bCommandComplete(pDevice);
796 break;
797
798 case WLAN_CMD_AP_MODE_START :
799 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"eCommandState == WLAN_CMD_AP_MODE_START\n");
800
801 if (pMgmt->eConfigMode == WMAC_CONFIG_AP) {
802 del_timer(&pMgmt->sTimerSecondCallback);
803 pMgmt->eCurrState = WMAC_STATE_IDLE;
804 pMgmt->eCurrMode = WMAC_MODE_STANDBY;
805 pDevice->bLinkPass = FALSE;
806 if (pDevice->bEnableHostWEP == TRUE)
807 BSSvClearNodeDBTable(pDevice, 1);
808 else
809 BSSvClearNodeDBTable(pDevice, 0);
810 pDevice->uAssocCount = 0;
811 pMgmt->eCurrState = WMAC_STATE_IDLE;
812 pDevice->bFixRate = FALSE;
813
814 vMgrCreateOwnIBSS((HANDLE)pDevice, &Status);
815 if (Status != CMD_STATUS_SUCCESS){
816 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO " vMgrCreateOwnIBSS fail ! \n");
817 };
818 // alway turn off unicast bit
819 MACvRegBitsOff(pDevice->PortOffset, MAC_REG_RCR, RCR_UNICAST);
820 pDevice->byRxMode &= ~RCR_UNICAST;
821 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "wcmd: rx_mode = %x\n", pDevice->byRxMode );
822 BSSvAddMulticastNode(pDevice);
823 if (netif_queue_stopped(pDevice->dev)){
824 netif_wake_queue(pDevice->dev);
825 }
826 pDevice->bLinkPass = TRUE;
827 add_timer(&pMgmt->sTimerSecondCallback);
828 }
829 s_bCommandComplete(pDevice);
830 break;
831
832 case WLAN_CMD_TX_PSPACKET_START :
833 // DTIM Multicast tx
834 if (pMgmt->sNodeDBTable[0].bRxPSPoll) {
835 while ((skb = skb_dequeue(&pMgmt->sNodeDBTable[0].sTxPSQueue)) != NULL) {
836 if (skb_queue_empty(&pMgmt->sNodeDBTable[0].sTxPSQueue)) {
837 pMgmt->abyPSTxMap[0] &= ~byMask[0];
838 pDevice->bMoreData = FALSE;
839 }
840 else {
841 pDevice->bMoreData = TRUE;
842 }
843 if (!device_dma0_xmit(pDevice, skb, 0)) {
844 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Multicast ps tx fail \n");
845 }
846 pMgmt->sNodeDBTable[0].wEnQueueCnt--;
847 }
848 };
849
850 // PS nodes tx
851 for (ii = 1; ii < (MAX_NODE_NUM + 1); ii++) {
852 if (pMgmt->sNodeDBTable[ii].bActive &&
853 pMgmt->sNodeDBTable[ii].bRxPSPoll) {
854 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Index=%d Enqueu Cnt= %d\n",
855 ii, pMgmt->sNodeDBTable[ii].wEnQueueCnt);
856 while ((skb = skb_dequeue(&pMgmt->sNodeDBTable[ii].sTxPSQueue)) != NULL) {
857 if (skb_queue_empty(&pMgmt->sNodeDBTable[ii].sTxPSQueue)) {
858 // clear tx map
859 pMgmt->abyPSTxMap[pMgmt->sNodeDBTable[ii].wAID >> 3] &=
860 ~byMask[pMgmt->sNodeDBTable[ii].wAID & 7];
861 pDevice->bMoreData = FALSE;
862 }
863 else {
864 pDevice->bMoreData = TRUE;
865 }
866 if (!device_dma0_xmit(pDevice, skb, ii)) {
867 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "sta ps tx fail \n");
868 }
869 pMgmt->sNodeDBTable[ii].wEnQueueCnt--;
870 // check if sta ps enable, wait next pspoll
871 // if sta ps disable, send all pending buffers.
872 if (pMgmt->sNodeDBTable[ii].bPSEnable)
873 break;
874 }
875 if (skb_queue_empty(&pMgmt->sNodeDBTable[ii].sTxPSQueue)) {
876 // clear tx map
877 pMgmt->abyPSTxMap[pMgmt->sNodeDBTable[ii].wAID >> 3] &=
878 ~byMask[pMgmt->sNodeDBTable[ii].wAID & 7];
879 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Index=%d PS queue clear \n", ii);
880 }
881 pMgmt->sNodeDBTable[ii].bRxPSPoll = FALSE;
882 }
883 }
884
885 s_bCommandComplete(pDevice);
886 break;
887
888
889 case WLAN_CMD_RADIO_START :
890 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"eCommandState == WLAN_CMD_RADIO_START\n");
891 if (pDevice->bRadioCmd == TRUE)
892 CARDbRadioPowerOn(pDevice);
893 else
894 CARDbRadioPowerOff(pDevice);
895
896 s_bCommandComplete(pDevice);
897 break;
898
899
900 case WLAN_CMD_CHECK_BBSENSITIVITY_CHANGE :
901 //DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"eCommandState == WLAN_CMD_CHECK_BBSENSITIVITY_START\n");
902 // wait all TD complete
903 if (pDevice->iTDUsed[TYPE_AC0DMA] != 0){
904 vCommandTimerWait((HANDLE)pDevice, 10);
905 spin_unlock_irq(&pDevice->lock);
906 return;
907 }
908 if (pDevice->iTDUsed[TYPE_TXDMA0] != 0){
909 vCommandTimerWait((HANDLE)pDevice, 10);
910 spin_unlock_irq(&pDevice->lock);
911 return;
912 }
913 pDevice->byBBVGACurrent = pDevice->byBBVGANew;
914 BBvSetVGAGainOffset(pDevice, pDevice->byBBVGACurrent);
915 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"SetVGAGainOffset %02X\n", pDevice->byBBVGACurrent);
916 s_bCommandComplete(pDevice);
917 break;
918
919 default :
920 s_bCommandComplete(pDevice);
921 break;
922
923 } //switch
924 spin_unlock_irq(&pDevice->lock);
925 return;
926
927}
928
929
930static
931BOOL
932s_bCommandComplete (
933 PSDevice pDevice
934 )
935{
936 PWLAN_IE_SSID pSSID;
937 BOOL bRadioCmd = FALSE;
938 //WORD wDeAuthenReason = 0;
939 BOOL bForceSCAN = TRUE;
940 PSMgmtObject pMgmt = pDevice->pMgmt;
941
942
943 pDevice->eCommandState = WLAN_CMD_IDLE;
944 if (pDevice->cbFreeCmdQueue == CMD_Q_SIZE) {
945 //Command Queue Empty
946 pDevice->bCmdRunning = FALSE;
947 return TRUE;
948 }
949 else {
950 pDevice->eCommand = pDevice->eCmdQueue[pDevice->uCmdDequeueIdx].eCmd;
951 pSSID = (PWLAN_IE_SSID)pDevice->eCmdQueue[pDevice->uCmdDequeueIdx].abyCmdDesireSSID;
952 bRadioCmd = pDevice->eCmdQueue[pDevice->uCmdDequeueIdx].bRadioCmd;
953 bForceSCAN = pDevice->eCmdQueue[pDevice->uCmdDequeueIdx].bForceSCAN;
954 ADD_ONE_WITH_WRAP_AROUND(pDevice->uCmdDequeueIdx, CMD_Q_SIZE);
955 pDevice->cbFreeCmdQueue++;
956 pDevice->bCmdRunning = TRUE;
957 switch ( pDevice->eCommand ) {
958 case WLAN_CMD_BSSID_SCAN:
959 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"eCommandState= WLAN_CMD_BSSID_SCAN\n");
960 pDevice->eCommandState = WLAN_CMD_SCAN_START;
961 pMgmt->uScanChannel = 0;
962 if (pSSID->len != 0) {
963 MEMvCopy(pMgmt->abyScanSSID, pSSID, WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1);
964 } else {
965 memset(pMgmt->abyScanSSID, 0, WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1);
966 }
967/*
968 if ((bForceSCAN == FALSE) && (pDevice->bLinkPass == TRUE)) {
969 if ((pSSID->len == ((PWLAN_IE_SSID)pMgmt->abyCurrSSID)->len) &&
970 (MEMEqualMemory(pSSID->abySSID, ((PWLAN_IE_SSID)pMgmt->abyCurrSSID)->abySSID, pSSID->len))) {
971 pDevice->eCommandState = WLAN_CMD_IDLE;
972 }
973 }
974*/
975 break;
976 case WLAN_CMD_SSID:
977 pDevice->eCommandState = WLAN_CMD_SSID_START;
978 if (pSSID->len > WLAN_SSID_MAXLEN)
979 pSSID->len = WLAN_SSID_MAXLEN;
980 if (pSSID->len != 0)
981 MEMvCopy(pDevice->pMgmt->abyDesireSSID, pSSID, WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1);
982 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"eCommandState= WLAN_CMD_SSID_START\n");
983 break;
984 case WLAN_CMD_DISASSOCIATE:
985 pDevice->eCommandState = WLAN_CMD_DISASSOCIATE_START;
986 break;
987 case WLAN_CMD_RX_PSPOLL:
988 pDevice->eCommandState = WLAN_CMD_TX_PSPACKET_START;
989 break;
990 case WLAN_CMD_RUN_AP:
991 pDevice->eCommandState = WLAN_CMD_AP_MODE_START;
992 break;
993 case WLAN_CMD_RADIO:
994 pDevice->eCommandState = WLAN_CMD_RADIO_START;
995 pDevice->bRadioCmd = bRadioCmd;
996 break;
997 case WLAN_CMD_CHANGE_BBSENSITIVITY:
998 pDevice->eCommandState = WLAN_CMD_CHECK_BBSENSITIVITY_CHANGE;
999 break;
1000
1001 default:
1002 break;
1003
1004 }
1005
1006 vCommandTimerWait((HANDLE)pDevice, 0);
1007 }
1008
1009 return TRUE;
1010}
1011
1012
1013
1014BOOL bScheduleCommand (
1015 IN HANDLE hDeviceContext,
1016 IN CMD_CODE eCommand,
1017 IN PBYTE pbyItem0
1018 )
1019{
1020 PSDevice pDevice = (PSDevice)hDeviceContext;
1021
1022
1023 if (pDevice->cbFreeCmdQueue == 0) {
1024 return (FALSE);
1025 }
1026 pDevice->eCmdQueue[pDevice->uCmdEnqueueIdx].eCmd = eCommand;
1027 pDevice->eCmdQueue[pDevice->uCmdEnqueueIdx].bForceSCAN = TRUE;
1028 memset(pDevice->eCmdQueue[pDevice->uCmdEnqueueIdx].abyCmdDesireSSID, 0 , WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1);
1029
1030 if (pbyItem0 != NULL) {
1031 switch (eCommand) {
1032
1033 case WLAN_CMD_BSSID_SCAN:
1034 MEMvCopy(pDevice->eCmdQueue[pDevice->uCmdEnqueueIdx].abyCmdDesireSSID,
1035 pbyItem0, WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1);
1036 pDevice->eCmdQueue[pDevice->uCmdEnqueueIdx].bForceSCAN = FALSE;
1037 break;
1038
1039 case WLAN_CMD_SSID:
1040 MEMvCopy(pDevice->eCmdQueue[pDevice->uCmdEnqueueIdx].abyCmdDesireSSID,
1041 pbyItem0, WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1);
1042 break;
1043
1044 case WLAN_CMD_DISASSOCIATE:
1045 pDevice->eCmdQueue[pDevice->uCmdEnqueueIdx].bNeedRadioOFF = *((PBOOL)pbyItem0);
1046 break;
1047/*
1048 case WLAN_CMD_DEAUTH:
1049 pDevice->eCmdQueue[pDevice->uCmdEnqueueIdx].wDeAuthenReason = *((PWORD)pbyItem0);
1050 break;
1051*/
1052
1053 case WLAN_CMD_RX_PSPOLL:
1054 break;
1055
1056 case WLAN_CMD_RADIO:
1057 pDevice->eCmdQueue[pDevice->uCmdEnqueueIdx].bRadioCmd = *((PBOOL)pbyItem0);
1058 break;
1059
1060 case WLAN_CMD_CHANGE_BBSENSITIVITY:
1061 pDevice->eCommandState = WLAN_CMD_CHECK_BBSENSITIVITY_CHANGE;
1062 break;
1063
1064 default:
1065 break;
1066 }
1067 }
1068
1069 ADD_ONE_WITH_WRAP_AROUND(pDevice->uCmdEnqueueIdx, CMD_Q_SIZE);
1070 pDevice->cbFreeCmdQueue--;
1071
1072 if (pDevice->bCmdRunning == FALSE) {
1073 s_bCommandComplete(pDevice);
1074 }
1075 else {
1076 }
1077 return (TRUE);
1078
1079}
1080
1081/*
1082 * Description:
1083 * Clear BSSID_SCAN cmd in CMD Queue
1084 *
1085 * Parameters:
1086 * In:
1087 * hDeviceContext - Pointer to the adapter
1088 * eCommand - Command
1089 * Out:
1090 * none
1091 *
1092 * Return Value: TRUE if success; otherwise FALSE
1093 *
1094 */
1095BOOL bClearBSSID_SCAN (
1096 IN HANDLE hDeviceContext
1097 )
1098{
1099 PSDevice pDevice = (PSDevice)hDeviceContext;
1100 UINT uCmdDequeueIdx = pDevice->uCmdDequeueIdx;
1101 UINT ii;
1102
1103 if ((pDevice->cbFreeCmdQueue < CMD_Q_SIZE) && (uCmdDequeueIdx != pDevice->uCmdEnqueueIdx)) {
1104 for (ii = 0; ii < (CMD_Q_SIZE - pDevice->cbFreeCmdQueue); ii ++) {
1105 if (pDevice->eCmdQueue[uCmdDequeueIdx].eCmd == WLAN_CMD_BSSID_SCAN)
1106 pDevice->eCmdQueue[uCmdDequeueIdx].eCmd = WLAN_CMD_IDLE;
1107 ADD_ONE_WITH_WRAP_AROUND(uCmdDequeueIdx, CMD_Q_SIZE);
1108 if (uCmdDequeueIdx == pDevice->uCmdEnqueueIdx)
1109 break;
1110 }
1111 }
1112 return TRUE;
1113}
1114
1115//mike add:reset command timer
1116VOID
1117vResetCommandTimer(
1118 IN HANDLE hDeviceContext
1119 )
1120{
1121 PSDevice pDevice = (PSDevice)hDeviceContext;
1122
1123 //delete timer
1124 del_timer(&pDevice->sTimerCommand);
1125 //init timer
1126 init_timer(&pDevice->sTimerCommand);
1127 pDevice->sTimerCommand.data = (ULONG)pDevice;
1128 pDevice->sTimerCommand.function = (TimerFunction)vCommandTimer;
1129 pDevice->sTimerCommand.expires = RUN_AT(HZ);
1130 pDevice->cbFreeCmdQueue = CMD_Q_SIZE;
1131 pDevice->uCmdDequeueIdx = 0;
1132 pDevice->uCmdEnqueueIdx = 0;
1133 pDevice->eCommandState = WLAN_CMD_IDLE;
1134 pDevice->bCmdRunning = FALSE;
1135 pDevice->bCmdClear = FALSE;
1136}
1137
1138
1139#ifdef TxInSleep
1140VOID
1141BSSvSecondTxData(
1142 IN HANDLE hDeviceContext
1143 )
1144{
1145 PSDevice pDevice = (PSDevice)hDeviceContext;
1146 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
1147 pDevice->nTxDataTimeCout++;
1148
1149 if(pDevice->nTxDataTimeCout<4) //don't tx data if timer less than 40s
1150 {
1151 // printk("mike:%s-->no data Tx not exceed the desired Time as %d\n",__FUNCTION__,
1152 // (int)pDevice->nTxDataTimeCout);
1153 pDevice->sTimerTxData.expires = RUN_AT(10*HZ); //10s callback
1154 add_timer(&pDevice->sTimerTxData);
1155 return;
1156 }
1157
1158 spin_lock_irq(&pDevice->lock);
1159 #if 1
1160 if(((pDevice->bLinkPass ==TRUE)&&(pMgmt->eAuthenMode < WMAC_AUTH_WPA)) || //open && sharekey linking
1161 (pDevice->fWPA_Authened == TRUE)) { //wpa linking
1162 #else
1163 if(pDevice->bLinkPass ==TRUE) {
1164 #endif
1165
1166 // printk("mike:%s-->InSleep Tx Data Procedure\n",__FUNCTION__);
1167 pDevice->fTxDataInSleep = TRUE;
1168 PSbSendNullPacket(pDevice); //send null packet
1169 pDevice->fTxDataInSleep = FALSE;
1170 }
1171 spin_unlock_irq(&pDevice->lock);
1172
1173 pDevice->sTimerTxData.expires = RUN_AT(10*HZ); //10s callback
1174 add_timer(&pDevice->sTimerTxData);
1175 return;
1176}
1177#endif
1178
diff --git a/drivers/staging/vt6655/wcmd.h b/drivers/staging/vt6655/wcmd.h
new file mode 100644
index 000000000000..8c6bbc49f0bc
--- /dev/null
+++ b/drivers/staging/vt6655/wcmd.h
@@ -0,0 +1,151 @@
1/*
2 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
3 * All rights reserved.
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * File: wcmd.h
20 *
21 * Purpose: Handles the management command interface functions
22 *
23 * Author: Lyndon Chen
24 *
25 * Date: May 8, 2002
26 *
27 */
28
29#ifndef __WCMD_H__
30#define __WCMD_H__
31
32#if !defined(__TTYPE_H__)
33#include "ttype.h"
34#endif
35#if !defined(__80211HDR_H__)
36#include "80211hdr.h"
37#endif
38#if !defined(__80211MGR_H__)
39#include "80211mgr.h"
40#endif
41
42/*--------------------- Export Definitions -------------------------*/
43
44
45
46#define AUTHENTICATE_TIMEOUT 1000 //ms
47#define ASSOCIATE_TIMEOUT 1000 //ms
48
49// Command code
50typedef enum tagCMD_CODE {
51 WLAN_CMD_BSSID_SCAN,
52 WLAN_CMD_SSID,
53 WLAN_CMD_DISASSOCIATE,
54 WLAN_CMD_DEAUTH,
55 WLAN_CMD_RX_PSPOLL,
56 WLAN_CMD_RADIO,
57 WLAN_CMD_CHANGE_BBSENSITIVITY,
58 WLAN_CMD_SETPOWER,
59 WLAN_CMD_TBTT_WAKEUP,
60 WLAN_CMD_BECON_SEND,
61 WLAN_CMD_CHANGE_ANTENNA,
62 WLAN_CMD_REMOVE_ALLKEY,
63 WLAN_CMD_MAC_DISPOWERSAVING,
64 WLAN_CMD_11H_CHSW,
65 WLAN_CMD_RUN_AP
66} CMD_CODE, DEF* PCMD_CODE;
67
68#define CMD_Q_SIZE 32
69
70
71// Command code
72typedef enum tagCMD_STATUS {
73
74 CMD_STATUS_SUCCESS,
75 CMD_STATUS_FAILURE,
76 CMD_STATUS_RESOURCES,
77 CMD_STATUS_TIMEOUT,
78 CMD_STATUS_PENDING
79
80} CMD_STATUS, DEF* PCMD_STATUS;
81
82
83typedef struct tagCMD_ITEM {
84 CMD_CODE eCmd;
85 BYTE abyCmdDesireSSID[WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1];
86 BOOL bNeedRadioOFF;
87 WORD wDeAuthenReason;
88 BOOL bRadioCmd;
89 BOOL bForceSCAN;
90} CMD_ITEM, DEF* PCMD_ITEM;
91
92// Command state
93typedef enum tagCMD_STATE {
94 WLAN_CMD_SCAN_START,
95 WLAN_CMD_SCAN_END,
96 WLAN_CMD_DISASSOCIATE_START,
97 WLAN_CMD_SSID_START,
98 WLAN_AUTHENTICATE_WAIT,
99 WLAN_ASSOCIATE_WAIT,
100 WLAN_DISASSOCIATE_WAIT,
101 WLAN_CMD_TX_PSPACKET_START,
102 WLAN_CMD_AP_MODE_START,
103 WLAN_CMD_RADIO_START,
104 WLAN_CMD_CHECK_BBSENSITIVITY_CHANGE,
105 WLAN_CMD_IDLE
106} CMD_STATE, DEF* PCMD_STATE;
107
108
109/*--------------------- Export Classes ----------------------------*/
110
111/*--------------------- Export Variables --------------------------*/
112
113
114/*--------------------- Export Types ------------------------------*/
115
116
117/*--------------------- Export Functions --------------------------*/
118
119VOID
120vResetCommandTimer(
121 IN HANDLE hDeviceContext
122 );
123
124VOID
125vCommandTimer (
126 IN HANDLE hDeviceContext
127 );
128
129BOOL bClearBSSID_SCAN(
130 IN HANDLE hDeviceContext
131 );
132
133BOOL
134bScheduleCommand(
135 IN HANDLE hDeviceContext,
136 IN CMD_CODE eCommand,
137 IN PBYTE pbyItem0
138 );
139
140VOID
141vCommandTimerWait(
142 IN HANDLE hDeviceContext,
143 IN UINT MSecond
144 );
145#ifdef TxInSleep
146VOID
147BSSvSecondTxData(
148 IN HANDLE hDeviceContext
149 );
150#endif
151#endif //__WCMD_H__
diff --git a/drivers/staging/vt6655/wctl.c b/drivers/staging/vt6655/wctl.c
new file mode 100644
index 000000000000..b4fecc2ed55c
--- /dev/null
+++ b/drivers/staging/vt6655/wctl.c
@@ -0,0 +1,261 @@
1/*
2 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
3 * All rights reserved.
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * File: wctl.c
20 *
21 * Purpose: handle WMAC duplicate filter & defragment
22 *
23 * Author: Jerry Chen
24 *
25 * Date: Jun. 27, 2002
26 *
27 * Functions:
28 * WCTLbIsDuplicate - Test if duplicate packet
29 * WCTLuSearchDFCB - Search DeFragment Control Database
30 * WCTLuInsertDFCB - Insert DeFragment Control Database
31 * WCTLbHandleFragment - Handle received fragment packet
32 *
33 * Revision History:
34 *
35 */
36
37
38#if !defined(__WCTL_H__)
39#include "wctl.h"
40#endif
41#if !defined(__DEVICE_H__)
42#include "device.h"
43#endif
44#if !defined(__CARD_H__)
45#include "card.h"
46#endif
47
48/*--------------------- Static Definitions -------------------------*/
49
50/*--------------------- Static Classes ----------------------------*/
51
52/*--------------------- Static Variables --------------------------*/
53// static int msglevel =MSG_LEVEL_INFO;
54/*--------------------- Static Functions --------------------------*/
55
56/*--------------------- Export Variables --------------------------*/
57
58
59
60/*
61 * Description:
62 * Scan Rx cache. Return TRUE if packet is duplicate, else
63 * inserts in receive cache and returns FALSE.
64 *
65 * Parameters:
66 * In:
67 * pCache - Receive packets history
68 * pMACHeader - 802.11 MAC Header of received packet
69 * Out:
70 * none
71 *
72 * Return Value: TRUE if packet duplicate; otherwise FALSE
73 *
74 */
75
76BOOL WCTLbIsDuplicate (PSCache pCache, PS802_11Header pMACHeader)
77{
78 UINT uIndex;
79 UINT ii;
80 PSCacheEntry pCacheEntry;
81
82 if (IS_FC_RETRY(pMACHeader)) {
83
84 uIndex = pCache->uInPtr;
85 for (ii = 0; ii < DUPLICATE_RX_CACHE_LENGTH; ii++) {
86 pCacheEntry = &(pCache->asCacheEntry[uIndex]);
87 if ((pCacheEntry->wFmSequence == pMACHeader->wSeqCtl) &&
88 (IS_ETH_ADDRESS_EQUAL (&(pCacheEntry->abyAddr2[0]), &(pMACHeader->abyAddr2[0])))
89 ) {
90 /* Duplicate match */
91 return TRUE;
92 }
93 ADD_ONE_WITH_WRAP_AROUND(uIndex, DUPLICATE_RX_CACHE_LENGTH);
94 }
95 }
96 /* Not fount in cache - insert */
97 pCacheEntry = &pCache->asCacheEntry[pCache->uInPtr];
98 pCacheEntry->wFmSequence = pMACHeader->wSeqCtl;
99 memcpy(&(pCacheEntry->abyAddr2[0]), &(pMACHeader->abyAddr2[0]), U_ETHER_ADDR_LEN);
100 ADD_ONE_WITH_WRAP_AROUND(pCache->uInPtr, DUPLICATE_RX_CACHE_LENGTH);
101 return FALSE;
102}
103
104/*
105 * Description:
106 * Found if sequence number of received fragment packet in Defragment Database
107 *
108 * Parameters:
109 * In:
110 * pDevice - Pointer to adapter
111 * pMACHeader - 802.11 MAC Header of received packet
112 * Out:
113 * none
114 *
115 * Return Value: index number in Defragment Database
116 *
117 */
118UINT WCTLuSearchDFCB (PSDevice pDevice, PS802_11Header pMACHeader)
119{
120UINT ii;
121
122 for(ii=0;ii<pDevice->cbDFCB;ii++) {
123 if ((pDevice->sRxDFCB[ii].bInUse == TRUE) &&
124 (IS_ETH_ADDRESS_EQUAL (&(pDevice->sRxDFCB[ii].abyAddr2[0]), &(pMACHeader->abyAddr2[0])))
125 ) {
126 //
127 return(ii);
128 }
129 }
130 return(pDevice->cbDFCB);
131}
132
133
134/*
135 * Description:
136 * Insert received fragment packet in Defragment Database
137 *
138 * Parameters:
139 * In:
140 * pDevice - Pointer to adapter
141 * pMACHeader - 802.11 MAC Header of received packet
142 * Out:
143 * none
144 *
145 * Return Value: index number in Defragment Database
146 *
147 */
148UINT WCTLuInsertDFCB (PSDevice pDevice, PS802_11Header pMACHeader)
149{
150UINT ii;
151
152 if (pDevice->cbFreeDFCB == 0)
153 return(pDevice->cbDFCB);
154 for(ii=0;ii<pDevice->cbDFCB;ii++) {
155 if (pDevice->sRxDFCB[ii].bInUse == FALSE) {
156 pDevice->cbFreeDFCB--;
157 pDevice->sRxDFCB[ii].uLifetime = pDevice->dwMaxReceiveLifetime;
158 pDevice->sRxDFCB[ii].bInUse = TRUE;
159 pDevice->sRxDFCB[ii].wSequence = (pMACHeader->wSeqCtl >> 4);
160 pDevice->sRxDFCB[ii].wFragNum = (pMACHeader->wSeqCtl & 0x000F);
161 memcpy(&(pDevice->sRxDFCB[ii].abyAddr2[0]), &(pMACHeader->abyAddr2[0]), U_ETHER_ADDR_LEN);
162 return(ii);
163 }
164 }
165 return(pDevice->cbDFCB);
166}
167
168
169/*
170 * Description:
171 * Handle received fragment packet
172 *
173 * Parameters:
174 * In:
175 * pDevice - Pointer to adapter
176 * pMACHeader - 802.11 MAC Header of received packet
177 * cbFrameLength - Frame length
178 * bWEP - is WEP packet
179 * Out:
180 * none
181 *
182 * Return Value: TRUE if it is valid fragment packet and we have resource to defragment; otherwise FALSE
183 *
184 */
185BOOL WCTLbHandleFragment (PSDevice pDevice, PS802_11Header pMACHeader, UINT cbFrameLength, BOOL bWEP, BOOL bExtIV)
186{
187UINT uHeaderSize;
188
189
190 if (bWEP == TRUE) {
191 uHeaderSize = 28;
192 if (bExtIV)
193 // ExtIV
194 uHeaderSize +=4;
195 }
196 else {
197 uHeaderSize = 24;
198 }
199
200 if (IS_FIRST_FRAGMENT_PKT(pMACHeader)) {
201 pDevice->uCurrentDFCBIdx = WCTLuSearchDFCB(pDevice, pMACHeader);
202 if (pDevice->uCurrentDFCBIdx < pDevice->cbDFCB) {
203 // duplicate, we must flush previous DCB
204 pDevice->sRxDFCB[pDevice->uCurrentDFCBIdx].uLifetime = pDevice->dwMaxReceiveLifetime;
205 pDevice->sRxDFCB[pDevice->uCurrentDFCBIdx].wSequence = (pMACHeader->wSeqCtl >> 4);
206 pDevice->sRxDFCB[pDevice->uCurrentDFCBIdx].wFragNum = (pMACHeader->wSeqCtl & 0x000F);
207 }
208 else {
209 pDevice->uCurrentDFCBIdx = WCTLuInsertDFCB(pDevice, pMACHeader);
210 if (pDevice->uCurrentDFCBIdx == pDevice->cbDFCB) {
211 return(FALSE);
212 }
213 }
214 // reserve 4 byte to match MAC RX Buffer
215#ifdef PRIVATE_OBJ
216 pDevice->sRxDFCB[pDevice->uCurrentDFCBIdx].pbyRxBuffer = (PBYTE) (pDevice->sRxDFCB[pDevice->uCurrentDFCBIdx].ref_skb.data + 4);
217#else
218 pDevice->sRxDFCB[pDevice->uCurrentDFCBIdx].pbyRxBuffer = (PBYTE) (pDevice->sRxDFCB[pDevice->uCurrentDFCBIdx].skb->data + 4);
219#endif
220 memcpy(pDevice->sRxDFCB[pDevice->uCurrentDFCBIdx].pbyRxBuffer, pMACHeader, cbFrameLength);
221 pDevice->sRxDFCB[pDevice->uCurrentDFCBIdx].cbFrameLength = cbFrameLength;
222 pDevice->sRxDFCB[pDevice->uCurrentDFCBIdx].pbyRxBuffer += cbFrameLength;
223 pDevice->sRxDFCB[pDevice->uCurrentDFCBIdx].wFragNum++;
224 //DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "First pDevice->uCurrentDFCBIdx= %d\n", pDevice->uCurrentDFCBIdx);
225 return(FALSE);
226 }
227 else {
228 pDevice->uCurrentDFCBIdx = WCTLuSearchDFCB(pDevice, pMACHeader);
229 if (pDevice->uCurrentDFCBIdx != pDevice->cbDFCB) {
230 if ((pDevice->sRxDFCB[pDevice->uCurrentDFCBIdx].wSequence == (pMACHeader->wSeqCtl >> 4)) &&
231 (pDevice->sRxDFCB[pDevice->uCurrentDFCBIdx].wFragNum == (pMACHeader->wSeqCtl & 0x000F)) &&
232 ((pDevice->sRxDFCB[pDevice->uCurrentDFCBIdx].cbFrameLength + cbFrameLength - uHeaderSize) < 2346)) {
233
234 memcpy(pDevice->sRxDFCB[pDevice->uCurrentDFCBIdx].pbyRxBuffer, ((PBYTE) (pMACHeader) + uHeaderSize), (cbFrameLength - uHeaderSize));
235 pDevice->sRxDFCB[pDevice->uCurrentDFCBIdx].cbFrameLength += (cbFrameLength - uHeaderSize);
236 pDevice->sRxDFCB[pDevice->uCurrentDFCBIdx].pbyRxBuffer += (cbFrameLength - uHeaderSize);
237 pDevice->sRxDFCB[pDevice->uCurrentDFCBIdx].wFragNum++;
238 //DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Second pDevice->uCurrentDFCBIdx= %d\n", pDevice->uCurrentDFCBIdx);
239 }
240 else {
241 // seq error or frag # error flush DFCB
242 pDevice->cbFreeDFCB++;
243 pDevice->sRxDFCB[pDevice->uCurrentDFCBIdx].bInUse = FALSE;
244 return(FALSE);
245 }
246 }
247 else {
248 return(FALSE);
249 }
250 if (IS_LAST_FRAGMENT_PKT(pMACHeader)) {
251 //enq defragcontrolblock
252 pDevice->cbFreeDFCB++;
253 pDevice->sRxDFCB[pDevice->uCurrentDFCBIdx].bInUse = FALSE;
254 //DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Last pDevice->uCurrentDFCBIdx= %d\n", pDevice->uCurrentDFCBIdx);
255 return(TRUE);
256 }
257 return(FALSE);
258 }
259}
260
261
diff --git a/drivers/staging/vt6655/wctl.h b/drivers/staging/vt6655/wctl.h
new file mode 100644
index 000000000000..f75ca59f6c61
--- /dev/null
+++ b/drivers/staging/vt6655/wctl.h
@@ -0,0 +1,127 @@
1/*
2 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
3 * All rights reserved.
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * File: wctl.h
20 *
21 * Purpose:
22 *
23 * Author: Jerry Chen
24 *
25 * Date: Jun. 27, 2002
26 *
27 */
28
29
30#ifndef __WCTL_H__
31#define __WCTL_H__
32
33#if !defined(__TTYPE_H__)
34#include "ttype.h"
35#endif
36#if !defined(__TETHER_H__)
37#include "tether.h"
38#endif
39#if !defined(__DEVICE_H__)
40#include "device.h"
41#endif
42
43
44
45/*--------------------- Export Definitions -------------------------*/
46
47#define IS_TYPE_DATA(pMACHeader) \
48 ((((PS802_11Header) pMACHeader)->wFrameCtl & TYPE_802_11_MASK) == TYPE_802_11_DATA)
49
50#define IS_TYPE_MGMT(pMACHeader) \
51 ((((PS802_11Header) pMACHeader)->wFrameCtl & TYPE_802_11_MASK) == TYPE_802_11_MGMT)
52
53#define IS_TYPE_CONTROL(pMACHeader) \
54 ((((PS802_11Header) pMACHeader)->wFrameCtl & TYPE_802_11_MASK) == TYPE_802_11_CTL)
55
56#define IS_FC_MOREDATA(pMACHeader) \
57 ((((PS802_11Header) pMACHeader)->wFrameCtl & FC_MOREDATA) == FC_MOREDATA)
58
59#define IS_FC_POWERMGT(pMACHeader) \
60 ((((PS802_11Header) pMACHeader)->wFrameCtl & FC_POWERMGT) == FC_POWERMGT)
61
62#define IS_FC_RETRY(pMACHeader) \
63 ((((PS802_11Header) pMACHeader)->wFrameCtl & FC_RETRY) == FC_RETRY)
64
65#define IS_FC_WEP(pMACHeader) \
66 ((((PS802_11Header) pMACHeader)->wFrameCtl & FC_WEP) == FC_WEP)
67
68#ifdef __BIG_ENDIAN
69
70#define IS_FRAGMENT_PKT(pMACHeader) \
71 (((((PS802_11Header) pMACHeader)->wFrameCtl & FC_MOREFRAG) != 0) | \
72 ((((PS802_11Header) pMACHeader)->wSeqCtl & 0x0F00) != 0))
73
74#define IS_FIRST_FRAGMENT_PKT(pMACHeader) \
75 ((((PS802_11Header) pMACHeader)->wSeqCtl & 0x0F00) == 0)
76
77#else
78
79#define IS_FRAGMENT_PKT(pMACHeader) \
80 (((((PS802_11Header) pMACHeader)->wFrameCtl & FC_MOREFRAG) != 0) | \
81 ((((PS802_11Header) pMACHeader)->wSeqCtl & 0x000F) != 0))
82
83#define IS_FIRST_FRAGMENT_PKT(pMACHeader) \
84 ((((PS802_11Header) pMACHeader)->wSeqCtl & 0x000F) == 0)
85
86#endif//#ifdef __BIG_ENDIAN
87
88#define IS_LAST_FRAGMENT_PKT(pMACHeader) \
89 ((((PS802_11Header) pMACHeader)->wFrameCtl & FC_MOREFRAG) == 0)
90
91#define IS_CTL_PSPOLL(pMACHeader) \
92 ((((PS802_11Header) pMACHeader)->wFrameCtl & TYPE_SUBTYPE_MASK) == TYPE_CTL_PSPOLL)
93
94
95#define ADD_ONE_WITH_WRAP_AROUND(uVar, uModulo) { \
96 if ((uVar) >= ((uModulo) - 1)) \
97 (uVar) = 0; \
98 else \
99 (uVar)++; \
100}
101
102
103/*--------------------- Export Classes ----------------------------*/
104
105/*--------------------- Export Variables --------------------------*/
106
107/*--------------------- Export Functions --------------------------*/
108#ifdef __cplusplus
109extern "C" { /* Assume C declarations for C++ */
110#endif /* __cplusplus */
111
112BOOL WCTLbIsDuplicate(PSCache pCache, PS802_11Header pMACHeader);
113BOOL WCTLbHandleFragment(PSDevice pDevice, PS802_11Header pMACHeader, UINT cbFrameLength, BOOL bWEP, BOOL bExtIV);
114UINT WCTLuSearchDFCB(PSDevice pDevice, PS802_11Header pMACHeader);
115UINT WCTLuInsertDFCB(PSDevice pDevice, PS802_11Header pMACHeader);
116
117#ifdef __cplusplus
118} /* End of extern "C" { */
119#endif /* __cplusplus */
120
121
122
123
124#endif // __WCTL_H__
125
126
127
diff --git a/drivers/staging/vt6655/wmgr.c b/drivers/staging/vt6655/wmgr.c
new file mode 100644
index 000000000000..c5f52e990bd6
--- /dev/null
+++ b/drivers/staging/vt6655/wmgr.c
@@ -0,0 +1,5100 @@
1/*
2 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
3 * All rights reserved.
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * File: wmgr.c
20 *
21 * Purpose: Handles the 802.11 management functions
22 *
23 * Author: Lyndon Chen
24 *
25 * Date: May 8, 2002
26 *
27 * Functions:
28 * nsMgrObjectInitial - Initialize Management Objet data structure
29 * vMgrObjectReset - Reset Management Objet data structure
30 * vMgrAssocBeginSta - Start associate function
31 * vMgrReAssocBeginSta - Start reassociate function
32 * vMgrDisassocBeginSta - Start disassociate function
33 * s_vMgrRxAssocRequest - Handle Rcv associate_request
34 * s_vMgrRxAssocResponse - Handle Rcv associate_response
35 * vMrgAuthenBeginSta - Start authentication function
36 * vMgrDeAuthenDeginSta - Start deauthentication function
37 * s_vMgrRxAuthentication - Handle Rcv authentication
38 * s_vMgrRxAuthenSequence_1 - Handle Rcv authentication sequence 1
39 * s_vMgrRxAuthenSequence_2 - Handle Rcv authentication sequence 2
40 * s_vMgrRxAuthenSequence_3 - Handle Rcv authentication sequence 3
41 * s_vMgrRxAuthenSequence_4 - Handle Rcv authentication sequence 4
42 * s_vMgrRxDisassociation - Handle Rcv disassociation
43 * s_vMgrRxBeacon - Handle Rcv Beacon
44 * vMgrCreateOwnIBSS - Create ad_hoc IBSS or AP BSS
45 * vMgrJoinBSSBegin - Join BSS function
46 * s_vMgrSynchBSS - Synch & adopt BSS parameters
47 * s_MgrMakeBeacon - Create Baecon frame
48 * s_MgrMakeProbeResponse - Create Probe Response frame
49 * s_MgrMakeAssocRequest - Create Associate Request frame
50 * s_MgrMakeReAssocRequest - Create ReAssociate Request frame
51 * s_vMgrRxProbeResponse - Handle Rcv probe_response
52 * s_vMrgRxProbeRequest - Handle Rcv probe_request
53 * bMgrPrepareBeaconToSend - Prepare Beacon frame
54 * s_vMgrLogStatus - Log 802.11 Status
55 * vMgrRxManagePacket - Rcv management frame dispatch function
56 * s_vMgrFormatTIM- Assember TIM field of beacon
57 * vMgrTimerInit- Initial 1-sec and command call back funtions
58 *
59 * Revision History:
60 *
61 */
62
63
64#if !defined(__TMACRO_H__)
65#include "tmacro.h"
66#endif
67#if !defined(__TBIT_H__)
68#include "tbit.h"
69#endif
70#if !defined(__DESC_H__)
71#include "desc.h"
72#endif
73#if !defined(__DEVICE_H__)
74#include "device.h"
75#endif
76#if !defined(__CARD_H__)
77#include "card.h"
78#endif
79#if !defined(__80211HDR_H__)
80#include "80211hdr.h"
81#endif
82#if !defined(__80211MGR_H__)
83#include "80211mgr.h"
84#endif
85#if !defined(__WMGR_H__)
86#include "wmgr.h"
87#endif
88#if !defined(__WCMD_H__)
89#include "wcmd.h"
90#endif
91#if !defined(__MAC_H__)
92#include "mac.h"
93#endif
94#if !defined(__BSSDB_H__)
95#include "bssdb.h"
96#endif
97#if !defined(__POWER_H__)
98#include "power.h"
99#endif
100#if !defined(__DATARATE_H__)
101#include "datarate.h"
102#endif
103#if !defined(__BASEBAND_H__)
104#include "baseband.h"
105#endif
106#if !defined(__RXTX_H__)
107#include "rxtx.h"
108#endif
109#if !defined(__WPA_H__)
110#include "wpa.h"
111#endif
112#if !defined(__RF_H__)
113#include "rf.h"
114#endif
115#if !defined(__UMEM_H__)
116#include "umem.h"
117#endif
118#if !defined(__IOWPA_H__)
119#include "iowpa.h"
120#endif
121
122#define PLICE_DEBUG
123
124/*--------------------- Static Definitions -------------------------*/
125
126
127
128/*--------------------- Static Classes ----------------------------*/
129
130/*--------------------- Static Variables --------------------------*/
131static int msglevel =MSG_LEVEL_INFO;
132//static int msglevel =MSG_LEVEL_DEBUG;
133
134/*--------------------- Static Functions --------------------------*/
135//2008-8-4 <add> by chester
136static BOOL ChannelExceedZoneType(
137 IN PSDevice pDevice,
138 IN BYTE byCurrChannel
139 );
140// Association/diassociation functions
141static
142PSTxMgmtPacket
143s_MgrMakeAssocRequest(
144 IN PSDevice pDevice,
145 IN PSMgmtObject pMgmt,
146 IN PBYTE pDAddr,
147 IN WORD wCurrCapInfo,
148 IN WORD wListenInterval,
149 IN PWLAN_IE_SSID pCurrSSID,
150 IN PWLAN_IE_SUPP_RATES pCurrRates,
151 IN PWLAN_IE_SUPP_RATES pCurrExtSuppRates
152 );
153
154static
155VOID
156s_vMgrRxAssocRequest(
157 IN PSDevice pDevice,
158 IN PSMgmtObject pMgmt,
159 IN PSRxMgmtPacket pRxPacket,
160 IN UINT uNodeIndex
161 );
162
163static
164PSTxMgmtPacket
165s_MgrMakeReAssocRequest(
166 IN PSDevice pDevice,
167 IN PSMgmtObject pMgmt,
168 IN PBYTE pDAddr,
169 IN WORD wCurrCapInfo,
170 IN WORD wListenInterval,
171 IN PWLAN_IE_SSID pCurrSSID,
172 IN PWLAN_IE_SUPP_RATES pCurrRates,
173 IN PWLAN_IE_SUPP_RATES pCurrExtSuppRates
174 );
175
176static
177VOID
178s_vMgrRxAssocResponse(
179 IN PSDevice pDevice,
180 IN PSMgmtObject pMgmt,
181 IN PSRxMgmtPacket pRxPacket,
182 IN BOOL bReAssocType
183 );
184
185static
186VOID
187s_vMgrRxDisassociation(
188 IN PSDevice pDevice,
189 IN PSMgmtObject pMgmt,
190 IN PSRxMgmtPacket pRxPacket
191 );
192
193// Authentication/deauthen functions
194static
195VOID
196s_vMgrRxAuthenSequence_1(
197 IN PSDevice pDevice,
198 IN PSMgmtObject pMgmt,
199 IN PWLAN_FR_AUTHEN pFrame
200 );
201
202static
203VOID
204s_vMgrRxAuthenSequence_2(
205 IN PSDevice pDevice,
206 IN PSMgmtObject pMgmt,
207 IN PWLAN_FR_AUTHEN pFrame
208 );
209
210static
211VOID
212s_vMgrRxAuthenSequence_3(
213 IN PSDevice pDevice,
214 IN PSMgmtObject pMgmt,
215 IN PWLAN_FR_AUTHEN pFrame
216 );
217
218static
219VOID
220s_vMgrRxAuthenSequence_4(
221 IN PSDevice pDevice,
222 IN PSMgmtObject pMgmt,
223 IN PWLAN_FR_AUTHEN pFrame
224 );
225
226static
227VOID
228s_vMgrRxAuthentication(
229 IN PSDevice pDevice,
230 IN PSMgmtObject pMgmt,
231 IN PSRxMgmtPacket pRxPacket
232 );
233
234static
235VOID
236s_vMgrRxDeauthentication(
237 IN PSDevice pDevice,
238 IN PSMgmtObject pMgmt,
239 IN PSRxMgmtPacket pRxPacket
240 );
241
242// Scan functions
243// probe request/response functions
244static
245VOID
246s_vMgrRxProbeRequest(
247 IN PSDevice pDevice,
248 IN PSMgmtObject pMgmt,
249 IN PSRxMgmtPacket pRxPacket
250 );
251
252static
253VOID
254s_vMgrRxProbeResponse(
255 IN PSDevice pDevice,
256 IN PSMgmtObject pMgmt,
257 IN PSRxMgmtPacket pRxPacket
258 );
259
260// beacon functions
261static
262VOID
263s_vMgrRxBeacon(
264 IN PSDevice pDevice,
265 IN PSMgmtObject pMgmt,
266 IN PSRxMgmtPacket pRxPacket,
267 IN BOOL bInScan
268 );
269
270static
271VOID
272s_vMgrFormatTIM(
273 IN PSMgmtObject pMgmt,
274 IN PWLAN_IE_TIM pTIM
275 );
276
277static
278PSTxMgmtPacket
279s_MgrMakeBeacon(
280 IN PSDevice pDevice,
281 IN PSMgmtObject pMgmt,
282 IN WORD wCurrCapInfo,
283 IN WORD wCurrBeaconPeriod,
284 IN UINT uCurrChannel,
285 IN WORD wCurrATIMWinodw,
286 IN PWLAN_IE_SSID pCurrSSID,
287 IN PBYTE pCurrBSSID,
288 IN PWLAN_IE_SUPP_RATES pCurrSuppRates,
289 IN PWLAN_IE_SUPP_RATES pCurrExtSuppRates
290 );
291
292
293// Association response
294static
295PSTxMgmtPacket
296s_MgrMakeAssocResponse(
297 IN PSDevice pDevice,
298 IN PSMgmtObject pMgmt,
299 IN WORD wCurrCapInfo,
300 IN WORD wAssocStatus,
301 IN WORD wAssocAID,
302 IN PBYTE pDstAddr,
303 IN PWLAN_IE_SUPP_RATES pCurrSuppRates,
304 IN PWLAN_IE_SUPP_RATES pCurrExtSuppRates
305 );
306
307// ReAssociation response
308static
309PSTxMgmtPacket
310s_MgrMakeReAssocResponse(
311 IN PSDevice pDevice,
312 IN PSMgmtObject pMgmt,
313 IN WORD wCurrCapInfo,
314 IN WORD wAssocStatus,
315 IN WORD wAssocAID,
316 IN PBYTE pDstAddr,
317 IN PWLAN_IE_SUPP_RATES pCurrSuppRates,
318 IN PWLAN_IE_SUPP_RATES pCurrExtSuppRates
319 );
320
321// Probe response
322static
323PSTxMgmtPacket
324s_MgrMakeProbeResponse(
325 IN PSDevice pDevice,
326 IN PSMgmtObject pMgmt,
327 IN WORD wCurrCapInfo,
328 IN WORD wCurrBeaconPeriod,
329 IN UINT uCurrChannel,
330 IN WORD wCurrATIMWinodw,
331 IN PBYTE pDstAddr,
332 IN PWLAN_IE_SSID pCurrSSID,
333 IN PBYTE pCurrBSSID,
334 IN PWLAN_IE_SUPP_RATES pCurrSuppRates,
335 IN PWLAN_IE_SUPP_RATES pCurrExtSuppRates,
336 IN BYTE byPHYType
337 );
338
339// received status
340static
341VOID
342s_vMgrLogStatus(
343 IN PSMgmtObject pMgmt,
344 IN WORD wStatus
345 );
346
347
348static
349VOID
350s_vMgrSynchBSS (
351 IN PSDevice pDevice,
352 IN UINT uBSSMode,
353 IN PKnownBSS pCurr,
354 OUT PCMD_STATUS pStatus
355 );
356
357
358static BOOL
359s_bCipherMatch (
360 IN PKnownBSS pBSSNode,
361 IN NDIS_802_11_ENCRYPTION_STATUS EncStatus,
362 OUT PBYTE pbyCCSPK,
363 OUT PBYTE pbyCCSGK
364 );
365
366
367 static VOID Encyption_Rebuild(
368 IN PSDevice pDevice,
369 IN PKnownBSS pCurr
370 );
371/*
372static
373VOID
374s_vProbeChannel(
375 IN PSDevice pDevice
376 );
377
378static
379VOID
380s_vListenChannel(
381 IN PSDevice pDevice
382 );
383
384static
385PSTxMgmtPacket
386s_MgrMakeProbeRequest(
387 IN PSMgmtObject pMgmt,
388 IN PBYTE pScanBSSID,
389 IN PWLAN_IE_SSID pSSID,
390 IN PWLAN_IE_SUPP_RATES pCurrRates
391 );
392*/
393
394
395
396/*--------------------- Export Variables --------------------------*/
397
398
399/*--------------------- Export Functions --------------------------*/
400
401
402/*+
403 *
404 * Routine Description:
405 * Allocates and initializes the Management object.
406 *
407 * Return Value:
408 * Ndis_staus.
409 *
410-*/
411
412VOID
413vMgrObjectInit(
414 IN HANDLE hDeviceContext
415 )
416{
417 PSDevice pDevice = (PSDevice)hDeviceContext;
418 PSMgmtObject pMgmt = pDevice->pMgmt;
419 int ii;
420
421
422 pMgmt->pbyPSPacketPool = &pMgmt->byPSPacketPool[0];
423 pMgmt->pbyMgmtPacketPool = &pMgmt->byMgmtPacketPool[0];
424 pMgmt->uCurrChannel = pDevice->uChannel;
425 for(ii=0;ii<WLAN_BSSID_LEN;ii++) {
426 pMgmt->abyDesireBSSID[ii] = 0xFF;
427 }
428 pMgmt->sAssocInfo.AssocInfo.Length = sizeof(NDIS_802_11_ASSOCIATION_INFORMATION);
429 //memset(pMgmt->abyDesireSSID, 0, WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN +1);
430 pMgmt->byCSSPK = KEY_CTL_NONE;
431 pMgmt->byCSSGK = KEY_CTL_NONE;
432 pMgmt->wIBSSBeaconPeriod = DEFAULT_IBSS_BI;
433 BSSvClearBSSList((HANDLE)pDevice, FALSE);
434
435 return;
436}
437
438/*+
439 *
440 * Routine Description:
441 * Initializes timer object
442 *
443 * Return Value:
444 * Ndis_staus.
445 *
446-*/
447
448void
449vMgrTimerInit(
450 IN HANDLE hDeviceContext
451 )
452{
453 PSDevice pDevice = (PSDevice)hDeviceContext;
454 PSMgmtObject pMgmt = pDevice->pMgmt;
455
456
457 init_timer(&pMgmt->sTimerSecondCallback);
458 pMgmt->sTimerSecondCallback.data = (ULONG)pDevice;
459 pMgmt->sTimerSecondCallback.function = (TimerFunction)BSSvSecondCallBack;
460 pMgmt->sTimerSecondCallback.expires = RUN_AT(HZ);
461
462 init_timer(&pDevice->sTimerCommand);
463 pDevice->sTimerCommand.data = (ULONG)pDevice;
464 pDevice->sTimerCommand.function = (TimerFunction)vCommandTimer;
465 pDevice->sTimerCommand.expires = RUN_AT(HZ);
466
467 #ifdef TxInSleep
468 init_timer(&pDevice->sTimerTxData);
469 pDevice->sTimerTxData.data = (ULONG)pDevice;
470 pDevice->sTimerTxData.function = (TimerFunction)BSSvSecondTxData;
471 pDevice->sTimerTxData.expires = RUN_AT(10*HZ); //10s callback
472 pDevice->fTxDataInSleep = FALSE;
473 pDevice->IsTxDataTrigger = FALSE;
474 pDevice->nTxDataTimeCout = 0;
475 #endif
476
477 pDevice->cbFreeCmdQueue = CMD_Q_SIZE;
478 pDevice->uCmdDequeueIdx = 0;
479 pDevice->uCmdEnqueueIdx = 0;
480
481 return;
482}
483
484
485
486/*+
487 *
488 * Routine Description:
489 * Reset the management object structure.
490 *
491 * Return Value:
492 * None.
493 *
494-*/
495
496VOID
497vMgrObjectReset(
498 IN HANDLE hDeviceContext
499 )
500{
501 PSDevice pDevice = (PSDevice)hDeviceContext;
502 PSMgmtObject pMgmt = pDevice->pMgmt;
503
504 pMgmt->eCurrMode = WMAC_MODE_STANDBY;
505 pMgmt->eCurrState = WMAC_STATE_IDLE;
506 pDevice->bEnablePSMode = FALSE;
507 // TODO: timer
508
509 return;
510}
511
512
513/*+
514 *
515 * Routine Description:
516 * Start the station association procedure. Namely, send an
517 * association request frame to the AP.
518 *
519 * Return Value:
520 * None.
521 *
522-*/
523
524
525VOID
526vMgrAssocBeginSta(
527 IN HANDLE hDeviceContext,
528 IN PSMgmtObject pMgmt,
529 OUT PCMD_STATUS pStatus
530 )
531{
532 PSDevice pDevice = (PSDevice)hDeviceContext;
533 PSTxMgmtPacket pTxPacket;
534
535
536 pMgmt->wCurrCapInfo = 0;
537 pMgmt->wCurrCapInfo |= WLAN_SET_CAP_INFO_ESS(1);
538 if (pDevice->bEncryptionEnable) {
539 pMgmt->wCurrCapInfo |= WLAN_SET_CAP_INFO_PRIVACY(1);
540 }
541 // always allow receive short preamble
542 //if (pDevice->byPreambleType == 1) {
543 // pMgmt->wCurrCapInfo |= WLAN_SET_CAP_INFO_SHORTPREAMBLE(1);
544 //}
545 pMgmt->wCurrCapInfo |= WLAN_SET_CAP_INFO_SHORTPREAMBLE(1);
546 if (pMgmt->wListenInterval == 0)
547 pMgmt->wListenInterval = 1; // at least one.
548
549 // ERP Phy (802.11g) should support short preamble.
550 if (pMgmt->eCurrentPHYMode == PHY_TYPE_11G) {
551 pMgmt->wCurrCapInfo |= WLAN_SET_CAP_INFO_SHORTPREAMBLE(1);
552 if (CARDbIsShorSlotTime(pMgmt->pAdapter) == TRUE) {
553 pMgmt->wCurrCapInfo |= WLAN_SET_CAP_INFO_SHORTSLOTTIME(1);
554 }
555 } else if (pMgmt->eCurrentPHYMode == PHY_TYPE_11B) {
556 if (CARDbIsShortPreamble(pMgmt->pAdapter) == TRUE) {
557 pMgmt->wCurrCapInfo |= WLAN_SET_CAP_INFO_SHORTPREAMBLE(1);
558 }
559 }
560 if (pMgmt->b11hEnable == TRUE)
561 pMgmt->wCurrCapInfo |= WLAN_SET_CAP_INFO_SPECTRUMMNG(1);
562
563 /* build an assocreq frame and send it */
564 pTxPacket = s_MgrMakeAssocRequest
565 (
566 pDevice,
567 pMgmt,
568 pMgmt->abyCurrBSSID,
569 pMgmt->wCurrCapInfo,
570 pMgmt->wListenInterval,
571 (PWLAN_IE_SSID)pMgmt->abyCurrSSID,
572 (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates,
573 (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates
574 );
575
576 if (pTxPacket != NULL ){
577 /* send the frame */
578 *pStatus = csMgmt_xmit(pDevice, pTxPacket);
579 if (*pStatus == CMD_STATUS_PENDING) {
580 pMgmt->eCurrState = WMAC_STATE_ASSOCPENDING;
581 *pStatus = CMD_STATUS_SUCCESS;
582 }
583 }
584 else
585 *pStatus = CMD_STATUS_RESOURCES;
586
587 return ;
588}
589
590
591/*+
592 *
593 * Routine Description:
594 * Start the station re-association procedure.
595 *
596 * Return Value:
597 * None.
598 *
599-*/
600
601VOID
602vMgrReAssocBeginSta(
603 IN HANDLE hDeviceContext,
604 IN PSMgmtObject pMgmt,
605 OUT PCMD_STATUS pStatus
606 )
607{
608 PSDevice pDevice = (PSDevice)hDeviceContext;
609 PSTxMgmtPacket pTxPacket;
610
611
612
613 pMgmt->wCurrCapInfo = 0;
614 pMgmt->wCurrCapInfo |= WLAN_SET_CAP_INFO_ESS(1);
615 if (pDevice->bEncryptionEnable) {
616 pMgmt->wCurrCapInfo |= WLAN_SET_CAP_INFO_PRIVACY(1);
617 }
618
619 //if (pDevice->byPreambleType == 1) {
620 // pMgmt->wCurrCapInfo |= WLAN_SET_CAP_INFO_SHORTPREAMBLE(1);
621 //}
622 pMgmt->wCurrCapInfo |= WLAN_SET_CAP_INFO_SHORTPREAMBLE(1);
623
624 if (pMgmt->wListenInterval == 0)
625 pMgmt->wListenInterval = 1; // at least one.
626
627
628 // ERP Phy (802.11g) should support short preamble.
629 if (pMgmt->eCurrentPHYMode == PHY_TYPE_11G) {
630 pMgmt->wCurrCapInfo |= WLAN_SET_CAP_INFO_SHORTPREAMBLE(1);
631 if (CARDbIsShorSlotTime(pMgmt->pAdapter) == TRUE) {
632 pMgmt->wCurrCapInfo |= WLAN_SET_CAP_INFO_SHORTSLOTTIME(1);
633 }
634 } else if (pMgmt->eCurrentPHYMode == PHY_TYPE_11B) {
635 if (CARDbIsShortPreamble(pMgmt->pAdapter) == TRUE) {
636 pMgmt->wCurrCapInfo |= WLAN_SET_CAP_INFO_SHORTPREAMBLE(1);
637 }
638 }
639 if (pMgmt->b11hEnable == TRUE)
640 pMgmt->wCurrCapInfo |= WLAN_SET_CAP_INFO_SPECTRUMMNG(1);
641
642
643 pTxPacket = s_MgrMakeReAssocRequest
644 (
645 pDevice,
646 pMgmt,
647 pMgmt->abyCurrBSSID,
648 pMgmt->wCurrCapInfo,
649 pMgmt->wListenInterval,
650 (PWLAN_IE_SSID)pMgmt->abyCurrSSID,
651 (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates,
652 (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates
653 );
654
655 if (pTxPacket != NULL ){
656 /* send the frame */
657 *pStatus = csMgmt_xmit(pDevice, pTxPacket);
658 if (*pStatus != CMD_STATUS_PENDING) {
659 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Mgt:Reassociation tx failed.\n");
660 }
661 else {
662 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Mgt:Reassociation tx sending.\n");
663 }
664 }
665
666
667 return ;
668}
669
670/*+
671 *
672 * Routine Description:
673 * Send an dis-association request frame to the AP.
674 *
675 * Return Value:
676 * None.
677 *
678-*/
679
680VOID
681vMgrDisassocBeginSta(
682 IN HANDLE hDeviceContext,
683 IN PSMgmtObject pMgmt,
684 IN PBYTE abyDestAddress,
685 IN WORD wReason,
686 OUT PCMD_STATUS pStatus
687 )
688{
689 PSDevice pDevice = (PSDevice)hDeviceContext;
690 PSTxMgmtPacket pTxPacket = NULL;
691 WLAN_FR_DISASSOC sFrame;
692
693 pTxPacket = (PSTxMgmtPacket)pMgmt->pbyMgmtPacketPool;
694 memset(pTxPacket, 0, sizeof(STxMgmtPacket) + WLAN_DISASSOC_FR_MAXLEN);
695 pTxPacket->p80211Header = (PUWLAN_80211HDR)((PBYTE)pTxPacket + sizeof(STxMgmtPacket));
696
697 // Setup the sFrame structure
698 sFrame.pBuf = (PBYTE)pTxPacket->p80211Header;
699 sFrame.len = WLAN_DISASSOC_FR_MAXLEN;
700
701 // format fixed field frame structure
702 vMgrEncodeDisassociation(&sFrame);
703
704 // Setup the header
705 sFrame.pHdr->sA3.wFrameCtl = cpu_to_le16(
706 (
707 WLAN_SET_FC_FTYPE(WLAN_TYPE_MGR) |
708 WLAN_SET_FC_FSTYPE(WLAN_FSTYPE_DISASSOC)
709 ));
710
711 memcpy( sFrame.pHdr->sA3.abyAddr1, abyDestAddress, WLAN_ADDR_LEN);
712 memcpy( sFrame.pHdr->sA3.abyAddr2, pMgmt->abyMACAddr, WLAN_ADDR_LEN);
713 memcpy( sFrame.pHdr->sA3.abyAddr3, pMgmt->abyCurrBSSID, WLAN_BSSID_LEN);
714
715 // Set reason code
716 *(sFrame.pwReason) = cpu_to_le16(wReason);
717 pTxPacket->cbMPDULen = sFrame.len;
718 pTxPacket->cbPayloadLen = sFrame.len - WLAN_HDR_ADDR3_LEN;
719
720 // send the frame
721 *pStatus = csMgmt_xmit(pDevice, pTxPacket);
722 if (*pStatus == CMD_STATUS_PENDING) {
723 pMgmt->eCurrState = WMAC_STATE_IDLE;
724 *pStatus = CMD_STATUS_SUCCESS;
725 };
726
727 return;
728}
729
730
731
732/*+
733 *
734 * Routine Description:(AP function)
735 * Handle incoming station association request frames.
736 *
737 * Return Value:
738 * None.
739 *
740-*/
741
742static
743VOID
744s_vMgrRxAssocRequest(
745 IN PSDevice pDevice,
746 IN PSMgmtObject pMgmt,
747 IN PSRxMgmtPacket pRxPacket,
748 IN UINT uNodeIndex
749 )
750{
751 WLAN_FR_ASSOCREQ sFrame;
752 CMD_STATUS Status;
753 PSTxMgmtPacket pTxPacket;
754 WORD wAssocStatus = 0;
755 WORD wAssocAID = 0;
756 UINT uRateLen = WLAN_RATES_MAXLEN;
757 BYTE abyCurrSuppRates[WLAN_IEHDR_LEN + WLAN_RATES_MAXLEN + 1];
758 BYTE abyCurrExtSuppRates[WLAN_IEHDR_LEN + WLAN_RATES_MAXLEN + 1];
759
760
761 if (pMgmt->eCurrMode != WMAC_MODE_ESS_AP)
762 return;
763 // node index not found
764 if (!uNodeIndex)
765 return;
766
767 //check if node is authenticated
768 //decode the frame
769 memset(&sFrame, 0, sizeof(WLAN_FR_ASSOCREQ));
770 memset(abyCurrSuppRates, 0, WLAN_IEHDR_LEN + WLAN_RATES_MAXLEN + 1);
771 memset(abyCurrExtSuppRates, 0, WLAN_IEHDR_LEN + WLAN_RATES_MAXLEN + 1);
772 sFrame.len = pRxPacket->cbMPDULen;
773 sFrame.pBuf = (PBYTE)pRxPacket->p80211Header;
774
775 vMgrDecodeAssocRequest(&sFrame);
776
777 if (pMgmt->sNodeDBTable[uNodeIndex].eNodeState >= NODE_AUTH) {
778 pMgmt->sNodeDBTable[uNodeIndex].eNodeState = NODE_ASSOC;
779 pMgmt->sNodeDBTable[uNodeIndex].wCapInfo = cpu_to_le16(*sFrame.pwCapInfo);
780 pMgmt->sNodeDBTable[uNodeIndex].wListenInterval = cpu_to_le16(*sFrame.pwListenInterval);
781 pMgmt->sNodeDBTable[uNodeIndex].bPSEnable =
782 WLAN_GET_FC_PWRMGT(sFrame.pHdr->sA3.wFrameCtl) ? TRUE : FALSE;
783 // Todo: check sta basic rate, if ap can't support, set status code
784 if (pDevice->eCurrentPHYType == PHY_TYPE_11B) {
785 uRateLen = WLAN_RATES_MAXLEN_11B;
786 }
787 abyCurrSuppRates[0] = WLAN_EID_SUPP_RATES;
788 abyCurrSuppRates[1] = RATEuSetIE((PWLAN_IE_SUPP_RATES)sFrame.pSuppRates,
789 (PWLAN_IE_SUPP_RATES)abyCurrSuppRates,
790 uRateLen);
791 abyCurrExtSuppRates[0] = WLAN_EID_EXTSUPP_RATES;
792 if (pDevice->eCurrentPHYType == PHY_TYPE_11G) {
793 abyCurrExtSuppRates[1] = RATEuSetIE((PWLAN_IE_SUPP_RATES)sFrame.pExtSuppRates,
794 (PWLAN_IE_SUPP_RATES)abyCurrExtSuppRates,
795 uRateLen);
796 } else {
797 abyCurrExtSuppRates[1] = 0;
798 }
799
800
801 RATEvParseMaxRate((PVOID)pDevice,
802 (PWLAN_IE_SUPP_RATES)abyCurrSuppRates,
803 (PWLAN_IE_SUPP_RATES)abyCurrExtSuppRates,
804 FALSE, // do not change our basic rate
805 &(pMgmt->sNodeDBTable[uNodeIndex].wMaxBasicRate),
806 &(pMgmt->sNodeDBTable[uNodeIndex].wMaxSuppRate),
807 &(pMgmt->sNodeDBTable[uNodeIndex].wSuppRate),
808 &(pMgmt->sNodeDBTable[uNodeIndex].byTopCCKBasicRate),
809 &(pMgmt->sNodeDBTable[uNodeIndex].byTopOFDMBasicRate)
810 );
811
812 // set max tx rate
813 pMgmt->sNodeDBTable[uNodeIndex].wTxDataRate =
814 pMgmt->sNodeDBTable[uNodeIndex].wMaxSuppRate;
815#ifdef PLICE_DEBUG
816 printk("RxAssocRequest:wTxDataRate is %d\n",pMgmt->sNodeDBTable[uNodeIndex].wTxDataRate);
817#endif
818 // Todo: check sta preamble, if ap can't support, set status code
819 pMgmt->sNodeDBTable[uNodeIndex].bShortPreamble =
820 WLAN_GET_CAP_INFO_SHORTPREAMBLE(*sFrame.pwCapInfo);
821 pMgmt->sNodeDBTable[uNodeIndex].bShortSlotTime =
822 WLAN_GET_CAP_INFO_SHORTSLOTTIME(*sFrame.pwCapInfo);
823 pMgmt->sNodeDBTable[uNodeIndex].wAID = (WORD)uNodeIndex;
824 wAssocStatus = WLAN_MGMT_STATUS_SUCCESS;
825 wAssocAID = (WORD)uNodeIndex;
826 // check if ERP support
827 if(pMgmt->sNodeDBTable[uNodeIndex].wMaxSuppRate > RATE_11M)
828 pMgmt->sNodeDBTable[uNodeIndex].bERPExist = TRUE;
829
830 if (pMgmt->sNodeDBTable[uNodeIndex].wMaxSuppRate <= RATE_11M) {
831 // B only STA join
832 pDevice->bProtectMode = TRUE;
833 pDevice->bNonERPPresent = TRUE;
834 }
835 if (pMgmt->sNodeDBTable[uNodeIndex].bShortPreamble == FALSE) {
836 pDevice->bBarkerPreambleMd = TRUE;
837 }
838
839 DEVICE_PRT(MSG_LEVEL_INFO, KERN_INFO "Associate AID= %d \n", wAssocAID);
840 DEVICE_PRT(MSG_LEVEL_INFO, KERN_INFO "MAC=%2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X \n",
841 sFrame.pHdr->sA3.abyAddr2[0],
842 sFrame.pHdr->sA3.abyAddr2[1],
843 sFrame.pHdr->sA3.abyAddr2[2],
844 sFrame.pHdr->sA3.abyAddr2[3],
845 sFrame.pHdr->sA3.abyAddr2[4],
846 sFrame.pHdr->sA3.abyAddr2[5]
847 ) ;
848 DEVICE_PRT(MSG_LEVEL_INFO, KERN_INFO "Max Support rate = %d \n",
849 pMgmt->sNodeDBTable[uNodeIndex].wMaxSuppRate);
850 }//else { TODO: received STA under state1 handle }
851 else {
852 return;
853 }
854
855
856 // assoc response reply..
857 pTxPacket = s_MgrMakeAssocResponse
858 (
859 pDevice,
860 pMgmt,
861 pMgmt->wCurrCapInfo,
862 wAssocStatus,
863 wAssocAID,
864 sFrame.pHdr->sA3.abyAddr2,
865 (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates,
866 (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates
867 );
868 if (pTxPacket != NULL ){
869
870 if (pDevice->bEnableHostapd) {
871 return;
872 }
873 /* send the frame */
874 Status = csMgmt_xmit(pDevice, pTxPacket);
875 if (Status != CMD_STATUS_PENDING) {
876 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Mgt:Assoc response tx failed\n");
877 }
878 else {
879 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Mgt:Assoc response tx sending..\n");
880 }
881
882 }
883
884 return;
885}
886
887
888/*+
889 *
890 * Description:(AP function)
891 * Handle incoming station re-association request frames.
892 *
893 * Parameters:
894 * In:
895 * pMgmt - Management Object structure
896 * pRxPacket - Received Packet
897 * Out:
898 * none
899 *
900 * Return Value: None.
901 *
902-*/
903
904static
905VOID
906s_vMgrRxReAssocRequest(
907 IN PSDevice pDevice,
908 IN PSMgmtObject pMgmt,
909 IN PSRxMgmtPacket pRxPacket,
910 IN UINT uNodeIndex
911 )
912{
913 WLAN_FR_REASSOCREQ sFrame;
914 CMD_STATUS Status;
915 PSTxMgmtPacket pTxPacket;
916 WORD wAssocStatus = 0;
917 WORD wAssocAID = 0;
918 UINT uRateLen = WLAN_RATES_MAXLEN;
919 BYTE abyCurrSuppRates[WLAN_IEHDR_LEN + WLAN_RATES_MAXLEN + 1];
920 BYTE abyCurrExtSuppRates[WLAN_IEHDR_LEN + WLAN_RATES_MAXLEN + 1];
921
922 if (pMgmt->eCurrMode != WMAC_MODE_ESS_AP)
923 return;
924 // node index not found
925 if (!uNodeIndex)
926 return;
927 //check if node is authenticated
928 //decode the frame
929 memset(&sFrame, 0, sizeof(WLAN_FR_REASSOCREQ));
930 sFrame.len = pRxPacket->cbMPDULen;
931 sFrame.pBuf = (PBYTE)pRxPacket->p80211Header;
932 vMgrDecodeReassocRequest(&sFrame);
933
934 if (pMgmt->sNodeDBTable[uNodeIndex].eNodeState >= NODE_AUTH) {
935 pMgmt->sNodeDBTable[uNodeIndex].eNodeState = NODE_ASSOC;
936 pMgmt->sNodeDBTable[uNodeIndex].wCapInfo = cpu_to_le16(*sFrame.pwCapInfo);
937 pMgmt->sNodeDBTable[uNodeIndex].wListenInterval = cpu_to_le16(*sFrame.pwListenInterval);
938 pMgmt->sNodeDBTable[uNodeIndex].bPSEnable =
939 WLAN_GET_FC_PWRMGT(sFrame.pHdr->sA3.wFrameCtl) ? TRUE : FALSE;
940 // Todo: check sta basic rate, if ap can't support, set status code
941
942 if (pDevice->eCurrentPHYType == PHY_TYPE_11B) {
943 uRateLen = WLAN_RATES_MAXLEN_11B;
944 }
945
946 abyCurrSuppRates[0] = WLAN_EID_SUPP_RATES;
947 abyCurrSuppRates[1] = RATEuSetIE((PWLAN_IE_SUPP_RATES)sFrame.pSuppRates,
948 (PWLAN_IE_SUPP_RATES)abyCurrSuppRates,
949 uRateLen);
950 abyCurrExtSuppRates[0] = WLAN_EID_EXTSUPP_RATES;
951 if (pDevice->eCurrentPHYType == PHY_TYPE_11G) {
952 abyCurrExtSuppRates[1] = RATEuSetIE((PWLAN_IE_SUPP_RATES)sFrame.pExtSuppRates,
953 (PWLAN_IE_SUPP_RATES)abyCurrExtSuppRates,
954 uRateLen);
955 } else {
956 abyCurrExtSuppRates[1] = 0;
957 }
958
959
960 RATEvParseMaxRate((PVOID)pDevice,
961 (PWLAN_IE_SUPP_RATES)abyCurrSuppRates,
962 (PWLAN_IE_SUPP_RATES)abyCurrExtSuppRates,
963 FALSE, // do not change our basic rate
964 &(pMgmt->sNodeDBTable[uNodeIndex].wMaxBasicRate),
965 &(pMgmt->sNodeDBTable[uNodeIndex].wMaxSuppRate),
966 &(pMgmt->sNodeDBTable[uNodeIndex].wSuppRate),
967 &(pMgmt->sNodeDBTable[uNodeIndex].byTopCCKBasicRate),
968 &(pMgmt->sNodeDBTable[uNodeIndex].byTopOFDMBasicRate)
969 );
970
971 // set max tx rate
972 pMgmt->sNodeDBTable[uNodeIndex].wTxDataRate =
973 pMgmt->sNodeDBTable[uNodeIndex].wMaxSuppRate;
974#ifdef PLICE_DEBUG
975 printk("RxReAssocRequest:TxDataRate is %d\n",pMgmt->sNodeDBTable[uNodeIndex].wTxDataRate);
976#endif
977 // Todo: check sta preamble, if ap can't support, set status code
978 pMgmt->sNodeDBTable[uNodeIndex].bShortPreamble =
979 WLAN_GET_CAP_INFO_SHORTPREAMBLE(*sFrame.pwCapInfo);
980 pMgmt->sNodeDBTable[uNodeIndex].bShortSlotTime =
981 WLAN_GET_CAP_INFO_SHORTSLOTTIME(*sFrame.pwCapInfo);
982 pMgmt->sNodeDBTable[uNodeIndex].wAID = (WORD)uNodeIndex;
983 wAssocStatus = WLAN_MGMT_STATUS_SUCCESS;
984 wAssocAID = (WORD)uNodeIndex;
985
986 // if suppurt ERP
987 if(pMgmt->sNodeDBTable[uNodeIndex].wMaxSuppRate > RATE_11M)
988 pMgmt->sNodeDBTable[uNodeIndex].bERPExist = TRUE;
989
990 if (pMgmt->sNodeDBTable[uNodeIndex].wMaxSuppRate <= RATE_11M) {
991 // B only STA join
992 pDevice->bProtectMode = TRUE;
993 pDevice->bNonERPPresent = TRUE;
994 }
995 if (pMgmt->sNodeDBTable[uNodeIndex].bShortPreamble == FALSE) {
996 pDevice->bBarkerPreambleMd = TRUE;
997 }
998
999 DEVICE_PRT(MSG_LEVEL_INFO, KERN_INFO "Rx ReAssociate AID= %d \n", wAssocAID);
1000 DEVICE_PRT(MSG_LEVEL_INFO, KERN_INFO "MAC=%2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X \n",
1001 sFrame.pHdr->sA3.abyAddr2[0],
1002 sFrame.pHdr->sA3.abyAddr2[1],
1003 sFrame.pHdr->sA3.abyAddr2[2],
1004 sFrame.pHdr->sA3.abyAddr2[3],
1005 sFrame.pHdr->sA3.abyAddr2[4],
1006 sFrame.pHdr->sA3.abyAddr2[5]
1007 ) ;
1008 DEVICE_PRT(MSG_LEVEL_INFO, KERN_INFO "Max Support rate = %d \n",
1009 pMgmt->sNodeDBTable[uNodeIndex].wMaxSuppRate);
1010
1011 }
1012
1013
1014 // assoc response reply..
1015 pTxPacket = s_MgrMakeReAssocResponse
1016 (
1017 pDevice,
1018 pMgmt,
1019 pMgmt->wCurrCapInfo,
1020 wAssocStatus,
1021 wAssocAID,
1022 sFrame.pHdr->sA3.abyAddr2,
1023 (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates,
1024 (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates
1025 );
1026
1027 if (pTxPacket != NULL ){
1028 /* send the frame */
1029 if (pDevice->bEnableHostapd) {
1030 return;
1031 }
1032 Status = csMgmt_xmit(pDevice, pTxPacket);
1033 if (Status != CMD_STATUS_PENDING) {
1034 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Mgt:ReAssoc response tx failed\n");
1035 }
1036 else {
1037 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Mgt:ReAssoc response tx sending..\n");
1038 }
1039 }
1040 return;
1041}
1042
1043
1044/*+
1045 *
1046 * Routine Description:
1047 * Handle incoming association response frames.
1048 *
1049 * Return Value:
1050 * None.
1051 *
1052-*/
1053
1054static
1055VOID
1056s_vMgrRxAssocResponse(
1057 IN PSDevice pDevice,
1058 IN PSMgmtObject pMgmt,
1059 IN PSRxMgmtPacket pRxPacket,
1060 IN BOOL bReAssocType
1061 )
1062{
1063 WLAN_FR_ASSOCRESP sFrame;
1064 PWLAN_IE_SSID pItemSSID;
1065 PBYTE pbyIEs;
1066 viawget_wpa_header *wpahdr;
1067
1068
1069
1070 if (pMgmt->eCurrState == WMAC_STATE_ASSOCPENDING ||
1071 pMgmt->eCurrState == WMAC_STATE_ASSOC) {
1072
1073 sFrame.len = pRxPacket->cbMPDULen;
1074 sFrame.pBuf = (PBYTE)pRxPacket->p80211Header;
1075 // decode the frame
1076 vMgrDecodeAssocResponse(&sFrame);
1077 if ((sFrame.pwCapInfo == 0) ||
1078 (sFrame.pwStatus == 0) ||
1079 (sFrame.pwAid == 0) ||
1080 (sFrame.pSuppRates == 0)){
1081 DBG_PORT80(0xCC);
1082 return;
1083 };
1084
1085 pMgmt->sAssocInfo.AssocInfo.ResponseFixedIEs.Capabilities = *(sFrame.pwCapInfo);
1086 pMgmt->sAssocInfo.AssocInfo.ResponseFixedIEs.StatusCode = *(sFrame.pwStatus);
1087 pMgmt->sAssocInfo.AssocInfo.ResponseFixedIEs.AssociationId = *(sFrame.pwAid);
1088 pMgmt->sAssocInfo.AssocInfo.AvailableResponseFixedIEs |= 0x07;
1089
1090 pMgmt->sAssocInfo.AssocInfo.ResponseIELength = sFrame.len - 24 - 6;
1091 pMgmt->sAssocInfo.AssocInfo.OffsetResponseIEs = pMgmt->sAssocInfo.AssocInfo.OffsetRequestIEs + pMgmt->sAssocInfo.AssocInfo.RequestIELength;
1092 pbyIEs = pMgmt->sAssocInfo.abyIEs;
1093 pbyIEs += pMgmt->sAssocInfo.AssocInfo.RequestIELength;
1094 memcpy(pbyIEs, (sFrame.pBuf + 24 +6), pMgmt->sAssocInfo.AssocInfo.ResponseIELength);
1095
1096 // save values and set current BSS state
1097 if (cpu_to_le16((*(sFrame.pwStatus))) == WLAN_MGMT_STATUS_SUCCESS ){
1098 // set AID
1099 pMgmt->wCurrAID = cpu_to_le16((*(sFrame.pwAid)));
1100 if ( (pMgmt->wCurrAID >> 14) != (BIT0 | BIT1) )
1101 {
1102 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "AID from AP, has two msb clear.\n");
1103 };
1104 DEVICE_PRT(MSG_LEVEL_INFO, KERN_INFO "Association Successful, AID=%d.\n", pMgmt->wCurrAID & ~(BIT14|BIT15));
1105 pMgmt->eCurrState = WMAC_STATE_ASSOC;
1106 BSSvUpdateAPNode((HANDLE)pDevice, sFrame.pwCapInfo, sFrame.pSuppRates, sFrame.pExtSuppRates);
1107 pItemSSID = (PWLAN_IE_SSID)pMgmt->abyCurrSSID;
1108 DEVICE_PRT(MSG_LEVEL_INFO, KERN_INFO "Link with AP(SSID): %s\n", pItemSSID->abySSID);
1109 pDevice->bLinkPass = TRUE;
1110 pDevice->uBBVGADiffCount = 0;
1111 if ((pDevice->bWPADEVUp) && (pDevice->skb != NULL)) {
1112 if(skb_tailroom(pDevice->skb) <(sizeof(viawget_wpa_header)+pMgmt->sAssocInfo.AssocInfo.ResponseIELength+
1113 pMgmt->sAssocInfo.AssocInfo.RequestIELength)) { //data room not enough
1114 dev_kfree_skb(pDevice->skb);
1115 pDevice->skb = dev_alloc_skb((int)pDevice->rx_buf_sz);
1116 }
1117 wpahdr = (viawget_wpa_header *)pDevice->skb->data;
1118 wpahdr->type = VIAWGET_ASSOC_MSG;
1119 wpahdr->resp_ie_len = pMgmt->sAssocInfo.AssocInfo.ResponseIELength;
1120 wpahdr->req_ie_len = pMgmt->sAssocInfo.AssocInfo.RequestIELength;
1121 memcpy(pDevice->skb->data + sizeof(viawget_wpa_header), pMgmt->sAssocInfo.abyIEs, wpahdr->req_ie_len);
1122 memcpy(pDevice->skb->data + sizeof(viawget_wpa_header) + wpahdr->req_ie_len,
1123 pbyIEs,
1124 wpahdr->resp_ie_len
1125 );
1126 skb_put(pDevice->skb, sizeof(viawget_wpa_header) + wpahdr->resp_ie_len + wpahdr->req_ie_len);
1127 pDevice->skb->dev = pDevice->wpadev;
1128#if LINUX_VERSION_CODE > KERNEL_VERSION(2,6,21)
1129 pDevice->skb->mac_header = pDevice->skb->data;
1130#else
1131 pDevice->skb->mac.raw = pDevice->skb->data;
1132#endif
1133 pDevice->skb->pkt_type = PACKET_HOST;
1134 pDevice->skb->protocol = htons(ETH_P_802_2);
1135 memset(pDevice->skb->cb, 0, sizeof(pDevice->skb->cb));
1136 netif_rx(pDevice->skb);
1137 pDevice->skb = dev_alloc_skb((int)pDevice->rx_buf_sz);
1138 }
1139
1140//2008-0409-07, <Add> by Einsn Liu
1141#ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
1142 //if(pDevice->bWPADevEnable == TRUE)
1143 {
1144 BYTE buf[512];
1145 size_t len;
1146 union iwreq_data wrqu;
1147 int we_event;
1148
1149 memset(buf, 0, 512);
1150
1151 len = pMgmt->sAssocInfo.AssocInfo.RequestIELength;
1152 if(len) {
1153 memcpy(buf, pMgmt->sAssocInfo.abyIEs, len);
1154 memset(&wrqu, 0, sizeof (wrqu));
1155 wrqu.data.length = len;
1156 we_event = IWEVASSOCREQIE;
1157 wireless_send_event(pDevice->dev, we_event, &wrqu, buf);
1158 }
1159
1160 memset(buf, 0, 512);
1161 len = pMgmt->sAssocInfo.AssocInfo.ResponseIELength;
1162
1163 if(len) {
1164 memcpy(buf, pbyIEs, len);
1165 memset(&wrqu, 0, sizeof (wrqu));
1166 wrqu.data.length = len;
1167 we_event = IWEVASSOCRESPIE;
1168 wireless_send_event(pDevice->dev, we_event, &wrqu, buf);
1169 }
1170
1171
1172 memset(&wrqu, 0, sizeof (wrqu));
1173 memcpy(wrqu.ap_addr.sa_data, &pMgmt->abyCurrBSSID[0], ETH_ALEN);
1174 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
1175 wireless_send_event(pDevice->dev, SIOCGIWAP, &wrqu, NULL);
1176 }
1177#endif //#ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
1178//End Add -- //2008-0409-07, <Add> by Einsn Liu
1179 }
1180 else {
1181 if (bReAssocType) {
1182 pMgmt->eCurrState = WMAC_STATE_IDLE;
1183 }
1184 else {
1185 // jump back to the auth state and indicate the error
1186 pMgmt->eCurrState = WMAC_STATE_AUTH;
1187 }
1188 s_vMgrLogStatus(pMgmt,cpu_to_le16((*(sFrame.pwStatus))));
1189 }
1190
1191 }
1192
1193#ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
1194//need clear flags related to Networkmanager
1195
1196 pDevice->bwextcount = 0;
1197 pDevice->bWPASuppWextEnabled = FALSE;
1198#endif
1199
1200
1201if(pMgmt->eCurrState == WMAC_STATE_ASSOC)
1202 timer_expire(pDevice->sTimerCommand, 0);
1203 return;
1204}
1205
1206
1207
1208/*+
1209 *
1210 * Routine Description:
1211 * Start the station authentication procedure. Namely, send an
1212 * authentication frame to the AP.
1213 *
1214 * Return Value:
1215 * None.
1216 *
1217-*/
1218
1219VOID
1220vMgrAuthenBeginSta(
1221 IN HANDLE hDeviceContext,
1222 IN PSMgmtObject pMgmt,
1223 OUT PCMD_STATUS pStatus
1224 )
1225{
1226 PSDevice pDevice = (PSDevice)hDeviceContext;
1227 WLAN_FR_AUTHEN sFrame;
1228 PSTxMgmtPacket pTxPacket = NULL;
1229
1230 pTxPacket = (PSTxMgmtPacket)pMgmt->pbyMgmtPacketPool;
1231 memset(pTxPacket, 0, sizeof(STxMgmtPacket) + WLAN_AUTHEN_FR_MAXLEN);
1232 pTxPacket->p80211Header = (PUWLAN_80211HDR)((PBYTE)pTxPacket + sizeof(STxMgmtPacket));
1233 sFrame.pBuf = (PBYTE)pTxPacket->p80211Header;
1234 sFrame.len = WLAN_AUTHEN_FR_MAXLEN;
1235 vMgrEncodeAuthen(&sFrame);
1236 /* insert values */
1237 sFrame.pHdr->sA3.wFrameCtl = cpu_to_le16(
1238 (
1239 WLAN_SET_FC_FTYPE(WLAN_TYPE_MGR) |
1240 WLAN_SET_FC_FSTYPE(WLAN_FSTYPE_AUTHEN)
1241 ));
1242 memcpy( sFrame.pHdr->sA3.abyAddr1, pMgmt->abyCurrBSSID, WLAN_ADDR_LEN);
1243 memcpy( sFrame.pHdr->sA3.abyAddr2, pMgmt->abyMACAddr, WLAN_ADDR_LEN);
1244 memcpy( sFrame.pHdr->sA3.abyAddr3, pMgmt->abyCurrBSSID, WLAN_BSSID_LEN);
1245 if (pMgmt->bShareKeyAlgorithm)
1246 *(sFrame.pwAuthAlgorithm) = cpu_to_le16(WLAN_AUTH_ALG_SHAREDKEY);
1247 else
1248 *(sFrame.pwAuthAlgorithm) = cpu_to_le16(WLAN_AUTH_ALG_OPENSYSTEM);
1249
1250 *(sFrame.pwAuthSequence) = cpu_to_le16(1);
1251 /* Adjust the length fields */
1252 pTxPacket->cbMPDULen = sFrame.len;
1253 pTxPacket->cbPayloadLen = sFrame.len - WLAN_HDR_ADDR3_LEN;
1254
1255 *pStatus = csMgmt_xmit(pDevice, pTxPacket);
1256 if (*pStatus == CMD_STATUS_PENDING){
1257 pMgmt->eCurrState = WMAC_STATE_AUTHPENDING;
1258 *pStatus = CMD_STATUS_SUCCESS;
1259 }
1260
1261 return ;
1262}
1263
1264
1265
1266/*+
1267 *
1268 * Routine Description:
1269 * Start the station(AP) deauthentication procedure. Namely, send an
1270 * deauthentication frame to the AP or Sta.
1271 *
1272 * Return Value:
1273 * None.
1274 *
1275-*/
1276
1277VOID
1278vMgrDeAuthenBeginSta(
1279 IN HANDLE hDeviceContext,
1280 IN PSMgmtObject pMgmt,
1281 IN PBYTE abyDestAddress,
1282 IN WORD wReason,
1283 OUT PCMD_STATUS pStatus
1284 )
1285{
1286 PSDevice pDevice = (PSDevice)hDeviceContext;
1287 WLAN_FR_DEAUTHEN sFrame;
1288 PSTxMgmtPacket pTxPacket = NULL;
1289
1290
1291 pTxPacket = (PSTxMgmtPacket)pMgmt->pbyMgmtPacketPool;
1292 memset(pTxPacket, 0, sizeof(STxMgmtPacket) + WLAN_DEAUTHEN_FR_MAXLEN);
1293 pTxPacket->p80211Header = (PUWLAN_80211HDR)((PBYTE)pTxPacket + sizeof(STxMgmtPacket));
1294 sFrame.pBuf = (PBYTE)pTxPacket->p80211Header;
1295 sFrame.len = WLAN_DEAUTHEN_FR_MAXLEN;
1296 vMgrEncodeDeauthen(&sFrame);
1297 /* insert values */
1298 sFrame.pHdr->sA3.wFrameCtl = cpu_to_le16(
1299 (
1300 WLAN_SET_FC_FTYPE(WLAN_TYPE_MGR) |
1301 WLAN_SET_FC_FSTYPE(WLAN_FSTYPE_DEAUTHEN)
1302 ));
1303
1304 memcpy( sFrame.pHdr->sA3.abyAddr1, abyDestAddress, WLAN_ADDR_LEN);
1305 memcpy( sFrame.pHdr->sA3.abyAddr2, pMgmt->abyMACAddr, WLAN_ADDR_LEN);
1306 memcpy( sFrame.pHdr->sA3.abyAddr3, pMgmt->abyCurrBSSID, WLAN_BSSID_LEN);
1307
1308 *(sFrame.pwReason) = cpu_to_le16(wReason); // deauthen. bcs left BSS
1309 /* Adjust the length fields */
1310 pTxPacket->cbMPDULen = sFrame.len;
1311 pTxPacket->cbPayloadLen = sFrame.len - WLAN_HDR_ADDR3_LEN;
1312
1313 *pStatus = csMgmt_xmit(pDevice, pTxPacket);
1314 if (*pStatus == CMD_STATUS_PENDING){
1315 *pStatus = CMD_STATUS_SUCCESS;
1316 }
1317
1318
1319 return ;
1320}
1321
1322
1323/*+
1324 *
1325 * Routine Description:
1326 * Handle incoming authentication frames.
1327 *
1328 * Return Value:
1329 * None.
1330 *
1331-*/
1332
1333static
1334VOID
1335s_vMgrRxAuthentication(
1336 IN PSDevice pDevice,
1337 IN PSMgmtObject pMgmt,
1338 IN PSRxMgmtPacket pRxPacket
1339 )
1340{
1341 WLAN_FR_AUTHEN sFrame;
1342
1343 // we better be an AP or a STA in AUTHPENDING otherwise ignore
1344 if (!(pMgmt->eCurrMode == WMAC_MODE_ESS_AP ||
1345 pMgmt->eCurrState == WMAC_STATE_AUTHPENDING)) {
1346 return;
1347 }
1348
1349 // decode the frame
1350 sFrame.len = pRxPacket->cbMPDULen;
1351 sFrame.pBuf = (PBYTE)pRxPacket->p80211Header;
1352 vMgrDecodeAuthen(&sFrame);
1353 switch (cpu_to_le16((*(sFrame.pwAuthSequence )))){
1354 case 1:
1355 //AP funciton
1356 s_vMgrRxAuthenSequence_1(pDevice,pMgmt, &sFrame);
1357 break;
1358 case 2:
1359 s_vMgrRxAuthenSequence_2(pDevice, pMgmt, &sFrame);
1360 break;
1361 case 3:
1362 //AP funciton
1363 s_vMgrRxAuthenSequence_3(pDevice, pMgmt, &sFrame);
1364 break;
1365 case 4:
1366 s_vMgrRxAuthenSequence_4(pDevice, pMgmt, &sFrame);
1367 break;
1368 default:
1369 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Auth Sequence error, seq = %d\n",
1370 cpu_to_le16((*(sFrame.pwAuthSequence))));
1371 break;
1372 }
1373 return;
1374}
1375
1376
1377
1378/*+
1379 *
1380 * Routine Description:
1381 * Handles incoming authen frames with sequence 1. Currently
1382 * assumes we're an AP. So far, no one appears to use authentication
1383 * in Ad-Hoc mode.
1384 *
1385 * Return Value:
1386 * None.
1387 *
1388-*/
1389
1390
1391static
1392VOID
1393s_vMgrRxAuthenSequence_1(
1394 IN PSDevice pDevice,
1395 IN PSMgmtObject pMgmt,
1396 IN PWLAN_FR_AUTHEN pFrame
1397 )
1398{
1399 PSTxMgmtPacket pTxPacket = NULL;
1400 UINT uNodeIndex;
1401 WLAN_FR_AUTHEN sFrame;
1402 PSKeyItem pTransmitKey;
1403
1404 // Insert a Node entry
1405 if (!BSSDBbIsSTAInNodeDB(pMgmt, pFrame->pHdr->sA3.abyAddr2, &uNodeIndex)) {
1406 BSSvCreateOneNode((PSDevice)pDevice, &uNodeIndex);
1407 memcpy(pMgmt->sNodeDBTable[uNodeIndex].abyMACAddr, pFrame->pHdr->sA3.abyAddr2,
1408 WLAN_ADDR_LEN);
1409 }
1410
1411 if (pMgmt->bShareKeyAlgorithm) {
1412 pMgmt->sNodeDBTable[uNodeIndex].eNodeState = NODE_KNOWN;
1413 pMgmt->sNodeDBTable[uNodeIndex].byAuthSequence = 1;
1414 }
1415 else {
1416 pMgmt->sNodeDBTable[uNodeIndex].eNodeState = NODE_AUTH;
1417 }
1418
1419 // send auth reply
1420 pTxPacket = (PSTxMgmtPacket)pMgmt->pbyMgmtPacketPool;
1421 memset(pTxPacket, 0, sizeof(STxMgmtPacket) + WLAN_AUTHEN_FR_MAXLEN);
1422 pTxPacket->p80211Header = (PUWLAN_80211HDR)((PBYTE)pTxPacket + sizeof(STxMgmtPacket));
1423 sFrame.pBuf = (PBYTE)pTxPacket->p80211Header;
1424 sFrame.len = WLAN_AUTHEN_FR_MAXLEN;
1425 // format buffer structure
1426 vMgrEncodeAuthen(&sFrame);
1427 // insert values
1428 sFrame.pHdr->sA3.wFrameCtl = cpu_to_le16(
1429 (
1430 WLAN_SET_FC_FTYPE(WLAN_TYPE_MGR) |
1431 WLAN_SET_FC_FSTYPE(WLAN_FSTYPE_AUTHEN)|
1432 WLAN_SET_FC_ISWEP(0)
1433 ));
1434 memcpy( sFrame.pHdr->sA3.abyAddr1, pFrame->pHdr->sA3.abyAddr2, WLAN_ADDR_LEN);
1435 memcpy( sFrame.pHdr->sA3.abyAddr2, pMgmt->abyMACAddr, WLAN_ADDR_LEN);
1436 memcpy( sFrame.pHdr->sA3.abyAddr3, pMgmt->abyCurrBSSID, WLAN_BSSID_LEN);
1437 *(sFrame.pwAuthAlgorithm) = *(pFrame->pwAuthAlgorithm);
1438 *(sFrame.pwAuthSequence) = cpu_to_le16(2);
1439
1440 if (cpu_to_le16(*(pFrame->pwAuthAlgorithm)) == WLAN_AUTH_ALG_SHAREDKEY) {
1441 if (pMgmt->bShareKeyAlgorithm)
1442 *(sFrame.pwStatus) = cpu_to_le16(WLAN_MGMT_STATUS_SUCCESS);
1443 else
1444 *(sFrame.pwStatus) = cpu_to_le16(WLAN_MGMT_STATUS_UNSUPPORTED_AUTHALG);
1445 }
1446 else {
1447 if (pMgmt->bShareKeyAlgorithm)
1448 *(sFrame.pwStatus) = cpu_to_le16(WLAN_MGMT_STATUS_UNSUPPORTED_AUTHALG);
1449 else
1450 *(sFrame.pwStatus) = cpu_to_le16(WLAN_MGMT_STATUS_SUCCESS);
1451 }
1452
1453 if (pMgmt->bShareKeyAlgorithm &&
1454 (cpu_to_le16(*(sFrame.pwStatus)) == WLAN_MGMT_STATUS_SUCCESS)) {
1455
1456 sFrame.pChallenge = (PWLAN_IE_CHALLENGE)(sFrame.pBuf + sFrame.len);
1457 sFrame.len += WLAN_CHALLENGE_IE_LEN;
1458 sFrame.pChallenge->byElementID = WLAN_EID_CHALLENGE;
1459 sFrame.pChallenge->len = WLAN_CHALLENGE_LEN;
1460 memset(pMgmt->abyChallenge, 0, WLAN_CHALLENGE_LEN);
1461 // get group key
1462 if(KeybGetTransmitKey(&(pDevice->sKey), pDevice->abyBroadcastAddr, GROUP_KEY, &pTransmitKey) == TRUE) {
1463 rc4_init(&pDevice->SBox, pDevice->abyPRNG, pTransmitKey->uKeyLength+3);
1464 rc4_encrypt(&pDevice->SBox, pMgmt->abyChallenge, pMgmt->abyChallenge, WLAN_CHALLENGE_LEN);
1465 }
1466 memcpy(sFrame.pChallenge->abyChallenge, pMgmt->abyChallenge , WLAN_CHALLENGE_LEN);
1467 }
1468
1469 /* Adjust the length fields */
1470 pTxPacket->cbMPDULen = sFrame.len;
1471 pTxPacket->cbPayloadLen = sFrame.len - WLAN_HDR_ADDR3_LEN;
1472 // send the frame
1473 if (pDevice->bEnableHostapd) {
1474 return;
1475 }
1476 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Mgt:Authreq_reply sequence_1 tx.. \n");
1477 if (csMgmt_xmit(pDevice, pTxPacket) != CMD_STATUS_PENDING) {
1478 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Mgt:Authreq_reply sequence_1 tx failed.\n");
1479 }
1480 return;
1481}
1482
1483
1484
1485/*+
1486 *
1487 * Routine Description:
1488 * Handles incoming auth frames with sequence number 2. Currently
1489 * assumes we're a station.
1490 *
1491 *
1492 * Return Value:
1493 * None.
1494 *
1495-*/
1496
1497static
1498VOID
1499s_vMgrRxAuthenSequence_2(
1500 IN PSDevice pDevice,
1501 IN PSMgmtObject pMgmt,
1502 IN PWLAN_FR_AUTHEN pFrame
1503 )
1504{
1505 WLAN_FR_AUTHEN sFrame;
1506 PSTxMgmtPacket pTxPacket = NULL;
1507
1508
1509 switch (cpu_to_le16((*(pFrame->pwAuthAlgorithm))))
1510 {
1511 case WLAN_AUTH_ALG_OPENSYSTEM:
1512 if ( cpu_to_le16((*(pFrame->pwStatus))) == WLAN_MGMT_STATUS_SUCCESS ){
1513 DEVICE_PRT(MSG_LEVEL_INFO, KERN_INFO "802.11 Authen (OPEN) Successful.\n");
1514 pMgmt->eCurrState = WMAC_STATE_AUTH;
1515 timer_expire(pDevice->sTimerCommand, 0);
1516 }
1517 else {
1518 DEVICE_PRT(MSG_LEVEL_INFO, KERN_INFO "802.11 Authen (OPEN) Failed.\n");
1519 s_vMgrLogStatus(pMgmt, cpu_to_le16((*(pFrame->pwStatus))));
1520 pMgmt->eCurrState = WMAC_STATE_IDLE;
1521 }
1522 if (pDevice->eCommandState == WLAN_AUTHENTICATE_WAIT ) {
1523// spin_unlock_irq(&pDevice->lock);
1524// vCommandTimerWait((HANDLE)pDevice, 0);
1525// spin_lock_irq(&pDevice->lock);
1526 }
1527
1528 break;
1529
1530 case WLAN_AUTH_ALG_SHAREDKEY:
1531
1532 if (cpu_to_le16((*(pFrame->pwStatus))) == WLAN_MGMT_STATUS_SUCCESS) {
1533 pTxPacket = (PSTxMgmtPacket)pMgmt->pbyMgmtPacketPool;
1534 memset(pTxPacket, 0, sizeof(STxMgmtPacket) + WLAN_AUTHEN_FR_MAXLEN);
1535 pTxPacket->p80211Header = (PUWLAN_80211HDR)((PBYTE)pTxPacket + sizeof(STxMgmtPacket));
1536 sFrame.pBuf = (PBYTE)pTxPacket->p80211Header;
1537 sFrame.len = WLAN_AUTHEN_FR_MAXLEN;
1538 // format buffer structure
1539 vMgrEncodeAuthen(&sFrame);
1540 // insert values
1541 sFrame.pHdr->sA3.wFrameCtl = cpu_to_le16(
1542 (
1543 WLAN_SET_FC_FTYPE(WLAN_TYPE_MGR) |
1544 WLAN_SET_FC_FSTYPE(WLAN_FSTYPE_AUTHEN)|
1545 WLAN_SET_FC_ISWEP(1)
1546 ));
1547 memcpy( sFrame.pHdr->sA3.abyAddr1, pMgmt->abyCurrBSSID, WLAN_BSSID_LEN);
1548 memcpy( sFrame.pHdr->sA3.abyAddr2, pMgmt->abyMACAddr, WLAN_ADDR_LEN);
1549 memcpy( sFrame.pHdr->sA3.abyAddr3, pMgmt->abyCurrBSSID, WLAN_BSSID_LEN);
1550 *(sFrame.pwAuthAlgorithm) = *(pFrame->pwAuthAlgorithm);
1551 *(sFrame.pwAuthSequence) = cpu_to_le16(3);
1552 *(sFrame.pwStatus) = cpu_to_le16(WLAN_MGMT_STATUS_SUCCESS);
1553 sFrame.pChallenge = (PWLAN_IE_CHALLENGE)(sFrame.pBuf + sFrame.len);
1554 sFrame.len += WLAN_CHALLENGE_IE_LEN;
1555 sFrame.pChallenge->byElementID = WLAN_EID_CHALLENGE;
1556 sFrame.pChallenge->len = WLAN_CHALLENGE_LEN;
1557 memcpy( sFrame.pChallenge->abyChallenge, pFrame->pChallenge->abyChallenge, WLAN_CHALLENGE_LEN);
1558 // Adjust the length fields
1559 pTxPacket->cbMPDULen = sFrame.len;
1560 pTxPacket->cbPayloadLen = sFrame.len - WLAN_HDR_ADDR3_LEN;
1561 // send the frame
1562 if (csMgmt_xmit(pDevice, pTxPacket) != CMD_STATUS_PENDING) {
1563 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Mgt:Auth_reply sequence_2 tx failed.\n");
1564 }
1565 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Mgt:Auth_reply sequence_2 tx ...\n");
1566 }
1567 else {
1568 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Mgt:rx Auth_reply sequence_2 status error ...\n");
1569 if ( pDevice->eCommandState == WLAN_AUTHENTICATE_WAIT ) {
1570// spin_unlock_irq(&pDevice->lock);
1571// vCommandTimerWait((HANDLE)pDevice, 0);
1572// spin_lock_irq(&pDevice->lock);
1573 }
1574 s_vMgrLogStatus(pMgmt, cpu_to_le16((*(pFrame->pwStatus))));
1575 }
1576 break;
1577 default:
1578 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Mgt: rx auth.seq = 2 unknown AuthAlgorithm=%d\n", cpu_to_le16((*(pFrame->pwAuthAlgorithm))));
1579 break;
1580 }
1581 return;
1582}
1583
1584
1585
1586/*+
1587 *
1588 * Routine Description:
1589 * Handles incoming authen frames with sequence 3. Currently
1590 * assumes we're an AP. This function assumes the frame has
1591 * already been successfully decrypted.
1592 *
1593 *
1594 * Return Value:
1595 * None.
1596 *
1597-*/
1598
1599static
1600VOID
1601s_vMgrRxAuthenSequence_3(
1602 IN PSDevice pDevice,
1603 IN PSMgmtObject pMgmt,
1604 IN PWLAN_FR_AUTHEN pFrame
1605 )
1606{
1607 PSTxMgmtPacket pTxPacket = NULL;
1608 UINT uStatusCode = 0 ;
1609 UINT uNodeIndex = 0;
1610 WLAN_FR_AUTHEN sFrame;
1611
1612 if (!WLAN_GET_FC_ISWEP(pFrame->pHdr->sA3.wFrameCtl)) {
1613 uStatusCode = WLAN_MGMT_STATUS_CHALLENGE_FAIL;
1614 goto reply;
1615 }
1616 if (BSSDBbIsSTAInNodeDB(pMgmt, pFrame->pHdr->sA3.abyAddr2, &uNodeIndex)) {
1617 if (pMgmt->sNodeDBTable[uNodeIndex].byAuthSequence != 1) {
1618 uStatusCode = WLAN_MGMT_STATUS_RX_AUTH_NOSEQ;
1619 goto reply;
1620 }
1621 if (memcmp(pMgmt->abyChallenge, pFrame->pChallenge->abyChallenge, WLAN_CHALLENGE_LEN) != 0) {
1622 uStatusCode = WLAN_MGMT_STATUS_CHALLENGE_FAIL;
1623 goto reply;
1624 }
1625 }
1626 else {
1627 uStatusCode = WLAN_MGMT_STATUS_UNSPEC_FAILURE;
1628 goto reply;
1629 }
1630
1631 if (uNodeIndex) {
1632 pMgmt->sNodeDBTable[uNodeIndex].eNodeState = NODE_AUTH;
1633 pMgmt->sNodeDBTable[uNodeIndex].byAuthSequence = 0;
1634 }
1635 uStatusCode = WLAN_MGMT_STATUS_SUCCESS;
1636 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Challenge text check ok..\n");
1637
1638reply:
1639 // send auth reply
1640 pTxPacket = (PSTxMgmtPacket)pMgmt->pbyMgmtPacketPool;
1641 memset(pTxPacket, 0, sizeof(STxMgmtPacket) + WLAN_AUTHEN_FR_MAXLEN);
1642 pTxPacket->p80211Header = (PUWLAN_80211HDR)((PBYTE)pTxPacket + sizeof(STxMgmtPacket));
1643 sFrame.pBuf = (PBYTE)pTxPacket->p80211Header;
1644 sFrame.len = WLAN_AUTHEN_FR_MAXLEN;
1645 // format buffer structure
1646 vMgrEncodeAuthen(&sFrame);
1647 /* insert values */
1648 sFrame.pHdr->sA3.wFrameCtl = cpu_to_le16(
1649 (
1650 WLAN_SET_FC_FTYPE(WLAN_TYPE_MGR) |
1651 WLAN_SET_FC_FSTYPE(WLAN_FSTYPE_AUTHEN)|
1652 WLAN_SET_FC_ISWEP(0)
1653 ));
1654 memcpy( sFrame.pHdr->sA3.abyAddr1, pFrame->pHdr->sA3.abyAddr2, WLAN_ADDR_LEN);
1655 memcpy( sFrame.pHdr->sA3.abyAddr2, pMgmt->abyMACAddr, WLAN_ADDR_LEN);
1656 memcpy( sFrame.pHdr->sA3.abyAddr3, pMgmt->abyCurrBSSID, WLAN_BSSID_LEN);
1657 *(sFrame.pwAuthAlgorithm) = *(pFrame->pwAuthAlgorithm);
1658 *(sFrame.pwAuthSequence) = cpu_to_le16(4);
1659 *(sFrame.pwStatus) = cpu_to_le16(uStatusCode);
1660
1661 /* Adjust the length fields */
1662 pTxPacket->cbMPDULen = sFrame.len;
1663 pTxPacket->cbPayloadLen = sFrame.len - WLAN_HDR_ADDR3_LEN;
1664 // send the frame
1665 if (pDevice->bEnableHostapd) {
1666 return;
1667 }
1668 if (csMgmt_xmit(pDevice, pTxPacket) != CMD_STATUS_PENDING) {
1669 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Mgt:Authreq_reply sequence_4 tx failed.\n");
1670 }
1671 return;
1672
1673}
1674
1675
1676
1677/*+
1678 *
1679 * Routine Description:
1680 * Handles incoming authen frames with sequence 4
1681 *
1682 *
1683 * Return Value:
1684 * None.
1685 *
1686-*/
1687static
1688VOID
1689s_vMgrRxAuthenSequence_4(
1690 IN PSDevice pDevice,
1691 IN PSMgmtObject pMgmt,
1692 IN PWLAN_FR_AUTHEN pFrame
1693 )
1694{
1695
1696 if ( cpu_to_le16((*(pFrame->pwStatus))) == WLAN_MGMT_STATUS_SUCCESS ){
1697 DEVICE_PRT(MSG_LEVEL_INFO, KERN_INFO "802.11 Authen (SHAREDKEY) Successful.\n");
1698 pMgmt->eCurrState = WMAC_STATE_AUTH;
1699 timer_expire(pDevice->sTimerCommand, 0);
1700 }
1701 else{
1702 DEVICE_PRT(MSG_LEVEL_INFO, KERN_INFO "802.11 Authen (SHAREDKEY) Failed.\n");
1703 s_vMgrLogStatus(pMgmt, cpu_to_le16((*(pFrame->pwStatus))) );
1704 pMgmt->eCurrState = WMAC_STATE_IDLE;
1705 }
1706
1707 if ( pDevice->eCommandState == WLAN_AUTHENTICATE_WAIT ) {
1708// spin_unlock_irq(&pDevice->lock);
1709// vCommandTimerWait((HANDLE)pDevice, 0);
1710// spin_lock_irq(&pDevice->lock);
1711 }
1712
1713}
1714
1715/*+
1716 *
1717 * Routine Description:
1718 * Handles incoming disassociation frames
1719 *
1720 *
1721 * Return Value:
1722 * None.
1723 *
1724-*/
1725
1726static
1727VOID
1728s_vMgrRxDisassociation(
1729 IN PSDevice pDevice,
1730 IN PSMgmtObject pMgmt,
1731 IN PSRxMgmtPacket pRxPacket
1732 )
1733{
1734 WLAN_FR_DISASSOC sFrame;
1735 UINT uNodeIndex = 0;
1736// CMD_STATUS CmdStatus;
1737 viawget_wpa_header *wpahdr;
1738
1739 if ( pMgmt->eCurrMode == WMAC_MODE_ESS_AP ){
1740 // if is acting an AP..
1741 // a STA is leaving this BSS..
1742 sFrame.len = pRxPacket->cbMPDULen;
1743 sFrame.pBuf = (PBYTE)pRxPacket->p80211Header;
1744 if (BSSDBbIsSTAInNodeDB(pMgmt, pRxPacket->p80211Header->sA3.abyAddr2, &uNodeIndex)) {
1745 BSSvRemoveOneNode(pDevice, uNodeIndex);
1746 }
1747 else {
1748 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Rx disassoc, sta not found\n");
1749 }
1750 }
1751 else if (pMgmt->eCurrMode == WMAC_MODE_ESS_STA ){
1752 sFrame.len = pRxPacket->cbMPDULen;
1753 sFrame.pBuf = (PBYTE)pRxPacket->p80211Header;
1754 vMgrDecodeDisassociation(&sFrame);
1755 DEVICE_PRT(MSG_LEVEL_NOTICE, KERN_INFO "AP disassociated me, reason=%d.\n", cpu_to_le16(*(sFrame.pwReason)));
1756 //TODO: do something let upper layer know or
1757 //try to send associate packet again because of inactivity timeout
1758 // if (pMgmt->eCurrState == WMAC_STATE_ASSOC) {
1759 // vMgrReAssocBeginSta((PSDevice)pDevice, pMgmt, &CmdStatus);
1760 // };
1761 if ((pDevice->bWPADEVUp) && (pDevice->skb != NULL)) {
1762 wpahdr = (viawget_wpa_header *)pDevice->skb->data;
1763 wpahdr->type = VIAWGET_DISASSOC_MSG;
1764 wpahdr->resp_ie_len = 0;
1765 wpahdr->req_ie_len = 0;
1766 skb_put(pDevice->skb, sizeof(viawget_wpa_header));
1767 pDevice->skb->dev = pDevice->wpadev;
1768#if LINUX_VERSION_CODE > KERNEL_VERSION(2,6,21)
1769 pDevice->skb->mac_header = pDevice->skb->data;
1770#else
1771 pDevice->skb->mac.raw = pDevice->skb->data;
1772#endif
1773
1774 pDevice->skb->pkt_type = PACKET_HOST;
1775 pDevice->skb->protocol = htons(ETH_P_802_2);
1776 memset(pDevice->skb->cb, 0, sizeof(pDevice->skb->cb));
1777 netif_rx(pDevice->skb);
1778 pDevice->skb = dev_alloc_skb((int)pDevice->rx_buf_sz);
1779 };
1780
1781 #ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
1782 // if(pDevice->bWPASuppWextEnabled == TRUE)
1783 {
1784 union iwreq_data wrqu;
1785 memset(&wrqu, 0, sizeof (wrqu));
1786 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
1787 printk("wireless_send_event--->SIOCGIWAP(disassociated)\n");
1788 wireless_send_event(pDevice->dev, SIOCGIWAP, &wrqu, NULL);
1789 }
1790 #endif
1791
1792 }
1793 /* else, ignore it */
1794
1795 return;
1796}
1797
1798
1799/*+
1800 *
1801 * Routine Description:
1802 * Handles incoming deauthentication frames
1803 *
1804 *
1805 * Return Value:
1806 * None.
1807 *
1808-*/
1809
1810static
1811VOID
1812s_vMgrRxDeauthentication(
1813 IN PSDevice pDevice,
1814 IN PSMgmtObject pMgmt,
1815 IN PSRxMgmtPacket pRxPacket
1816 )
1817{
1818 WLAN_FR_DEAUTHEN sFrame;
1819 UINT uNodeIndex = 0;
1820 viawget_wpa_header *wpahdr;
1821
1822
1823 if (pMgmt->eCurrMode == WMAC_MODE_ESS_AP ){
1824 //Todo:
1825 // if is acting an AP..
1826 // a STA is leaving this BSS..
1827 sFrame.len = pRxPacket->cbMPDULen;
1828 sFrame.pBuf = (PBYTE)pRxPacket->p80211Header;
1829 if (BSSDBbIsSTAInNodeDB(pMgmt, pRxPacket->p80211Header->sA3.abyAddr2, &uNodeIndex)) {
1830 BSSvRemoveOneNode(pDevice, uNodeIndex);
1831 }
1832 else {
1833 DEVICE_PRT(MSG_LEVEL_NOTICE, KERN_INFO "Rx deauth, sta not found\n");
1834 }
1835 }
1836 else {
1837 if (pMgmt->eCurrMode == WMAC_MODE_ESS_STA ) {
1838 sFrame.len = pRxPacket->cbMPDULen;
1839 sFrame.pBuf = (PBYTE)pRxPacket->p80211Header;
1840 vMgrDecodeDeauthen(&sFrame);
1841 DEVICE_PRT(MSG_LEVEL_NOTICE, KERN_INFO "AP deauthed me, reason=%d.\n", cpu_to_le16((*(sFrame.pwReason))));
1842 // TODO: update BSS list for specific BSSID if pre-authentication case
1843 if (IS_ETH_ADDRESS_EQUAL(sFrame.pHdr->sA3.abyAddr3, pMgmt->abyCurrBSSID)) {
1844 if (pMgmt->eCurrState >= WMAC_STATE_AUTHPENDING) {
1845 pMgmt->sNodeDBTable[0].bActive = FALSE;
1846 pMgmt->eCurrMode = WMAC_MODE_STANDBY;
1847 pMgmt->eCurrState = WMAC_STATE_IDLE;
1848 netif_stop_queue(pDevice->dev);
1849 pDevice->bLinkPass = FALSE;
1850 }
1851 };
1852
1853 if ((pDevice->bWPADEVUp) && (pDevice->skb != NULL)) {
1854 wpahdr = (viawget_wpa_header *)pDevice->skb->data;
1855 wpahdr->type = VIAWGET_DISASSOC_MSG;
1856 wpahdr->resp_ie_len = 0;
1857 wpahdr->req_ie_len = 0;
1858 skb_put(pDevice->skb, sizeof(viawget_wpa_header));
1859 pDevice->skb->dev = pDevice->wpadev;
1860#if LINUX_VERSION_CODE > KERNEL_VERSION(2,6,21)
1861 pDevice->skb->mac_header = pDevice->skb->data;
1862#else
1863 pDevice->skb->mac.raw = pDevice->skb->data;
1864#endif
1865 pDevice->skb->pkt_type = PACKET_HOST;
1866 pDevice->skb->protocol = htons(ETH_P_802_2);
1867 memset(pDevice->skb->cb, 0, sizeof(pDevice->skb->cb));
1868 netif_rx(pDevice->skb);
1869 pDevice->skb = dev_alloc_skb((int)pDevice->rx_buf_sz);
1870 };
1871
1872 #ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
1873 // if(pDevice->bWPASuppWextEnabled == TRUE)
1874 {
1875 union iwreq_data wrqu;
1876 memset(&wrqu, 0, sizeof (wrqu));
1877 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
1878 printk("wireless_send_event--->SIOCGIWAP(disauthen)\n");
1879 wireless_send_event(pDevice->dev, SIOCGIWAP, &wrqu, NULL);
1880 }
1881 #endif
1882
1883 }
1884 /* else, ignore it. TODO: IBSS authentication service
1885 would be implemented here */
1886 };
1887 return;
1888}
1889
1890
1891//2008-8-4 <add> by chester
1892/*+
1893 *
1894 * Routine Description:
1895 * check if current channel is match ZoneType.
1896 *for USA:1~11;
1897 * Japan:1~13;
1898 * Europe:1~13
1899 * Return Value:
1900 * True:exceed;
1901 * False:normal case
1902-*/
1903static BOOL
1904ChannelExceedZoneType(
1905 IN PSDevice pDevice,
1906 IN BYTE byCurrChannel
1907 )
1908{
1909 BOOL exceed=FALSE;
1910
1911 switch(pDevice->byZoneType) {
1912 case 0x00: //USA:1~11
1913 if((byCurrChannel<1) ||(byCurrChannel>11))
1914 exceed = TRUE;
1915 break;
1916 case 0x01: //Japan:1~13
1917 case 0x02: //Europe:1~13
1918 if((byCurrChannel<1) ||(byCurrChannel>13))
1919 exceed = TRUE;
1920 break;
1921 default: //reserve for other zonetype
1922 break;
1923 }
1924
1925 return exceed;
1926}
1927
1928
1929/*+
1930 *
1931 * Routine Description:
1932 * Handles and analysis incoming beacon frames.
1933 *
1934 *
1935 * Return Value:
1936 * None.
1937 *
1938-*/
1939
1940static
1941VOID
1942s_vMgrRxBeacon(
1943 IN PSDevice pDevice,
1944 IN PSMgmtObject pMgmt,
1945 IN PSRxMgmtPacket pRxPacket,
1946 IN BOOL bInScan
1947 )
1948{
1949
1950 PKnownBSS pBSSList;
1951 WLAN_FR_BEACON sFrame;
1952 QWORD qwTSFOffset;
1953 BOOL bIsBSSIDEqual = FALSE;
1954 BOOL bIsSSIDEqual = FALSE;
1955 BOOL bTSFLargeDiff = FALSE;
1956 BOOL bTSFOffsetPostive = FALSE;
1957 BOOL bUpdateTSF = FALSE;
1958 BOOL bIsAPBeacon = FALSE;
1959 BOOL bIsChannelEqual = FALSE;
1960 UINT uLocateByteIndex;
1961 BYTE byTIMBitOn = 0;
1962 WORD wAIDNumber = 0;
1963 UINT uNodeIndex;
1964 QWORD qwTimestamp, qwLocalTSF;
1965 QWORD qwCurrTSF;
1966 WORD wStartIndex = 0;
1967 WORD wAIDIndex = 0;
1968 BYTE byCurrChannel = pRxPacket->byRxChannel;
1969 ERPObject sERP;
1970 UINT uRateLen = WLAN_RATES_MAXLEN;
1971 BOOL bChannelHit = FALSE;
1972 BOOL bUpdatePhyParameter = FALSE;
1973 BYTE byIEChannel = 0;
1974
1975
1976 memset(&sFrame, 0, sizeof(WLAN_FR_BEACON));
1977 sFrame.len = pRxPacket->cbMPDULen;
1978 sFrame.pBuf = (PBYTE)pRxPacket->p80211Header;
1979
1980 // decode the beacon frame
1981 vMgrDecodeBeacon(&sFrame);
1982
1983 if ((sFrame.pwBeaconInterval == 0) ||
1984 (sFrame.pwCapInfo == 0) ||
1985 (sFrame.pSSID == 0) ||
1986 (sFrame.pSuppRates == 0) ) {
1987 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Rx beacon frame error\n");
1988 return;
1989 };
1990
1991
1992 if (sFrame.pDSParms != NULL) {
1993 if (byCurrChannel > CB_MAX_CHANNEL_24G) {
1994 // channel remapping to
1995 byIEChannel = CARDbyGetChannelMapping(pDevice, sFrame.pDSParms->byCurrChannel, PHY_TYPE_11A);
1996 } else {
1997 byIEChannel = sFrame.pDSParms->byCurrChannel;
1998 }
1999 if (byCurrChannel != byIEChannel) {
2000 // adjust channel info. bcs we rcv adjcent channel pakckets
2001 bChannelHit = FALSE;
2002 byCurrChannel = byIEChannel;
2003 }
2004 } else {
2005 // no DS channel info
2006 bChannelHit = TRUE;
2007 }
2008//2008-0730-01<Add>by MikeLiu
2009if(ChannelExceedZoneType(pDevice,byCurrChannel)==TRUE)
2010 return;
2011
2012 if (sFrame.pERP != NULL) {
2013 sERP.byERP = sFrame.pERP->byContext;
2014 sERP.bERPExist = TRUE;
2015
2016 } else {
2017 sERP.bERPExist = FALSE;
2018 sERP.byERP = 0;
2019 }
2020
2021 pBSSList = BSSpAddrIsInBSSList((HANDLE)pDevice, sFrame.pHdr->sA3.abyAddr3, sFrame.pSSID);
2022 if (pBSSList == NULL) {
2023 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Beacon/insert: RxChannel = : %d\n", byCurrChannel);
2024 BSSbInsertToBSSList((HANDLE)pDevice,
2025 sFrame.pHdr->sA3.abyAddr3,
2026 *sFrame.pqwTimestamp,
2027 *sFrame.pwBeaconInterval,
2028 *sFrame.pwCapInfo,
2029 byCurrChannel,
2030 sFrame.pSSID,
2031 sFrame.pSuppRates,
2032 sFrame.pExtSuppRates,
2033 &sERP,
2034 sFrame.pRSN,
2035 sFrame.pRSNWPA,
2036 sFrame.pIE_Country,
2037 sFrame.pIE_Quiet,
2038 sFrame.len - WLAN_HDR_ADDR3_LEN,
2039 sFrame.pHdr->sA4.abyAddr4, // payload of beacon
2040 (HANDLE)pRxPacket
2041 );
2042 }
2043 else {
2044// DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"update bcn: RxChannel = : %d\n", byCurrChannel);
2045 BSSbUpdateToBSSList((HANDLE)pDevice,
2046 *sFrame.pqwTimestamp,
2047 *sFrame.pwBeaconInterval,
2048 *sFrame.pwCapInfo,
2049 byCurrChannel,
2050 bChannelHit,
2051 sFrame.pSSID,
2052 sFrame.pSuppRates,
2053 sFrame.pExtSuppRates,
2054 &sERP,
2055 sFrame.pRSN,
2056 sFrame.pRSNWPA,
2057 sFrame.pIE_Country,
2058 sFrame.pIE_Quiet,
2059 pBSSList,
2060 sFrame.len - WLAN_HDR_ADDR3_LEN,
2061 sFrame.pHdr->sA4.abyAddr4, // payload of probresponse
2062 (HANDLE)pRxPacket
2063 );
2064
2065 }
2066
2067 if (bInScan) {
2068 return;
2069 }
2070
2071 if(byCurrChannel == (BYTE)pMgmt->uCurrChannel)
2072 bIsChannelEqual = TRUE;
2073
2074 if (bIsChannelEqual && (pMgmt->eCurrMode == WMAC_MODE_ESS_AP)) {
2075
2076 // if rx beacon without ERP field
2077 if (sERP.bERPExist) {
2078 if (WLAN_GET_ERP_USE_PROTECTION(sERP.byERP)){
2079 pDevice->byERPFlag |= WLAN_SET_ERP_USE_PROTECTION(1);
2080 pDevice->wUseProtectCntDown = USE_PROTECT_PERIOD;
2081 }
2082 }
2083 else {
2084 pDevice->byERPFlag |= WLAN_SET_ERP_USE_PROTECTION(1);
2085 pDevice->wUseProtectCntDown = USE_PROTECT_PERIOD;
2086 }
2087
2088 if (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) {
2089 if(!WLAN_GET_CAP_INFO_SHORTPREAMBLE(*sFrame.pwCapInfo))
2090 pDevice->byERPFlag |= WLAN_SET_ERP_BARKER_MODE(1);
2091 if(!sERP.bERPExist)
2092 pDevice->byERPFlag |= WLAN_SET_ERP_NONERP_PRESENT(1);
2093 }
2094
2095 // set to MAC&BBP
2096 if (WLAN_GET_ERP_USE_PROTECTION(pDevice->byERPFlag)){
2097 if (!pDevice->bProtectMode) {
2098 MACvEnableProtectMD(pDevice->PortOffset);
2099 pDevice->bProtectMode = TRUE;
2100 }
2101 }
2102 }
2103
2104
2105 if (pMgmt->eCurrMode == WMAC_MODE_ESS_AP)
2106 return;
2107
2108 // check if BSSID the same
2109 if (memcmp(sFrame.pHdr->sA3.abyAddr3,
2110 pMgmt->abyCurrBSSID,
2111 WLAN_BSSID_LEN) == 0) {
2112
2113 bIsBSSIDEqual = TRUE;
2114
2115// 2008-05-21 <add> by Richardtai
2116 pDevice->uCurrRSSI = pRxPacket->uRSSI;
2117 pDevice->byCurrSQ = pRxPacket->bySQ;
2118
2119 if (pMgmt->sNodeDBTable[0].uInActiveCount != 0) {
2120 pMgmt->sNodeDBTable[0].uInActiveCount = 0;
2121 //DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"BCN:Wake Count= [%d]\n", pMgmt->wCountToWakeUp);
2122 }
2123 }
2124 // check if SSID the same
2125 if (sFrame.pSSID->len == ((PWLAN_IE_SSID)pMgmt->abyCurrSSID)->len) {
2126 if (memcmp(sFrame.pSSID->abySSID,
2127 ((PWLAN_IE_SSID)pMgmt->abyCurrSSID)->abySSID,
2128 sFrame.pSSID->len
2129 ) == 0) {
2130 bIsSSIDEqual = TRUE;
2131 };
2132 }
2133
2134 if ((WLAN_GET_CAP_INFO_ESS(*sFrame.pwCapInfo)== TRUE) &&
2135 (bIsBSSIDEqual == TRUE) &&
2136 (bIsSSIDEqual == TRUE) &&
2137 (pMgmt->eCurrMode == WMAC_MODE_ESS_STA) &&
2138 (pMgmt->eCurrState == WMAC_STATE_ASSOC)) {
2139 // add state check to prevent reconnect fail since we'll receive Beacon
2140
2141 bIsAPBeacon = TRUE;
2142
2143 if (pBSSList != NULL) {
2144
2145 // Compare PHY paramater setting
2146 if (pMgmt->wCurrCapInfo != pBSSList->wCapInfo) {
2147 bUpdatePhyParameter = TRUE;
2148 pMgmt->wCurrCapInfo = pBSSList->wCapInfo;
2149 }
2150 if (sFrame.pERP != NULL) {
2151 if ((sFrame.pERP->byElementID == WLAN_EID_ERP) &&
2152 (pMgmt->byERPContext != sFrame.pERP->byContext)) {
2153 bUpdatePhyParameter = TRUE;
2154 pMgmt->byERPContext = sFrame.pERP->byContext;
2155 }
2156 }
2157 //
2158 // Basic Rate Set may change dynamiclly
2159 //
2160 if (pBSSList->eNetworkTypeInUse == PHY_TYPE_11B) {
2161 uRateLen = WLAN_RATES_MAXLEN_11B;
2162 }
2163 pMgmt->abyCurrSuppRates[1] = RATEuSetIE((PWLAN_IE_SUPP_RATES)pBSSList->abySuppRates,
2164 (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates,
2165 uRateLen);
2166 pMgmt->abyCurrExtSuppRates[1] = RATEuSetIE((PWLAN_IE_SUPP_RATES)pBSSList->abyExtSuppRates,
2167 (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates,
2168 uRateLen);
2169 RATEvParseMaxRate( (PVOID)pDevice,
2170 (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates,
2171 (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates,
2172 TRUE,
2173 &(pMgmt->sNodeDBTable[0].wMaxBasicRate),
2174 &(pMgmt->sNodeDBTable[0].wMaxSuppRate),
2175 &(pMgmt->sNodeDBTable[0].wSuppRate),
2176 &(pMgmt->sNodeDBTable[0].byTopCCKBasicRate),
2177 &(pMgmt->sNodeDBTable[0].byTopOFDMBasicRate)
2178 );
2179#ifdef PLICE_DEBUG
2180 //printk("RxBeacon:MaxSuppRate is %d\n",pMgmt->sNodeDBTable[0].wMaxSuppRate);
2181#endif
2182 if (bUpdatePhyParameter == TRUE) {
2183 CARDbSetPhyParameter( pMgmt->pAdapter,
2184 pMgmt->eCurrentPHYMode,
2185 pMgmt->wCurrCapInfo,
2186 pMgmt->byERPContext,
2187 pMgmt->abyCurrSuppRates,
2188 pMgmt->abyCurrExtSuppRates
2189 );
2190 }
2191 if (sFrame.pIE_PowerConstraint != NULL) {
2192 CARDvSetPowerConstraint(pMgmt->pAdapter,
2193 (BYTE) pBSSList->uChannel,
2194 sFrame.pIE_PowerConstraint->byPower
2195 );
2196 }
2197 if (sFrame.pIE_CHSW != NULL) {
2198 CARDbChannelSwitch( pMgmt->pAdapter,
2199 sFrame.pIE_CHSW->byMode,
2200 CARDbyGetChannelMapping(pMgmt->pAdapter, sFrame.pIE_CHSW->byMode, pMgmt->eCurrentPHYMode),
2201 sFrame.pIE_CHSW->byCount
2202 );
2203
2204 } else if (bIsChannelEqual == FALSE) {
2205 CARDbSetChannel(pMgmt->pAdapter, pBSSList->uChannel);
2206 }
2207 }
2208 }
2209
2210// DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Beacon 2 \n");
2211 // check if CF field exisit
2212 if (WLAN_GET_CAP_INFO_ESS(*sFrame.pwCapInfo)) {
2213 if (sFrame.pCFParms->wCFPDurRemaining > 0) {
2214 // TODO: deal with CFP period to set NAV
2215 };
2216 };
2217
2218 HIDWORD(qwTimestamp) = cpu_to_le32(HIDWORD(*sFrame.pqwTimestamp));
2219 LODWORD(qwTimestamp) = cpu_to_le32(LODWORD(*sFrame.pqwTimestamp));
2220 HIDWORD(qwLocalTSF) = HIDWORD(pRxPacket->qwLocalTSF);
2221 LODWORD(qwLocalTSF) = LODWORD(pRxPacket->qwLocalTSF);
2222
2223 // check if beacon TSF larger or small than our local TSF
2224 if (HIDWORD(qwTimestamp) == HIDWORD(qwLocalTSF)) {
2225 if (LODWORD(qwTimestamp) >= LODWORD(qwLocalTSF)) {
2226 bTSFOffsetPostive = TRUE;
2227 }
2228 else {
2229 bTSFOffsetPostive = FALSE;
2230 }
2231 }
2232 else if (HIDWORD(qwTimestamp) > HIDWORD(qwLocalTSF)) {
2233 bTSFOffsetPostive = TRUE;
2234 }
2235 else if (HIDWORD(qwTimestamp) < HIDWORD(qwLocalTSF)) {
2236 bTSFOffsetPostive = FALSE;
2237 };
2238
2239 if (bTSFOffsetPostive) {
2240 qwTSFOffset = CARDqGetTSFOffset(pRxPacket->byRxRate, (qwTimestamp), (qwLocalTSF));
2241 }
2242 else {
2243 qwTSFOffset = CARDqGetTSFOffset(pRxPacket->byRxRate, (qwLocalTSF), (qwTimestamp));
2244 }
2245
2246 if (HIDWORD(qwTSFOffset) != 0 ||
2247 (LODWORD(qwTSFOffset) > TRIVIAL_SYNC_DIFFERENCE )) {
2248 bTSFLargeDiff = TRUE;
2249 }
2250
2251
2252 // if infra mode
2253 if (bIsAPBeacon == TRUE) {
2254
2255 // Infra mode: Local TSF always follow AP's TSF if Difference huge.
2256 if (bTSFLargeDiff)
2257 bUpdateTSF = TRUE;
2258
2259 if ((pDevice->bEnablePSMode == TRUE) &&(sFrame.pTIM != 0)) {
2260
2261 // deal with DTIM, analysis TIM
2262 pMgmt->bMulticastTIM = WLAN_MGMT_IS_MULTICAST_TIM(sFrame.pTIM->byBitMapCtl) ? TRUE : FALSE ;
2263 pMgmt->byDTIMCount = sFrame.pTIM->byDTIMCount;
2264 pMgmt->byDTIMPeriod = sFrame.pTIM->byDTIMPeriod;
2265 wAIDNumber = pMgmt->wCurrAID & ~(BIT14|BIT15);
2266
2267 // check if AID in TIM field bit on
2268 // wStartIndex = N1
2269 wStartIndex = WLAN_MGMT_GET_TIM_OFFSET(sFrame.pTIM->byBitMapCtl) << 1;
2270 // AIDIndex = N2
2271 wAIDIndex = (wAIDNumber >> 3);
2272 if ((wAIDNumber > 0) && (wAIDIndex >= wStartIndex)) {
2273 uLocateByteIndex = wAIDIndex - wStartIndex;
2274 // len = byDTIMCount + byDTIMPeriod + byDTIMPeriod + byVirtBitMap[0~250]
2275 if (sFrame.pTIM->len >= (uLocateByteIndex + 4)) {
2276 byTIMBitOn = (0x01) << ((wAIDNumber) % 8);
2277 pMgmt->bInTIM = sFrame.pTIM->byVirtBitMap[uLocateByteIndex] & byTIMBitOn ? TRUE : FALSE;
2278 }
2279 else {
2280 pMgmt->bInTIM = FALSE;
2281 };
2282 }
2283 else {
2284 pMgmt->bInTIM = FALSE;
2285 };
2286
2287 if (pMgmt->bInTIM ||
2288 (pMgmt->bMulticastTIM && (pMgmt->byDTIMCount == 0))) {
2289 pMgmt->bInTIMWake = TRUE;
2290 // send out ps-poll packet
2291// DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "BCN:In TIM\n");
2292 if (pMgmt->bInTIM) {
2293 PSvSendPSPOLL((PSDevice)pDevice);
2294// DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "BCN:PS-POLL sent..\n");
2295 };
2296
2297 }
2298 else {
2299 pMgmt->bInTIMWake = FALSE;
2300 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "BCN: Not In TIM..\n");
2301 if (pDevice->bPWBitOn == FALSE) {
2302 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "BCN: Send Null Packet\n");
2303 if (PSbSendNullPacket(pDevice))
2304 pDevice->bPWBitOn = TRUE;
2305 }
2306 if(PSbConsiderPowerDown(pDevice, FALSE, FALSE)) {
2307 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "BCN: Power down now...\n");
2308 };
2309 }
2310
2311 }
2312
2313 }
2314 // if adhoc mode
2315 if ((pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) && !bIsAPBeacon && bIsChannelEqual) {
2316 if (bIsBSSIDEqual) {
2317 // Use sNodeDBTable[0].uInActiveCount as IBSS beacons received count.
2318 if (pMgmt->sNodeDBTable[0].uInActiveCount != 0)
2319 pMgmt->sNodeDBTable[0].uInActiveCount = 0;
2320
2321 // adhoc mode:TSF updated only when beacon larger then local TSF
2322 if (bTSFLargeDiff && bTSFOffsetPostive &&
2323 (pMgmt->eCurrState == WMAC_STATE_JOINTED))
2324 bUpdateTSF = TRUE;
2325
2326 // During dpc, already in spinlocked.
2327 if (BSSDBbIsSTAInNodeDB(pMgmt, sFrame.pHdr->sA3.abyAddr2, &uNodeIndex)) {
2328
2329 // Update the STA, (Techically the Beacons of all the IBSS nodes
2330 // should be identical, but that's not happening in practice.
2331 pMgmt->abyCurrSuppRates[1] = RATEuSetIE((PWLAN_IE_SUPP_RATES)sFrame.pSuppRates,
2332 (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates,
2333 WLAN_RATES_MAXLEN_11B);
2334 RATEvParseMaxRate( (PVOID)pDevice,
2335 (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates,
2336 NULL,
2337 TRUE,
2338 &(pMgmt->sNodeDBTable[uNodeIndex].wMaxBasicRate),
2339 &(pMgmt->sNodeDBTable[uNodeIndex].wMaxSuppRate),
2340 &(pMgmt->sNodeDBTable[uNodeIndex].wSuppRate),
2341 &(pMgmt->sNodeDBTable[uNodeIndex].byTopCCKBasicRate),
2342 &(pMgmt->sNodeDBTable[uNodeIndex].byTopOFDMBasicRate)
2343 );
2344 pMgmt->sNodeDBTable[uNodeIndex].bShortPreamble = WLAN_GET_CAP_INFO_SHORTPREAMBLE(*sFrame.pwCapInfo);
2345 pMgmt->sNodeDBTable[uNodeIndex].bShortSlotTime = WLAN_GET_CAP_INFO_SHORTSLOTTIME(*sFrame.pwCapInfo);
2346 pMgmt->sNodeDBTable[uNodeIndex].uInActiveCount = 0;
2347 }
2348 else {
2349 // Todo, initial Node content
2350 BSSvCreateOneNode((PSDevice)pDevice, &uNodeIndex);
2351
2352 pMgmt->abyCurrSuppRates[1] = RATEuSetIE((PWLAN_IE_SUPP_RATES)sFrame.pSuppRates,
2353 (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates,
2354 WLAN_RATES_MAXLEN_11B);
2355 RATEvParseMaxRate( (PVOID)pDevice,
2356 (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates,
2357 NULL,
2358 TRUE,
2359 &(pMgmt->sNodeDBTable[uNodeIndex].wMaxBasicRate),
2360 &(pMgmt->sNodeDBTable[uNodeIndex].wMaxSuppRate),
2361 &(pMgmt->sNodeDBTable[uNodeIndex].wSuppRate),
2362 &(pMgmt->sNodeDBTable[uNodeIndex].byTopCCKBasicRate),
2363 &(pMgmt->sNodeDBTable[uNodeIndex].byTopOFDMBasicRate)
2364 );
2365
2366 memcpy(pMgmt->sNodeDBTable[uNodeIndex].abyMACAddr, sFrame.pHdr->sA3.abyAddr2, WLAN_ADDR_LEN);
2367 pMgmt->sNodeDBTable[uNodeIndex].bShortPreamble = WLAN_GET_CAP_INFO_SHORTPREAMBLE(*sFrame.pwCapInfo);
2368 pMgmt->sNodeDBTable[uNodeIndex].wTxDataRate = pMgmt->sNodeDBTable[uNodeIndex].wMaxSuppRate;
2369#ifdef PLICE_DEBUG
2370 //if (uNodeIndex == 0)
2371 {
2372 printk("s_vMgrRxBeacon:TxDataRate is %d,Index is %d\n",pMgmt->sNodeDBTable[uNodeIndex].wTxDataRate,uNodeIndex);
2373 }
2374#endif
2375/*
2376 pMgmt->sNodeDBTable[uNodeIndex].bShortSlotTime = WLAN_GET_CAP_INFO_SHORTSLOTTIME(*sFrame.pwCapInfo);
2377 if(pMgmt->sNodeDBTable[uNodeIndex].wMaxSuppRate > RATE_11M)
2378 pMgmt->sNodeDBTable[uNodeIndex].bERPExist = TRUE;
2379*/
2380 }
2381
2382 // if other stations jointed, indicate connect to upper layer..
2383 if (pMgmt->eCurrState == WMAC_STATE_STARTED) {
2384 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Current IBSS State: [Started]........to: [Jointed] \n");
2385 pMgmt->eCurrState = WMAC_STATE_JOINTED;
2386 pDevice->bLinkPass = TRUE;
2387 if (netif_queue_stopped(pDevice->dev)){
2388 netif_wake_queue(pDevice->dev);
2389 }
2390 pMgmt->sNodeDBTable[0].bActive = TRUE;
2391 pMgmt->sNodeDBTable[0].uInActiveCount = 0;
2392
2393 };
2394 }
2395 else if (bIsSSIDEqual) {
2396
2397 // See other adhoc sta with the same SSID but BSSID is different.
2398 // adpot this vars only when TSF larger then us.
2399 if (bTSFLargeDiff && bTSFOffsetPostive) {
2400 // we don't support ATIM under adhoc mode
2401 // if ( sFrame.pIBSSParms->wATIMWindow == 0) {
2402 // adpot this vars
2403 // TODO: check sFrame cap if privacy on, and support rate syn
2404 memcpy(pMgmt->abyCurrBSSID, sFrame.pHdr->sA3.abyAddr3, WLAN_BSSID_LEN);
2405 memcpy(pDevice->abyBSSID, pMgmt->abyCurrBSSID, WLAN_BSSID_LEN);
2406 pMgmt->wCurrATIMWindow = cpu_to_le16(sFrame.pIBSSParms->wATIMWindow);
2407 pMgmt->wCurrBeaconPeriod = cpu_to_le16(*sFrame.pwBeaconInterval);
2408 pMgmt->abyCurrSuppRates[1] = RATEuSetIE((PWLAN_IE_SUPP_RATES)sFrame.pSuppRates,
2409 (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates,
2410 WLAN_RATES_MAXLEN_11B);
2411 // set HW beacon interval and re-synchronizing....
2412 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Rejoining to Other Adhoc group with same SSID........\n");
2413 VNSvOutPortW(pDevice->PortOffset + MAC_REG_BI, pMgmt->wCurrBeaconPeriod);
2414 CARDbUpdateTSF(pDevice, pRxPacket->byRxRate, qwTimestamp, qwLocalTSF);
2415 CARDvUpdateNextTBTT(pDevice->PortOffset, qwTimestamp, pMgmt->wCurrBeaconPeriod);
2416 // Turn off bssid filter to avoid filter others adhoc station which bssid is different.
2417 MACvWriteBSSIDAddress(pDevice->PortOffset, pMgmt->abyCurrBSSID);
2418
2419 CARDbSetPhyParameter ( pMgmt->pAdapter,
2420 pMgmt->eCurrentPHYMode,
2421 pMgmt->wCurrCapInfo,
2422 pMgmt->byERPContext,
2423 pMgmt->abyCurrSuppRates,
2424 pMgmt->abyCurrExtSuppRates);
2425
2426
2427 // MACvRegBitsOff(pDevice->PortOffset, MAC_REG_RCR, RCR_BSSID);
2428 // set highest basic rate
2429 // s_vSetHighestBasicRate(pDevice, (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates);
2430 // Prepare beacon frame
2431 bMgrPrepareBeaconToSend((HANDLE)pDevice, pMgmt);
2432 // }
2433 };
2434 }
2435 };
2436 // endian issue ???
2437 // Update TSF
2438 if (bUpdateTSF) {
2439 CARDbGetCurrentTSF(pDevice->PortOffset, &qwCurrTSF);
2440 CARDbUpdateTSF(pDevice, pRxPacket->byRxRate, qwTimestamp, pRxPacket->qwLocalTSF);
2441 CARDbGetCurrentTSF(pDevice->PortOffset, &qwCurrTSF);
2442 CARDvUpdateNextTBTT(pDevice->PortOffset, qwTimestamp, pMgmt->wCurrBeaconPeriod);
2443 }
2444
2445 return;
2446}
2447
2448
2449
2450/*+
2451 *
2452 * Routine Description:
2453 * Instructs the hw to create a bss using the supplied
2454 * attributes. Note that this implementation only supports Ad-Hoc
2455 * BSS creation.
2456 *
2457 *
2458 * Return Value:
2459 * CMD_STATUS
2460 *
2461-*/
2462VOID
2463vMgrCreateOwnIBSS(
2464 IN HANDLE hDeviceContext,
2465 OUT PCMD_STATUS pStatus
2466 )
2467{
2468 PSDevice pDevice = (PSDevice)hDeviceContext;
2469 PSMgmtObject pMgmt = pDevice->pMgmt;
2470 WORD wMaxBasicRate;
2471 WORD wMaxSuppRate;
2472 BYTE byTopCCKBasicRate;
2473 BYTE byTopOFDMBasicRate;
2474 QWORD qwCurrTSF;
2475 UINT ii;
2476 BYTE abyRATE[] = {0x82, 0x84, 0x8B, 0x96, 0x24, 0x30, 0x48, 0x6C, 0x0C, 0x12, 0x18, 0x60};
2477 BYTE abyCCK_RATE[] = {0x82, 0x84, 0x8B, 0x96};
2478 BYTE abyOFDM_RATE[] = {0x0C, 0x12, 0x18, 0x24, 0x30, 0x48, 0x60, 0x6C};
2479 WORD wSuppRate;
2480
2481 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Create Basic Service Set .......\n");
2482
2483 if (pMgmt->eConfigMode == WMAC_CONFIG_IBSS_STA) {
2484 if ((pMgmt->eAuthenMode == WMAC_AUTH_WPANONE) &&
2485 (pDevice->eEncryptionStatus != Ndis802_11Encryption2Enabled) &&
2486 (pDevice->eEncryptionStatus != Ndis802_11Encryption3Enabled)) {
2487 // encryption mode error
2488 *pStatus = CMD_STATUS_FAILURE;
2489 return;
2490 }
2491 }
2492
2493 pMgmt->abyCurrSuppRates[0] = WLAN_EID_SUPP_RATES;
2494 pMgmt->abyCurrExtSuppRates[0] = WLAN_EID_EXTSUPP_RATES;
2495
2496 if (pMgmt->eConfigMode == WMAC_CONFIG_AP) {
2497 pMgmt->eCurrentPHYMode = pMgmt->byAPBBType;
2498 } else {
2499 if (pDevice->byBBType == BB_TYPE_11G)
2500 pMgmt->eCurrentPHYMode = PHY_TYPE_11G;
2501 if (pDevice->byBBType == BB_TYPE_11B)
2502 pMgmt->eCurrentPHYMode = PHY_TYPE_11B;
2503 if (pDevice->byBBType == BB_TYPE_11A)
2504 pMgmt->eCurrentPHYMode = PHY_TYPE_11A;
2505 }
2506
2507 if (pMgmt->eCurrentPHYMode != PHY_TYPE_11A) {
2508 pMgmt->abyCurrSuppRates[1] = WLAN_RATES_MAXLEN_11B;
2509 pMgmt->abyCurrExtSuppRates[1] = 0;
2510 for (ii = 0; ii < 4; ii++)
2511 pMgmt->abyCurrSuppRates[2+ii] = abyRATE[ii];
2512 } else {
2513 pMgmt->abyCurrSuppRates[1] = 8;
2514 pMgmt->abyCurrExtSuppRates[1] = 0;
2515 for (ii = 0; ii < 8; ii++)
2516 pMgmt->abyCurrSuppRates[2+ii] = abyRATE[ii];
2517 }
2518
2519
2520 if (pMgmt->eCurrentPHYMode == PHY_TYPE_11G) {
2521 pMgmt->abyCurrSuppRates[1] = 8;
2522 pMgmt->abyCurrExtSuppRates[1] = 4;
2523 for (ii = 0; ii < 4; ii++)
2524 pMgmt->abyCurrSuppRates[2+ii] = abyCCK_RATE[ii];
2525 for (ii = 4; ii < 8; ii++)
2526 pMgmt->abyCurrSuppRates[2+ii] = abyOFDM_RATE[ii-4];
2527 for (ii = 0; ii < 4; ii++)
2528 pMgmt->abyCurrExtSuppRates[2+ii] = abyOFDM_RATE[ii+4];
2529 }
2530
2531
2532 // Disable Protect Mode
2533 pDevice->bProtectMode = 0;
2534 MACvDisableProtectMD(pDevice->PortOffset);
2535
2536 pDevice->bBarkerPreambleMd = 0;
2537 MACvDisableBarkerPreambleMd(pDevice->PortOffset);
2538
2539 // Kyle Test 2003.11.04
2540
2541 // set HW beacon interval
2542 if (pMgmt->wIBSSBeaconPeriod == 0)
2543 pMgmt->wIBSSBeaconPeriod = DEFAULT_IBSS_BI;
2544
2545
2546 CARDbGetCurrentTSF(pDevice->PortOffset, &qwCurrTSF);
2547 // clear TSF counter
2548 VNSvOutPortB(pDevice->PortOffset + MAC_REG_TFTCTL, TFTCTL_TSFCNTRST);
2549 // enable TSF counter
2550 VNSvOutPortB(pDevice->PortOffset + MAC_REG_TFTCTL, TFTCTL_TSFCNTREN);
2551
2552 // set Next TBTT
2553 CARDvSetFirstNextTBTT(pDevice->PortOffset, pMgmt->wIBSSBeaconPeriod);
2554
2555 pMgmt->uIBSSChannel = pDevice->uChannel;
2556
2557 if (pMgmt->uIBSSChannel == 0)
2558 pMgmt->uIBSSChannel = DEFAULT_IBSS_CHANNEL;
2559
2560
2561 // set basic rate
2562
2563 RATEvParseMaxRate((PVOID)pDevice, (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates,
2564 (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates, TRUE,
2565 &wMaxBasicRate, &wMaxSuppRate, &wSuppRate,
2566 &byTopCCKBasicRate, &byTopOFDMBasicRate);
2567
2568
2569 if (pMgmt->eConfigMode == WMAC_CONFIG_AP) {
2570 pMgmt->eCurrMode = WMAC_MODE_ESS_AP;
2571 }
2572
2573 if (pMgmt->eConfigMode == WMAC_CONFIG_IBSS_STA) {
2574 MEMvCopy(pMgmt->abyIBSSDFSOwner, pDevice->abyCurrentNetAddr, 6);
2575 pMgmt->byIBSSDFSRecovery = 10;
2576 pMgmt->eCurrMode = WMAC_MODE_IBSS_STA;
2577 }
2578
2579 // Adopt pre-configured IBSS vars to current vars
2580 pMgmt->eCurrState = WMAC_STATE_STARTED;
2581 pMgmt->wCurrBeaconPeriod = pMgmt->wIBSSBeaconPeriod;
2582 pMgmt->uCurrChannel = pMgmt->uIBSSChannel;
2583 pMgmt->wCurrATIMWindow = pMgmt->wIBSSATIMWindow;
2584 MACvWriteATIMW(pDevice->PortOffset, pMgmt->wCurrATIMWindow);
2585 pDevice->uCurrRSSI = 0;
2586 pDevice->byCurrSQ = 0;
2587 //memcpy(pMgmt->abyDesireSSID,pMgmt->abyAdHocSSID,
2588 // ((PWLAN_IE_SSID)pMgmt->abyAdHocSSID)->len + WLAN_IEHDR_LEN);
2589 memset(pMgmt->abyCurrSSID, 0, WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1);
2590 memcpy(pMgmt->abyCurrSSID,
2591 pMgmt->abyDesireSSID,
2592 ((PWLAN_IE_SSID)pMgmt->abyDesireSSID)->len + WLAN_IEHDR_LEN
2593 );
2594
2595 if (pMgmt->eCurrMode == WMAC_MODE_ESS_AP) {
2596 // AP mode BSSID = MAC addr
2597 memcpy(pMgmt->abyCurrBSSID, pMgmt->abyMACAddr, WLAN_ADDR_LEN);
2598 DEVICE_PRT(MSG_LEVEL_INFO, KERN_INFO"AP beacon created BSSID:%02x-%02x-%02x-%02x-%02x-%02x \n",
2599 pMgmt->abyCurrBSSID[0],
2600 pMgmt->abyCurrBSSID[1],
2601 pMgmt->abyCurrBSSID[2],
2602 pMgmt->abyCurrBSSID[3],
2603 pMgmt->abyCurrBSSID[4],
2604 pMgmt->abyCurrBSSID[5]
2605 );
2606 }
2607
2608 if (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) {
2609
2610 // BSSID selected must be randomized as spec 11.1.3
2611 pMgmt->abyCurrBSSID[5] = (BYTE) (LODWORD(qwCurrTSF)& 0x000000ff);
2612 pMgmt->abyCurrBSSID[4] = (BYTE)((LODWORD(qwCurrTSF)& 0x0000ff00) >> 8);
2613 pMgmt->abyCurrBSSID[3] = (BYTE)((LODWORD(qwCurrTSF)& 0x00ff0000) >> 16);
2614 pMgmt->abyCurrBSSID[2] = (BYTE)((LODWORD(qwCurrTSF)& 0x00000ff0) >> 4);
2615 pMgmt->abyCurrBSSID[1] = (BYTE)((LODWORD(qwCurrTSF)& 0x000ff000) >> 12);
2616 pMgmt->abyCurrBSSID[0] = (BYTE)((LODWORD(qwCurrTSF)& 0x0ff00000) >> 20);
2617 pMgmt->abyCurrBSSID[5] ^= pMgmt->abyMACAddr[0];
2618 pMgmt->abyCurrBSSID[4] ^= pMgmt->abyMACAddr[1];
2619 pMgmt->abyCurrBSSID[3] ^= pMgmt->abyMACAddr[2];
2620 pMgmt->abyCurrBSSID[2] ^= pMgmt->abyMACAddr[3];
2621 pMgmt->abyCurrBSSID[1] ^= pMgmt->abyMACAddr[4];
2622 pMgmt->abyCurrBSSID[0] ^= pMgmt->abyMACAddr[5];
2623 pMgmt->abyCurrBSSID[0] &= ~IEEE_ADDR_GROUP;
2624 pMgmt->abyCurrBSSID[0] |= IEEE_ADDR_UNIVERSAL;
2625
2626
2627 DEVICE_PRT(MSG_LEVEL_INFO, KERN_INFO"Adhoc beacon created bssid:%02x-%02x-%02x-%02x-%02x-%02x \n",
2628 pMgmt->abyCurrBSSID[0],
2629 pMgmt->abyCurrBSSID[1],
2630 pMgmt->abyCurrBSSID[2],
2631 pMgmt->abyCurrBSSID[3],
2632 pMgmt->abyCurrBSSID[4],
2633 pMgmt->abyCurrBSSID[5]
2634 );
2635 }
2636
2637 // Set Capability Info
2638 pMgmt->wCurrCapInfo = 0;
2639
2640 if (pMgmt->eCurrMode == WMAC_MODE_ESS_AP) {
2641 pMgmt->wCurrCapInfo |= WLAN_SET_CAP_INFO_ESS(1);
2642 pMgmt->byDTIMPeriod = DEFAULT_DTIM_PERIOD;
2643 pMgmt->byDTIMCount = pMgmt->byDTIMPeriod - 1;
2644 }
2645
2646 if (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) {
2647 pMgmt->wCurrCapInfo |= WLAN_SET_CAP_INFO_IBSS(1);
2648 }
2649
2650 if (pDevice->bEncryptionEnable) {
2651 pMgmt->wCurrCapInfo |= WLAN_SET_CAP_INFO_PRIVACY(1);
2652 if (pMgmt->eAuthenMode == WMAC_AUTH_WPANONE) {
2653 if (pDevice->eEncryptionStatus == Ndis802_11Encryption3Enabled) {
2654 pMgmt->byCSSPK = KEY_CTL_CCMP;
2655 pMgmt->byCSSGK = KEY_CTL_CCMP;
2656 } else if (pDevice->eEncryptionStatus == Ndis802_11Encryption2Enabled) {
2657 pMgmt->byCSSPK = KEY_CTL_TKIP;
2658 pMgmt->byCSSGK = KEY_CTL_TKIP;
2659 } else {
2660 pMgmt->byCSSPK = KEY_CTL_NONE;
2661 pMgmt->byCSSGK = KEY_CTL_WEP;
2662 }
2663 } else {
2664 pMgmt->byCSSPK = KEY_CTL_WEP;
2665 pMgmt->byCSSGK = KEY_CTL_WEP;
2666 }
2667 };
2668
2669 pMgmt->byERPContext = 0;
2670
2671// memcpy(pDevice->abyBSSID, pMgmt->abyCurrBSSID, WLAN_BSSID_LEN);
2672
2673 if (pMgmt->eConfigMode == WMAC_CONFIG_AP) {
2674 CARDbSetBSSID(pMgmt->pAdapter, pMgmt->abyCurrBSSID, OP_MODE_AP);
2675 } else {
2676 CARDbSetBSSID(pMgmt->pAdapter, pMgmt->abyCurrBSSID, OP_MODE_ADHOC);
2677 }
2678
2679 CARDbSetPhyParameter( pMgmt->pAdapter,
2680 pMgmt->eCurrentPHYMode,
2681 pMgmt->wCurrCapInfo,
2682 pMgmt->byERPContext,
2683 pMgmt->abyCurrSuppRates,
2684 pMgmt->abyCurrExtSuppRates
2685 );
2686
2687 CARDbSetBeaconPeriod(pMgmt->pAdapter, pMgmt->wIBSSBeaconPeriod);
2688 // set channel and clear NAV
2689 CARDbSetChannel(pMgmt->pAdapter, pMgmt->uIBSSChannel);
2690 pMgmt->uCurrChannel = pMgmt->uIBSSChannel;
2691
2692 if (CARDbIsShortPreamble(pMgmt->pAdapter)) {
2693 pMgmt->wCurrCapInfo |= WLAN_SET_CAP_INFO_SHORTPREAMBLE(1);
2694 } else {
2695 pMgmt->wCurrCapInfo &= (~WLAN_SET_CAP_INFO_SHORTPREAMBLE(1));
2696 }
2697
2698 if ((pMgmt->b11hEnable == TRUE) &&
2699 (pMgmt->eCurrentPHYMode == PHY_TYPE_11A)) {
2700 pMgmt->wCurrCapInfo |= WLAN_SET_CAP_INFO_SPECTRUMMNG(1);
2701 } else {
2702 pMgmt->wCurrCapInfo &= (~WLAN_SET_CAP_INFO_SPECTRUMMNG(1));
2703 }
2704
2705 pMgmt->eCurrState = WMAC_STATE_STARTED;
2706 // Prepare beacon to send
2707 if (bMgrPrepareBeaconToSend((HANDLE)pDevice, pMgmt)) {
2708 *pStatus = CMD_STATUS_SUCCESS;
2709 }
2710
2711 return ;
2712}
2713
2714
2715
2716/*+
2717 *
2718 * Routine Description:
2719 * Instructs wmac to join a bss using the supplied attributes.
2720 * The arguments may the BSSID or SSID and the rest of the
2721 * attributes are obtained from the scan result of known bss list.
2722 *
2723 *
2724 * Return Value:
2725 * None.
2726 *
2727-*/
2728
2729VOID
2730vMgrJoinBSSBegin(
2731 IN HANDLE hDeviceContext,
2732 OUT PCMD_STATUS pStatus
2733 )
2734{
2735
2736 PSDevice pDevice = (PSDevice)hDeviceContext;
2737 PSMgmtObject pMgmt = pDevice->pMgmt;
2738 PKnownBSS pCurr = NULL;
2739 UINT ii, uu;
2740 PWLAN_IE_SUPP_RATES pItemRates = NULL;
2741 PWLAN_IE_SUPP_RATES pItemExtRates = NULL;
2742 PWLAN_IE_SSID pItemSSID;
2743 UINT uRateLen = WLAN_RATES_MAXLEN;
2744 WORD wMaxBasicRate = RATE_1M;
2745 WORD wMaxSuppRate = RATE_1M;
2746 WORD wSuppRate;
2747 BYTE byTopCCKBasicRate = RATE_1M;
2748 BYTE byTopOFDMBasicRate = RATE_1M;
2749
2750
2751 for (ii = 0; ii < MAX_BSS_NUM; ii++) {
2752 if (pMgmt->sBSSList[ii].bActive == TRUE)
2753 break;
2754 }
2755
2756 if (ii == MAX_BSS_NUM) {
2757 *pStatus = CMD_STATUS_RESOURCES;
2758 DEVICE_PRT(MSG_LEVEL_NOTICE, KERN_INFO "BSS finding:BSS list is empty.\n");
2759 return;
2760 };
2761
2762 // memset(pMgmt->abyDesireBSSID, 0, WLAN_BSSID_LEN);
2763 // Search known BSS list for prefer BSSID or SSID
2764
2765 pCurr = BSSpSearchBSSList(pDevice,
2766 pMgmt->abyDesireBSSID,
2767 pMgmt->abyDesireSSID,
2768 pMgmt->eConfigPHYMode
2769 );
2770
2771 if (pCurr == NULL){
2772 *pStatus = CMD_STATUS_RESOURCES;
2773 pItemSSID = (PWLAN_IE_SSID)pMgmt->abyDesireSSID;
2774 DEVICE_PRT(MSG_LEVEL_NOTICE, KERN_INFO "Scanning [%s] not found, disconnected !\n", pItemSSID->abySSID);
2775 return;
2776 };
2777
2778 DEVICE_PRT(MSG_LEVEL_NOTICE, KERN_INFO "AP(BSS) finding:Found a AP(BSS)..\n");
2779 if (WLAN_GET_CAP_INFO_ESS(cpu_to_le16(pCurr->wCapInfo))){
2780
2781 if ((pMgmt->eAuthenMode == WMAC_AUTH_WPA)||(pMgmt->eAuthenMode == WMAC_AUTH_WPAPSK)) {
2782
2783 // patch for CISCO migration mode
2784/*
2785 if (pDevice->eEncryptionStatus == Ndis802_11Encryption2Enabled) {
2786 if (WPA_SearchRSN(0, WPA_TKIP, pCurr) == FALSE) {
2787 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"No match RSN info. ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n");
2788 // encryption mode error
2789 pMgmt->eCurrState = WMAC_STATE_IDLE;
2790 return;
2791 }
2792 } else if (pDevice->eEncryptionStatus == Ndis802_11Encryption3Enabled) {
2793 if (WPA_SearchRSN(0, WPA_AESCCMP, pCurr) == FALSE) {
2794 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"No match RSN info. ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n");
2795 // encryption mode error
2796 pMgmt->eCurrState = WMAC_STATE_IDLE;
2797 return;
2798 }
2799 }
2800*/
2801 }
2802
2803#ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
2804 //if(pDevice->bWPASuppWextEnabled == TRUE)
2805 Encyption_Rebuild(pDevice, pCurr);
2806#endif
2807 // Infrastructure BSS
2808 s_vMgrSynchBSS(pDevice,
2809 WMAC_MODE_ESS_STA,
2810 pCurr,
2811 pStatus
2812 );
2813
2814 if (*pStatus == CMD_STATUS_SUCCESS){
2815
2816 // Adopt this BSS state vars in Mgmt Object
2817 pMgmt->uCurrChannel = pCurr->uChannel;
2818
2819 memset(pMgmt->abyCurrSuppRates, 0 , WLAN_IEHDR_LEN + WLAN_RATES_MAXLEN + 1);
2820 memset(pMgmt->abyCurrExtSuppRates, 0 , WLAN_IEHDR_LEN + WLAN_RATES_MAXLEN + 1);
2821
2822 if (pCurr->eNetworkTypeInUse == PHY_TYPE_11B) {
2823 uRateLen = WLAN_RATES_MAXLEN_11B;
2824 }
2825
2826 pItemRates = (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates;
2827 pItemExtRates = (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates;
2828
2829 // Parse Support Rate IE
2830 pItemRates->byElementID = WLAN_EID_SUPP_RATES;
2831 pItemRates->len = RATEuSetIE((PWLAN_IE_SUPP_RATES)pCurr->abySuppRates,
2832 pItemRates,
2833 uRateLen);
2834
2835 // Parse Extension Support Rate IE
2836 pItemExtRates->byElementID = WLAN_EID_EXTSUPP_RATES;
2837 pItemExtRates->len = RATEuSetIE((PWLAN_IE_SUPP_RATES)pCurr->abyExtSuppRates,
2838 pItemExtRates,
2839 uRateLen);
2840 // Stuffing Rate IE
2841 if ((pItemExtRates->len > 0) && (pItemRates->len < 8)) {
2842 for (ii = 0; ii < (UINT)(8 - pItemRates->len); ) {
2843 pItemRates->abyRates[pItemRates->len + ii] = pItemExtRates->abyRates[ii];
2844 ii ++;
2845 if (pItemExtRates->len <= ii)
2846 break;
2847 }
2848 pItemRates->len += (BYTE)ii;
2849 if (pItemExtRates->len - ii > 0) {
2850 pItemExtRates->len -= (BYTE)ii;
2851 for (uu = 0; uu < pItemExtRates->len; uu ++) {
2852 pItemExtRates->abyRates[uu] = pItemExtRates->abyRates[uu + ii];
2853 }
2854 } else {
2855 pItemExtRates->len = 0;
2856 }
2857 }
2858
2859 RATEvParseMaxRate((PVOID)pDevice, pItemRates, pItemExtRates, TRUE,
2860 &wMaxBasicRate, &wMaxSuppRate, &wSuppRate,
2861 &byTopCCKBasicRate, &byTopOFDMBasicRate);
2862
2863 // TODO: deal with if wCapInfo the privacy is on, but station WEP is off
2864 // TODO: deal with if wCapInfo the PS-Pollable is on.
2865 pMgmt->wCurrBeaconPeriod = pCurr->wBeaconInterval;
2866 memset(pMgmt->abyCurrSSID, 0, WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1);
2867 memcpy(pMgmt->abyCurrBSSID, pCurr->abyBSSID, WLAN_BSSID_LEN);
2868 memcpy(pMgmt->abyCurrSSID, pCurr->abySSID, WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1);
2869
2870 pMgmt->eCurrMode = WMAC_MODE_ESS_STA;
2871
2872 pMgmt->eCurrState = WMAC_STATE_JOINTED;
2873 // Adopt BSS state in Adapter Device Object
2874 //pDevice->byOpMode = OP_MODE_INFRASTRUCTURE;
2875// memcpy(pDevice->abyBSSID, pCurr->abyBSSID, WLAN_BSSID_LEN);
2876
2877 // Add current BSS to Candidate list
2878 // This should only works for WPA2 BSS, and WPA2 BSS check must be done before.
2879 if (pMgmt->eAuthenMode == WMAC_AUTH_WPA2) {
2880 BOOL bResult = bAdd_PMKID_Candidate((HANDLE)pDevice, pMgmt->abyCurrBSSID, &pCurr->sRSNCapObj);
2881 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"bAdd_PMKID_Candidate: 1(%d)\n", bResult);
2882 if (bResult == FALSE) {
2883 vFlush_PMKID_Candidate((HANDLE)pDevice);
2884 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"vFlush_PMKID_Candidate: 4\n");
2885 bAdd_PMKID_Candidate((HANDLE)pDevice, pMgmt->abyCurrBSSID, &pCurr->sRSNCapObj);
2886 }
2887 }
2888
2889 // Preamble type auto-switch: if AP can receive short-preamble cap,
2890 // we can turn on too.
2891
2892 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Join ESS\n");
2893
2894
2895
2896 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"End of Join AP -- A/B/G Action\n");
2897 }
2898 else {
2899 pMgmt->eCurrState = WMAC_STATE_IDLE;
2900 };
2901
2902
2903 }
2904 else {
2905 // ad-hoc mode BSS
2906 if (pMgmt->eAuthenMode == WMAC_AUTH_WPANONE) {
2907
2908 if (pDevice->eEncryptionStatus == Ndis802_11Encryption2Enabled) {
2909 if (WPA_SearchRSN(0, WPA_TKIP, pCurr) == FALSE) {
2910 // encryption mode error
2911 pMgmt->eCurrState = WMAC_STATE_IDLE;
2912 return;
2913 }
2914 } else if (pDevice->eEncryptionStatus == Ndis802_11Encryption3Enabled) {
2915 if (WPA_SearchRSN(0, WPA_AESCCMP, pCurr) == FALSE) {
2916 // encryption mode error
2917 pMgmt->eCurrState = WMAC_STATE_IDLE;
2918 return;
2919 }
2920 } else {
2921 // encryption mode error
2922 pMgmt->eCurrState = WMAC_STATE_IDLE;
2923 return;
2924 }
2925 }
2926
2927 s_vMgrSynchBSS(pDevice,
2928 WMAC_MODE_IBSS_STA,
2929 pCurr,
2930 pStatus
2931 );
2932
2933 if (*pStatus == CMD_STATUS_SUCCESS){
2934 // Adopt this BSS state vars in Mgmt Object
2935 // TODO: check if CapInfo privacy on, but we don't..
2936 pMgmt->uCurrChannel = pCurr->uChannel;
2937
2938
2939 // Parse Support Rate IE
2940 pMgmt->abyCurrSuppRates[0] = WLAN_EID_SUPP_RATES;
2941 pMgmt->abyCurrSuppRates[1] = RATEuSetIE((PWLAN_IE_SUPP_RATES)pCurr->abySuppRates,
2942 (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates,
2943 WLAN_RATES_MAXLEN_11B);
2944 // set basic rate
2945 RATEvParseMaxRate((PVOID)pDevice, (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates,
2946 NULL, TRUE, &wMaxBasicRate, &wMaxSuppRate, &wSuppRate,
2947 &byTopCCKBasicRate, &byTopOFDMBasicRate);
2948
2949 pMgmt->wCurrCapInfo = pCurr->wCapInfo;
2950 pMgmt->wCurrBeaconPeriod = pCurr->wBeaconInterval;
2951 memset(pMgmt->abyCurrSSID, 0, WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN);
2952 memcpy(pMgmt->abyCurrBSSID, pCurr->abyBSSID, WLAN_BSSID_LEN);
2953 memcpy(pMgmt->abyCurrSSID, pCurr->abySSID, WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN);
2954// pMgmt->wCurrATIMWindow = pCurr->wATIMWindow;
2955 MACvWriteATIMW(pDevice->PortOffset, pMgmt->wCurrATIMWindow);
2956 pMgmt->eCurrMode = WMAC_MODE_IBSS_STA;
2957
2958 pMgmt->eCurrState = WMAC_STATE_STARTED;
2959 // Adopt BSS state in Adapter Device Object
2960 //pDevice->byOpMode = OP_MODE_ADHOC;
2961// pDevice->bLinkPass = TRUE;
2962// memcpy(pDevice->abyBSSID, pCurr->abyBSSID, WLAN_BSSID_LEN);
2963
2964 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Join IBSS ok:%02x-%02x-%02x-%02x-%02x-%02x \n",
2965 pMgmt->abyCurrBSSID[0],
2966 pMgmt->abyCurrBSSID[1],
2967 pMgmt->abyCurrBSSID[2],
2968 pMgmt->abyCurrBSSID[3],
2969 pMgmt->abyCurrBSSID[4],
2970 pMgmt->abyCurrBSSID[5]
2971 );
2972 // Preamble type auto-switch: if AP can receive short-preamble cap,
2973 // and if registry setting is short preamble we can turn on too.
2974
2975 // Prepare beacon
2976 bMgrPrepareBeaconToSend((HANDLE)pDevice, pMgmt);
2977 }
2978 else {
2979 pMgmt->eCurrState = WMAC_STATE_IDLE;
2980 };
2981 };
2982 return;
2983}
2984
2985
2986
2987/*+
2988 *
2989 * Routine Description:
2990 * Set HW to synchronize a specific BSS from known BSS list.
2991 *
2992 *
2993 * Return Value:
2994 * PCM_STATUS
2995 *
2996-*/
2997static
2998VOID
2999s_vMgrSynchBSS (
3000 IN PSDevice pDevice,
3001 IN UINT uBSSMode,
3002 IN PKnownBSS pCurr,
3003 OUT PCMD_STATUS pStatus
3004 )
3005{
3006 CARD_PHY_TYPE ePhyType = PHY_TYPE_11B;
3007 PSMgmtObject pMgmt = pDevice->pMgmt;
3008// int ii;
3009 //1M, 2M, 5M, 11M, 18M, 24M, 36M, 54M
3010 BYTE abyCurrSuppRatesG[] = {WLAN_EID_SUPP_RATES, 8, 0x02, 0x04, 0x0B, 0x16, 0x24, 0x30, 0x48, 0x6C};
3011 BYTE abyCurrExtSuppRatesG[] = {WLAN_EID_EXTSUPP_RATES, 4, 0x0C, 0x12, 0x18, 0x60};
3012 //6M, 9M, 12M, 48M
3013 BYTE abyCurrSuppRatesA[] = {WLAN_EID_SUPP_RATES, 8, 0x0C, 0x12, 0x18, 0x24, 0x30, 0x48, 0x60, 0x6C};
3014 BYTE abyCurrSuppRatesB[] = {WLAN_EID_SUPP_RATES, 4, 0x02, 0x04, 0x0B, 0x16};
3015
3016
3017 *pStatus = CMD_STATUS_FAILURE;
3018
3019 if (s_bCipherMatch(pCurr,
3020 pDevice->eEncryptionStatus,
3021 &(pMgmt->byCSSPK),
3022 &(pMgmt->byCSSGK)) == FALSE) {
3023 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "s_bCipherMatch Fail .......\n");
3024 return;
3025 }
3026
3027 pMgmt->pCurrBSS = pCurr;
3028
3029 // if previous mode is IBSS.
3030 if(pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) {
3031 MACvRegBitsOff(pDevice->PortOffset, MAC_REG_BCNDMACTL, BEACON_READY);
3032 MACvRegBitsOff(pDevice->PortOffset, MAC_REG_TCR, TCR_AUTOBCNTX);
3033 }
3034
3035 // Init the BSS informations
3036 pDevice->bCCK = TRUE;
3037 pDevice->bProtectMode = FALSE;
3038 MACvDisableProtectMD(pDevice->PortOffset);
3039 pDevice->bBarkerPreambleMd = FALSE;
3040 MACvDisableBarkerPreambleMd(pDevice->PortOffset);
3041 pDevice->bNonERPPresent = FALSE;
3042 pDevice->byPreambleType = 0;
3043 pDevice->wBasicRate = 0;
3044 // Set Basic Rate
3045 CARDbAddBasicRate((PVOID)pDevice, RATE_1M);
3046 // calculate TSF offset
3047 // TSF Offset = Received Timestamp TSF - Marked Local's TSF
3048 CARDbUpdateTSF(pDevice, pCurr->byRxRate, pCurr->qwBSSTimestamp, pCurr->qwLocalTSF);
3049
3050 CARDbSetBeaconPeriod(pDevice, pCurr->wBeaconInterval);
3051
3052 // set Next TBTT
3053 // Next TBTT = ((local_current_TSF / beacon_interval) + 1 ) * beacon_interval
3054 CARDvSetFirstNextTBTT(pDevice->PortOffset, pCurr->wBeaconInterval);
3055
3056 // set BSSID
3057 MACvWriteBSSIDAddress(pDevice->PortOffset, pCurr->abyBSSID);
3058
3059 MACvReadBSSIDAddress(pDevice->PortOffset, pMgmt->abyCurrBSSID);
3060
3061 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Sync:set CurrBSSID address = %02x-%02x-%02x=%02x-%02x-%02x\n",
3062 pMgmt->abyCurrBSSID[0],
3063 pMgmt->abyCurrBSSID[1],
3064 pMgmt->abyCurrBSSID[2],
3065 pMgmt->abyCurrBSSID[3],
3066 pMgmt->abyCurrBSSID[4],
3067 pMgmt->abyCurrBSSID[5]);
3068
3069 if (pCurr->eNetworkTypeInUse == PHY_TYPE_11A) {
3070 if ((pMgmt->eConfigPHYMode == PHY_TYPE_11A) ||
3071 (pMgmt->eConfigPHYMode == PHY_TYPE_AUTO)) {
3072 ePhyType = PHY_TYPE_11A;
3073 } else {
3074 return;
3075 }
3076 } else if (pCurr->eNetworkTypeInUse == PHY_TYPE_11B) {
3077 if ((pMgmt->eConfigPHYMode == PHY_TYPE_11B) ||
3078 (pMgmt->eConfigPHYMode == PHY_TYPE_11G) ||
3079 (pMgmt->eConfigPHYMode == PHY_TYPE_AUTO)) {
3080 ePhyType = PHY_TYPE_11B;
3081 } else {
3082 return;
3083 }
3084 } else {
3085 if ((pMgmt->eConfigPHYMode == PHY_TYPE_11G) ||
3086 (pMgmt->eConfigPHYMode == PHY_TYPE_AUTO)) {
3087 ePhyType = PHY_TYPE_11G;
3088 } else if (pMgmt->eConfigPHYMode == PHY_TYPE_11B) {
3089 ePhyType = PHY_TYPE_11B;
3090 } else {
3091 return;
3092 }
3093 }
3094
3095 if (ePhyType == PHY_TYPE_11A) {
3096 MEMvCopy(pMgmt->abyCurrSuppRates, &abyCurrSuppRatesA[0], sizeof(abyCurrSuppRatesA));
3097 pMgmt->abyCurrExtSuppRates[1] = 0;
3098 } else if (ePhyType == PHY_TYPE_11B) {
3099 MEMvCopy(pMgmt->abyCurrSuppRates, &abyCurrSuppRatesB[0], sizeof(abyCurrSuppRatesB));
3100 pMgmt->abyCurrExtSuppRates[1] = 0;
3101 } else {
3102 MEMvCopy(pMgmt->abyCurrSuppRates, &abyCurrSuppRatesG[0], sizeof(abyCurrSuppRatesG));
3103 MEMvCopy(pMgmt->abyCurrExtSuppRates, &abyCurrExtSuppRatesG[0], sizeof(abyCurrExtSuppRatesG));
3104 }
3105
3106
3107 if (WLAN_GET_CAP_INFO_ESS(pCurr->wCapInfo)) {
3108 CARDbSetBSSID(pMgmt->pAdapter, pCurr->abyBSSID, OP_MODE_INFRASTRUCTURE);
3109 // Add current BSS to Candidate list
3110 // This should only works for WPA2 BSS, and WPA2 BSS check must be done before.
3111 if (pMgmt->eAuthenMode == WMAC_AUTH_WPA2) {
3112 CARDbAdd_PMKID_Candidate(pMgmt->pAdapter, pMgmt->abyCurrBSSID, pCurr->sRSNCapObj.bRSNCapExist, pCurr->sRSNCapObj.wRSNCap);
3113 }
3114 } else {
3115 CARDbSetBSSID(pMgmt->pAdapter, pCurr->abyBSSID, OP_MODE_ADHOC);
3116 }
3117
3118 if (CARDbSetPhyParameter( pMgmt->pAdapter,
3119 ePhyType,
3120 pCurr->wCapInfo,
3121 pCurr->sERP.byERP,
3122 pMgmt->abyCurrSuppRates,
3123 pMgmt->abyCurrExtSuppRates
3124 ) != TRUE) {
3125 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "<----s_bSynchBSS Set Phy Mode Fail [%d]\n", ePhyType);
3126 return;
3127 }
3128 // set channel and clear NAV
3129 if (CARDbSetChannel(pMgmt->pAdapter, pCurr->uChannel) == FALSE) {
3130 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "<----s_bSynchBSS Set Channel [%d]\n", pCurr->uChannel);
3131 return;
3132 }
3133
3134/*
3135 for (ii=0;ii<BB_VGA_LEVEL;ii++) {
3136 if (pCurr->ldBmMAX< pDevice->ldBmThreshold[ii]) {
3137 pDevice->byBBVGANew = pDevice->abyBBVGA[ii];
3138 break;
3139 }
3140 }
3141
3142 if (pDevice->byBBVGANew != pDevice->byBBVGACurrent) {
3143 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"RSSI[%d] NewGain[%d] OldGain[%d] \n",
3144 (int)pCurr->ldBmMAX, pDevice->byBBVGANew, pDevice->byBBVGACurrent);
3145 printk("RSSI[%d] NewGain[%d] OldGain[%d] \n",
3146 (int)pCurr->ldBmMAX, pDevice->byBBVGANew, pDevice->byBBVGACurrent);
3147 BBvSetVGAGainOffset(pDevice, pDevice->byBBVGANew);
3148 }
3149 printk("ldBmMAX[%d] NewGain[%d] OldGain[%d] \n",
3150 (int)pCurr->ldBmMAX, pDevice->byBBVGANew, pDevice->byBBVGACurrent);
3151*/
3152 pMgmt->uCurrChannel = pCurr->uChannel;
3153 pMgmt->eCurrentPHYMode = ePhyType;
3154 pMgmt->byERPContext = pCurr->sERP.byERP;
3155 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Sync:Set to channel = [%d]\n", (INT)pCurr->uChannel);
3156
3157
3158 *pStatus = CMD_STATUS_SUCCESS;
3159
3160
3161 return;
3162};
3163
3164//mike add: fix NetworkManager 0.7.0 hidden ssid mode in WPA encryption
3165// ,need reset eAuthenMode and eEncryptionStatus
3166 static VOID Encyption_Rebuild(
3167 IN PSDevice pDevice,
3168 IN PKnownBSS pCurr
3169 )
3170 {
3171 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
3172 // UINT ii , uSameBssidNum=0;
3173
3174 // for (ii = 0; ii < MAX_BSS_NUM; ii++) {
3175 // if (pMgmt->sBSSList[ii].bActive &&
3176 // IS_ETH_ADDRESS_EQUAL(pMgmt->sBSSList[ii].abyBSSID, pCurr->abyBSSID)) {
3177 // uSameBssidNum++;
3178 // }
3179 // }
3180 // if( uSameBssidNum>=2) { //we only check AP in hidden sssid mode
3181 if ((pMgmt->eAuthenMode == WMAC_AUTH_WPAPSK) || //networkmanager 0.7.0 does not give the pairwise-key selsection,
3182 (pMgmt->eAuthenMode == WMAC_AUTH_WPA2PSK)) { // so we need re-selsect it according to real pairwise-key info.
3183 if(pCurr->bWPAValid == TRUE) { //WPA-PSK
3184 pMgmt->eAuthenMode = WMAC_AUTH_WPAPSK;
3185 if(pCurr->abyPKType[0] == WPA_TKIP) {
3186 pDevice->eEncryptionStatus = Ndis802_11Encryption2Enabled; //TKIP
3187 printk("Encyption_Rebuild--->ssid reset config to [WPAPSK-TKIP]\n");
3188 }
3189 else if(pCurr->abyPKType[0] == WPA_AESCCMP) {
3190 pDevice->eEncryptionStatus = Ndis802_11Encryption3Enabled; //AES
3191 printk("Encyption_Rebuild--->ssid reset config to [WPAPSK-AES]\n");
3192 }
3193 }
3194 else if(pCurr->bWPA2Valid == TRUE) { //WPA2-PSK
3195 pMgmt->eAuthenMode = WMAC_AUTH_WPA2PSK;
3196 if(pCurr->abyCSSPK[0] == WLAN_11i_CSS_TKIP) {
3197 pDevice->eEncryptionStatus = Ndis802_11Encryption2Enabled; //TKIP
3198 printk("Encyption_Rebuild--->ssid reset config to [WPA2PSK-TKIP]\n");
3199 }
3200 else if(pCurr->abyCSSPK[0] == WLAN_11i_CSS_CCMP) {
3201 pDevice->eEncryptionStatus = Ndis802_11Encryption3Enabled; //AES
3202 printk("Encyption_Rebuild--->ssid reset config to [WPA2PSK-AES]\n");
3203 }
3204 }
3205 }
3206 // }
3207 return;
3208 }
3209
3210
3211/*+
3212 *
3213 * Routine Description:
3214 * Format TIM field
3215 *
3216 *
3217 * Return Value:
3218 * VOID
3219 *
3220-*/
3221
3222static
3223VOID
3224s_vMgrFormatTIM(
3225 IN PSMgmtObject pMgmt,
3226 IN PWLAN_IE_TIM pTIM
3227 )
3228{
3229 BYTE byMask[8] = {1, 2, 4, 8, 0x10, 0x20, 0x40, 0x80};
3230 BYTE byMap;
3231 UINT ii, jj;
3232 BOOL bStartFound = FALSE;
3233 BOOL bMulticast = FALSE;
3234 WORD wStartIndex = 0;
3235 WORD wEndIndex = 0;
3236
3237
3238 // Find size of partial virtual bitmap
3239 for (ii = 0; ii < (MAX_NODE_NUM + 1); ii++) {
3240 byMap = pMgmt->abyPSTxMap[ii];
3241 if (!ii) {
3242 // Mask out the broadcast bit which is indicated separately.
3243 bMulticast = (byMap & byMask[0]) != 0;
3244 if(bMulticast) {
3245 pMgmt->sNodeDBTable[0].bRxPSPoll = TRUE;
3246 }
3247 byMap = 0;
3248 }
3249 if (byMap) {
3250 if (!bStartFound) {
3251 bStartFound = TRUE;
3252 wStartIndex = ii;
3253 }
3254 wEndIndex = ii;
3255 }
3256 };
3257
3258
3259 // Round start index down to nearest even number
3260 wStartIndex &= ~BIT0;
3261
3262 // Round end index up to nearest even number
3263 wEndIndex = ((wEndIndex + 1) & ~BIT0);
3264
3265 // Size of element payload
3266
3267 pTIM->len = 3 + (wEndIndex - wStartIndex) + 1;
3268
3269 // Fill in the Fixed parts of the TIM
3270 pTIM->byDTIMCount = pMgmt->byDTIMCount;
3271 pTIM->byDTIMPeriod = pMgmt->byDTIMPeriod;
3272 pTIM->byBitMapCtl = (bMulticast ? TIM_MULTICAST_MASK : 0) |
3273 (((wStartIndex >> 1) << 1) & TIM_BITMAPOFFSET_MASK);
3274
3275 // Append variable part of TIM
3276
3277 for (ii = wStartIndex, jj =0 ; ii <= wEndIndex; ii++, jj++) {
3278 pTIM->byVirtBitMap[jj] = pMgmt->abyPSTxMap[ii];
3279 }
3280
3281 // Aid = 0 don't used.
3282 pTIM->byVirtBitMap[0] &= ~BIT0;
3283}
3284
3285
3286/*+
3287 *
3288 * Routine Description:
3289 * Constructs an Beacon frame( Ad-hoc mode)
3290 *
3291 *
3292 * Return Value:
3293 * PTR to frame; or NULL on allocation failue
3294 *
3295-*/
3296
3297static
3298PSTxMgmtPacket
3299s_MgrMakeBeacon(
3300 IN PSDevice pDevice,
3301 IN PSMgmtObject pMgmt,
3302 IN WORD wCurrCapInfo,
3303 IN WORD wCurrBeaconPeriod,
3304 IN UINT uCurrChannel,
3305 IN WORD wCurrATIMWinodw,
3306 IN PWLAN_IE_SSID pCurrSSID,
3307 IN PBYTE pCurrBSSID,
3308 IN PWLAN_IE_SUPP_RATES pCurrSuppRates,
3309 IN PWLAN_IE_SUPP_RATES pCurrExtSuppRates
3310 )
3311{
3312 PSTxMgmtPacket pTxPacket = NULL;
3313 WLAN_FR_BEACON sFrame;
3314 BYTE abyBroadcastAddr[] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
3315 PBYTE pbyBuffer;
3316 UINT uLength = 0;
3317 PWLAN_IE_IBSS_DFS pIBSSDFS = NULL;
3318 UINT ii;
3319
3320 // prepare beacon frame
3321 pTxPacket = (PSTxMgmtPacket)pMgmt->pbyMgmtPacketPool;
3322 memset(pTxPacket, 0, sizeof(STxMgmtPacket) + WLAN_BEACON_FR_MAXLEN);
3323 pTxPacket->p80211Header = (PUWLAN_80211HDR)((PBYTE)pTxPacket + sizeof(STxMgmtPacket));
3324 // Setup the sFrame structure.
3325 sFrame.pBuf = (PBYTE)pTxPacket->p80211Header;
3326 sFrame.len = WLAN_BEACON_FR_MAXLEN;
3327 vMgrEncodeBeacon(&sFrame);
3328 // Setup the header
3329 sFrame.pHdr->sA3.wFrameCtl = cpu_to_le16(
3330 (
3331 WLAN_SET_FC_FTYPE(WLAN_TYPE_MGR) |
3332 WLAN_SET_FC_FSTYPE(WLAN_FSTYPE_BEACON)
3333 ));
3334
3335 if (pDevice->bEnablePSMode) {
3336 sFrame.pHdr->sA3.wFrameCtl |= cpu_to_le16((WORD)WLAN_SET_FC_PWRMGT(1));
3337 }
3338
3339 memcpy( sFrame.pHdr->sA3.abyAddr1, abyBroadcastAddr, WLAN_ADDR_LEN);
3340 memcpy( sFrame.pHdr->sA3.abyAddr2, pMgmt->abyMACAddr, WLAN_ADDR_LEN);
3341 memcpy( sFrame.pHdr->sA3.abyAddr3, pCurrBSSID, WLAN_BSSID_LEN);
3342 *sFrame.pwBeaconInterval = cpu_to_le16(wCurrBeaconPeriod);
3343 *sFrame.pwCapInfo = cpu_to_le16(wCurrCapInfo);
3344 // Copy SSID
3345 sFrame.pSSID = (PWLAN_IE_SSID)(sFrame.pBuf + sFrame.len);
3346 sFrame.len += ((PWLAN_IE_SSID)pMgmt->abyCurrSSID)->len + WLAN_IEHDR_LEN;
3347 memcpy(sFrame.pSSID,
3348 pCurrSSID,
3349 ((PWLAN_IE_SSID)pCurrSSID)->len + WLAN_IEHDR_LEN
3350 );
3351 // Copy the rate set
3352 sFrame.pSuppRates = (PWLAN_IE_SUPP_RATES)(sFrame.pBuf + sFrame.len);
3353 sFrame.len += ((PWLAN_IE_SUPP_RATES)pCurrSuppRates)->len + WLAN_IEHDR_LEN;
3354 memcpy(sFrame.pSuppRates,
3355 pCurrSuppRates,
3356 ((PWLAN_IE_SUPP_RATES)pCurrSuppRates)->len + WLAN_IEHDR_LEN
3357 );
3358 // DS parameter
3359 if (pDevice->eCurrentPHYType != PHY_TYPE_11A) {
3360 sFrame.pDSParms = (PWLAN_IE_DS_PARMS)(sFrame.pBuf + sFrame.len);
3361 sFrame.len += (1) + WLAN_IEHDR_LEN;
3362 sFrame.pDSParms->byElementID = WLAN_EID_DS_PARMS;
3363 sFrame.pDSParms->len = 1;
3364 sFrame.pDSParms->byCurrChannel = (BYTE)uCurrChannel;
3365 }
3366 // TIM field
3367 if (pMgmt->eCurrMode == WMAC_MODE_ESS_AP) {
3368 sFrame.pTIM = (PWLAN_IE_TIM)(sFrame.pBuf + sFrame.len);
3369 sFrame.pTIM->byElementID = WLAN_EID_TIM;
3370 s_vMgrFormatTIM(pMgmt, sFrame.pTIM);
3371 sFrame.len += (WLAN_IEHDR_LEN + sFrame.pTIM->len);
3372 }
3373
3374 if (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) {
3375
3376 // IBSS parameter
3377 sFrame.pIBSSParms = (PWLAN_IE_IBSS_PARMS)(sFrame.pBuf + sFrame.len);
3378 sFrame.len += (2) + WLAN_IEHDR_LEN;
3379 sFrame.pIBSSParms->byElementID = WLAN_EID_IBSS_PARMS;
3380 sFrame.pIBSSParms->len = 2;
3381 sFrame.pIBSSParms->wATIMWindow = wCurrATIMWinodw;
3382 if (pMgmt->eAuthenMode == WMAC_AUTH_WPANONE) {
3383 /* RSN parameter */
3384 sFrame.pRSNWPA = (PWLAN_IE_RSN_EXT)(sFrame.pBuf + sFrame.len);
3385 sFrame.pRSNWPA->byElementID = WLAN_EID_RSN_WPA;
3386 sFrame.pRSNWPA->len = 12;
3387 sFrame.pRSNWPA->abyOUI[0] = 0x00;
3388 sFrame.pRSNWPA->abyOUI[1] = 0x50;
3389 sFrame.pRSNWPA->abyOUI[2] = 0xf2;
3390 sFrame.pRSNWPA->abyOUI[3] = 0x01;
3391 sFrame.pRSNWPA->wVersion = 1;
3392 sFrame.pRSNWPA->abyMulticast[0] = 0x00;
3393 sFrame.pRSNWPA->abyMulticast[1] = 0x50;
3394 sFrame.pRSNWPA->abyMulticast[2] = 0xf2;
3395 if (pDevice->eEncryptionStatus == Ndis802_11Encryption3Enabled)
3396 sFrame.pRSNWPA->abyMulticast[3] = 0x04;//AES
3397 else if (pDevice->eEncryptionStatus == Ndis802_11Encryption2Enabled)
3398 sFrame.pRSNWPA->abyMulticast[3] = 0x02;//TKIP
3399 else if (pDevice->eEncryptionStatus == Ndis802_11Encryption1Enabled)
3400 sFrame.pRSNWPA->abyMulticast[3] = 0x01;//WEP40
3401 else
3402 sFrame.pRSNWPA->abyMulticast[3] = 0x00;//NONE
3403
3404 // Pairwise Key Cipher Suite
3405 sFrame.pRSNWPA->wPKCount = 0;
3406 // Auth Key Management Suite
3407 *((PWORD)(sFrame.pBuf + sFrame.len + sFrame.pRSNWPA->len))=0;
3408 sFrame.pRSNWPA->len +=2;
3409
3410 // RSN Capabilites
3411 *((PWORD)(sFrame.pBuf + sFrame.len + sFrame.pRSNWPA->len))=0;
3412 sFrame.pRSNWPA->len +=2;
3413 sFrame.len += sFrame.pRSNWPA->len + WLAN_IEHDR_LEN;
3414 }
3415 }
3416
3417 if ((pMgmt->b11hEnable == TRUE) &&
3418 (pMgmt->eCurrentPHYMode == PHY_TYPE_11A)) {
3419 // Country IE
3420 pbyBuffer = (PBYTE)(sFrame.pBuf + sFrame.len);
3421 CARDvSetCountryIE(pMgmt->pAdapter, pbyBuffer);
3422 CARDvSetCountryInfo(pMgmt->pAdapter, PHY_TYPE_11A, pbyBuffer);
3423 uLength += ((PWLAN_IE_COUNTRY) pbyBuffer)->len + WLAN_IEHDR_LEN;
3424 pbyBuffer += (((PWLAN_IE_COUNTRY) pbyBuffer)->len + WLAN_IEHDR_LEN);
3425 // Power Constrain IE
3426 ((PWLAN_IE_PW_CONST) pbyBuffer)->byElementID = WLAN_EID_PWR_CONSTRAINT;
3427 ((PWLAN_IE_PW_CONST) pbyBuffer)->len = 1;
3428 ((PWLAN_IE_PW_CONST) pbyBuffer)->byPower = 0;
3429 pbyBuffer += (1) + WLAN_IEHDR_LEN;
3430 uLength += (1) + WLAN_IEHDR_LEN;
3431 if (pMgmt->bSwitchChannel == TRUE) {
3432 // Channel Switch IE
3433 ((PWLAN_IE_CH_SW) pbyBuffer)->byElementID = WLAN_EID_CH_SWITCH;
3434 ((PWLAN_IE_CH_SW) pbyBuffer)->len = 3;
3435 ((PWLAN_IE_CH_SW) pbyBuffer)->byMode = 1;
3436 ((PWLAN_IE_CH_SW) pbyBuffer)->byChannel = CARDbyGetChannelNumber(pMgmt->pAdapter, pMgmt->byNewChannel);
3437 ((PWLAN_IE_CH_SW) pbyBuffer)->byCount = 0;
3438 pbyBuffer += (3) + WLAN_IEHDR_LEN;
3439 uLength += (3) + WLAN_IEHDR_LEN;
3440 }
3441 // TPC report
3442 ((PWLAN_IE_TPC_REP) pbyBuffer)->byElementID = WLAN_EID_TPC_REP;
3443 ((PWLAN_IE_TPC_REP) pbyBuffer)->len = 2;
3444 ((PWLAN_IE_TPC_REP) pbyBuffer)->byTxPower = CARDbyGetTransmitPower(pMgmt->pAdapter);
3445 ((PWLAN_IE_TPC_REP) pbyBuffer)->byLinkMargin = 0;
3446 pbyBuffer += (2) + WLAN_IEHDR_LEN;
3447 uLength += (2) + WLAN_IEHDR_LEN;
3448 // IBSS DFS
3449 if (pMgmt->eCurrMode != WMAC_MODE_ESS_AP) {
3450 pIBSSDFS = (PWLAN_IE_IBSS_DFS) pbyBuffer;
3451 pIBSSDFS->byElementID = WLAN_EID_IBSS_DFS;
3452 pIBSSDFS->len = 7;
3453 MEMvCopy( pIBSSDFS->abyDFSOwner,
3454 pMgmt->abyIBSSDFSOwner,
3455 6);
3456 pIBSSDFS->byDFSRecovery = pMgmt->byIBSSDFSRecovery;
3457 pbyBuffer += (7) + WLAN_IEHDR_LEN;
3458 uLength += (7) + WLAN_IEHDR_LEN;
3459 for(ii=CB_MAX_CHANNEL_24G+1; ii<=CB_MAX_CHANNEL; ii++ ) {
3460 if (CARDbGetChannelMapInfo(pMgmt->pAdapter, ii, pbyBuffer, pbyBuffer+1) == TRUE) {
3461 pbyBuffer += 2;
3462 uLength += 2;
3463 pIBSSDFS->len += 2;
3464 }
3465 }
3466 }
3467 sFrame.len += uLength;
3468 }
3469
3470 if (pMgmt->eCurrentPHYMode == PHY_TYPE_11G) {
3471 sFrame.pERP = (PWLAN_IE_ERP)(sFrame.pBuf + sFrame.len);
3472 sFrame.len += 1 + WLAN_IEHDR_LEN;
3473 sFrame.pERP->byElementID = WLAN_EID_ERP;
3474 sFrame.pERP->len = 1;
3475 sFrame.pERP->byContext = 0;
3476 if (pDevice->bProtectMode == TRUE)
3477 sFrame.pERP->byContext |= WLAN_EID_ERP_USE_PROTECTION;
3478 if (pDevice->bNonERPPresent == TRUE)
3479 sFrame.pERP->byContext |= WLAN_EID_ERP_NONERP_PRESENT;
3480 if (pDevice->bBarkerPreambleMd == TRUE)
3481 sFrame.pERP->byContext |= WLAN_EID_ERP_BARKER_MODE;
3482 }
3483 if (((PWLAN_IE_SUPP_RATES)pCurrExtSuppRates)->len != 0) {
3484 sFrame.pExtSuppRates = (PWLAN_IE_SUPP_RATES)(sFrame.pBuf + sFrame.len);
3485 sFrame.len += ((PWLAN_IE_SUPP_RATES)pCurrExtSuppRates)->len + WLAN_IEHDR_LEN;
3486 MEMvCopy(sFrame.pExtSuppRates,
3487 pCurrExtSuppRates,
3488 ((PWLAN_IE_SUPP_RATES)pCurrExtSuppRates)->len + WLAN_IEHDR_LEN
3489 );
3490 }
3491 // hostapd wpa/wpa2 IE
3492 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_AP) && (pDevice->bEnableHostapd == TRUE)) {
3493 if (pMgmt->eAuthenMode == WMAC_AUTH_WPANONE) {
3494 if (pMgmt->wWPAIELen != 0) {
3495 sFrame.pRSN = (PWLAN_IE_RSN)(sFrame.pBuf + sFrame.len);
3496 memcpy(sFrame.pRSN, pMgmt->abyWPAIE, pMgmt->wWPAIELen);
3497 sFrame.len += pMgmt->wWPAIELen;
3498 }
3499 }
3500 }
3501
3502 /* Adjust the length fields */
3503 pTxPacket->cbMPDULen = sFrame.len;
3504 pTxPacket->cbPayloadLen = sFrame.len - WLAN_HDR_ADDR3_LEN;
3505
3506 return pTxPacket;
3507}
3508
3509
3510
3511
3512
3513/*+
3514 *
3515 * Routine Description:
3516 * Constructs an Prob-response frame
3517 *
3518 *
3519 * Return Value:
3520 * PTR to frame; or NULL on allocation failue
3521 *
3522-*/
3523
3524
3525
3526
3527PSTxMgmtPacket
3528s_MgrMakeProbeResponse(
3529 IN PSDevice pDevice,
3530 IN PSMgmtObject pMgmt,
3531 IN WORD wCurrCapInfo,
3532 IN WORD wCurrBeaconPeriod,
3533 IN UINT uCurrChannel,
3534 IN WORD wCurrATIMWinodw,
3535 IN PBYTE pDstAddr,
3536 IN PWLAN_IE_SSID pCurrSSID,
3537 IN PBYTE pCurrBSSID,
3538 IN PWLAN_IE_SUPP_RATES pCurrSuppRates,
3539 IN PWLAN_IE_SUPP_RATES pCurrExtSuppRates,
3540 IN BYTE byPHYType
3541 )
3542{
3543 PSTxMgmtPacket pTxPacket = NULL;
3544 WLAN_FR_PROBERESP sFrame;
3545 PBYTE pbyBuffer;
3546 UINT uLength = 0;
3547 PWLAN_IE_IBSS_DFS pIBSSDFS = NULL;
3548 UINT ii;
3549
3550
3551 pTxPacket = (PSTxMgmtPacket)pMgmt->pbyMgmtPacketPool;
3552 memset(pTxPacket, 0, sizeof(STxMgmtPacket) + WLAN_PROBERESP_FR_MAXLEN);
3553 pTxPacket->p80211Header = (PUWLAN_80211HDR)((PBYTE)pTxPacket + sizeof(STxMgmtPacket));
3554 // Setup the sFrame structure.
3555 sFrame.pBuf = (PBYTE)pTxPacket->p80211Header;
3556 sFrame.len = WLAN_PROBERESP_FR_MAXLEN;
3557 vMgrEncodeProbeResponse(&sFrame);
3558 // Setup the header
3559 sFrame.pHdr->sA3.wFrameCtl = cpu_to_le16(
3560 (
3561 WLAN_SET_FC_FTYPE(WLAN_TYPE_MGR) |
3562 WLAN_SET_FC_FSTYPE(WLAN_FSTYPE_PROBERESP)
3563 ));
3564 memcpy( sFrame.pHdr->sA3.abyAddr1, pDstAddr, WLAN_ADDR_LEN);
3565 memcpy( sFrame.pHdr->sA3.abyAddr2, pMgmt->abyMACAddr, WLAN_ADDR_LEN);
3566 memcpy( sFrame.pHdr->sA3.abyAddr3, pCurrBSSID, WLAN_BSSID_LEN);
3567 *sFrame.pwBeaconInterval = cpu_to_le16(wCurrBeaconPeriod);
3568 *sFrame.pwCapInfo = cpu_to_le16(wCurrCapInfo);
3569
3570 if (byPHYType == BB_TYPE_11B) {
3571 *sFrame.pwCapInfo &= cpu_to_le16((WORD)~(WLAN_SET_CAP_INFO_SHORTSLOTTIME(1)));
3572 }
3573
3574 // Copy SSID
3575 sFrame.pSSID = (PWLAN_IE_SSID)(sFrame.pBuf + sFrame.len);
3576 sFrame.len += ((PWLAN_IE_SSID)pMgmt->abyCurrSSID)->len + WLAN_IEHDR_LEN;
3577 memcpy(sFrame.pSSID,
3578 pCurrSSID,
3579 ((PWLAN_IE_SSID)pCurrSSID)->len + WLAN_IEHDR_LEN
3580 );
3581 // Copy the rate set
3582 sFrame.pSuppRates = (PWLAN_IE_SUPP_RATES)(sFrame.pBuf + sFrame.len);
3583
3584 sFrame.len += ((PWLAN_IE_SUPP_RATES)pCurrSuppRates)->len + WLAN_IEHDR_LEN;
3585 memcpy(sFrame.pSuppRates,
3586 pCurrSuppRates,
3587 ((PWLAN_IE_SUPP_RATES)pCurrSuppRates)->len + WLAN_IEHDR_LEN
3588 );
3589
3590 // DS parameter
3591 if (pDevice->eCurrentPHYType != PHY_TYPE_11A) {
3592 sFrame.pDSParms = (PWLAN_IE_DS_PARMS)(sFrame.pBuf + sFrame.len);
3593 sFrame.len += (1) + WLAN_IEHDR_LEN;
3594 sFrame.pDSParms->byElementID = WLAN_EID_DS_PARMS;
3595 sFrame.pDSParms->len = 1;
3596 sFrame.pDSParms->byCurrChannel = (BYTE)uCurrChannel;
3597 }
3598
3599 if (pMgmt->eCurrMode != WMAC_MODE_ESS_AP) {
3600 // IBSS parameter
3601 sFrame.pIBSSParms = (PWLAN_IE_IBSS_PARMS)(sFrame.pBuf + sFrame.len);
3602 sFrame.len += (2) + WLAN_IEHDR_LEN;
3603 sFrame.pIBSSParms->byElementID = WLAN_EID_IBSS_PARMS;
3604 sFrame.pIBSSParms->len = 2;
3605 sFrame.pIBSSParms->wATIMWindow = 0;
3606 }
3607 if (pDevice->eCurrentPHYType == PHY_TYPE_11G) {
3608 sFrame.pERP = (PWLAN_IE_ERP)(sFrame.pBuf + sFrame.len);
3609 sFrame.len += 1 + WLAN_IEHDR_LEN;
3610 sFrame.pERP->byElementID = WLAN_EID_ERP;
3611 sFrame.pERP->len = 1;
3612 sFrame.pERP->byContext = 0;
3613 if (pDevice->bProtectMode == TRUE)
3614 sFrame.pERP->byContext |= WLAN_EID_ERP_USE_PROTECTION;
3615 if (pDevice->bNonERPPresent == TRUE)
3616 sFrame.pERP->byContext |= WLAN_EID_ERP_NONERP_PRESENT;
3617 if (pDevice->bBarkerPreambleMd == TRUE)
3618 sFrame.pERP->byContext |= WLAN_EID_ERP_BARKER_MODE;
3619 }
3620
3621 if ((pMgmt->b11hEnable == TRUE) &&
3622 (pMgmt->eCurrentPHYMode == PHY_TYPE_11A)) {
3623 // Country IE
3624 pbyBuffer = (PBYTE)(sFrame.pBuf + sFrame.len);
3625 CARDvSetCountryIE(pMgmt->pAdapter, pbyBuffer);
3626 CARDvSetCountryInfo(pMgmt->pAdapter, PHY_TYPE_11A, pbyBuffer);
3627 uLength += ((PWLAN_IE_COUNTRY) pbyBuffer)->len + WLAN_IEHDR_LEN;
3628 pbyBuffer += (((PWLAN_IE_COUNTRY) pbyBuffer)->len + WLAN_IEHDR_LEN);
3629 // Power Constrain IE
3630 ((PWLAN_IE_PW_CONST) pbyBuffer)->byElementID = WLAN_EID_PWR_CONSTRAINT;
3631 ((PWLAN_IE_PW_CONST) pbyBuffer)->len = 1;
3632 ((PWLAN_IE_PW_CONST) pbyBuffer)->byPower = 0;
3633 pbyBuffer += (1) + WLAN_IEHDR_LEN;
3634 uLength += (1) + WLAN_IEHDR_LEN;
3635 if (pMgmt->bSwitchChannel == TRUE) {
3636 // Channel Switch IE
3637 ((PWLAN_IE_CH_SW) pbyBuffer)->byElementID = WLAN_EID_CH_SWITCH;
3638 ((PWLAN_IE_CH_SW) pbyBuffer)->len = 3;
3639 ((PWLAN_IE_CH_SW) pbyBuffer)->byMode = 1;
3640 ((PWLAN_IE_CH_SW) pbyBuffer)->byChannel = CARDbyGetChannelNumber(pMgmt->pAdapter, pMgmt->byNewChannel);
3641 ((PWLAN_IE_CH_SW) pbyBuffer)->byCount = 0;
3642 pbyBuffer += (3) + WLAN_IEHDR_LEN;
3643 uLength += (3) + WLAN_IEHDR_LEN;
3644 }
3645 // TPC report
3646 ((PWLAN_IE_TPC_REP) pbyBuffer)->byElementID = WLAN_EID_TPC_REP;
3647 ((PWLAN_IE_TPC_REP) pbyBuffer)->len = 2;
3648 ((PWLAN_IE_TPC_REP) pbyBuffer)->byTxPower = CARDbyGetTransmitPower(pMgmt->pAdapter);
3649 ((PWLAN_IE_TPC_REP) pbyBuffer)->byLinkMargin = 0;
3650 pbyBuffer += (2) + WLAN_IEHDR_LEN;
3651 uLength += (2) + WLAN_IEHDR_LEN;
3652 // IBSS DFS
3653 if (pMgmt->eCurrMode != WMAC_MODE_ESS_AP) {
3654 pIBSSDFS = (PWLAN_IE_IBSS_DFS) pbyBuffer;
3655 pIBSSDFS->byElementID = WLAN_EID_IBSS_DFS;
3656 pIBSSDFS->len = 7;
3657 MEMvCopy( pIBSSDFS->abyDFSOwner,
3658 pMgmt->abyIBSSDFSOwner,
3659 6);
3660 pIBSSDFS->byDFSRecovery = pMgmt->byIBSSDFSRecovery;
3661 pbyBuffer += (7) + WLAN_IEHDR_LEN;
3662 uLength += (7) + WLAN_IEHDR_LEN;
3663 for(ii=CB_MAX_CHANNEL_24G+1; ii<=CB_MAX_CHANNEL; ii++ ) {
3664 if (CARDbGetChannelMapInfo(pMgmt->pAdapter, ii, pbyBuffer, pbyBuffer+1) == TRUE) {
3665 pbyBuffer += 2;
3666 uLength += 2;
3667 pIBSSDFS->len += 2;
3668 }
3669 }
3670 }
3671 sFrame.len += uLength;
3672 }
3673
3674
3675 if (((PWLAN_IE_SUPP_RATES)pCurrExtSuppRates)->len != 0) {
3676 sFrame.pExtSuppRates = (PWLAN_IE_SUPP_RATES)(sFrame.pBuf + sFrame.len);
3677 sFrame.len += ((PWLAN_IE_SUPP_RATES)pCurrExtSuppRates)->len + WLAN_IEHDR_LEN;
3678 MEMvCopy(sFrame.pExtSuppRates,
3679 pCurrExtSuppRates,
3680 ((PWLAN_IE_SUPP_RATES)pCurrExtSuppRates)->len + WLAN_IEHDR_LEN
3681 );
3682 }
3683
3684 // hostapd wpa/wpa2 IE
3685 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_AP) && (pDevice->bEnableHostapd == TRUE)) {
3686 if (pMgmt->eAuthenMode == WMAC_AUTH_WPANONE) {
3687 if (pMgmt->wWPAIELen != 0) {
3688 sFrame.pRSN = (PWLAN_IE_RSN)(sFrame.pBuf + sFrame.len);
3689 memcpy(sFrame.pRSN, pMgmt->abyWPAIE, pMgmt->wWPAIELen);
3690 sFrame.len += pMgmt->wWPAIELen;
3691 }
3692 }
3693 }
3694
3695 // Adjust the length fields
3696 pTxPacket->cbMPDULen = sFrame.len;
3697 pTxPacket->cbPayloadLen = sFrame.len - WLAN_HDR_ADDR3_LEN;
3698
3699 return pTxPacket;
3700}
3701
3702
3703
3704/*+
3705 *
3706 * Routine Description:
3707 * Constructs an association request frame
3708 *
3709 *
3710 * Return Value:
3711 * A ptr to frame or NULL on allocation failue
3712 *
3713-*/
3714
3715
3716PSTxMgmtPacket
3717s_MgrMakeAssocRequest(
3718 IN PSDevice pDevice,
3719 IN PSMgmtObject pMgmt,
3720 IN PBYTE pDAddr,
3721 IN WORD wCurrCapInfo,
3722 IN WORD wListenInterval,
3723 IN PWLAN_IE_SSID pCurrSSID,
3724 IN PWLAN_IE_SUPP_RATES pCurrRates,
3725 IN PWLAN_IE_SUPP_RATES pCurrExtSuppRates
3726 )
3727{
3728 PSTxMgmtPacket pTxPacket = NULL;
3729 WLAN_FR_ASSOCREQ sFrame;
3730 PBYTE pbyIEs;
3731 PBYTE pbyRSN;
3732
3733
3734 pTxPacket = (PSTxMgmtPacket)pMgmt->pbyMgmtPacketPool;
3735 memset(pTxPacket, 0, sizeof(STxMgmtPacket) + WLAN_ASSOCREQ_FR_MAXLEN);
3736 pTxPacket->p80211Header = (PUWLAN_80211HDR)((PBYTE)pTxPacket + sizeof(STxMgmtPacket));
3737 // Setup the sFrame structure.
3738 sFrame.pBuf = (PBYTE)pTxPacket->p80211Header;
3739 sFrame.len = WLAN_ASSOCREQ_FR_MAXLEN;
3740 // format fixed field frame structure
3741 vMgrEncodeAssocRequest(&sFrame);
3742 // Setup the header
3743 sFrame.pHdr->sA3.wFrameCtl = cpu_to_le16(
3744 (
3745 WLAN_SET_FC_FTYPE(WLAN_TYPE_MGR) |
3746 WLAN_SET_FC_FSTYPE(WLAN_FSTYPE_ASSOCREQ)
3747 ));
3748 memcpy( sFrame.pHdr->sA3.abyAddr1, pDAddr, WLAN_ADDR_LEN);
3749 memcpy( sFrame.pHdr->sA3.abyAddr2, pMgmt->abyMACAddr, WLAN_ADDR_LEN);
3750 memcpy( sFrame.pHdr->sA3.abyAddr3, pMgmt->abyCurrBSSID, WLAN_BSSID_LEN);
3751
3752 // Set the capibility and listen interval
3753 *(sFrame.pwCapInfo) = cpu_to_le16(wCurrCapInfo);
3754 *(sFrame.pwListenInterval) = cpu_to_le16(wListenInterval);
3755
3756 // sFrame.len point to end of fixed field
3757 sFrame.pSSID = (PWLAN_IE_SSID)(sFrame.pBuf + sFrame.len);
3758 sFrame.len += pCurrSSID->len + WLAN_IEHDR_LEN;
3759 memcpy(sFrame.pSSID, pCurrSSID, pCurrSSID->len + WLAN_IEHDR_LEN);
3760
3761 pMgmt->sAssocInfo.AssocInfo.RequestIELength = pCurrSSID->len + WLAN_IEHDR_LEN;
3762 pMgmt->sAssocInfo.AssocInfo.OffsetRequestIEs = sizeof(NDIS_802_11_ASSOCIATION_INFORMATION);
3763 pbyIEs = pMgmt->sAssocInfo.abyIEs;
3764 MEMvCopy(pbyIEs, pCurrSSID, pCurrSSID->len + WLAN_IEHDR_LEN);
3765 pbyIEs += pCurrSSID->len + WLAN_IEHDR_LEN;
3766
3767 // Copy the rate set
3768 sFrame.pSuppRates = (PWLAN_IE_SUPP_RATES)(sFrame.pBuf + sFrame.len);
3769 if ((pDevice->eCurrentPHYType == PHY_TYPE_11B) && (pCurrRates->len > 4))
3770 sFrame.len += 4 + WLAN_IEHDR_LEN;
3771 else
3772 sFrame.len += pCurrRates->len + WLAN_IEHDR_LEN;
3773 memcpy(sFrame.pSuppRates, pCurrRates, pCurrRates->len + WLAN_IEHDR_LEN);
3774
3775 // Copy the extension rate set
3776 if ((pDevice->eCurrentPHYType == PHY_TYPE_11G) && (pCurrExtSuppRates->len > 0)) {
3777 sFrame.pExtSuppRates = (PWLAN_IE_SUPP_RATES)(sFrame.pBuf + sFrame.len);
3778 sFrame.len += pCurrExtSuppRates->len + WLAN_IEHDR_LEN;
3779 memcpy(sFrame.pExtSuppRates, pCurrExtSuppRates, pCurrExtSuppRates->len + WLAN_IEHDR_LEN);
3780 }
3781
3782 pMgmt->sAssocInfo.AssocInfo.RequestIELength += pCurrRates->len + WLAN_IEHDR_LEN;
3783 MEMvCopy(pbyIEs, pCurrRates, pCurrRates->len + WLAN_IEHDR_LEN);
3784 pbyIEs += pCurrRates->len + WLAN_IEHDR_LEN;
3785
3786 // for 802.11h
3787 if (pMgmt->b11hEnable == TRUE) {
3788 if (sFrame.pCurrPowerCap == NULL) {
3789 sFrame.pCurrPowerCap = (PWLAN_IE_PW_CAP)(sFrame.pBuf + sFrame.len);
3790 sFrame.len += (2 + WLAN_IEHDR_LEN);
3791 sFrame.pCurrPowerCap->byElementID = WLAN_EID_PWR_CAPABILITY;
3792 sFrame.pCurrPowerCap->len = 2;
3793 CARDvGetPowerCapability(pMgmt->pAdapter,
3794 &(sFrame.pCurrPowerCap->byMinPower),
3795 &(sFrame.pCurrPowerCap->byMaxPower)
3796 );
3797 }
3798 if (sFrame.pCurrSuppCh == NULL) {
3799 sFrame.pCurrSuppCh = (PWLAN_IE_SUPP_CH)(sFrame.pBuf + sFrame.len);
3800 sFrame.len += CARDbySetSupportChannels(pMgmt->pAdapter,(PBYTE)sFrame.pCurrSuppCh);
3801 }
3802 }
3803
3804 if (((pMgmt->eAuthenMode == WMAC_AUTH_WPA) ||
3805 (pMgmt->eAuthenMode == WMAC_AUTH_WPAPSK) ||
3806 (pMgmt->eAuthenMode == WMAC_AUTH_WPANONE)) &&
3807 (pMgmt->pCurrBSS != NULL)) {
3808 /* WPA IE */
3809 sFrame.pRSNWPA = (PWLAN_IE_RSN_EXT)(sFrame.pBuf + sFrame.len);
3810 sFrame.pRSNWPA->byElementID = WLAN_EID_RSN_WPA;
3811 sFrame.pRSNWPA->len = 16;
3812 sFrame.pRSNWPA->abyOUI[0] = 0x00;
3813 sFrame.pRSNWPA->abyOUI[1] = 0x50;
3814 sFrame.pRSNWPA->abyOUI[2] = 0xf2;
3815 sFrame.pRSNWPA->abyOUI[3] = 0x01;
3816 sFrame.pRSNWPA->wVersion = 1;
3817 //Group Key Cipher Suite
3818 sFrame.pRSNWPA->abyMulticast[0] = 0x00;
3819 sFrame.pRSNWPA->abyMulticast[1] = 0x50;
3820 sFrame.pRSNWPA->abyMulticast[2] = 0xf2;
3821 if (pMgmt->byCSSGK == KEY_CTL_WEP) {
3822 sFrame.pRSNWPA->abyMulticast[3] = pMgmt->pCurrBSS->byGKType;
3823 } else if (pMgmt->byCSSGK == KEY_CTL_TKIP) {
3824 sFrame.pRSNWPA->abyMulticast[3] = WPA_TKIP;
3825 } else if (pMgmt->byCSSGK == KEY_CTL_CCMP) {
3826 sFrame.pRSNWPA->abyMulticast[3] = WPA_AESCCMP;
3827 } else {
3828 sFrame.pRSNWPA->abyMulticast[3] = WPA_NONE;
3829 }
3830 // Pairwise Key Cipher Suite
3831 sFrame.pRSNWPA->wPKCount = 1;
3832 sFrame.pRSNWPA->PKSList[0].abyOUI[0] = 0x00;
3833 sFrame.pRSNWPA->PKSList[0].abyOUI[1] = 0x50;
3834 sFrame.pRSNWPA->PKSList[0].abyOUI[2] = 0xf2;
3835 if (pMgmt->byCSSPK == KEY_CTL_TKIP) {
3836 sFrame.pRSNWPA->PKSList[0].abyOUI[3] = WPA_TKIP;
3837 } else if (pMgmt->byCSSPK == KEY_CTL_CCMP) {
3838 sFrame.pRSNWPA->PKSList[0].abyOUI[3] = WPA_AESCCMP;
3839 } else {
3840 sFrame.pRSNWPA->PKSList[0].abyOUI[3] = WPA_NONE;
3841 }
3842 // Auth Key Management Suite
3843 pbyRSN = (PBYTE)(sFrame.pBuf + sFrame.len + 2 + sFrame.pRSNWPA->len);
3844 *pbyRSN++=0x01;
3845 *pbyRSN++=0x00;
3846 *pbyRSN++=0x00;
3847 *pbyRSN++=0x50;
3848 *pbyRSN++=0xf2;
3849 if (pMgmt->eAuthenMode == WMAC_AUTH_WPAPSK) {
3850 *pbyRSN++=WPA_AUTH_PSK;
3851 }
3852 else if (pMgmt->eAuthenMode == WMAC_AUTH_WPA) {
3853 *pbyRSN++=WPA_AUTH_IEEE802_1X;
3854 }
3855 else {
3856 *pbyRSN++=WPA_NONE;
3857 }
3858 sFrame.pRSNWPA->len +=6;
3859
3860 // RSN Capabilites
3861 *pbyRSN++=0x00;
3862 *pbyRSN++=0x00;
3863 sFrame.pRSNWPA->len +=2;
3864 sFrame.len += sFrame.pRSNWPA->len + WLAN_IEHDR_LEN;
3865 // copy to AssocInfo. for OID_802_11_ASSOCIATION_INFORMATION
3866 pMgmt->sAssocInfo.AssocInfo.RequestIELength += sFrame.pRSNWPA->len + WLAN_IEHDR_LEN;
3867 MEMvCopy(pbyIEs, sFrame.pRSNWPA, sFrame.pRSNWPA->len + WLAN_IEHDR_LEN);
3868 pbyIEs += sFrame.pRSNWPA->len + WLAN_IEHDR_LEN;
3869
3870 } else if (((pMgmt->eAuthenMode == WMAC_AUTH_WPA2) ||
3871 (pMgmt->eAuthenMode == WMAC_AUTH_WPA2PSK)) &&
3872 (pMgmt->pCurrBSS != NULL)) {
3873 UINT ii;
3874 PWORD pwPMKID;
3875
3876 // WPA IE
3877 sFrame.pRSN = (PWLAN_IE_RSN)(sFrame.pBuf + sFrame.len);
3878 sFrame.pRSN->byElementID = WLAN_EID_RSN;
3879 sFrame.pRSN->len = 6; //Version(2)+GK(4)
3880 sFrame.pRSN->wVersion = 1;
3881 //Group Key Cipher Suite
3882 sFrame.pRSN->abyRSN[0] = 0x00;
3883 sFrame.pRSN->abyRSN[1] = 0x0F;
3884 sFrame.pRSN->abyRSN[2] = 0xAC;
3885 if (pMgmt->byCSSGK == KEY_CTL_WEP) {
3886 sFrame.pRSN->abyRSN[3] = pMgmt->pCurrBSS->byCSSGK;
3887 } else if (pMgmt->byCSSGK == KEY_CTL_TKIP) {
3888 sFrame.pRSN->abyRSN[3] = WLAN_11i_CSS_TKIP;
3889 } else if (pMgmt->byCSSGK == KEY_CTL_CCMP) {
3890 sFrame.pRSN->abyRSN[3] = WLAN_11i_CSS_CCMP;
3891 } else {
3892 sFrame.pRSN->abyRSN[3] = WLAN_11i_CSS_UNKNOWN;
3893 }
3894
3895 // Pairwise Key Cipher Suite
3896 sFrame.pRSN->abyRSN[4] = 1;
3897 sFrame.pRSN->abyRSN[5] = 0;
3898 sFrame.pRSN->abyRSN[6] = 0x00;
3899 sFrame.pRSN->abyRSN[7] = 0x0F;
3900 sFrame.pRSN->abyRSN[8] = 0xAC;
3901 if (pMgmt->byCSSPK == KEY_CTL_TKIP) {
3902 sFrame.pRSN->abyRSN[9] = WLAN_11i_CSS_TKIP;
3903 } else if (pMgmt->byCSSPK == KEY_CTL_CCMP) {
3904 sFrame.pRSN->abyRSN[9] = WLAN_11i_CSS_CCMP;
3905 } else if (pMgmt->byCSSPK == KEY_CTL_NONE) {
3906 sFrame.pRSN->abyRSN[9] = WLAN_11i_CSS_USE_GROUP;
3907 } else {
3908 sFrame.pRSN->abyRSN[9] = WLAN_11i_CSS_UNKNOWN;
3909 }
3910 sFrame.pRSN->len += 6;
3911
3912 // Auth Key Management Suite
3913 sFrame.pRSN->abyRSN[10] = 1;
3914 sFrame.pRSN->abyRSN[11] = 0;
3915 sFrame.pRSN->abyRSN[12] = 0x00;
3916 sFrame.pRSN->abyRSN[13] = 0x0F;
3917 sFrame.pRSN->abyRSN[14] = 0xAC;
3918 if (pMgmt->eAuthenMode == WMAC_AUTH_WPA2PSK) {
3919 sFrame.pRSN->abyRSN[15] = WLAN_11i_AKMSS_PSK;
3920 } else if (pMgmt->eAuthenMode == WMAC_AUTH_WPA2) {
3921 sFrame.pRSN->abyRSN[15] = WLAN_11i_AKMSS_802_1X;
3922 } else {
3923 sFrame.pRSN->abyRSN[15] = WLAN_11i_AKMSS_UNKNOWN;
3924 }
3925 sFrame.pRSN->len +=6;
3926
3927 // RSN Capabilites
3928 if (pMgmt->pCurrBSS->sRSNCapObj.bRSNCapExist == TRUE) {
3929 MEMvCopy(&sFrame.pRSN->abyRSN[16], &pMgmt->pCurrBSS->sRSNCapObj.wRSNCap, 2);
3930 } else {
3931 sFrame.pRSN->abyRSN[16] = 0;
3932 sFrame.pRSN->abyRSN[17] = 0;
3933 }
3934 sFrame.pRSN->len +=2;
3935
3936 if ((pDevice->gsPMKID.BSSIDInfoCount > 0) && (pDevice->bRoaming == TRUE) && (pMgmt->eAuthenMode == WMAC_AUTH_WPA2)) {
3937 // RSN PMKID
3938 pbyRSN = &sFrame.pRSN->abyRSN[18];
3939 pwPMKID = (PWORD)pbyRSN; // Point to PMKID count
3940 *pwPMKID = 0; // Initialize PMKID count
3941 pbyRSN += 2; // Point to PMKID list
3942 for (ii = 0; ii < pDevice->gsPMKID.BSSIDInfoCount; ii++) {
3943 if (MEMEqualMemory(&pDevice->gsPMKID.BSSIDInfo[ii].BSSID[0], pMgmt->abyCurrBSSID, U_ETHER_ADDR_LEN)) {
3944 (*pwPMKID) ++;
3945 MEMvCopy(pbyRSN, pDevice->gsPMKID.BSSIDInfo[ii].PMKID, 16);
3946 pbyRSN += 16;
3947 }
3948 }
3949 if (*pwPMKID != 0) {
3950 sFrame.pRSN->len += (2 + (*pwPMKID)*16);
3951 }
3952 }
3953
3954 sFrame.len += sFrame.pRSN->len + WLAN_IEHDR_LEN;
3955 // copy to AssocInfo. for OID_802_11_ASSOCIATION_INFORMATION
3956 pMgmt->sAssocInfo.AssocInfo.RequestIELength += sFrame.pRSN->len + WLAN_IEHDR_LEN;
3957 MEMvCopy(pbyIEs, sFrame.pRSN, sFrame.pRSN->len + WLAN_IEHDR_LEN);
3958 pbyIEs += sFrame.pRSN->len + WLAN_IEHDR_LEN;
3959 }
3960
3961
3962 // Adjust the length fields
3963 pTxPacket->cbMPDULen = sFrame.len;
3964 pTxPacket->cbPayloadLen = sFrame.len - WLAN_HDR_ADDR3_LEN;
3965 return pTxPacket;
3966}
3967
3968
3969
3970
3971
3972
3973
3974
3975/*+
3976 *
3977 * Routine Description:
3978 * Constructs an re-association request frame
3979 *
3980 *
3981 * Return Value:
3982 * A ptr to frame or NULL on allocation failue
3983 *
3984-*/
3985
3986
3987PSTxMgmtPacket
3988s_MgrMakeReAssocRequest(
3989 IN PSDevice pDevice,
3990 IN PSMgmtObject pMgmt,
3991 IN PBYTE pDAddr,
3992 IN WORD wCurrCapInfo,
3993 IN WORD wListenInterval,
3994 IN PWLAN_IE_SSID pCurrSSID,
3995 IN PWLAN_IE_SUPP_RATES pCurrRates,
3996 IN PWLAN_IE_SUPP_RATES pCurrExtSuppRates
3997 )
3998{
3999 PSTxMgmtPacket pTxPacket = NULL;
4000 WLAN_FR_REASSOCREQ sFrame;
4001 PBYTE pbyIEs;
4002 PBYTE pbyRSN;
4003
4004
4005 pTxPacket = (PSTxMgmtPacket)pMgmt->pbyMgmtPacketPool;
4006 memset( pTxPacket, 0, sizeof(STxMgmtPacket) + WLAN_REASSOCREQ_FR_MAXLEN);
4007 pTxPacket->p80211Header = (PUWLAN_80211HDR)((PBYTE)pTxPacket + sizeof(STxMgmtPacket));
4008 /* Setup the sFrame structure. */
4009 sFrame.pBuf = (PBYTE)pTxPacket->p80211Header;
4010 sFrame.len = WLAN_REASSOCREQ_FR_MAXLEN;
4011
4012 // format fixed field frame structure
4013 vMgrEncodeReassocRequest(&sFrame);
4014
4015 /* Setup the header */
4016 sFrame.pHdr->sA3.wFrameCtl = cpu_to_le16(
4017 (
4018 WLAN_SET_FC_FTYPE(WLAN_TYPE_MGR) |
4019 WLAN_SET_FC_FSTYPE(WLAN_FSTYPE_REASSOCREQ)
4020 ));
4021 memcpy( sFrame.pHdr->sA3.abyAddr1, pDAddr, WLAN_ADDR_LEN);
4022 memcpy( sFrame.pHdr->sA3.abyAddr2, pMgmt->abyMACAddr, WLAN_ADDR_LEN);
4023 memcpy( sFrame.pHdr->sA3.abyAddr3, pMgmt->abyCurrBSSID, WLAN_BSSID_LEN);
4024
4025 /* Set the capibility and listen interval */
4026 *(sFrame.pwCapInfo) = cpu_to_le16(wCurrCapInfo);
4027 *(sFrame.pwListenInterval) = cpu_to_le16(wListenInterval);
4028
4029 memcpy(sFrame.pAddrCurrAP, pMgmt->abyCurrBSSID, WLAN_BSSID_LEN);
4030 /* Copy the SSID */
4031 /* sFrame.len point to end of fixed field */
4032 sFrame.pSSID = (PWLAN_IE_SSID)(sFrame.pBuf + sFrame.len);
4033 sFrame.len += pCurrSSID->len + WLAN_IEHDR_LEN;
4034 memcpy(sFrame.pSSID, pCurrSSID, pCurrSSID->len + WLAN_IEHDR_LEN);
4035
4036 pMgmt->sAssocInfo.AssocInfo.RequestIELength = pCurrSSID->len + WLAN_IEHDR_LEN;
4037 pMgmt->sAssocInfo.AssocInfo.OffsetRequestIEs = sizeof(NDIS_802_11_ASSOCIATION_INFORMATION);
4038 pbyIEs = pMgmt->sAssocInfo.abyIEs;
4039 MEMvCopy(pbyIEs, pCurrSSID, pCurrSSID->len + WLAN_IEHDR_LEN);
4040 pbyIEs += pCurrSSID->len + WLAN_IEHDR_LEN;
4041
4042 /* Copy the rate set */
4043 /* sFrame.len point to end of SSID */
4044 sFrame.pSuppRates = (PWLAN_IE_SUPP_RATES)(sFrame.pBuf + sFrame.len);
4045 sFrame.len += pCurrRates->len + WLAN_IEHDR_LEN;
4046 memcpy(sFrame.pSuppRates, pCurrRates, pCurrRates->len + WLAN_IEHDR_LEN);
4047
4048 // Copy the extension rate set
4049 if ((pMgmt->eCurrentPHYMode == PHY_TYPE_11G) && (pCurrExtSuppRates->len > 0)) {
4050 sFrame.pExtSuppRates = (PWLAN_IE_SUPP_RATES)(sFrame.pBuf + sFrame.len);
4051 sFrame.len += pCurrExtSuppRates->len + WLAN_IEHDR_LEN;
4052 memcpy(sFrame.pExtSuppRates, pCurrExtSuppRates, pCurrExtSuppRates->len + WLAN_IEHDR_LEN);
4053 }
4054
4055 pMgmt->sAssocInfo.AssocInfo.RequestIELength += pCurrRates->len + WLAN_IEHDR_LEN;
4056 MEMvCopy(pbyIEs, pCurrRates, pCurrRates->len + WLAN_IEHDR_LEN);
4057 pbyIEs += pCurrRates->len + WLAN_IEHDR_LEN;
4058
4059 if (((pMgmt->eAuthenMode == WMAC_AUTH_WPA) ||
4060 (pMgmt->eAuthenMode == WMAC_AUTH_WPAPSK) ||
4061 (pMgmt->eAuthenMode == WMAC_AUTH_WPANONE)) &&
4062 (pMgmt->pCurrBSS != NULL)) {
4063 /* WPA IE */
4064 sFrame.pRSNWPA = (PWLAN_IE_RSN_EXT)(sFrame.pBuf + sFrame.len);
4065 sFrame.pRSNWPA->byElementID = WLAN_EID_RSN_WPA;
4066 sFrame.pRSNWPA->len = 16;
4067 sFrame.pRSNWPA->abyOUI[0] = 0x00;
4068 sFrame.pRSNWPA->abyOUI[1] = 0x50;
4069 sFrame.pRSNWPA->abyOUI[2] = 0xf2;
4070 sFrame.pRSNWPA->abyOUI[3] = 0x01;
4071 sFrame.pRSNWPA->wVersion = 1;
4072 //Group Key Cipher Suite
4073 sFrame.pRSNWPA->abyMulticast[0] = 0x00;
4074 sFrame.pRSNWPA->abyMulticast[1] = 0x50;
4075 sFrame.pRSNWPA->abyMulticast[2] = 0xf2;
4076 if (pMgmt->byCSSGK == KEY_CTL_WEP) {
4077 sFrame.pRSNWPA->abyMulticast[3] = pMgmt->pCurrBSS->byGKType;
4078 } else if (pMgmt->byCSSGK == KEY_CTL_TKIP) {
4079 sFrame.pRSNWPA->abyMulticast[3] = WPA_TKIP;
4080 } else if (pMgmt->byCSSGK == KEY_CTL_CCMP) {
4081 sFrame.pRSNWPA->abyMulticast[3] = WPA_AESCCMP;
4082 } else {
4083 sFrame.pRSNWPA->abyMulticast[3] = WPA_NONE;
4084 }
4085 // Pairwise Key Cipher Suite
4086 sFrame.pRSNWPA->wPKCount = 1;
4087 sFrame.pRSNWPA->PKSList[0].abyOUI[0] = 0x00;
4088 sFrame.pRSNWPA->PKSList[0].abyOUI[1] = 0x50;
4089 sFrame.pRSNWPA->PKSList[0].abyOUI[2] = 0xf2;
4090 if (pMgmt->byCSSPK == KEY_CTL_TKIP) {
4091 sFrame.pRSNWPA->PKSList[0].abyOUI[3] = WPA_TKIP;
4092 } else if (pMgmt->byCSSPK == KEY_CTL_CCMP) {
4093 sFrame.pRSNWPA->PKSList[0].abyOUI[3] = WPA_AESCCMP;
4094 } else {
4095 sFrame.pRSNWPA->PKSList[0].abyOUI[3] = WPA_NONE;
4096 }
4097 // Auth Key Management Suite
4098 pbyRSN = (PBYTE)(sFrame.pBuf + sFrame.len + 2 + sFrame.pRSNWPA->len);
4099 *pbyRSN++=0x01;
4100 *pbyRSN++=0x00;
4101 *pbyRSN++=0x00;
4102 *pbyRSN++=0x50;
4103 *pbyRSN++=0xf2;
4104 if (pMgmt->eAuthenMode == WMAC_AUTH_WPAPSK) {
4105 *pbyRSN++=WPA_AUTH_PSK;
4106 } else if (pMgmt->eAuthenMode == WMAC_AUTH_WPA) {
4107 *pbyRSN++=WPA_AUTH_IEEE802_1X;
4108 } else {
4109 *pbyRSN++=WPA_NONE;
4110 }
4111 sFrame.pRSNWPA->len +=6;
4112
4113 // RSN Capabilites
4114 *pbyRSN++=0x00;
4115 *pbyRSN++=0x00;
4116 sFrame.pRSNWPA->len +=2;
4117 sFrame.len += sFrame.pRSNWPA->len + WLAN_IEHDR_LEN;
4118 // copy to AssocInfo. for OID_802_11_ASSOCIATION_INFORMATION
4119 pMgmt->sAssocInfo.AssocInfo.RequestIELength += sFrame.pRSNWPA->len + WLAN_IEHDR_LEN;
4120 MEMvCopy(pbyIEs, sFrame.pRSNWPA, sFrame.pRSNWPA->len + WLAN_IEHDR_LEN);
4121 pbyIEs += sFrame.pRSNWPA->len + WLAN_IEHDR_LEN;
4122
4123 } else if (((pMgmt->eAuthenMode == WMAC_AUTH_WPA2) ||
4124 (pMgmt->eAuthenMode == WMAC_AUTH_WPA2PSK)) &&
4125 (pMgmt->pCurrBSS != NULL)) {
4126 UINT ii;
4127 PWORD pwPMKID;
4128
4129 /* WPA IE */
4130 sFrame.pRSN = (PWLAN_IE_RSN)(sFrame.pBuf + sFrame.len);
4131 sFrame.pRSN->byElementID = WLAN_EID_RSN;
4132 sFrame.pRSN->len = 6; //Version(2)+GK(4)
4133 sFrame.pRSN->wVersion = 1;
4134 //Group Key Cipher Suite
4135 sFrame.pRSN->abyRSN[0] = 0x00;
4136 sFrame.pRSN->abyRSN[1] = 0x0F;
4137 sFrame.pRSN->abyRSN[2] = 0xAC;
4138 if (pMgmt->byCSSGK == KEY_CTL_WEP) {
4139 sFrame.pRSN->abyRSN[3] = pMgmt->pCurrBSS->byCSSGK;
4140 } else if (pMgmt->byCSSGK == KEY_CTL_TKIP) {
4141 sFrame.pRSN->abyRSN[3] = WLAN_11i_CSS_TKIP;
4142 } else if (pMgmt->byCSSGK == KEY_CTL_CCMP) {
4143 sFrame.pRSN->abyRSN[3] = WLAN_11i_CSS_CCMP;
4144 } else {
4145 sFrame.pRSN->abyRSN[3] = WLAN_11i_CSS_UNKNOWN;
4146 }
4147
4148 // Pairwise Key Cipher Suite
4149 sFrame.pRSN->abyRSN[4] = 1;
4150 sFrame.pRSN->abyRSN[5] = 0;
4151 sFrame.pRSN->abyRSN[6] = 0x00;
4152 sFrame.pRSN->abyRSN[7] = 0x0F;
4153 sFrame.pRSN->abyRSN[8] = 0xAC;
4154 if (pMgmt->byCSSPK == KEY_CTL_TKIP) {
4155 sFrame.pRSN->abyRSN[9] = WLAN_11i_CSS_TKIP;
4156 } else if (pMgmt->byCSSPK == KEY_CTL_CCMP) {
4157 sFrame.pRSN->abyRSN[9] = WLAN_11i_CSS_CCMP;
4158 } else if (pMgmt->byCSSPK == KEY_CTL_NONE) {
4159 sFrame.pRSN->abyRSN[9] = WLAN_11i_CSS_USE_GROUP;
4160 } else {
4161 sFrame.pRSN->abyRSN[9] = WLAN_11i_CSS_UNKNOWN;
4162 }
4163 sFrame.pRSN->len += 6;
4164
4165 // Auth Key Management Suite
4166 sFrame.pRSN->abyRSN[10] = 1;
4167 sFrame.pRSN->abyRSN[11] = 0;
4168 sFrame.pRSN->abyRSN[12] = 0x00;
4169 sFrame.pRSN->abyRSN[13] = 0x0F;
4170 sFrame.pRSN->abyRSN[14] = 0xAC;
4171 if (pMgmt->eAuthenMode == WMAC_AUTH_WPA2PSK) {
4172 sFrame.pRSN->abyRSN[15] = WLAN_11i_AKMSS_PSK;
4173 } else if (pMgmt->eAuthenMode == WMAC_AUTH_WPA2) {
4174 sFrame.pRSN->abyRSN[15] = WLAN_11i_AKMSS_802_1X;
4175 } else {
4176 sFrame.pRSN->abyRSN[15] = WLAN_11i_AKMSS_UNKNOWN;
4177 }
4178 sFrame.pRSN->len +=6;
4179
4180 // RSN Capabilites
4181 if (pMgmt->pCurrBSS->sRSNCapObj.bRSNCapExist == TRUE) {
4182 MEMvCopy(&sFrame.pRSN->abyRSN[16], &pMgmt->pCurrBSS->sRSNCapObj.wRSNCap, 2);
4183 } else {
4184 sFrame.pRSN->abyRSN[16] = 0;
4185 sFrame.pRSN->abyRSN[17] = 0;
4186 }
4187 sFrame.pRSN->len +=2;
4188
4189 if ((pDevice->gsPMKID.BSSIDInfoCount > 0) && (pDevice->bRoaming == TRUE) && (pMgmt->eAuthenMode == WMAC_AUTH_WPA2)) {
4190 // RSN PMKID
4191 pbyRSN = &sFrame.pRSN->abyRSN[18];
4192 pwPMKID = (PWORD)pbyRSN; // Point to PMKID count
4193 *pwPMKID = 0; // Initialize PMKID count
4194 pbyRSN += 2; // Point to PMKID list
4195 for (ii = 0; ii < pDevice->gsPMKID.BSSIDInfoCount; ii++) {
4196 if (MEMEqualMemory(&pDevice->gsPMKID.BSSIDInfo[ii].BSSID[0], pMgmt->abyCurrBSSID, U_ETHER_ADDR_LEN)) {
4197 (*pwPMKID) ++;
4198 MEMvCopy(pbyRSN, pDevice->gsPMKID.BSSIDInfo[ii].PMKID, 16);
4199 pbyRSN += 16;
4200 }
4201 }
4202 if (*pwPMKID != 0) {
4203 sFrame.pRSN->len += (2 + (*pwPMKID)*16);
4204 }
4205 }
4206
4207 sFrame.len += sFrame.pRSN->len + WLAN_IEHDR_LEN;
4208 // copy to AssocInfo. for OID_802_11_ASSOCIATION_INFORMATION
4209 pMgmt->sAssocInfo.AssocInfo.RequestIELength += sFrame.pRSN->len + WLAN_IEHDR_LEN;
4210 MEMvCopy(pbyIEs, sFrame.pRSN, sFrame.pRSN->len + WLAN_IEHDR_LEN);
4211 pbyIEs += sFrame.pRSN->len + WLAN_IEHDR_LEN;
4212 }
4213
4214
4215 /* Adjust the length fields */
4216 pTxPacket->cbMPDULen = sFrame.len;
4217 pTxPacket->cbPayloadLen = sFrame.len - WLAN_HDR_ADDR3_LEN;
4218
4219 return pTxPacket;
4220}
4221
4222
4223
4224/*+
4225 *
4226 * Routine Description:
4227 * Constructs an assoc-response frame
4228 *
4229 *
4230 * Return Value:
4231 * PTR to frame; or NULL on allocation failue
4232 *
4233-*/
4234
4235
4236PSTxMgmtPacket
4237s_MgrMakeAssocResponse(
4238 IN PSDevice pDevice,
4239 IN PSMgmtObject pMgmt,
4240 IN WORD wCurrCapInfo,
4241 IN WORD wAssocStatus,
4242 IN WORD wAssocAID,
4243 IN PBYTE pDstAddr,
4244 IN PWLAN_IE_SUPP_RATES pCurrSuppRates,
4245 IN PWLAN_IE_SUPP_RATES pCurrExtSuppRates
4246 )
4247{
4248 PSTxMgmtPacket pTxPacket = NULL;
4249 WLAN_FR_ASSOCRESP sFrame;
4250
4251
4252 pTxPacket = (PSTxMgmtPacket)pMgmt->pbyMgmtPacketPool;
4253 memset(pTxPacket, 0, sizeof(STxMgmtPacket) + WLAN_ASSOCREQ_FR_MAXLEN);
4254 pTxPacket->p80211Header = (PUWLAN_80211HDR)((PBYTE)pTxPacket + sizeof(STxMgmtPacket));
4255 // Setup the sFrame structure
4256 sFrame.pBuf = (PBYTE)pTxPacket->p80211Header;
4257 sFrame.len = WLAN_REASSOCRESP_FR_MAXLEN;
4258 vMgrEncodeAssocResponse(&sFrame);
4259 // Setup the header
4260 sFrame.pHdr->sA3.wFrameCtl = cpu_to_le16(
4261 (
4262 WLAN_SET_FC_FTYPE(WLAN_TYPE_MGR) |
4263 WLAN_SET_FC_FSTYPE(WLAN_FSTYPE_ASSOCRESP)
4264 ));
4265 memcpy( sFrame.pHdr->sA3.abyAddr1, pDstAddr, WLAN_ADDR_LEN);
4266 memcpy( sFrame.pHdr->sA3.abyAddr2, pMgmt->abyMACAddr, WLAN_ADDR_LEN);
4267 memcpy( sFrame.pHdr->sA3.abyAddr3, pMgmt->abyCurrBSSID, WLAN_BSSID_LEN);
4268
4269 *sFrame.pwCapInfo = cpu_to_le16(wCurrCapInfo);
4270 *sFrame.pwStatus = cpu_to_le16(wAssocStatus);
4271 *sFrame.pwAid = cpu_to_le16((WORD)(wAssocAID | BIT14 | BIT15));
4272
4273 // Copy the rate set
4274 sFrame.pSuppRates = (PWLAN_IE_SUPP_RATES)(sFrame.pBuf + sFrame.len);
4275 sFrame.len += ((PWLAN_IE_SUPP_RATES)pCurrSuppRates)->len + WLAN_IEHDR_LEN;
4276 memcpy(sFrame.pSuppRates,
4277 pCurrSuppRates,
4278 ((PWLAN_IE_SUPP_RATES)pCurrSuppRates)->len + WLAN_IEHDR_LEN
4279 );
4280
4281 if (((PWLAN_IE_SUPP_RATES)pCurrExtSuppRates)->len != 0) {
4282 sFrame.pExtSuppRates = (PWLAN_IE_SUPP_RATES)(sFrame.pBuf + sFrame.len);
4283 sFrame.len += ((PWLAN_IE_SUPP_RATES)pCurrExtSuppRates)->len + WLAN_IEHDR_LEN;
4284 MEMvCopy(sFrame.pExtSuppRates,
4285 pCurrExtSuppRates,
4286 ((PWLAN_IE_SUPP_RATES)pCurrExtSuppRates)->len + WLAN_IEHDR_LEN
4287 );
4288 }
4289
4290 // Adjust the length fields
4291 pTxPacket->cbMPDULen = sFrame.len;
4292 pTxPacket->cbPayloadLen = sFrame.len - WLAN_HDR_ADDR3_LEN;
4293
4294 return pTxPacket;
4295}
4296
4297
4298/*+
4299 *
4300 * Routine Description:
4301 * Constructs an reassoc-response frame
4302 *
4303 *
4304 * Return Value:
4305 * PTR to frame; or NULL on allocation failue
4306 *
4307-*/
4308
4309
4310PSTxMgmtPacket
4311s_MgrMakeReAssocResponse(
4312 IN PSDevice pDevice,
4313 IN PSMgmtObject pMgmt,
4314 IN WORD wCurrCapInfo,
4315 IN WORD wAssocStatus,
4316 IN WORD wAssocAID,
4317 IN PBYTE pDstAddr,
4318 IN PWLAN_IE_SUPP_RATES pCurrSuppRates,
4319 IN PWLAN_IE_SUPP_RATES pCurrExtSuppRates
4320 )
4321{
4322 PSTxMgmtPacket pTxPacket = NULL;
4323 WLAN_FR_REASSOCRESP sFrame;
4324
4325
4326 pTxPacket = (PSTxMgmtPacket)pMgmt->pbyMgmtPacketPool;
4327 memset(pTxPacket, 0, sizeof(STxMgmtPacket) + WLAN_ASSOCREQ_FR_MAXLEN);
4328 pTxPacket->p80211Header = (PUWLAN_80211HDR)((PBYTE)pTxPacket + sizeof(STxMgmtPacket));
4329 // Setup the sFrame structure
4330 sFrame.pBuf = (PBYTE)pTxPacket->p80211Header;
4331 sFrame.len = WLAN_REASSOCRESP_FR_MAXLEN;
4332 vMgrEncodeReassocResponse(&sFrame);
4333 // Setup the header
4334 sFrame.pHdr->sA3.wFrameCtl = cpu_to_le16(
4335 (
4336 WLAN_SET_FC_FTYPE(WLAN_TYPE_MGR) |
4337 WLAN_SET_FC_FSTYPE(WLAN_FSTYPE_REASSOCRESP)
4338 ));
4339 memcpy( sFrame.pHdr->sA3.abyAddr1, pDstAddr, WLAN_ADDR_LEN);
4340 memcpy( sFrame.pHdr->sA3.abyAddr2, pMgmt->abyMACAddr, WLAN_ADDR_LEN);
4341 memcpy( sFrame.pHdr->sA3.abyAddr3, pMgmt->abyCurrBSSID, WLAN_BSSID_LEN);
4342
4343 *sFrame.pwCapInfo = cpu_to_le16(wCurrCapInfo);
4344 *sFrame.pwStatus = cpu_to_le16(wAssocStatus);
4345 *sFrame.pwAid = cpu_to_le16((WORD)(wAssocAID | BIT14 | BIT15));
4346
4347 // Copy the rate set
4348 sFrame.pSuppRates = (PWLAN_IE_SUPP_RATES)(sFrame.pBuf + sFrame.len);
4349 sFrame.len += ((PWLAN_IE_SUPP_RATES)pCurrSuppRates)->len + WLAN_IEHDR_LEN;
4350 memcpy(sFrame.pSuppRates,
4351 pCurrSuppRates,
4352 ((PWLAN_IE_SUPP_RATES)pCurrSuppRates)->len + WLAN_IEHDR_LEN
4353 );
4354
4355 if (((PWLAN_IE_SUPP_RATES)pCurrExtSuppRates)->len != 0) {
4356 sFrame.pExtSuppRates = (PWLAN_IE_SUPP_RATES)(sFrame.pBuf + sFrame.len);
4357 sFrame.len += ((PWLAN_IE_SUPP_RATES)pCurrExtSuppRates)->len + WLAN_IEHDR_LEN;
4358 MEMvCopy(sFrame.pExtSuppRates,
4359 pCurrExtSuppRates,
4360 ((PWLAN_IE_SUPP_RATES)pCurrExtSuppRates)->len + WLAN_IEHDR_LEN
4361 );
4362 }
4363
4364 // Adjust the length fields
4365 pTxPacket->cbMPDULen = sFrame.len;
4366 pTxPacket->cbPayloadLen = sFrame.len - WLAN_HDR_ADDR3_LEN;
4367
4368 return pTxPacket;
4369}
4370
4371
4372/*+
4373 *
4374 * Routine Description:
4375 * Handles probe response management frames.
4376 *
4377 *
4378 * Return Value:
4379 * none.
4380 *
4381-*/
4382
4383static
4384VOID
4385s_vMgrRxProbeResponse(
4386 IN PSDevice pDevice,
4387 IN PSMgmtObject pMgmt,
4388 IN PSRxMgmtPacket pRxPacket
4389 )
4390{
4391 PKnownBSS pBSSList = NULL;
4392 WLAN_FR_PROBERESP sFrame;
4393 BYTE byCurrChannel = pRxPacket->byRxChannel;
4394 ERPObject sERP;
4395 BYTE byIEChannel = 0;
4396 BOOL bChannelHit = TRUE;
4397
4398
4399 memset(&sFrame, 0, sizeof(WLAN_FR_PROBERESP));
4400 // decode the frame
4401 sFrame.len = pRxPacket->cbMPDULen;
4402 sFrame.pBuf = (PBYTE)pRxPacket->p80211Header;
4403 vMgrDecodeProbeResponse(&sFrame);
4404
4405 if ((sFrame.pqwTimestamp == 0) ||
4406 (sFrame.pwBeaconInterval == 0) ||
4407 (sFrame.pwCapInfo == 0) ||
4408 (sFrame.pSSID == 0) ||
4409 (sFrame.pSuppRates == 0)) {
4410 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Probe resp:Fail addr:[%p] \n", pRxPacket->p80211Header);
4411 DBG_PORT80(0xCC);
4412 return;
4413 };
4414
4415 if(sFrame.pSSID->len == 0)
4416 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Rx Probe resp: SSID len = 0 \n");
4417
4418 if (sFrame.pDSParms != 0) {
4419 if (byCurrChannel > CB_MAX_CHANNEL_24G) {
4420 // channel remapping to
4421 byIEChannel = CARDbyGetChannelMapping(pMgmt->pAdapter, sFrame.pDSParms->byCurrChannel, PHY_TYPE_11A);
4422 } else {
4423 byIEChannel = sFrame.pDSParms->byCurrChannel;
4424 }
4425 if (byCurrChannel != byIEChannel) {
4426 // adjust channel info. bcs we rcv adjcent channel pakckets
4427 bChannelHit = FALSE;
4428 byCurrChannel = byIEChannel;
4429 }
4430 } else {
4431 // no DS channel info
4432 bChannelHit = TRUE;
4433 }
4434
4435//2008-0730-01<Add>by MikeLiu
4436if(ChannelExceedZoneType(pDevice,byCurrChannel)==TRUE)
4437 return;
4438
4439 if (sFrame.pERP != NULL) {
4440 sERP.byERP = sFrame.pERP->byContext;
4441 sERP.bERPExist = TRUE;
4442 } else {
4443 sERP.bERPExist = FALSE;
4444 sERP.byERP = 0;
4445 }
4446
4447
4448 // update or insert the bss
4449 pBSSList = BSSpAddrIsInBSSList((HANDLE)pDevice, sFrame.pHdr->sA3.abyAddr3, sFrame.pSSID);
4450 if (pBSSList) {
4451 BSSbUpdateToBSSList((HANDLE)pDevice,
4452 *sFrame.pqwTimestamp,
4453 *sFrame.pwBeaconInterval,
4454 *sFrame.pwCapInfo,
4455 byCurrChannel,
4456 bChannelHit,
4457 sFrame.pSSID,
4458 sFrame.pSuppRates,
4459 sFrame.pExtSuppRates,
4460 &sERP,
4461 sFrame.pRSN,
4462 sFrame.pRSNWPA,
4463 sFrame.pIE_Country,
4464 sFrame.pIE_Quiet,
4465 pBSSList,
4466 sFrame.len - WLAN_HDR_ADDR3_LEN,
4467 sFrame.pHdr->sA4.abyAddr4, // payload of probresponse
4468 (HANDLE)pRxPacket
4469 );
4470 }
4471 else {
4472 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Probe resp/insert: RxChannel = : %d\n", byCurrChannel);
4473 BSSbInsertToBSSList((HANDLE)pDevice,
4474 sFrame.pHdr->sA3.abyAddr3,
4475 *sFrame.pqwTimestamp,
4476 *sFrame.pwBeaconInterval,
4477 *sFrame.pwCapInfo,
4478 byCurrChannel,
4479 sFrame.pSSID,
4480 sFrame.pSuppRates,
4481 sFrame.pExtSuppRates,
4482 &sERP,
4483 sFrame.pRSN,
4484 sFrame.pRSNWPA,
4485 sFrame.pIE_Country,
4486 sFrame.pIE_Quiet,
4487 sFrame.len - WLAN_HDR_ADDR3_LEN,
4488 sFrame.pHdr->sA4.abyAddr4, // payload of beacon
4489 (HANDLE)pRxPacket
4490 );
4491 }
4492 return;
4493
4494}
4495
4496/*+
4497 *
4498 * Routine Description:(AP)or(Ad-hoc STA)
4499 * Handles probe request management frames.
4500 *
4501 *
4502 * Return Value:
4503 * none.
4504 *
4505-*/
4506
4507
4508static
4509VOID
4510s_vMgrRxProbeRequest(
4511 IN PSDevice pDevice,
4512 IN PSMgmtObject pMgmt,
4513 IN PSRxMgmtPacket pRxPacket
4514 )
4515{
4516 WLAN_FR_PROBEREQ sFrame;
4517 CMD_STATUS Status;
4518 PSTxMgmtPacket pTxPacket;
4519 BYTE byPHYType = BB_TYPE_11B;
4520
4521 // STA in Ad-hoc mode: when latest TBTT beacon transmit success,
4522 // STA have to response this request.
4523 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_AP) ||
4524 ((pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) && pDevice->bBeaconSent)) {
4525
4526 memset(&sFrame, 0, sizeof(WLAN_FR_PROBEREQ));
4527 // decode the frame
4528 sFrame.len = pRxPacket->cbMPDULen;
4529 sFrame.pBuf = (PBYTE)pRxPacket->p80211Header;
4530 vMgrDecodeProbeRequest(&sFrame);
4531/*
4532 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Probe request rx:MAC addr:%02x-%02x-%02x=%02x-%02x-%02x \n",
4533 sFrame.pHdr->sA3.abyAddr2[0],
4534 sFrame.pHdr->sA3.abyAddr2[1],
4535 sFrame.pHdr->sA3.abyAddr2[2],
4536 sFrame.pHdr->sA3.abyAddr2[3],
4537 sFrame.pHdr->sA3.abyAddr2[4],
4538 sFrame.pHdr->sA3.abyAddr2[5]
4539 );
4540*/
4541 if (sFrame.pSSID->len != 0) {
4542 if (sFrame.pSSID->len != ((PWLAN_IE_SSID)pMgmt->abyCurrSSID)->len)
4543 return;
4544 if (memcmp(sFrame.pSSID->abySSID,
4545 ((PWLAN_IE_SSID)pMgmt->abyCurrSSID)->abySSID,
4546 ((PWLAN_IE_SSID)pMgmt->abyCurrSSID)->len) != 0) {
4547 return;
4548 }
4549 }
4550
4551 if ((sFrame.pSuppRates->len > 4) || (sFrame.pExtSuppRates != NULL)) {
4552 byPHYType = BB_TYPE_11G;
4553 }
4554
4555 // Probe response reply..
4556 pTxPacket = s_MgrMakeProbeResponse
4557 (
4558 pDevice,
4559 pMgmt,
4560 pMgmt->wCurrCapInfo,
4561 pMgmt->wCurrBeaconPeriod,
4562 pMgmt->uCurrChannel,
4563 0,
4564 sFrame.pHdr->sA3.abyAddr2,
4565 (PWLAN_IE_SSID)pMgmt->abyCurrSSID,
4566 (PBYTE)pMgmt->abyCurrBSSID,
4567 (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates,
4568 (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates,
4569 byPHYType
4570 );
4571 if (pTxPacket != NULL ){
4572 /* send the frame */
4573 Status = csMgmt_xmit(pDevice, pTxPacket);
4574 if (Status != CMD_STATUS_PENDING) {
4575 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Mgt:Probe response tx failed\n");
4576 }
4577 else {
4578// DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Mgt:Probe response tx sending..\n");
4579 }
4580 }
4581 }
4582
4583 return;
4584}
4585
4586
4587
4588
4589
4590/*+
4591 *
4592 * Routine Description:
4593 *
4594 * Entry point for the reception and handling of 802.11 management
4595 * frames. Makes a determination of the frame type and then calls
4596 * the appropriate function.
4597 *
4598 *
4599 * Return Value:
4600 * none.
4601 *
4602-*/
4603
4604
4605VOID
4606vMgrRxManagePacket(
4607 IN HANDLE hDeviceContext,
4608 IN PSMgmtObject pMgmt,
4609 IN PSRxMgmtPacket pRxPacket
4610 )
4611{
4612 PSDevice pDevice = (PSDevice)hDeviceContext;
4613 BOOL bInScan = FALSE;
4614 UINT uNodeIndex = 0;
4615 NODE_STATE eNodeState = 0;
4616 CMD_STATUS Status;
4617
4618
4619 if (pMgmt->eCurrMode == WMAC_MODE_ESS_AP) {
4620 if (BSSDBbIsSTAInNodeDB(pMgmt, pRxPacket->p80211Header->sA3.abyAddr2, &uNodeIndex))
4621 eNodeState = pMgmt->sNodeDBTable[uNodeIndex].eNodeState;
4622 }
4623
4624 switch( WLAN_GET_FC_FSTYPE((pRxPacket->p80211Header->sA3.wFrameCtl)) ){
4625
4626 case WLAN_FSTYPE_ASSOCREQ:
4627 // Frame Clase = 2
4628 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "rx assocreq\n");
4629 if (eNodeState < NODE_AUTH) {
4630 // send deauth notification
4631 // reason = (6) class 2 received from nonauth sta
4632 vMgrDeAuthenBeginSta(pDevice,
4633 pMgmt,
4634 pRxPacket->p80211Header->sA3.abyAddr2,
4635 (6),
4636 &Status
4637 );
4638 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "wmgr: send vMgrDeAuthenBeginSta 1\n");
4639 }
4640 else {
4641 s_vMgrRxAssocRequest(pDevice, pMgmt, pRxPacket, uNodeIndex);
4642 }
4643 break;
4644
4645 case WLAN_FSTYPE_ASSOCRESP:
4646 // Frame Clase = 2
4647 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "rx assocresp1\n");
4648 s_vMgrRxAssocResponse(pDevice, pMgmt, pRxPacket, FALSE);
4649 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "rx assocresp2\n");
4650 break;
4651
4652 case WLAN_FSTYPE_REASSOCREQ:
4653 // Frame Clase = 2
4654 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "rx reassocreq\n");
4655 // Todo: reassoc
4656 if (eNodeState < NODE_AUTH) {
4657 // send deauth notification
4658 // reason = (6) class 2 received from nonauth sta
4659 vMgrDeAuthenBeginSta(pDevice,
4660 pMgmt,
4661 pRxPacket->p80211Header->sA3.abyAddr2,
4662 (6),
4663 &Status
4664 );
4665 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "wmgr: send vMgrDeAuthenBeginSta 2\n");
4666
4667 }
4668 s_vMgrRxReAssocRequest(pDevice, pMgmt, pRxPacket, uNodeIndex);
4669 break;
4670
4671 case WLAN_FSTYPE_REASSOCRESP:
4672 // Frame Clase = 2
4673 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "rx reassocresp\n");
4674 s_vMgrRxAssocResponse(pDevice, pMgmt, pRxPacket, TRUE);
4675 break;
4676
4677 case WLAN_FSTYPE_PROBEREQ:
4678 // Frame Clase = 0
4679 //DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "rx probereq\n");
4680 s_vMgrRxProbeRequest(pDevice, pMgmt, pRxPacket);
4681 break;
4682
4683 case WLAN_FSTYPE_PROBERESP:
4684 // Frame Clase = 0
4685 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "rx proberesp\n");
4686
4687 s_vMgrRxProbeResponse(pDevice, pMgmt, pRxPacket);
4688 break;
4689
4690 case WLAN_FSTYPE_BEACON:
4691 // Frame Clase = 0
4692 // DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "rx beacon\n");
4693 if (pMgmt->eScanState != WMAC_NO_SCANNING) {
4694 bInScan = TRUE;
4695 };
4696 s_vMgrRxBeacon(pDevice, pMgmt, pRxPacket, bInScan);
4697 break;
4698
4699 case WLAN_FSTYPE_ATIM:
4700 // Frame Clase = 1
4701 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "rx atim\n");
4702 break;
4703
4704 case WLAN_FSTYPE_DISASSOC:
4705 // Frame Clase = 2
4706 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "rx disassoc\n");
4707 if (eNodeState < NODE_AUTH) {
4708 // send deauth notification
4709 // reason = (6) class 2 received from nonauth sta
4710 vMgrDeAuthenBeginSta(pDevice,
4711 pMgmt,
4712 pRxPacket->p80211Header->sA3.abyAddr2,
4713 (6),
4714 &Status
4715 );
4716 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "wmgr: send vMgrDeAuthenBeginSta 3\n");
4717 }
4718 s_vMgrRxDisassociation(pDevice, pMgmt, pRxPacket);
4719 break;
4720
4721 case WLAN_FSTYPE_AUTHEN:
4722 // Frame Clase = 1
4723 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "rx authen\n");
4724 s_vMgrRxAuthentication(pDevice, pMgmt, pRxPacket);
4725 break;
4726
4727 case WLAN_FSTYPE_DEAUTHEN:
4728 // Frame Clase = 1
4729 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "rx deauthen\n");
4730 s_vMgrRxDeauthentication(pDevice, pMgmt, pRxPacket);
4731 break;
4732
4733 default:
4734 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "rx unknown mgmt\n");
4735 }
4736
4737 return;
4738}
4739
4740
4741
4742
4743/*+
4744 *
4745 * Routine Description:
4746 *
4747 *
4748 * Prepare beacon to send
4749 *
4750 * Return Value:
4751 * TRUE if success; FALSE if failed.
4752 *
4753-*/
4754BOOL
4755bMgrPrepareBeaconToSend(
4756 IN HANDLE hDeviceContext,
4757 IN PSMgmtObject pMgmt
4758 )
4759{
4760 PSDevice pDevice = (PSDevice)hDeviceContext;
4761 PSTxMgmtPacket pTxPacket;
4762
4763// pDevice->bBeaconBufReady = FALSE;
4764 if (pDevice->bEncryptionEnable || pDevice->bEnable8021x){
4765 pMgmt->wCurrCapInfo |= WLAN_SET_CAP_INFO_PRIVACY(1);
4766 }
4767 else {
4768 pMgmt->wCurrCapInfo &= ~WLAN_SET_CAP_INFO_PRIVACY(1);
4769 }
4770 pTxPacket = s_MgrMakeBeacon
4771 (
4772 pDevice,
4773 pMgmt,
4774 pMgmt->wCurrCapInfo,
4775 pMgmt->wCurrBeaconPeriod,
4776 pMgmt->uCurrChannel,
4777 pMgmt->wCurrATIMWindow, //0,
4778 (PWLAN_IE_SSID)pMgmt->abyCurrSSID,
4779 (PBYTE)pMgmt->abyCurrBSSID,
4780 (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates,
4781 (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates
4782 );
4783
4784 if ((pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) &&
4785 (pMgmt->abyCurrBSSID[0] == 0))
4786 return FALSE;
4787
4788 csBeacon_xmit(pDevice, pTxPacket);
4789
4790 return TRUE;
4791}
4792
4793
4794
4795
4796/*+
4797 *
4798 * Routine Description:
4799 *
4800 * Log a warning message based on the contents of the Status
4801 * Code field of an 802.11 management frame. Defines are
4802 * derived from 802.11-1997 SPEC.
4803 *
4804 * Return Value:
4805 * none.
4806 *
4807-*/
4808static
4809VOID
4810s_vMgrLogStatus(
4811 IN PSMgmtObject pMgmt,
4812 IN WORD wStatus
4813 )
4814{
4815 switch( wStatus ){
4816 case WLAN_MGMT_STATUS_UNSPEC_FAILURE:
4817 DEVICE_PRT(MSG_LEVEL_NOTICE, KERN_INFO "Status code == Unspecified error.\n");
4818 break;
4819 case WLAN_MGMT_STATUS_CAPS_UNSUPPORTED:
4820 DEVICE_PRT(MSG_LEVEL_NOTICE, KERN_INFO "Status code == Can't support all requested capabilities.\n");
4821 break;
4822 case WLAN_MGMT_STATUS_REASSOC_NO_ASSOC:
4823 DEVICE_PRT(MSG_LEVEL_NOTICE, KERN_INFO "Status code == Reassoc denied, can't confirm original Association.\n");
4824 break;
4825 case WLAN_MGMT_STATUS_ASSOC_DENIED_UNSPEC:
4826 DEVICE_PRT(MSG_LEVEL_NOTICE, KERN_INFO "Status code == Assoc denied, undefine in spec\n");
4827 break;
4828 case WLAN_MGMT_STATUS_UNSUPPORTED_AUTHALG:
4829 DEVICE_PRT(MSG_LEVEL_NOTICE, KERN_INFO "Status code == Peer doesn't support authen algorithm.\n");
4830 break;
4831 case WLAN_MGMT_STATUS_RX_AUTH_NOSEQ:
4832 DEVICE_PRT(MSG_LEVEL_NOTICE, KERN_INFO "Status code == Authen frame received out of sequence.\n");
4833 break;
4834 case WLAN_MGMT_STATUS_CHALLENGE_FAIL:
4835 DEVICE_PRT(MSG_LEVEL_NOTICE, KERN_INFO "Status code == Authen rejected, challenge failure.\n");
4836 break;
4837 case WLAN_MGMT_STATUS_AUTH_TIMEOUT:
4838 DEVICE_PRT(MSG_LEVEL_NOTICE, KERN_INFO "Status code == Authen rejected, timeout waiting for next frame.\n");
4839 break;
4840 case WLAN_MGMT_STATUS_ASSOC_DENIED_BUSY:
4841 DEVICE_PRT(MSG_LEVEL_NOTICE, KERN_INFO "Status code == Assoc denied, AP too busy.\n");
4842 break;
4843 case WLAN_MGMT_STATUS_ASSOC_DENIED_RATES:
4844 DEVICE_PRT(MSG_LEVEL_NOTICE, KERN_INFO "Status code == Assoc denied, we haven't enough basic rates.\n");
4845 break;
4846 case WLAN_MGMT_STATUS_ASSOC_DENIED_SHORTPREAMBLE:
4847 DEVICE_PRT(MSG_LEVEL_NOTICE, KERN_INFO "Status code == Assoc denied, we do not support short preamble.\n");
4848 break;
4849 case WLAN_MGMT_STATUS_ASSOC_DENIED_PBCC:
4850 DEVICE_PRT(MSG_LEVEL_NOTICE, KERN_INFO "Status code == Assoc denied, we do not support PBCC.\n");
4851 break;
4852 case WLAN_MGMT_STATUS_ASSOC_DENIED_AGILITY:
4853 DEVICE_PRT(MSG_LEVEL_NOTICE, KERN_INFO "Status code == Assoc denied, we do not support channel agility.\n");
4854 break;
4855 default:
4856 DEVICE_PRT(MSG_LEVEL_NOTICE, KERN_INFO "Unknown status code %d.\n", wStatus);
4857 break;
4858 }
4859}
4860
4861
4862/*
4863 *
4864 * Description:
4865 * Add BSSID in PMKID Candidate list.
4866 *
4867 * Parameters:
4868 * In:
4869 * hDeviceContext - device structure point
4870 * pbyBSSID - BSSID address for adding
4871 * wRSNCap - BSS's RSN capability
4872 * Out:
4873 * none
4874 *
4875 * Return Value: none.
4876 *
4877-*/
4878BOOL
4879bAdd_PMKID_Candidate (
4880 IN HANDLE hDeviceContext,
4881 IN PBYTE pbyBSSID,
4882 IN PSRSNCapObject psRSNCapObj
4883 )
4884{
4885 PSDevice pDevice = (PSDevice)hDeviceContext;
4886 PPMKID_CANDIDATE pCandidateList;
4887 UINT ii = 0;
4888
4889 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"bAdd_PMKID_Candidate START: (%d)\n", (int)pDevice->gsPMKIDCandidate.NumCandidates);
4890
4891 if ((pDevice == NULL) || (pbyBSSID == NULL) || (psRSNCapObj == NULL))
4892 return FALSE;
4893
4894 if (pDevice->gsPMKIDCandidate.NumCandidates >= MAX_PMKIDLIST)
4895 return FALSE;
4896
4897
4898
4899 // Update Old Candidate
4900 for (ii = 0; ii < pDevice->gsPMKIDCandidate.NumCandidates; ii++) {
4901 pCandidateList = &pDevice->gsPMKIDCandidate.CandidateList[ii];
4902 if (MEMEqualMemory(pCandidateList->BSSID, pbyBSSID, U_ETHER_ADDR_LEN)) {
4903 if ((psRSNCapObj->bRSNCapExist == TRUE) && (psRSNCapObj->wRSNCap & BIT0)) {
4904 pCandidateList->Flags |= NDIS_802_11_PMKID_CANDIDATE_PREAUTH_ENABLED;
4905 } else {
4906 pCandidateList->Flags &= ~(NDIS_802_11_PMKID_CANDIDATE_PREAUTH_ENABLED);
4907 }
4908 return TRUE;
4909 }
4910 }
4911
4912 // New Candidate
4913 pCandidateList = &pDevice->gsPMKIDCandidate.CandidateList[pDevice->gsPMKIDCandidate.NumCandidates];
4914 if ((psRSNCapObj->bRSNCapExist == TRUE) && (psRSNCapObj->wRSNCap & BIT0)) {
4915 pCandidateList->Flags |= NDIS_802_11_PMKID_CANDIDATE_PREAUTH_ENABLED;
4916 } else {
4917 pCandidateList->Flags &= ~(NDIS_802_11_PMKID_CANDIDATE_PREAUTH_ENABLED);
4918 }
4919 MEMvCopy(pCandidateList->BSSID, pbyBSSID, U_ETHER_ADDR_LEN);
4920 pDevice->gsPMKIDCandidate.NumCandidates++;
4921 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"NumCandidates:%d\n", (int)pDevice->gsPMKIDCandidate.NumCandidates);
4922 return TRUE;
4923}
4924
4925/*
4926 *
4927 * Description:
4928 * Flush PMKID Candidate list.
4929 *
4930 * Parameters:
4931 * In:
4932 * hDeviceContext - device structure point
4933 * Out:
4934 * none
4935 *
4936 * Return Value: none.
4937 *
4938-*/
4939VOID
4940vFlush_PMKID_Candidate (
4941 IN HANDLE hDeviceContext
4942 )
4943{
4944 PSDevice pDevice = (PSDevice)hDeviceContext;
4945
4946 if (pDevice == NULL)
4947 return;
4948
4949 ZERO_MEMORY(&pDevice->gsPMKIDCandidate, sizeof(SPMKIDCandidateEvent));
4950}
4951
4952static BOOL
4953s_bCipherMatch (
4954 IN PKnownBSS pBSSNode,
4955 IN NDIS_802_11_ENCRYPTION_STATUS EncStatus,
4956 OUT PBYTE pbyCCSPK,
4957 OUT PBYTE pbyCCSGK
4958 )
4959{
4960 BYTE byMulticastCipher = KEY_CTL_INVALID;
4961 BYTE byCipherMask = 0x00;
4962 int i;
4963
4964 if (pBSSNode == NULL)
4965 return FALSE;
4966
4967 // check cap. of BSS
4968
4969 if ((WLAN_GET_CAP_INFO_PRIVACY(pBSSNode->wCapInfo) != 0) &&
4970 (EncStatus == Ndis802_11Encryption1Enabled)) {
4971 // default is WEP only
4972 byMulticastCipher = KEY_CTL_WEP;
4973 }
4974
4975 if ((WLAN_GET_CAP_INFO_PRIVACY(pBSSNode->wCapInfo) != 0) &&
4976 (pBSSNode->bWPA2Valid == TRUE) &&
4977 ((EncStatus == Ndis802_11Encryption3Enabled)||(EncStatus == Ndis802_11Encryption2Enabled))) {
4978
4979 //WPA2
4980 // check Group Key Cipher
4981 if ((pBSSNode->byCSSGK == WLAN_11i_CSS_WEP40) ||
4982 (pBSSNode->byCSSGK == WLAN_11i_CSS_WEP104)) {
4983 byMulticastCipher = KEY_CTL_WEP;
4984 } else if (pBSSNode->byCSSGK == WLAN_11i_CSS_TKIP) {
4985 byMulticastCipher = KEY_CTL_TKIP;
4986 } else if (pBSSNode->byCSSGK == WLAN_11i_CSS_CCMP) {
4987 byMulticastCipher = KEY_CTL_CCMP;
4988 } else {
4989 byMulticastCipher = KEY_CTL_INVALID;
4990 }
4991
4992 // check Pairwise Key Cipher
4993 for(i=0;i<pBSSNode->wCSSPKCount;i++) {
4994 if ((pBSSNode->abyCSSPK[i] == WLAN_11i_CSS_WEP40) ||
4995 (pBSSNode->abyCSSPK[i] == WLAN_11i_CSS_WEP104)) {
4996 // this should not happen as defined 802.11i
4997 byCipherMask |= 0x01;
4998 } else if (pBSSNode->abyCSSPK[i] == WLAN_11i_CSS_TKIP) {
4999 byCipherMask |= 0x02;
5000 } else if (pBSSNode->abyCSSPK[i] == WLAN_11i_CSS_CCMP) {
5001 byCipherMask |= 0x04;
5002 } else if (pBSSNode->abyCSSPK[i] == WLAN_11i_CSS_USE_GROUP) {
5003 // use group key only ignore all others
5004 byCipherMask = 0;
5005 i = pBSSNode->wCSSPKCount;
5006 }
5007 }
5008 } else if ((WLAN_GET_CAP_INFO_PRIVACY(pBSSNode->wCapInfo) != 0) &&
5009 (pBSSNode->bWPAValid == TRUE) &&
5010 ((EncStatus == Ndis802_11Encryption3Enabled)||(EncStatus == Ndis802_11Encryption2Enabled))) {
5011
5012 //WPA
5013 // check Group Key Cipher
5014 if ((pBSSNode->byGKType == WPA_WEP40) ||
5015 (pBSSNode->byGKType == WPA_WEP104)) {
5016 byMulticastCipher = KEY_CTL_WEP;
5017 } else if (pBSSNode->byGKType == WPA_TKIP) {
5018 byMulticastCipher = KEY_CTL_TKIP;
5019 } else if (pBSSNode->byGKType == WPA_AESCCMP) {
5020 byMulticastCipher = KEY_CTL_CCMP;
5021 } else {
5022 byMulticastCipher = KEY_CTL_INVALID;
5023 }
5024
5025 // check Pairwise Key Cipher
5026 for(i=0;i<pBSSNode->wPKCount;i++) {
5027 if (pBSSNode->abyPKType[i] == WPA_TKIP) {
5028 byCipherMask |= 0x02;
5029 } else if (pBSSNode->abyPKType[i] == WPA_AESCCMP) {
5030 byCipherMask |= 0x04;
5031 } else if (pBSSNode->abyPKType[i] == WPA_NONE) {
5032 // use group key only ignore all others
5033 byCipherMask = 0;
5034 i = pBSSNode->wPKCount;
5035 }
5036 }
5037 }
5038
5039 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"%d, %d, %d, %d, EncStatus:%d\n",
5040 byMulticastCipher, byCipherMask, pBSSNode->bWPAValid, pBSSNode->bWPA2Valid, EncStatus);
5041
5042 // mask our cap. with BSS
5043 if (EncStatus == Ndis802_11Encryption1Enabled) {
5044 // For supporting Cisco migration mode, don't care pairwise key cipher
5045 if ((byMulticastCipher == KEY_CTL_WEP) &&
5046 (byCipherMask == 0)) {
5047 *pbyCCSGK = KEY_CTL_WEP;
5048 *pbyCCSPK = KEY_CTL_NONE;
5049 return TRUE;
5050 } else {
5051 return FALSE;
5052 }
5053
5054 } else if (EncStatus == Ndis802_11Encryption2Enabled) {
5055 if ((byMulticastCipher == KEY_CTL_TKIP) &&
5056 (byCipherMask == 0)) {
5057 *pbyCCSGK = KEY_CTL_TKIP;
5058 *pbyCCSPK = KEY_CTL_NONE;
5059 return TRUE;
5060 } else if ((byMulticastCipher == KEY_CTL_WEP) &&
5061 ((byCipherMask & 0x02) != 0)) {
5062 *pbyCCSGK = KEY_CTL_WEP;
5063 *pbyCCSPK = KEY_CTL_TKIP;
5064 return TRUE;
5065 } else if ((byMulticastCipher == KEY_CTL_TKIP) &&
5066 ((byCipherMask & 0x02) != 0)) {
5067 *pbyCCSGK = KEY_CTL_TKIP;
5068 *pbyCCSPK = KEY_CTL_TKIP;
5069 return TRUE;
5070 } else {
5071 return FALSE;
5072 }
5073 } else if (EncStatus == Ndis802_11Encryption3Enabled) {
5074 if ((byMulticastCipher == KEY_CTL_CCMP) &&
5075 (byCipherMask == 0)) {
5076 // When CCMP is enable, "Use group cipher suite" shall not be a valid option.
5077 return FALSE;
5078 } else if ((byMulticastCipher == KEY_CTL_WEP) &&
5079 ((byCipherMask & 0x04) != 0)) {
5080 *pbyCCSGK = KEY_CTL_WEP;
5081 *pbyCCSPK = KEY_CTL_CCMP;
5082 return TRUE;
5083 } else if ((byMulticastCipher == KEY_CTL_TKIP) &&
5084 ((byCipherMask & 0x04) != 0)) {
5085 *pbyCCSGK = KEY_CTL_TKIP;
5086 *pbyCCSPK = KEY_CTL_CCMP;
5087 return TRUE;
5088 } else if ((byMulticastCipher == KEY_CTL_CCMP) &&
5089 ((byCipherMask & 0x04) != 0)) {
5090 *pbyCCSGK = KEY_CTL_CCMP;
5091 *pbyCCSPK = KEY_CTL_CCMP;
5092 return TRUE;
5093 } else {
5094 return FALSE;
5095 }
5096 }
5097 return TRUE;
5098}
5099
5100
diff --git a/drivers/staging/vt6655/wmgr.h b/drivers/staging/vt6655/wmgr.h
new file mode 100644
index 000000000000..5b526ab2d912
--- /dev/null
+++ b/drivers/staging/vt6655/wmgr.h
@@ -0,0 +1,521 @@
1/*
2 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
3 * All rights reserved.
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 *
20 * File: wmgr.h
21 *
22 * Purpose:
23 *
24 * Author: lyndon chen
25 *
26 * Date: Jan 2, 2003
27 *
28 * Functions:
29 *
30 * Revision History:
31 *
32 */
33
34
35#ifndef __WMGR_H__
36#define __WMGR_H__
37
38#if !defined(__TTYPE_H__)
39#include "ttype.h"
40#endif
41#if !defined(__80211MGR_H__)
42#include "80211mgr.h"
43#endif
44#if !defined(__80211HDR_H__)
45#include "80211hdr.h"
46#endif
47#if !defined(__WCMD_H__)
48#include "wcmd.h"
49#endif
50#if !defined(__BSSDB_H__)
51#include "bssdb.h"
52#endif
53#if !defined(__CARD_H__)
54#include "card.h"
55#endif
56#if !defined(__WPA2_H__)
57#include "wpa2.h"
58#endif
59#if !defined(__VNTWIFI_H__)
60#include "vntwifi.h"
61#endif
62
63
64
65/*--------------------- Export Definitions -------------------------*/
66
67
68
69// Scan time
70#define PROBE_DELAY 100 // (us)
71#define SWITCH_CHANNEL_DELAY 200 // (us)
72#define WLAN_SCAN_MINITIME 25 // (ms)
73#define WLAN_SCAN_MAXTIME 100 // (ms)
74#define TRIVIAL_SYNC_DIFFERENCE 0 // (us)
75#define DEFAULT_IBSS_BI 100 // (ms)
76
77#define WCMD_ACTIVE_SCAN_TIME 50 //(ms)
78#define WCMD_PASSIVE_SCAN_TIME 100 //(ms)
79
80
81#define DEFAULT_MSDU_LIFETIME 512 // ms
82#define DEFAULT_MSDU_LIFETIME_RES_64us 8000 // 64us
83
84#define DEFAULT_MGN_LIFETIME 8 // ms
85#define DEFAULT_MGN_LIFETIME_RES_64us 125 // 64us
86
87#define MAKE_BEACON_RESERVED 10 //(us)
88
89
90#define TIM_MULTICAST_MASK 0x01
91#define TIM_BITMAPOFFSET_MASK 0xFE
92#define DEFAULT_DTIM_PERIOD 1
93
94#define AP_LONG_RETRY_LIMIT 4
95
96#define DEFAULT_IBSS_CHANNEL 6 //2.4G
97
98
99/*--------------------- Export Classes ----------------------------*/
100
101/*--------------------- Export Variables --------------------------*/
102
103/*--------------------- Export Types ------------------------------*/
104#define timer_expire(timer,next_tick) mod_timer(&timer, RUN_AT(next_tick))
105typedef void (*TimerFunction)(ULONG);
106
107
108//+++ NDIS related
109
110typedef UCHAR NDIS_802_11_MAC_ADDRESS[6];
111typedef struct _NDIS_802_11_AI_REQFI
112{
113 USHORT Capabilities;
114 USHORT ListenInterval;
115 NDIS_802_11_MAC_ADDRESS CurrentAPAddress;
116} NDIS_802_11_AI_REQFI, *PNDIS_802_11_AI_REQFI;
117
118typedef struct _NDIS_802_11_AI_RESFI
119{
120 USHORT Capabilities;
121 USHORT StatusCode;
122 USHORT AssociationId;
123} NDIS_802_11_AI_RESFI, *PNDIS_802_11_AI_RESFI;
124
125typedef struct _NDIS_802_11_ASSOCIATION_INFORMATION
126{
127 ULONG Length;
128 USHORT AvailableRequestFixedIEs;
129 NDIS_802_11_AI_REQFI RequestFixedIEs;
130 ULONG RequestIELength;
131 ULONG OffsetRequestIEs;
132 USHORT AvailableResponseFixedIEs;
133 NDIS_802_11_AI_RESFI ResponseFixedIEs;
134 ULONG ResponseIELength;
135 ULONG OffsetResponseIEs;
136} NDIS_802_11_ASSOCIATION_INFORMATION, *PNDIS_802_11_ASSOCIATION_INFORMATION;
137
138
139
140typedef struct tagSAssocInfo {
141 NDIS_802_11_ASSOCIATION_INFORMATION AssocInfo;
142 BYTE abyIEs[WLAN_BEACON_FR_MAXLEN+WLAN_BEACON_FR_MAXLEN];
143 // store ReqIEs set by OID_802_11_ASSOCIATION_INFORMATION
144 ULONG RequestIELength;
145 BYTE abyReqIEs[WLAN_BEACON_FR_MAXLEN];
146} SAssocInfo, DEF* PSAssocInfo;
147//---
148
149
150/*
151typedef enum tagWMAC_AUTHENTICATION_MODE {
152
153
154 WMAC_AUTH_OPEN,
155 WMAC_AUTH_SHAREKEY,
156 WMAC_AUTH_AUTO,
157 WMAC_AUTH_WPA,
158 WMAC_AUTH_WPAPSK,
159 WMAC_AUTH_WPANONE,
160 WMAC_AUTH_WPA2,
161 WMAC_AUTH_WPA2PSK,
162 WMAC_AUTH_MAX // Not a real mode, defined as upper bound
163
164
165} WMAC_AUTHENTICATION_MODE, *PWMAC_AUTHENTICATION_MODE;
166*/
167
168
169// Pre-configured Mode (from XP)
170/*
171typedef enum tagWMAC_CONFIG_MODE {
172 WMAC_CONFIG_ESS_STA,
173 WMAC_CONFIG_IBSS_STA,
174 WMAC_CONFIG_AUTO,
175 WMAC_CONFIG_AP
176
177} WMAC_CONFIG_MODE, *PWMAC_CONFIG_MODE;
178*/
179
180typedef enum tagWMAC_SCAN_TYPE {
181
182 WMAC_SCAN_ACTIVE,
183 WMAC_SCAN_PASSIVE,
184 WMAC_SCAN_HYBRID
185
186} WMAC_SCAN_TYPE, *PWMAC_SCAN_TYPE;
187
188
189typedef enum tagWMAC_SCAN_STATE {
190
191 WMAC_NO_SCANNING,
192 WMAC_IS_SCANNING,
193 WMAC_IS_PROBEPENDING
194
195} WMAC_SCAN_STATE, *PWMAC_SCAN_STATE;
196
197
198
199// Notes:
200// Basic Service Set state explained as following:
201// WMAC_STATE_IDLE : no BSS is selected (Adhoc or Infra)
202// WMAC_STATE_STARTED : no BSS is selected, start own IBSS (Adhoc only)
203// WMAC_STATE_JOINTED : BSS is selected and synchronized (Adhoc or Infra)
204// WMAC_STATE_AUTHPENDING : Authentication pending (Infra)
205// WMAC_STATE_AUTH : Authenticated (Infra)
206// WMAC_STATE_ASSOCPENDING : Association pending (Infra)
207// WMAC_STATE_ASSOC : Associated (Infra)
208
209typedef enum tagWMAC_BSS_STATE {
210
211 WMAC_STATE_IDLE,
212 WMAC_STATE_STARTED,
213 WMAC_STATE_JOINTED,
214 WMAC_STATE_AUTHPENDING,
215 WMAC_STATE_AUTH,
216 WMAC_STATE_ASSOCPENDING,
217 WMAC_STATE_ASSOC
218
219} WMAC_BSS_STATE, *PWMAC_BSS_STATE;
220
221// WMAC selected running mode
222typedef enum tagWMAC_CURRENT_MODE {
223
224 WMAC_MODE_STANDBY,
225 WMAC_MODE_ESS_STA,
226 WMAC_MODE_IBSS_STA,
227 WMAC_MODE_ESS_AP
228
229} WMAC_CURRENT_MODE, *PWMAC_CURRENT_MODE;
230
231/*
232typedef enum tagWMAC_POWER_MODE {
233
234 WMAC_POWER_CAM,
235 WMAC_POWER_FAST,
236 WMAC_POWER_MAX
237
238} WMAC_POWER_MODE, *PWMAC_POWER_MODE;
239*/
240
241
242// Tx Managment Packet descriptor
243typedef struct tagSTxMgmtPacket {
244
245 PUWLAN_80211HDR p80211Header;
246 UINT cbMPDULen;
247 UINT cbPayloadLen;
248
249} STxMgmtPacket, DEF* PSTxMgmtPacket;
250
251
252// Rx Managment Packet descriptor
253typedef struct tagSRxMgmtPacket {
254
255 PUWLAN_80211HDR p80211Header;
256 QWORD qwLocalTSF;
257 UINT cbMPDULen;
258 UINT cbPayloadLen;
259 UINT uRSSI;
260 BYTE bySQ;
261 BYTE byRxRate;
262 BYTE byRxChannel;
263
264} SRxMgmtPacket, DEF* PSRxMgmtPacket;
265
266
267
268typedef struct tagSMgmtObject
269{
270
271 PVOID pAdapter;
272 // MAC address
273 BYTE abyMACAddr[WLAN_ADDR_LEN];
274
275 // Configuration Mode
276 WMAC_CONFIG_MODE eConfigMode; // MAC pre-configed mode
277 CARD_PHY_TYPE eCurrentPHYMode;
278 CARD_PHY_TYPE eConfigPHYMode;
279
280
281 // Operation state variables
282 WMAC_CURRENT_MODE eCurrMode; // MAC current connection mode
283 WMAC_BSS_STATE eCurrState; // MAC current BSS state
284
285 PKnownBSS pCurrBSS;
286 BYTE byCSSGK;
287 BYTE byCSSPK;
288
289// BYTE abyNewSuppRates[WLAN_IEHDR_LEN + WLAN_RATES_MAXLEN];
290// BYTE abyNewExtSuppRates[WLAN_IEHDR_LEN + WLAN_RATES_MAXLEN];
291
292 // Current state vars
293 UINT uCurrChannel;
294 BYTE abyCurrSuppRates[WLAN_IEHDR_LEN + WLAN_RATES_MAXLEN + 1];
295 BYTE abyCurrExtSuppRates[WLAN_IEHDR_LEN + WLAN_RATES_MAXLEN + 1];
296 BYTE abyCurrSSID[WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1];
297 BYTE abyCurrBSSID[WLAN_BSSID_LEN];
298 WORD wCurrCapInfo;
299 WORD wCurrAID;
300 WORD wCurrATIMWindow;
301 WORD wCurrBeaconPeriod;
302 BOOL bIsDS;
303 BYTE byERPContext;
304
305 CMD_STATE eCommandState;
306 UINT uScanChannel;
307
308 // Desire joinning BSS vars
309 BYTE abyDesireSSID[WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1];
310 BYTE abyDesireBSSID[WLAN_BSSID_LEN];
311
312 // Adhoc or AP configuration vars
313 //BYTE abyAdHocSSID[WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1];
314 WORD wIBSSBeaconPeriod;
315 WORD wIBSSATIMWindow;
316 UINT uIBSSChannel;
317 BYTE abyIBSSSuppRates[WLAN_IEHDR_LEN + WLAN_RATES_MAXLEN + 1];
318 BYTE byAPBBType;
319 BYTE abyWPAIE[MAX_WPA_IE_LEN];
320 WORD wWPAIELen;
321
322 UINT uAssocCount;
323 BOOL bMoreData;
324
325 // Scan state vars
326 WMAC_SCAN_STATE eScanState;
327 WMAC_SCAN_TYPE eScanType;
328 UINT uScanStartCh;
329 UINT uScanEndCh;
330 WORD wScanSteps;
331 UINT uScanBSSType;
332 // Desire scannig vars
333 BYTE abyScanSSID[WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1];
334 BYTE abyScanBSSID[WLAN_BSSID_LEN];
335
336 // Privacy
337 WMAC_AUTHENTICATION_MODE eAuthenMode;
338 WMAC_ENCRYPTION_MODE eEncryptionMode;
339 BOOL bShareKeyAlgorithm;
340 BYTE abyChallenge[WLAN_CHALLENGE_LEN];
341 BOOL bPrivacyInvoked;
342
343 // Received beacon state vars
344 BOOL bInTIM;
345 BOOL bMulticastTIM;
346 BYTE byDTIMCount;
347 BYTE byDTIMPeriod;
348
349 // Power saving state vars
350 WMAC_POWER_MODE ePSMode;
351 WORD wListenInterval;
352 WORD wCountToWakeUp;
353 BOOL bInTIMWake;
354 PBYTE pbyPSPacketPool;
355 BYTE byPSPacketPool[sizeof(STxMgmtPacket) + WLAN_NULLDATA_FR_MAXLEN];
356 BOOL bRxBeaconInTBTTWake;
357 BYTE abyPSTxMap[MAX_NODE_NUM + 1];
358
359 // managment command related
360 UINT uCmdBusy;
361 UINT uCmdHostAPBusy;
362
363 // managment packet pool
364 PBYTE pbyMgmtPacketPool;
365 BYTE byMgmtPacketPool[sizeof(STxMgmtPacket) + WLAN_A3FR_MAXLEN];
366
367
368 // One second callback timer
369 struct timer_list sTimerSecondCallback;
370
371 // Temporarily Rx Mgmt Packet Descriptor
372 SRxMgmtPacket sRxPacket;
373
374 // link list of known bss's (scan results)
375 KnownBSS sBSSList[MAX_BSS_NUM];
376
377
378
379 // table list of known node
380 // sNodeDBList[0] is reserved for AP under Infra mode
381 // sNodeDBList[0] is reserved for Multicast under adhoc/AP mode
382 KnownNodeDB sNodeDBTable[MAX_NODE_NUM + 1];
383
384
385
386 // WPA2 PMKID Cache
387 SPMKIDCache gsPMKIDCache;
388 BOOL bRoaming;
389
390 // rate fall back vars
391
392
393
394 // associate info
395 SAssocInfo sAssocInfo;
396
397
398 // for 802.11h
399 BOOL b11hEnable;
400 BOOL bSwitchChannel;
401 BYTE byNewChannel;
402 PWLAN_IE_MEASURE_REP pCurrMeasureEIDRep;
403 UINT uLengthOfRepEIDs;
404 BYTE abyCurrentMSRReq[sizeof(STxMgmtPacket) + WLAN_A3FR_MAXLEN];
405 BYTE abyCurrentMSRRep[sizeof(STxMgmtPacket) + WLAN_A3FR_MAXLEN];
406 BYTE abyIECountry[WLAN_A3FR_MAXLEN];
407 BYTE abyIBSSDFSOwner[6];
408 BYTE byIBSSDFSRecovery;
409
410 struct sk_buff skb;
411
412} SMgmtObject, DEF *PSMgmtObject;
413
414
415/*--------------------- Export Macros ------------------------------*/
416
417
418/*--------------------- Export Functions --------------------------*/
419
420
421void
422vMgrObjectInit(
423 IN HANDLE hDeviceContext
424 );
425
426void
427vMgrTimerInit(
428 IN HANDLE hDeviceContext
429 );
430
431VOID
432vMgrObjectReset(
433 IN HANDLE hDeviceContext
434 );
435
436void
437vMgrAssocBeginSta(
438 IN HANDLE hDeviceContext,
439 IN PSMgmtObject pMgmt,
440 OUT PCMD_STATUS pStatus
441 );
442
443VOID
444vMgrReAssocBeginSta(
445 IN HANDLE hDeviceContext,
446 IN PSMgmtObject pMgmt,
447 OUT PCMD_STATUS pStatus
448 );
449
450VOID
451vMgrDisassocBeginSta(
452 IN HANDLE hDeviceContext,
453 IN PSMgmtObject pMgmt,
454 IN PBYTE abyDestAddress,
455 IN WORD wReason,
456 OUT PCMD_STATUS pStatus
457 );
458
459VOID
460vMgrAuthenBeginSta(
461 IN HANDLE hDeviceContext,
462 IN PSMgmtObject pMgmt,
463 OUT PCMD_STATUS pStatus
464 );
465
466VOID
467vMgrCreateOwnIBSS(
468 IN HANDLE hDeviceContext,
469 OUT PCMD_STATUS pStatus
470 );
471
472VOID
473vMgrJoinBSSBegin(
474 IN HANDLE hDeviceContext,
475 OUT PCMD_STATUS pStatus
476 );
477
478VOID
479vMgrRxManagePacket(
480 IN HANDLE hDeviceContext,
481 IN PSMgmtObject pMgmt,
482 IN PSRxMgmtPacket pRxPacket
483 );
484
485/*
486VOID
487vMgrScanBegin(
488 IN HANDLE hDeviceContext,
489 OUT PCMD_STATUS pStatus
490 );
491*/
492
493VOID
494vMgrDeAuthenBeginSta(
495 IN HANDLE hDeviceContext,
496 IN PSMgmtObject pMgmt,
497 IN PBYTE abyDestAddress,
498 IN WORD wReason,
499 OUT PCMD_STATUS pStatus
500 );
501
502BOOL
503bMgrPrepareBeaconToSend(
504 IN HANDLE hDeviceContext,
505 IN PSMgmtObject pMgmt
506 );
507
508
509BOOL
510bAdd_PMKID_Candidate (
511 IN HANDLE hDeviceContext,
512 IN PBYTE pbyBSSID,
513 IN PSRSNCapObject psRSNCapObj
514 );
515
516VOID
517vFlush_PMKID_Candidate (
518 IN HANDLE hDeviceContext
519 );
520
521#endif // __WMGR_H__
diff --git a/drivers/staging/vt6655/wpa.c b/drivers/staging/vt6655/wpa.c
new file mode 100644
index 000000000000..8b4e7fc31efa
--- /dev/null
+++ b/drivers/staging/vt6655/wpa.c
@@ -0,0 +1,339 @@
1/*
2 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
3 * All rights reserved.
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 *
20 * File: wpa.c
21 *
22 * Purpose: Handles the Basic Service Set & Node Database functions
23 *
24 * Functions:
25 * WPA_ParseRSN - Parse RSN IE.
26 *
27 * Revision History:
28 *
29 * Author: Kyle Hsu
30 *
31 * Date: July 14, 2003
32 *
33 */
34
35
36#if !defined(__TTYPE_H__)
37#include "ttype.h"
38#endif
39#if !defined(__UMEM_H__)
40#include "umem.h"
41#endif
42#if !defined(__TMACRO_H__)
43#include "tmacro.h"
44#endif
45#if !defined(__TETHER_H__)
46#include "tether.h"
47#endif
48#if !defined(__DEVICE_H__)
49#include "device.h"
50#endif
51#if !defined(__80211HDR_H__)
52#include "80211hdr.h"
53#endif
54#if !defined(__BSSDB_H__)
55#include "bssdb.h"
56#endif
57#if !defined(__WMGR_H__)
58#include "wmgr.h"
59#endif
60#if !defined(__WPA_H__)
61#include "wpa.h"
62#endif
63#if !defined(__80211MGR_H__)
64#include "80211mgr.h"
65#endif
66
67
68/*--------------------- Static Variables --------------------------*/
69static int msglevel =MSG_LEVEL_INFO;
70
71const BYTE abyOUI00[4] = { 0x00, 0x50, 0xf2, 0x00 };
72const BYTE abyOUI01[4] = { 0x00, 0x50, 0xf2, 0x01 };
73const BYTE abyOUI02[4] = { 0x00, 0x50, 0xf2, 0x02 };
74const BYTE abyOUI03[4] = { 0x00, 0x50, 0xf2, 0x03 };
75const BYTE abyOUI04[4] = { 0x00, 0x50, 0xf2, 0x04 };
76const BYTE abyOUI05[4] = { 0x00, 0x50, 0xf2, 0x05 };
77
78
79/*+
80 *
81 * Description:
82 * Clear RSN information in BSSList.
83 *
84 * Parameters:
85 * In:
86 * pBSSList - BSS list.
87 * Out:
88 * none
89 *
90 * Return Value: none.
91 *
92-*/
93
94VOID
95WPA_ClearRSN (
96 IN PKnownBSS pBSSList
97 )
98{
99 int ii;
100 pBSSList->byGKType = WPA_TKIP;
101 for (ii=0; ii < 4; ii ++)
102 pBSSList->abyPKType[ii] = WPA_TKIP;
103 pBSSList->wPKCount = 0;
104 for (ii=0; ii < 4; ii ++)
105 pBSSList->abyAuthType[ii] = WPA_AUTH_IEEE802_1X;
106 pBSSList->wAuthCount = 0;
107 pBSSList->byDefaultK_as_PK = 0;
108 pBSSList->byReplayIdx = 0;
109 pBSSList->sRSNCapObj.bRSNCapExist = FALSE;
110 pBSSList->sRSNCapObj.wRSNCap = 0;
111 pBSSList->bWPAValid = FALSE;
112}
113
114
115/*+
116 *
117 * Description:
118 * Parse RSN IE.
119 *
120 * Parameters:
121 * In:
122 * pBSSList - BSS list.
123 * pRSN - Pointer to the RSN IE.
124 * Out:
125 * none
126 *
127 * Return Value: none.
128 *
129-*/
130VOID
131WPA_ParseRSN (
132 IN PKnownBSS pBSSList,
133 IN PWLAN_IE_RSN_EXT pRSN
134 )
135{
136 PWLAN_IE_RSN_AUTH pIE_RSN_Auth = NULL;
137 int i, j, m, n = 0;
138 PBYTE pbyCaps;
139
140 WPA_ClearRSN(pBSSList);
141
142 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"WPA_ParseRSN: [%d]\n", pRSN->len);
143
144 // information element header makes sense
145 if ((pRSN->len >= 6) // oui1(4)+ver(2)
146 && (pRSN->byElementID == WLAN_EID_RSN_WPA) && MEMEqualMemory(pRSN->abyOUI, abyOUI01, 4)
147 && (pRSN->wVersion == 1)) {
148
149 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Legal RSN\n");
150 // update each variable if pRSN is long enough to contain the variable
151 if (pRSN->len >= 10) //oui1(4)+ver(2)+GKSuite(4)
152 {
153 if (MEMEqualMemory(pRSN->abyMulticast, abyOUI01, 4))
154 pBSSList->byGKType = WPA_WEP40;
155 else if (MEMEqualMemory(pRSN->abyMulticast, abyOUI02, 4))
156 pBSSList->byGKType = WPA_TKIP;
157 else if (MEMEqualMemory(pRSN->abyMulticast, abyOUI03, 4))
158 pBSSList->byGKType = WPA_AESWRAP;
159 else if (MEMEqualMemory(pRSN->abyMulticast, abyOUI04, 4))
160 pBSSList->byGKType = WPA_AESCCMP;
161 else if (MEMEqualMemory(pRSN->abyMulticast, abyOUI05, 4))
162 pBSSList->byGKType = WPA_WEP104;
163 else
164 // any vendor checks here
165 pBSSList->byGKType = WPA_NONE;
166
167 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"byGKType: %x\n", pBSSList->byGKType);
168 }
169
170 if (pRSN->len >= 12) //oui1(4)+ver(2)+GKS(4)+PKSCnt(2)
171 {
172 j = 0;
173 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"wPKCount: %d, sizeof(pBSSList->abyPKType): %d\n", pRSN->wPKCount, sizeof(pBSSList->abyPKType));
174 for(i = 0; (i < pRSN->wPKCount) && (j < sizeof(pBSSList->abyPKType)/sizeof(BYTE)); i++) {
175 if(pRSN->len >= 12+i*4+4) { //oui1(4)+ver(2)+GKS(4)+PKSCnt(2)+PKS(4*i)
176 if (MEMEqualMemory(pRSN->PKSList[i].abyOUI, abyOUI00, 4))
177 pBSSList->abyPKType[j++] = WPA_NONE;
178 else if (MEMEqualMemory(pRSN->PKSList[i].abyOUI, abyOUI02, 4))
179 pBSSList->abyPKType[j++] = WPA_TKIP;
180 else if (MEMEqualMemory(pRSN->PKSList[i].abyOUI, abyOUI03, 4))
181 pBSSList->abyPKType[j++] = WPA_AESWRAP;
182 else if (MEMEqualMemory(pRSN->PKSList[i].abyOUI, abyOUI04, 4))
183 pBSSList->abyPKType[j++] = WPA_AESCCMP;
184 else
185 // any vendor checks here
186 ;
187 }
188 else
189 break;
190 //DBG_PRN_GRP14(("abyPKType[%d]: %X\n", j-1, pBSSList->abyPKType[j-1]));
191 } //for
192 pBSSList->wPKCount = (WORD)j;
193 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"wPKCount: %d\n", pBSSList->wPKCount);
194 }
195
196 m = pRSN->wPKCount;
197 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"m: %d\n", m);
198 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"14+m*4: %d\n", 14+m*4);
199
200 if (pRSN->len >= 14+m*4) { //oui1(4)+ver(2)+GKS(4)+PKSCnt(2)+PKS(4*m)+AKC(2)
201 // overlay IE_RSN_Auth structure into correct place
202 pIE_RSN_Auth = (PWLAN_IE_RSN_AUTH) pRSN->PKSList[m].abyOUI;
203 j = 0;
204 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"wAuthCount: %d, sizeof(pBSSList->abyAuthType): %d\n",
205 pIE_RSN_Auth->wAuthCount, sizeof(pBSSList->abyAuthType));
206 for(i = 0; (i < pIE_RSN_Auth->wAuthCount) && (j < sizeof(pBSSList->abyAuthType)/sizeof(BYTE)); i++) {
207 if(pRSN->len >= 14+4+(m+i)*4) { //oui1(4)+ver(2)+GKS(4)+PKSCnt(2)+PKS(4*m)+AKC(2)+AKS(4*i)
208 if (MEMEqualMemory(pIE_RSN_Auth->AuthKSList[i].abyOUI, abyOUI01, 4))
209 pBSSList->abyAuthType[j++] = WPA_AUTH_IEEE802_1X;
210 else if (MEMEqualMemory(pIE_RSN_Auth->AuthKSList[i].abyOUI, abyOUI02, 4))
211 pBSSList->abyAuthType[j++] = WPA_AUTH_PSK;
212 else
213 // any vendor checks here
214 ;
215 }
216 else
217 break;
218 //DBG_PRN_GRP14(("abyAuthType[%d]: %X\n", j-1, pBSSList->abyAuthType[j-1]));
219 }
220 if(j > 0)
221 pBSSList->wAuthCount = (WORD)j;
222 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"wAuthCount: %d\n", pBSSList->wAuthCount);
223 }
224
225 if (pIE_RSN_Auth != NULL) {
226
227 n = pIE_RSN_Auth->wAuthCount;
228
229 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"n: %d\n", n);
230 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"14+4+(m+n)*4: %d\n", 14+4+(m+n)*4);
231
232 if(pRSN->len+2 >= 14+4+(m+n)*4) { //oui1(4)+ver(2)+GKS(4)+PKSCnt(2)+PKS(4*m)+AKC(2)+AKS(4*n)+Cap(2)
233 pbyCaps = (PBYTE)pIE_RSN_Auth->AuthKSList[n].abyOUI;
234 pBSSList->byDefaultK_as_PK = (*pbyCaps) & WPA_GROUPFLAG;
235 pBSSList->byReplayIdx = 2 << ((*pbyCaps >> WPA_REPLAYBITSSHIFT) & WPA_REPLAYBITS);
236 pBSSList->sRSNCapObj.bRSNCapExist = TRUE;
237 pBSSList->sRSNCapObj.wRSNCap = *(PWORD)pbyCaps;
238 //DBG_PRN_GRP14(("pbyCaps: %X\n", *pbyCaps));
239 //DBG_PRN_GRP14(("byDefaultK_as_PK: %X\n", pBSSList->byDefaultK_as_PK));
240 //DBG_PRN_GRP14(("byReplayIdx: %X\n", pBSSList->byReplayIdx));
241 }
242 }
243 pBSSList->bWPAValid = TRUE;
244 }
245}
246
247/*+
248 *
249 * Description:
250 * Search RSN information in BSSList.
251 *
252 * Parameters:
253 * In:
254 * byCmd - Search type
255 * byEncrypt- Encrcypt Type
256 * pBSSList - BSS list
257 * Out:
258 * none
259 *
260 * Return Value: none.
261 *
262-*/
263BOOL
264WPA_SearchRSN (
265 BYTE byCmd,
266 BYTE byEncrypt,
267 IN PKnownBSS pBSSList
268 )
269{
270 int ii;
271 BYTE byPKType = WPA_NONE;
272
273 if (pBSSList->bWPAValid == FALSE)
274 return FALSE;
275
276 switch(byCmd) {
277 case 0:
278
279 if (byEncrypt != pBSSList->byGKType)
280 return FALSE;
281
282 if (pBSSList->wPKCount > 0) {
283 for (ii = 0; ii < pBSSList->wPKCount; ii ++) {
284 if (pBSSList->abyPKType[ii] == WPA_AESCCMP)
285 byPKType = WPA_AESCCMP;
286 else if ((pBSSList->abyPKType[ii] == WPA_TKIP) && (byPKType != WPA_AESCCMP))
287 byPKType = WPA_TKIP;
288 else if ((pBSSList->abyPKType[ii] == WPA_WEP40) && (byPKType != WPA_AESCCMP) && (byPKType != WPA_TKIP))
289 byPKType = WPA_WEP40;
290 else if ((pBSSList->abyPKType[ii] == WPA_WEP104) && (byPKType != WPA_AESCCMP) && (byPKType != WPA_TKIP))
291 byPKType = WPA_WEP104;
292 }
293 if (byEncrypt != byPKType)
294 return FALSE;
295 }
296 return TRUE;
297// if (pBSSList->wAuthCount > 0)
298// for (ii=0; ii < pBSSList->wAuthCount; ii ++)
299// if (byAuth == pBSSList->abyAuthType[ii])
300// break;
301 break;
302
303 default:
304 break;
305 }
306 return FALSE;
307}
308
309/*+
310 *
311 * Description:
312 * Check if RSN IE makes sense.
313 *
314 * Parameters:
315 * In:
316 * pRSN - Pointer to the RSN IE.
317 * Out:
318 * none
319 *
320 * Return Value: none.
321 *
322-*/
323BOOL
324WPAb_Is_RSN (
325 IN PWLAN_IE_RSN_EXT pRSN
326 )
327{
328 if (pRSN == NULL)
329 return FALSE;
330
331 if ((pRSN->len >= 6) && // oui1(4)+ver(2)
332 (pRSN->byElementID == WLAN_EID_RSN_WPA) && MEMEqualMemory(pRSN->abyOUI, abyOUI01, 4) &&
333 (pRSN->wVersion == 1)) {
334 return TRUE;
335 }
336 else
337 return FALSE;
338}
339
diff --git a/drivers/staging/vt6655/wpa.h b/drivers/staging/vt6655/wpa.h
new file mode 100644
index 000000000000..8000a37c6fc3
--- /dev/null
+++ b/drivers/staging/vt6655/wpa.h
@@ -0,0 +1,98 @@
1/*
2 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
3 * All rights reserved.
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 *
20 * File: wpa.h
21 *
22 * Purpose: Defines the macros, types, and functions for dealing
23 * with WPA informations.
24 *
25 * Author: Kyle Hsu
26 *
27 * Date: Jul 14, 2003
28 *
29 */
30
31#ifndef __WPA_H__
32#define __WPA_H__
33
34
35#if !defined(__TTYPE_H__)
36#include "ttype.h"
37#endif
38#if !defined(__80211HDR_H__)
39#include "80211hdr.h"
40#endif
41
42
43/*--------------------- Export Definitions -------------------------*/
44
45#define WPA_NONE 0
46#define WPA_WEP40 1
47#define WPA_TKIP 2
48#define WPA_AESWRAP 3
49#define WPA_AESCCMP 4
50#define WPA_WEP104 5
51#define WPA_AUTH_IEEE802_1X 1
52#define WPA_AUTH_PSK 2
53
54#define WPA_GROUPFLAG 0x02
55#define WPA_REPLAYBITSSHIFT 2
56#define WPA_REPLAYBITS 0x03
57
58/*--------------------- Export Classes ----------------------------*/
59
60/*--------------------- Export Variables --------------------------*/
61
62/*--------------------- Export Types ------------------------------*/
63
64
65/*--------------------- Export Functions --------------------------*/
66#ifdef __cplusplus
67extern "C" { /* Assume C declarations for C++ */
68#endif /* __cplusplus */
69
70VOID
71WPA_ClearRSN(
72 IN PKnownBSS pBSSList
73 );
74
75VOID
76WPA_ParseRSN(
77 IN PKnownBSS pBSSList,
78 IN PWLAN_IE_RSN_EXT pRSN
79 );
80
81BOOL
82WPA_SearchRSN(
83 BYTE byCmd,
84 BYTE byEncrypt,
85 IN PKnownBSS pBSSList
86 );
87
88BOOL
89WPAb_Is_RSN(
90 IN PWLAN_IE_RSN_EXT pRSN
91 );
92
93#ifdef __cplusplus
94} /* End of extern "C" { */
95#endif /* __cplusplus */
96
97
98#endif // __WPA_H__
diff --git a/drivers/staging/vt6655/wpa2.c b/drivers/staging/vt6655/wpa2.c
new file mode 100644
index 000000000000..e2fdb331069e
--- /dev/null
+++ b/drivers/staging/vt6655/wpa2.c
@@ -0,0 +1,373 @@
1/*
2 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
3 * All rights reserved.
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 *
20 * File: wpa2.c
21 *
22 * Purpose: Handles the Basic Service Set & Node Database functions
23 *
24 * Functions:
25 *
26 * Revision History:
27 *
28 * Author: Yiching Chen
29 *
30 * Date: Oct. 4, 2004
31 *
32 */
33#if !defined(__WPA2_H__)
34#include "wpa2.h"
35#endif
36#if !defined(__UMEM_H__)
37#include "umem.h"
38#endif
39#if !defined(__DEVICE_H__)
40#include "device.h"
41#endif
42#if !defined(__WMGR_H__)
43#include "wmgr.h"
44#endif
45
46
47/*--------------------- Static Definitions -------------------------*/
48static int msglevel =MSG_LEVEL_INFO;
49//static int msglevel =MSG_LEVEL_DEBUG;
50/*--------------------- Static Classes ----------------------------*/
51
52/*--------------------- Static Variables --------------------------*/
53
54const BYTE abyOUIGK[4] = { 0x00, 0x0F, 0xAC, 0x00 };
55const BYTE abyOUIWEP40[4] = { 0x00, 0x0F, 0xAC, 0x01 };
56const BYTE abyOUIWEP104[4] = { 0x00, 0x0F, 0xAC, 0x05 };
57const BYTE abyOUITKIP[4] = { 0x00, 0x0F, 0xAC, 0x02 };
58const BYTE abyOUICCMP[4] = { 0x00, 0x0F, 0xAC, 0x04 };
59
60const BYTE abyOUI8021X[4] = { 0x00, 0x0F, 0xAC, 0x01 };
61const BYTE abyOUIPSK[4] = { 0x00, 0x0F, 0xAC, 0x02 };
62
63
64/*--------------------- Static Functions --------------------------*/
65
66/*--------------------- Export Variables --------------------------*/
67
68/*--------------------- Export Functions --------------------------*/
69
70/*+
71 *
72 * Description:
73 * Clear RSN information in BSSList.
74 *
75 * Parameters:
76 * In:
77 * pBSSNode - BSS list.
78 * Out:
79 * none
80 *
81 * Return Value: none.
82 *
83-*/
84VOID
85WPA2_ClearRSN (
86 IN PKnownBSS pBSSNode
87 )
88{
89 int ii;
90
91 pBSSNode->bWPA2Valid = FALSE;
92
93 pBSSNode->byCSSGK = WLAN_11i_CSS_CCMP;
94 for (ii=0; ii < 4; ii ++)
95 pBSSNode->abyCSSPK[ii] = WLAN_11i_CSS_CCMP;
96 pBSSNode->wCSSPKCount = 1;
97 for (ii=0; ii < 4; ii ++)
98 pBSSNode->abyAKMSSAuthType[ii] = WLAN_11i_AKMSS_802_1X;
99 pBSSNode->wAKMSSAuthCount = 1;
100 pBSSNode->sRSNCapObj.bRSNCapExist = FALSE;
101 pBSSNode->sRSNCapObj.wRSNCap = 0;
102}
103
104/*+
105 *
106 * Description:
107 * Parse RSN IE.
108 *
109 * Parameters:
110 * In:
111 * pBSSNode - BSS list.
112 * pRSN - Pointer to the RSN IE.
113 * Out:
114 * none
115 *
116 * Return Value: none.
117 *
118-*/
119VOID
120WPA2vParseRSN (
121 IN PKnownBSS pBSSNode,
122 IN PWLAN_IE_RSN pRSN
123 )
124{
125 int i, j;
126 WORD m = 0, n = 0;
127 PBYTE pbyOUI;
128 BOOL bUseGK = FALSE;
129
130 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"WPA2_ParseRSN: [%d]\n", pRSN->len);
131
132 WPA2_ClearRSN(pBSSNode);
133
134 if (pRSN->len == 2) { // ver(2)
135 if ((pRSN->byElementID == WLAN_EID_RSN) && (pRSN->wVersion == 1)) {
136 pBSSNode->bWPA2Valid = TRUE;
137 }
138 return;
139 }
140
141 if (pRSN->len < 6) { // ver(2) + GK(4)
142 // invalid CSS, P802.11i/D10.0, p31
143 return;
144 }
145
146 // information element header makes sense
147 if ((pRSN->byElementID == WLAN_EID_RSN) &&
148 (pRSN->wVersion == 1)) {
149
150 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Legal 802.11i RSN\n");
151
152 pbyOUI = &(pRSN->abyRSN[0]);
153 if (MEMEqualMemory(pbyOUI, abyOUIWEP40, 4))
154 pBSSNode->byCSSGK = WLAN_11i_CSS_WEP40;
155 else if (MEMEqualMemory(pbyOUI, abyOUITKIP, 4))
156 pBSSNode->byCSSGK = WLAN_11i_CSS_TKIP;
157 else if (MEMEqualMemory(pbyOUI, abyOUICCMP, 4))
158 pBSSNode->byCSSGK = WLAN_11i_CSS_CCMP;
159 else if (MEMEqualMemory(pbyOUI, abyOUIWEP104, 4))
160 pBSSNode->byCSSGK = WLAN_11i_CSS_WEP104;
161 else if (MEMEqualMemory(pbyOUI, abyOUIGK, 4)) {
162 // invalid CSS, P802.11i/D10.0, p32
163 return;
164 } else
165 // any vendor checks here
166 pBSSNode->byCSSGK = WLAN_11i_CSS_UNKNOWN;
167
168 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"802.11i CSS: %X\n", pBSSNode->byCSSGK);
169
170 if (pRSN->len == 6) {
171 pBSSNode->bWPA2Valid = TRUE;
172 return;
173 }
174
175 if (pRSN->len >= 8) { // ver(2) + GK(4) + PK count(2)
176 pBSSNode->wCSSPKCount = *((PWORD) &(pRSN->abyRSN[4]));
177 j = 0;
178 pbyOUI = &(pRSN->abyRSN[6]);
179
180 for (i = 0; (i < pBSSNode->wCSSPKCount) && (j < sizeof(pBSSNode->abyCSSPK)/sizeof(BYTE)); i++) {
181
182 if (pRSN->len >= 8+i*4+4) { // ver(2)+GK(4)+PKCnt(2)+PKS(4*i)
183 if (MEMEqualMemory(pbyOUI, abyOUIGK, 4)) {
184 pBSSNode->abyCSSPK[j++] = WLAN_11i_CSS_USE_GROUP;
185 bUseGK = TRUE;
186 } else if (MEMEqualMemory(pbyOUI, abyOUIWEP40, 4)) {
187 // Invialid CSS, continue to parsing
188 } else if (MEMEqualMemory(pbyOUI, abyOUITKIP, 4)) {
189 if (pBSSNode->byCSSGK != WLAN_11i_CSS_CCMP)
190 pBSSNode->abyCSSPK[j++] = WLAN_11i_CSS_TKIP;
191 else
192 ; // Invialid CSS, continue to parsing
193 } else if (MEMEqualMemory(pbyOUI, abyOUICCMP, 4)) {
194 pBSSNode->abyCSSPK[j++] = WLAN_11i_CSS_CCMP;
195 } else if (MEMEqualMemory(pbyOUI, abyOUIWEP104, 4)) {
196 // Invialid CSS, continue to parsing
197 } else {
198 // any vendor checks here
199 pBSSNode->abyCSSPK[j++] = WLAN_11i_CSS_UNKNOWN;
200 }
201 pbyOUI += 4;
202 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"abyCSSPK[%d]: %X\n", j-1, pBSSNode->abyCSSPK[j-1]);
203 } else
204 break;
205 } //for
206
207 if (bUseGK == TRUE) {
208 if (j != 1) {
209 // invalid CSS, This should be only PK CSS.
210 return;
211 }
212 if (pBSSNode->byCSSGK == WLAN_11i_CSS_CCMP) {
213 // invalid CSS, If CCMP is enable , PK can't be CSSGK.
214 return;
215 }
216 }
217 if ((pBSSNode->wCSSPKCount != 0) && (j == 0)) {
218 // invalid CSS, No valid PK.
219 return;
220 }
221 pBSSNode->wCSSPKCount = (WORD)j;
222 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"wCSSPKCount: %d\n", pBSSNode->wCSSPKCount);
223 }
224
225 m = *((PWORD) &(pRSN->abyRSN[4]));
226
227 if (pRSN->len >= 10+m*4) { // ver(2) + GK(4) + PK count(2) + PKS(4*m) + AKMSS count(2)
228 pBSSNode->wAKMSSAuthCount = *((PWORD) &(pRSN->abyRSN[6+4*m]));;
229 j = 0;
230 pbyOUI = &(pRSN->abyRSN[8+4*m]);
231 for (i = 0; (i < pBSSNode->wAKMSSAuthCount) && (j < sizeof(pBSSNode->abyAKMSSAuthType)/sizeof(BYTE)); i++) {
232 if (pRSN->len >= 10+(m+i)*4+4) { // ver(2)+GK(4)+PKCnt(2)+PKS(4*m)+AKMSS(2)+AKS(4*i)
233 if (MEMEqualMemory(pbyOUI, abyOUI8021X, 4))
234 pBSSNode->abyAKMSSAuthType[j++] = WLAN_11i_AKMSS_802_1X;
235 else if (MEMEqualMemory(pbyOUI, abyOUIPSK, 4))
236 pBSSNode->abyAKMSSAuthType[j++] = WLAN_11i_AKMSS_PSK;
237 else
238 // any vendor checks here
239 pBSSNode->abyAKMSSAuthType[j++] = WLAN_11i_AKMSS_UNKNOWN;
240 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"abyAKMSSAuthType[%d]: %X\n", j-1, pBSSNode->abyAKMSSAuthType[j-1]);
241 } else
242 break;
243 }
244 pBSSNode->wAKMSSAuthCount = (WORD)j;
245 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"wAKMSSAuthCount: %d\n", pBSSNode->wAKMSSAuthCount);
246
247 n = *((PWORD) &(pRSN->abyRSN[6+4*m]));;
248 if (pRSN->len >= 12+4*m+4*n) { // ver(2)+GK(4)+PKCnt(2)+PKS(4*m)+AKMSSCnt(2)+AKMSS(4*n)+Cap(2)
249 pBSSNode->sRSNCapObj.bRSNCapExist = TRUE;
250 pBSSNode->sRSNCapObj.wRSNCap = *((PWORD) &(pRSN->abyRSN[8+4*m+4*n]));
251 }
252 }
253 //ignore PMKID lists bcs only (Re)Assocrequest has this field
254 pBSSNode->bWPA2Valid = TRUE;
255 }
256}
257
258
259/*+
260 *
261 * Description:
262 * Set WPA IEs
263 *
264 * Parameters:
265 * In:
266 * pMgmtHandle - Pointer to management object
267 * Out:
268 * pRSNIEs - Pointer to the RSN IE to set.
269 *
270 * Return Value: length of IEs.
271 *
272-*/
273UINT
274WPA2uSetIEs(
275 IN PVOID pMgmtHandle,
276 OUT PWLAN_IE_RSN pRSNIEs
277 )
278{
279 PSMgmtObject pMgmt = (PSMgmtObject) pMgmtHandle;
280 PBYTE pbyBuffer = NULL;
281 UINT ii = 0;
282 PWORD pwPMKID = NULL;
283
284 if (pRSNIEs == NULL) {
285 return(0);
286 }
287 if (((pMgmt->eAuthenMode == WMAC_AUTH_WPA2) ||
288 (pMgmt->eAuthenMode == WMAC_AUTH_WPA2PSK)) &&
289 (pMgmt->pCurrBSS != NULL)) {
290 /* WPA2 IE */
291 pbyBuffer = (PBYTE) pRSNIEs;
292 pRSNIEs->byElementID = WLAN_EID_RSN;
293 pRSNIEs->len = 6; //Version(2)+GK(4)
294 pRSNIEs->wVersion = 1;
295 //Group Key Cipher Suite
296 pRSNIEs->abyRSN[0] = 0x00;
297 pRSNIEs->abyRSN[1] = 0x0F;
298 pRSNIEs->abyRSN[2] = 0xAC;
299 if (pMgmt->byCSSGK == KEY_CTL_WEP) {
300 pRSNIEs->abyRSN[3] = pMgmt->pCurrBSS->byCSSGK;
301 } else if (pMgmt->byCSSGK == KEY_CTL_TKIP) {
302 pRSNIEs->abyRSN[3] = WLAN_11i_CSS_TKIP;
303 } else if (pMgmt->byCSSGK == KEY_CTL_CCMP) {
304 pRSNIEs->abyRSN[3] = WLAN_11i_CSS_CCMP;
305 } else {
306 pRSNIEs->abyRSN[3] = WLAN_11i_CSS_UNKNOWN;
307 }
308
309 // Pairwise Key Cipher Suite
310 pRSNIEs->abyRSN[4] = 1;
311 pRSNIEs->abyRSN[5] = 0;
312 pRSNIEs->abyRSN[6] = 0x00;
313 pRSNIEs->abyRSN[7] = 0x0F;
314 pRSNIEs->abyRSN[8] = 0xAC;
315 if (pMgmt->byCSSPK == KEY_CTL_TKIP) {
316 pRSNIEs->abyRSN[9] = WLAN_11i_CSS_TKIP;
317 } else if (pMgmt->byCSSPK == KEY_CTL_CCMP) {
318 pRSNIEs->abyRSN[9] = WLAN_11i_CSS_CCMP;
319 } else if (pMgmt->byCSSPK == KEY_CTL_NONE) {
320 pRSNIEs->abyRSN[9] = WLAN_11i_CSS_USE_GROUP;
321 } else {
322 pRSNIEs->abyRSN[9] = WLAN_11i_CSS_UNKNOWN;
323 }
324 pRSNIEs->len += 6;
325
326 // Auth Key Management Suite
327 pRSNIEs->abyRSN[10] = 1;
328 pRSNIEs->abyRSN[11] = 0;
329 pRSNIEs->abyRSN[12] = 0x00;
330 pRSNIEs->abyRSN[13] = 0x0F;
331 pRSNIEs->abyRSN[14] = 0xAC;
332 if (pMgmt->eAuthenMode == WMAC_AUTH_WPA2PSK) {
333 pRSNIEs->abyRSN[15] = WLAN_11i_AKMSS_PSK;
334 } else if (pMgmt->eAuthenMode == WMAC_AUTH_WPA2) {
335 pRSNIEs->abyRSN[15] = WLAN_11i_AKMSS_802_1X;
336 } else {
337 pRSNIEs->abyRSN[15] = WLAN_11i_AKMSS_UNKNOWN;
338 }
339 pRSNIEs->len +=6;
340
341 // RSN Capabilites
342 if (pMgmt->pCurrBSS->sRSNCapObj.bRSNCapExist == TRUE) {
343 MEMvCopy(&pRSNIEs->abyRSN[16], &pMgmt->pCurrBSS->sRSNCapObj.wRSNCap, 2);
344 } else {
345 pRSNIEs->abyRSN[16] = 0;
346 pRSNIEs->abyRSN[17] = 0;
347 }
348 pRSNIEs->len +=2;
349
350 if ((pMgmt->gsPMKIDCache.BSSIDInfoCount > 0) &&
351 (pMgmt->bRoaming == TRUE) &&
352 (pMgmt->eAuthenMode == WMAC_AUTH_WPA2)) {
353 // RSN PMKID
354 pwPMKID = (PWORD)(&pRSNIEs->abyRSN[18]); // Point to PMKID count
355 *pwPMKID = 0; // Initialize PMKID count
356 pbyBuffer = &pRSNIEs->abyRSN[20]; // Point to PMKID list
357 for (ii = 0; ii < pMgmt->gsPMKIDCache.BSSIDInfoCount; ii++) {
358 if (MEMEqualMemory(&pMgmt->gsPMKIDCache.BSSIDInfo[ii].abyBSSID[0], pMgmt->abyCurrBSSID, U_ETHER_ADDR_LEN)) {
359 (*pwPMKID) ++;
360 MEMvCopy(pbyBuffer, pMgmt->gsPMKIDCache.BSSIDInfo[ii].abyPMKID, 16);
361 pbyBuffer += 16;
362 }
363 }
364 if (*pwPMKID != 0) {
365 pRSNIEs->len += (2 + (*pwPMKID)*16);
366 } else {
367 pbyBuffer = &pRSNIEs->abyRSN[18];
368 }
369 }
370 return(pRSNIEs->len + WLAN_IEHDR_LEN);
371 }
372 return(0);
373}
diff --git a/drivers/staging/vt6655/wpa2.h b/drivers/staging/vt6655/wpa2.h
new file mode 100644
index 000000000000..bda045b313b9
--- /dev/null
+++ b/drivers/staging/vt6655/wpa2.h
@@ -0,0 +1,100 @@
1/*
2 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
3 * All rights reserved.
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 *
20 * File: wpa2.h
21 *
22 * Purpose: Defines the macros, types, and functions for dealing
23 * with WPA2 informations.
24 *
25 * Author: Yiching Chen
26 *
27 * Date: Oct. 4, 2004
28 *
29 */
30
31#ifndef __WPA2_H__
32#define __WPA2_H__
33
34
35#if !defined(__TTYPE_H__)
36#include "ttype.h"
37#endif
38#if !defined(__80211MGR_H__)
39#include "80211mgr.h"
40#endif
41#if !defined(__80211HDR_H__)
42#include "80211hdr.h"
43#endif
44#if !defined(__BSSDB_H__)
45#include "bssdb.h"
46#endif
47#if !defined(__VNTWIFI_H__)
48#include "vntwifi.h"
49#endif
50
51
52
53/*--------------------- Export Definitions -------------------------*/
54
55typedef struct tagsPMKIDInfo {
56 BYTE abyBSSID[6];
57 BYTE abyPMKID[16];
58} PMKIDInfo, *PPMKIDInfo;
59
60typedef struct tagSPMKIDCache {
61 ULONG BSSIDInfoCount;
62 PMKIDInfo BSSIDInfo[MAX_PMKID_CACHE];
63} SPMKIDCache, *PSPMKIDCache;
64
65
66/*--------------------- Export Classes ----------------------------*/
67
68/*--------------------- Export Variables --------------------------*/
69
70/*--------------------- Export Types ------------------------------*/
71
72/*--------------------- Export Functions --------------------------*/
73#ifdef __cplusplus
74extern "C" { /* Assume C declarations for C++ */
75#endif /* __cplusplus */
76
77VOID
78WPA2_ClearRSN (
79 IN PKnownBSS pBSSNode
80 );
81
82VOID
83WPA2vParseRSN (
84 IN PKnownBSS pBSSNode,
85 IN PWLAN_IE_RSN pRSN
86 );
87
88UINT
89WPA2uSetIEs(
90 IN PVOID pMgmtHandle,
91 OUT PWLAN_IE_RSN pRSNIEs
92 );
93
94
95#ifdef __cplusplus
96} /* End of extern "C" { */
97#endif /* __cplusplus */
98
99
100#endif // __WPA2_H__
diff --git a/drivers/staging/vt6655/wpactl.c b/drivers/staging/vt6655/wpactl.c
new file mode 100644
index 000000000000..ee7109d1b8ec
--- /dev/null
+++ b/drivers/staging/vt6655/wpactl.c
@@ -0,0 +1,1014 @@
1/*
2 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
3 * All rights reserved.
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * File: wpactl.c
20 *
21 * Purpose: handle wpa supplicant ioctl input/out functions
22 *
23 * Author: Lyndon Chen
24 *
25 * Date: Oct. 20, 2003
26 *
27 * Functions:
28 *
29 * Revision History:
30 *
31 */
32
33
34#if !defined(__WPACTL_H__)
35#include "wpactl.h"
36#endif
37#if !defined(__KEY_H__)
38#include "key.h"
39#endif
40#if !defined(__MAC_H__)
41#include "mac.h"
42#endif
43#if !defined(__DEVICE_H__)
44#include "device.h"
45#endif
46#if !defined(__WMGR_H__)
47#include "wmgr.h"
48#endif
49#if !defined(__IOCMD_H__)
50#include "iocmd.h"
51#endif
52#if !defined(__IOWPA_H__)
53#include "iowpa.h"
54#endif
55//2008-0717-05, <Add> by James
56#if !defined(__RF_H__)
57#include "rf.h"
58#endif
59
60/*--------------------- Static Definitions -------------------------*/
61
62#define VIAWGET_WPA_MAX_BUF_SIZE 1024
63
64
65
66static const int frequency_list[] = {
67 2412, 2417, 2422, 2427, 2432, 2437, 2442,
68 2447, 2452, 2457, 2462, 2467, 2472, 2484
69};
70/*--------------------- Static Classes ----------------------------*/
71
72/*--------------------- Static Variables --------------------------*/
73//static int msglevel =MSG_LEVEL_DEBUG;
74static int msglevel =MSG_LEVEL_INFO;
75
76/*--------------------- Static Functions --------------------------*/
77
78
79
80
81/*--------------------- Export Variables --------------------------*/
82
83
84static void wpadev_setup(struct net_device *dev)
85{
86 dev->type = ARPHRD_IEEE80211;
87 dev->hard_header_len = ETH_HLEN;
88 dev->mtu = 2048;
89 dev->addr_len = ETH_ALEN;
90 dev->tx_queue_len = 1000;
91
92 memset(dev->broadcast,0xFF, ETH_ALEN);
93
94 dev->flags = IFF_BROADCAST|IFF_MULTICAST;
95}
96
97
98
99/*
100 * Description:
101 * register netdev for wpa supplicant deamon
102 *
103 * Parameters:
104 * In:
105 * pDevice -
106 * enable -
107 * Out:
108 *
109 * Return Value:
110 *
111 */
112
113static int wpa_init_wpadev(PSDevice pDevice)
114{
115 struct net_device *dev = pDevice->dev;
116 int ret=0;
117
118 pDevice->wpadev = alloc_netdev(0, "vntwpa", wpadev_setup);
119 if (pDevice->wpadev == NULL)
120 return -ENOMEM;
121
122 pDevice->wpadev->priv = pDevice;
123 memcpy(pDevice->wpadev->dev_addr, dev->dev_addr, U_ETHER_ADDR_LEN);
124 pDevice->wpadev->base_addr = dev->base_addr;
125 pDevice->wpadev->irq = dev->irq;
126 pDevice->wpadev->mem_start = dev->mem_start;
127 pDevice->wpadev->mem_end = dev->mem_end;
128 ret = register_netdev(pDevice->wpadev);
129 if (ret) {
130 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: register_netdev(WPA) failed!\n",
131 dev->name);
132 free_netdev(pDevice->wpadev);
133 return -1;
134 }
135
136 if (pDevice->skb == NULL) {
137 pDevice->skb = dev_alloc_skb((int)pDevice->rx_buf_sz);
138 if (pDevice->skb == NULL)
139 return -ENOMEM;
140 }
141
142 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Registered netdev %s for WPA management\n",
143 dev->name, pDevice->wpadev->name);
144
145 return 0;
146}
147
148
149/*
150 * Description:
151 * unregister net_device (wpadev)
152 *
153 * Parameters:
154 * In:
155 * pDevice -
156 * Out:
157 *
158 * Return Value:
159 *
160 */
161
162static int wpa_release_wpadev(PSDevice pDevice)
163{
164
165 if (pDevice->skb) {
166 dev_kfree_skb(pDevice->skb);
167 pDevice->skb = NULL;
168 }
169
170 if (pDevice->wpadev) {
171 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Netdevice %s unregistered\n",
172 pDevice->dev->name, pDevice->wpadev->name);
173 unregister_netdev(pDevice->wpadev);
174 free_netdev(pDevice->wpadev);
175 pDevice->wpadev = NULL;
176 }
177
178 return 0;
179}
180
181
182
183
184
185/*
186 * Description:
187 * Set enable/disable dev for wpa supplicant deamon
188 *
189 * Parameters:
190 * In:
191 * pDevice -
192 * val -
193 * Out:
194 *
195 * Return Value:
196 *
197 */
198
199int wpa_set_wpadev(PSDevice pDevice, int val)
200{
201
202
203 if (val)
204 return wpa_init_wpadev(pDevice);
205 else
206 return wpa_release_wpadev(pDevice);
207}
208
209
210/*
211 * Description:
212 * Set WPA algorithm & keys
213 *
214 * Parameters:
215 * In:
216 * pDevice -
217 * param -
218 * Out:
219 *
220 * Return Value:
221 *
222 */
223
224int wpa_set_keys(PSDevice pDevice, void *ctx, BOOL fcpfkernel)
225{
226 struct viawget_wpa_param *param=ctx;
227 PSMgmtObject pMgmt = pDevice->pMgmt;
228 DWORD dwKeyIndex = 0;
229 BYTE abyKey[MAX_KEY_LEN];
230 BYTE abySeq[MAX_KEY_LEN];
231 QWORD KeyRSC;
232// NDIS_802_11_KEY_RSC KeyRSC;
233 BYTE byKeyDecMode = KEY_CTL_WEP;
234 int ret = 0;
235 int uu, ii;
236
237
238 if (param->u.wpa_key.alg_name > WPA_ALG_CCMP)
239 return -EINVAL;
240
241 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "param->u.wpa_key.alg_name = %d \n", param->u.wpa_key.alg_name);
242 if (param->u.wpa_key.alg_name == WPA_ALG_NONE) {
243 pDevice->eEncryptionStatus = Ndis802_11EncryptionDisabled;
244 pDevice->bEncryptionEnable = FALSE;
245 pDevice->byKeyIndex = 0;
246 pDevice->bTransmitKey = FALSE;
247 KeyvRemoveAllWEPKey(&(pDevice->sKey), pDevice->PortOffset);
248 for (uu=0; uu<MAX_KEY_TABLE; uu++) {
249 MACvDisableKeyEntry(pDevice->PortOffset, uu);
250 }
251 return ret;
252 }
253
254 //spin_unlock_irq(&pDevice->lock);
255 if(param->u.wpa_key.key && fcpfkernel) {
256 memcpy(&abyKey[0], param->u.wpa_key.key, param->u.wpa_key.key_len);
257 }
258 else {
259 spin_unlock_irq(&pDevice->lock);
260 if (param->u.wpa_key.key &&
261 copy_from_user(&abyKey[0], param->u.wpa_key.key, param->u.wpa_key.key_len)){
262 spin_lock_irq(&pDevice->lock);
263 return -EINVAL;
264 }
265spin_lock_irq(&pDevice->lock);
266 }
267
268 dwKeyIndex = (DWORD)(param->u.wpa_key.key_index);
269
270 if (param->u.wpa_key.alg_name == WPA_ALG_WEP) {
271 if (dwKeyIndex > 3) {
272 return -EINVAL;
273 }
274 else {
275 if (param->u.wpa_key.set_tx) {
276 pDevice->byKeyIndex = (BYTE)dwKeyIndex;
277 pDevice->bTransmitKey = TRUE;
278 dwKeyIndex |= (1 << 31);
279 }
280 KeybSetDefaultKey(&(pDevice->sKey),
281 dwKeyIndex & ~(BIT30 | USE_KEYRSC),
282 param->u.wpa_key.key_len,
283 NULL,
284 abyKey,
285 KEY_CTL_WEP,
286 pDevice->PortOffset,
287 pDevice->byLocalID);
288
289 }
290 pDevice->eEncryptionStatus = Ndis802_11Encryption1Enabled;
291 pDevice->bEncryptionEnable = TRUE;
292 return ret;
293 }
294
295 //spin_unlock_irq(&pDevice->lock);
296 if(param->u.wpa_key.seq && fcpfkernel) {
297 memcpy(&abySeq[0], param->u.wpa_key.seq, param->u.wpa_key.seq_len);
298 }
299 else {
300 spin_unlock_irq(&pDevice->lock);
301 if (param->u.wpa_key.seq &&
302 copy_from_user(&abySeq[0], param->u.wpa_key.seq, param->u.wpa_key.seq_len)){
303
304 spin_lock_irq(&pDevice->lock);
305 return -EINVAL;
306 }
307spin_lock_irq(&pDevice->lock);
308}
309
310 if (param->u.wpa_key.seq_len > 0) {
311 for (ii = 0 ; ii < param->u.wpa_key.seq_len ; ii++) {
312 if (ii < 4)
313 LODWORD(KeyRSC) |= (abySeq[ii] << (ii * 8));
314 else
315 HIDWORD(KeyRSC) |= (abySeq[ii] << ((ii-4) * 8));
316 //KeyRSC |= (abySeq[ii] << (ii * 8));
317 }
318 dwKeyIndex |= 1 << 29;
319 }
320
321 if (param->u.wpa_key.key_index >= MAX_GROUP_KEY) {
322 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "return dwKeyIndex > 3\n");
323 return -EINVAL;
324 }
325
326 if (param->u.wpa_key.alg_name == WPA_ALG_TKIP) {
327 pDevice->eEncryptionStatus = Ndis802_11Encryption2Enabled;
328 }
329
330 if (param->u.wpa_key.alg_name == WPA_ALG_CCMP) {
331 pDevice->eEncryptionStatus = Ndis802_11Encryption3Enabled;
332 }
333
334 if (param->u.wpa_key.set_tx)
335 dwKeyIndex |= (1 << 31);
336
337 if (pDevice->eEncryptionStatus == Ndis802_11Encryption3Enabled)
338 byKeyDecMode = KEY_CTL_CCMP;
339 else if (pDevice->eEncryptionStatus == Ndis802_11Encryption2Enabled)
340 byKeyDecMode = KEY_CTL_TKIP;
341 else
342 byKeyDecMode = KEY_CTL_WEP;
343
344 // Fix HCT test that set 256 bits KEY and Ndis802_11Encryption3Enabled
345 if (pDevice->eEncryptionStatus == Ndis802_11Encryption3Enabled) {
346 if (param->u.wpa_key.key_len == MAX_KEY_LEN)
347 byKeyDecMode = KEY_CTL_TKIP;
348 else if (param->u.wpa_key.key_len == WLAN_WEP40_KEYLEN)
349 byKeyDecMode = KEY_CTL_WEP;
350 else if (param->u.wpa_key.key_len == WLAN_WEP104_KEYLEN)
351 byKeyDecMode = KEY_CTL_WEP;
352 } else if (pDevice->eEncryptionStatus == Ndis802_11Encryption2Enabled) {
353 if (param->u.wpa_key.key_len == WLAN_WEP40_KEYLEN)
354 byKeyDecMode = KEY_CTL_WEP;
355 else if (param->u.wpa_key.key_len == WLAN_WEP104_KEYLEN)
356 byKeyDecMode = KEY_CTL_WEP;
357 }
358
359
360 // Check TKIP key length
361 if ((byKeyDecMode == KEY_CTL_TKIP) &&
362 (param->u.wpa_key.key_len != MAX_KEY_LEN)) {
363 // TKIP Key must be 256 bits
364 //DBG_PRN_WLAN03(("return NDIS_STATUS_INVALID_DATA - TKIP Key must be 256 bits\n"));
365 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "return- TKIP Key must be 256 bits!\n");
366 return -EINVAL;
367 }
368 // Check AES key length
369 if ((byKeyDecMode == KEY_CTL_CCMP) &&
370 (param->u.wpa_key.key_len != AES_KEY_LEN)) {
371 // AES Key must be 128 bits
372 //DBG_PRN_WLAN03(("return NDIS_STATUS_INVALID_DATA - AES Key must be 128 bits\n"));
373 return -EINVAL;
374 }
375
376 // spin_lock_irq(&pDevice->lock);
377 if (IS_BROADCAST_ADDRESS(&param->addr[0]) || (param->addr == NULL)) {
378 // If IS_BROADCAST_ADDRESS, set the key as every key entry's group key.
379 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Groupe Key Assign.\n");
380
381 if ((KeybSetAllGroupKey(&(pDevice->sKey),
382 dwKeyIndex,
383 param->u.wpa_key.key_len,
384 (PQWORD) &(KeyRSC),
385 (PBYTE)abyKey,
386 byKeyDecMode,
387 pDevice->PortOffset,
388 pDevice->byLocalID) == TRUE) &&
389 (KeybSetDefaultKey(&(pDevice->sKey),
390 dwKeyIndex,
391 param->u.wpa_key.key_len,
392 (PQWORD) &(KeyRSC),
393 (PBYTE)abyKey,
394 byKeyDecMode,
395 pDevice->PortOffset,
396 pDevice->byLocalID) == TRUE) ) {
397 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "GROUP Key Assign.\n");
398
399 } else {
400 //DBG_PRN_WLAN03(("return NDIS_STATUS_INVALID_DATA -KeybSetDefaultKey Fail.0\n"));
401 // spin_unlock_irq(&pDevice->lock);
402 return -EINVAL;
403 }
404
405 } else {
406 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Pairwise Key Assign.\n");
407 // BSSID not 0xffffffffffff
408 // Pairwise Key can't be WEP
409 if (byKeyDecMode == KEY_CTL_WEP) {
410 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Pairwise Key can't be WEP\n");
411 //spin_unlock_irq(&pDevice->lock);
412 return -EINVAL;
413 }
414
415 dwKeyIndex |= (1 << 30); // set pairwise key
416 if (pMgmt->eConfigMode == WMAC_CONFIG_IBSS_STA) {
417 //DBG_PRN_WLAN03(("return NDIS_STATUS_INVALID_DATA - WMAC_CONFIG_IBSS_STA\n"));
418 //spin_unlock_irq(&pDevice->lock);
419 return -EINVAL;
420 }
421 if (KeybSetKey(&(pDevice->sKey),
422 &param->addr[0],
423 dwKeyIndex,
424 param->u.wpa_key.key_len,
425 (PQWORD) &(KeyRSC),
426 (PBYTE)abyKey,
427 byKeyDecMode,
428 pDevice->PortOffset,
429 pDevice->byLocalID) == TRUE) {
430 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Pairwise Key Set\n");
431
432 } else {
433 // Key Table Full
434 if (IS_ETH_ADDRESS_EQUAL(&param->addr[0], pDevice->abyBSSID)) {
435 //DBG_PRN_WLAN03(("return NDIS_STATUS_INVALID_DATA -Key Table Full.2\n"));
436 //spin_unlock_irq(&pDevice->lock);
437 return -EINVAL;
438
439 } else {
440 // Save Key and configure just before associate/reassociate to BSSID
441 // we do not implement now
442 //spin_unlock_irq(&pDevice->lock);
443 return -EINVAL;
444 }
445 }
446 } // BSSID not 0xffffffffffff
447 if ((ret == 0) && ((param->u.wpa_key.set_tx) != 0)) {
448 pDevice->byKeyIndex = (BYTE)param->u.wpa_key.key_index;
449 pDevice->bTransmitKey = TRUE;
450 }
451 pDevice->bEncryptionEnable = TRUE;
452 //spin_unlock_irq(&pDevice->lock);
453
454/*
455 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO " key=%x-%x-%x-%x-%x-xxxxx \n",
456 pMgmt->sNodeDBTable[iNodeIndex].abyWepKey[byKeyIndex][0],
457 pMgmt->sNodeDBTable[iNodeIndex].abyWepKey[byKeyIndex][1],
458 pMgmt->sNodeDBTable[iNodeIndex].abyWepKey[byKeyIndex][2],
459 pMgmt->sNodeDBTable[iNodeIndex].abyWepKey[byKeyIndex][3],
460 pMgmt->sNodeDBTable[iNodeIndex].abyWepKey[byKeyIndex][4]
461 );
462*/
463
464 return ret;
465
466}
467
468
469/*
470 * Description:
471 * enable wpa auth & mode
472 *
473 * Parameters:
474 * In:
475 * pDevice -
476 * param -
477 * Out:
478 *
479 * Return Value:
480 *
481 */
482
483static int wpa_set_wpa(PSDevice pDevice,
484 struct viawget_wpa_param *param)
485{
486
487 PSMgmtObject pMgmt = pDevice->pMgmt;
488 int ret = 0;
489
490 pMgmt->eAuthenMode = WMAC_AUTH_OPEN;
491 pMgmt->bShareKeyAlgorithm = FALSE;
492
493 return ret;
494}
495
496
497
498
499 /*
500 * Description:
501 * set disassociate
502 *
503 * Parameters:
504 * In:
505 * pDevice -
506 * param -
507 * Out:
508 *
509 * Return Value:
510 *
511 */
512
513static int wpa_set_disassociate(PSDevice pDevice,
514 struct viawget_wpa_param *param)
515{
516 PSMgmtObject pMgmt = pDevice->pMgmt;
517 int ret = 0;
518
519 spin_lock_irq(&pDevice->lock);
520 if (pDevice->bLinkPass) {
521 if (!memcmp(param->addr, pMgmt->abyCurrBSSID, 6))
522 bScheduleCommand((HANDLE)pDevice, WLAN_CMD_DISASSOCIATE, NULL);
523 }
524 spin_unlock_irq(&pDevice->lock);
525
526 return ret;
527}
528
529
530
531/*
532 * Description:
533 * enable scan process
534 *
535 * Parameters:
536 * In:
537 * pDevice -
538 * param -
539 * Out:
540 *
541 * Return Value:
542 *
543 */
544
545static int wpa_set_scan(PSDevice pDevice,
546 struct viawget_wpa_param *param)
547{
548 int ret = 0;
549
550 spin_lock_irq(&pDevice->lock);
551 BSSvClearBSSList((HANDLE)pDevice, pDevice->bLinkPass);
552 bScheduleCommand((HANDLE) pDevice, WLAN_CMD_BSSID_SCAN, NULL);
553 spin_unlock_irq(&pDevice->lock);
554
555 return ret;
556}
557
558
559
560/*
561 * Description:
562 * get bssid
563 *
564 * Parameters:
565 * In:
566 * pDevice -
567 * param -
568 * Out:
569 *
570 * Return Value:
571 *
572 */
573
574static int wpa_get_bssid(PSDevice pDevice,
575 struct viawget_wpa_param *param)
576{
577 PSMgmtObject pMgmt = pDevice->pMgmt;
578 int ret = 0;
579
580 memcpy(param->u.wpa_associate.bssid, pMgmt->abyCurrBSSID , 6);
581
582 return ret;
583
584}
585
586
587/*
588 * Description:
589 * get bssid
590 *
591 * Parameters:
592 * In:
593 * pDevice -
594 * param -
595 * Out:
596 *
597 * Return Value:
598 *
599 */
600
601static int wpa_get_ssid(PSDevice pDevice,
602 struct viawget_wpa_param *param)
603{
604 PSMgmtObject pMgmt = pDevice->pMgmt;
605 PWLAN_IE_SSID pItemSSID;
606 int ret = 0;
607
608 pItemSSID = (PWLAN_IE_SSID)pMgmt->abyCurrSSID;
609
610 memcpy(param->u.wpa_associate.ssid, pItemSSID->abySSID , pItemSSID->len);
611 param->u.wpa_associate.ssid_len = pItemSSID->len;
612
613 return ret;
614}
615
616
617
618/*
619 * Description:
620 * get scan results
621 *
622 * Parameters:
623 * In:
624 * pDevice -
625 * param -
626 * Out:
627 *
628 * Return Value:
629 *
630 */
631
632static int wpa_get_scan(PSDevice pDevice,
633 struct viawget_wpa_param *param)
634{
635 struct viawget_scan_result *scan_buf;
636 PSMgmtObject pMgmt = pDevice->pMgmt;
637 PWLAN_IE_SSID pItemSSID;
638 PKnownBSS pBSS;
639 PBYTE pBuf;
640 int ret = 0;
641 u16 count = 0;
642 u16 ii, jj;
643#if 1
644
645 PBYTE ptempBSS;
646
647
648
649 ptempBSS = kmalloc(sizeof(KnownBSS), (int)GFP_ATOMIC);
650
651 if (ptempBSS == NULL) {
652
653 printk("bubble sort kmalloc memory fail@@@\n");
654
655 ret = -ENOMEM;
656
657 return ret;
658
659 }
660
661 for (ii = 0; ii < MAX_BSS_NUM; ii++) {
662
663 for(jj=0;jj<MAX_BSS_NUM-ii-1;jj++) {
664
665 if((pMgmt->sBSSList[jj].bActive!=TRUE) ||
666
667 ((pMgmt->sBSSList[jj].uRSSI>pMgmt->sBSSList[jj+1].uRSSI) &&(pMgmt->sBSSList[jj+1].bActive!=FALSE))) {
668
669 memcpy(ptempBSS,&pMgmt->sBSSList[jj],sizeof(KnownBSS));
670
671 memcpy(&pMgmt->sBSSList[jj],&pMgmt->sBSSList[jj+1],sizeof(KnownBSS));
672
673 memcpy(&pMgmt->sBSSList[jj+1],ptempBSS,sizeof(KnownBSS));
674
675 }
676
677 }
678
679 };
680
681 kfree(ptempBSS);
682
683 // printk("bubble sort result:\n");
684
685 //for (ii = 0; ii < MAX_BSS_NUM; ii++)
686
687 // printk("%d [%s]:RSSI=%d\n",ii,((PWLAN_IE_SSID)(pMgmt->sBSSList[ii].abySSID))->abySSID,
688
689 // pMgmt->sBSSList[ii].uRSSI);
690
691 #endif
692
693//******mike:bubble sort by stronger RSSI*****//
694
695
696
697
698 count = 0;
699 pBSS = &(pMgmt->sBSSList[0]);
700 for (ii = 0; ii < MAX_BSS_NUM; ii++) {
701 pBSS = &(pMgmt->sBSSList[ii]);
702 if (!pBSS->bActive)
703 continue;
704 count++;
705 };
706
707 pBuf = kmalloc(sizeof(struct viawget_scan_result) * count, (int)GFP_ATOMIC);
708
709 if (pBuf == NULL) {
710 ret = -ENOMEM;
711 return ret;
712 }
713 memset(pBuf, 0, sizeof(struct viawget_scan_result) * count);
714 scan_buf = (struct viawget_scan_result *)pBuf;
715 pBSS = &(pMgmt->sBSSList[0]);
716 for (ii = 0, jj = 0; ii < MAX_BSS_NUM ; ii++) {
717 pBSS = &(pMgmt->sBSSList[ii]);
718 if (pBSS->bActive) {
719 if (jj >= count)
720 break;
721 memcpy(scan_buf->bssid, pBSS->abyBSSID, WLAN_BSSID_LEN);
722 pItemSSID = (PWLAN_IE_SSID)pBSS->abySSID;
723 memcpy(scan_buf->ssid, pItemSSID->abySSID, pItemSSID->len);
724 scan_buf->ssid_len = pItemSSID->len;
725 scan_buf->freq = frequency_list[pBSS->uChannel-1];
726 scan_buf->caps = pBSS->wCapInfo;
727 //scan_buf->caps = pBSS->wCapInfo;
728 //scan_buf->qual =
729 //scan_buf->noise =
730 //scan_buf->level =
731 //scan_buf->maxrate =
732 if (pBSS->wWPALen != 0) {
733 scan_buf->wpa_ie_len = pBSS->wWPALen;
734 memcpy(scan_buf->wpa_ie, pBSS->byWPAIE, pBSS->wWPALen);
735 }
736 if (pBSS->wRSNLen != 0) {
737 scan_buf->rsn_ie_len = pBSS->wRSNLen;
738 memcpy(scan_buf->rsn_ie, pBSS->byRSNIE, pBSS->wRSNLen);
739 }
740 scan_buf = (struct viawget_scan_result *)((PBYTE)scan_buf + sizeof(struct viawget_scan_result));
741 jj ++;
742 }
743 }
744
745 if (jj < count)
746 count = jj;
747
748 if (copy_to_user(param->u.scan_results.buf, pBuf, sizeof(struct viawget_scan_result) * count)) {
749 ret = -EFAULT;
750 };
751 param->u.scan_results.scan_count = count;
752 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO " param->u.scan_results.scan_count = %d\n", count)
753
754 kfree(pBuf);
755 return ret;
756}
757
758
759
760/*
761 * Description:
762 * set associate with AP
763 *
764 * Parameters:
765 * In:
766 * pDevice -
767 * param -
768 * Out:
769 *
770 * Return Value:
771 *
772 */
773
774static int wpa_set_associate(PSDevice pDevice,
775 struct viawget_wpa_param *param)
776{
777 PSMgmtObject pMgmt = pDevice->pMgmt;
778 PWLAN_IE_SSID pItemSSID;
779 BYTE abyNullAddr[] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
780 BYTE abyWPAIE[64];
781 int ret = 0;
782 BOOL bWepEnabled=FALSE;
783
784 // set key type & algorithm
785 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "pairwise_suite = %d\n", param->u.wpa_associate.pairwise_suite);
786 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "group_suite = %d\n", param->u.wpa_associate.group_suite);
787 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "key_mgmt_suite = %d\n", param->u.wpa_associate.key_mgmt_suite);
788 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "auth_alg = %d\n", param->u.wpa_associate.auth_alg);
789 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "mode = %d\n", param->u.wpa_associate.mode);
790 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "wpa_ie_len = %d\n", param->u.wpa_associate.wpa_ie_len);
791
792
793 if (param->u.wpa_associate.wpa_ie &&
794 copy_from_user(&abyWPAIE[0], param->u.wpa_associate.wpa_ie, param->u.wpa_associate.wpa_ie_len))
795 return -EINVAL;
796
797 if (param->u.wpa_associate.mode == 1)
798 pMgmt->eConfigMode = WMAC_CONFIG_IBSS_STA;
799 else
800 pMgmt->eConfigMode = WMAC_CONFIG_ESS_STA;
801 // set ssid
802 memset(pMgmt->abyDesireSSID, 0, WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1);
803 pItemSSID = (PWLAN_IE_SSID)pMgmt->abyDesireSSID;
804 pItemSSID->byElementID = WLAN_EID_SSID;
805 pItemSSID->len = param->u.wpa_associate.ssid_len;
806 memcpy(pItemSSID->abySSID, param->u.wpa_associate.ssid, pItemSSID->len);
807 // set bssid
808 if (memcmp(param->u.wpa_associate.bssid, &abyNullAddr[0], 6) != 0)
809 memcpy(pMgmt->abyDesireBSSID, param->u.wpa_associate.bssid, 6);
810else
811{
812 bScheduleCommand((HANDLE) pDevice, WLAN_CMD_BSSID_SCAN, pItemSSID->abySSID);
813}
814
815 if (param->u.wpa_associate.wpa_ie_len == 0) {
816 if (param->u.wpa_associate.auth_alg & AUTH_ALG_SHARED_KEY)
817 pMgmt->eAuthenMode = WMAC_AUTH_SHAREKEY;
818 else
819 pMgmt->eAuthenMode = WMAC_AUTH_OPEN;
820 } else if (abyWPAIE[0] == RSN_INFO_ELEM) {
821 if (param->u.wpa_associate.key_mgmt_suite == KEY_MGMT_PSK)
822 pMgmt->eAuthenMode = WMAC_AUTH_WPA2PSK;
823 else
824 pMgmt->eAuthenMode = WMAC_AUTH_WPA2;
825 } else {
826 if (param->u.wpa_associate.key_mgmt_suite == KEY_MGMT_WPA_NONE)
827 pMgmt->eAuthenMode = WMAC_AUTH_WPANONE;
828 else if (param->u.wpa_associate.key_mgmt_suite == KEY_MGMT_PSK)
829 pMgmt->eAuthenMode = WMAC_AUTH_WPAPSK;
830 else
831 pMgmt->eAuthenMode = WMAC_AUTH_WPA;
832 }
833
834 switch (param->u.wpa_associate.pairwise_suite) {
835 case CIPHER_CCMP:
836 pDevice->eEncryptionStatus = Ndis802_11Encryption3Enabled;
837 break;
838 case CIPHER_TKIP:
839 pDevice->eEncryptionStatus = Ndis802_11Encryption2Enabled;
840 break;
841 case CIPHER_WEP40:
842 case CIPHER_WEP104:
843 pDevice->eEncryptionStatus = Ndis802_11Encryption1Enabled;
844 bWepEnabled=TRUE;
845 break;
846 case CIPHER_NONE:
847 if (param->u.wpa_associate.group_suite == CIPHER_CCMP)
848 pDevice->eEncryptionStatus = Ndis802_11Encryption3Enabled;
849 else
850 pDevice->eEncryptionStatus = Ndis802_11Encryption2Enabled;
851 break;
852 default:
853 pDevice->eEncryptionStatus = Ndis802_11EncryptionDisabled;
854 };
855
856//DavidWang add for WPA_supplicant support open/share mode
857
858 if (pMgmt->eAuthenMode == WMAC_AUTH_SHAREKEY) {
859 pDevice->eEncryptionStatus = Ndis802_11Encryption1Enabled;
860 //pMgmt->eAuthenMode = WMAC_AUTH_SHAREKEY;
861 pMgmt->bShareKeyAlgorithm = TRUE;
862 }
863 else if (pMgmt->eAuthenMode == WMAC_AUTH_OPEN) {
864 if(!bWepEnabled) pDevice->eEncryptionStatus = Ndis802_11EncryptionDisabled;
865 else pDevice->eEncryptionStatus = Ndis802_11Encryption1Enabled;
866 //pMgmt->eAuthenMode = WMAC_AUTH_OPEN;
867 //pMgmt->bShareKeyAlgorithm = FALSE; //20080717-06,<Modify> by chester//Fix Open mode, WEP encrytion
868 }
869//mike save old encryption status
870 pDevice->eOldEncryptionStatus = pDevice->eEncryptionStatus;
871
872 if (pDevice->eEncryptionStatus != Ndis802_11EncryptionDisabled)
873 pDevice->bEncryptionEnable = TRUE;
874 else
875 pDevice->bEncryptionEnable = FALSE;
876if (!((pMgmt->eAuthenMode == WMAC_AUTH_SHAREKEY) ||
877 ((pMgmt->eAuthenMode == WMAC_AUTH_OPEN) && (bWepEnabled==TRUE))) ) //DavidWang //20080717-06,<Modify> by chester//Not to initial WEP
878 KeyvInitTable(&pDevice->sKey, pDevice->PortOffset);
879 spin_lock_irq(&pDevice->lock);
880 pDevice->bLinkPass = FALSE;
881 memset(pMgmt->abyCurrBSSID, 0, 6);
882 pMgmt->eCurrState = WMAC_STATE_IDLE;
883 netif_stop_queue(pDevice->dev);
884 //20080701-02,<Add> by Mike Liu
885/*******search if ap_scan=2 ,which is associating request in hidden ssid mode ****/
886{
887 PKnownBSS pCurr = NULL;
888 pCurr = BSSpSearchBSSList(pDevice,
889 pMgmt->abyDesireBSSID,
890 pMgmt->abyDesireSSID,
891 pMgmt->eConfigPHYMode
892 );
893
894 if (pCurr == NULL){
895 printk("wpa_set_associate---->hidden mode site survey before associate.......\n");
896 bScheduleCommand((HANDLE) pDevice, WLAN_CMD_BSSID_SCAN, pMgmt->abyDesireSSID);
897 };
898}
899/****************************************************************/
900 bScheduleCommand((HANDLE) pDevice, WLAN_CMD_SSID, NULL);
901 spin_unlock_irq(&pDevice->lock);
902
903 return ret;
904}
905
906
907/*
908 * Description:
909 * wpa_ioctl main function supported for wpa supplicant
910 *
911 * Parameters:
912 * In:
913 * pDevice -
914 * iw_point -
915 * Out:
916 *
917 * Return Value:
918 *
919 */
920
921int wpa_ioctl(PSDevice pDevice, struct iw_point *p)
922{
923 struct viawget_wpa_param *param;
924 int ret = 0;
925 int wpa_ioctl = 0;
926
927 if (p->length < sizeof(struct viawget_wpa_param) ||
928 p->length > VIAWGET_WPA_MAX_BUF_SIZE || !p->pointer)
929 return -EINVAL;
930
931 param = (struct viawget_wpa_param *) kmalloc((int)p->length, (int)GFP_KERNEL);
932 if (param == NULL)
933 return -ENOMEM;
934
935 if (copy_from_user(param, p->pointer, p->length)) {
936 ret = -EFAULT;
937 goto out;
938 }
939
940 switch (param->cmd) {
941 case VIAWGET_SET_WPA:
942 ret = wpa_set_wpa(pDevice, param);
943 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "VIAWGET_SET_WPA \n");
944 break;
945
946 case VIAWGET_SET_KEY:
947 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "VIAWGET_SET_KEY \n");
948 spin_lock_irq(&pDevice->lock);
949 ret = wpa_set_keys(pDevice, param, FALSE);
950 spin_unlock_irq(&pDevice->lock);
951 break;
952
953 case VIAWGET_SET_SCAN:
954 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "VIAWGET_SET_SCAN \n");
955 ret = wpa_set_scan(pDevice, param);
956 break;
957
958 case VIAWGET_GET_SCAN:
959 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "VIAWGET_GET_SCAN\n");
960 ret = wpa_get_scan(pDevice, param);
961 wpa_ioctl = 1;
962 break;
963
964 case VIAWGET_GET_SSID:
965 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "VIAWGET_GET_SSID \n");
966 ret = wpa_get_ssid(pDevice, param);
967 wpa_ioctl = 1;
968 break;
969
970 case VIAWGET_GET_BSSID:
971 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "VIAWGET_GET_BSSID \n");
972 ret = wpa_get_bssid(pDevice, param);
973 wpa_ioctl = 1;
974 break;
975
976 case VIAWGET_SET_ASSOCIATE:
977 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "VIAWGET_SET_ASSOCIATE \n");
978 ret = wpa_set_associate(pDevice, param);
979 break;
980
981 case VIAWGET_SET_DISASSOCIATE:
982 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "VIAWGET_SET_DISASSOCIATE \n");
983 ret = wpa_set_disassociate(pDevice, param);
984 break;
985
986 case VIAWGET_SET_DROP_UNENCRYPT:
987 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "VIAWGET_SET_DROP_UNENCRYPT \n");
988 break;
989
990 case VIAWGET_SET_DEAUTHENTICATE:
991 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "VIAWGET_SET_DEAUTHENTICATE \n");
992 break;
993
994 default:
995 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "wpa_ioctl: unknown cmd=%d\n",
996 param->cmd);
997 return -EOPNOTSUPP;
998 break;
999 }
1000
1001 if ((ret == 0) && wpa_ioctl) {
1002 if (copy_to_user(p->pointer, param, p->length)) {
1003 ret = -EFAULT;
1004 goto out;
1005 }
1006 }
1007
1008out:
1009 if (param != NULL)
1010 kfree(param);
1011
1012 return ret;
1013}
1014
diff --git a/drivers/staging/vt6655/wpactl.h b/drivers/staging/vt6655/wpactl.h
new file mode 100644
index 000000000000..9e7889785306
--- /dev/null
+++ b/drivers/staging/vt6655/wpactl.h
@@ -0,0 +1,89 @@
1/*
2 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
3 * All rights reserved.
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * File: wpactl.h
20 *
21 * Purpose:
22 *
23 * Author: Lyndon Chen
24 *
25 * Date: March 1, 2005
26 *
27 */
28
29
30#ifndef __WPACTL_H__
31#define __WPACTL_H__
32
33#if !defined(__DEVICE_H__)
34#include "device.h"
35#endif
36#ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
37#if !defined(__IOWPA_H__)
38#include "iowpa.h"
39#endif
40#endif
41
42/*--------------------- Export Definitions -------------------------*/
43
44
45//WPA related
46
47typedef enum { WPA_ALG_NONE, WPA_ALG_WEP, WPA_ALG_TKIP, WPA_ALG_CCMP } wpa_alg;
48typedef enum { CIPHER_NONE, CIPHER_WEP40, CIPHER_TKIP, CIPHER_CCMP,
49 CIPHER_WEP104 } wpa_cipher;
50typedef enum { KEY_MGMT_802_1X, KEY_MGMT_CCKM,KEY_MGMT_PSK, KEY_MGMT_NONE,
51 KEY_MGMT_802_1X_NO_WPA, KEY_MGMT_WPA_NONE } wpa_key_mgmt;
52
53#define AUTH_ALG_OPEN_SYSTEM 0x01
54#define AUTH_ALG_SHARED_KEY 0x02
55#define AUTH_ALG_LEAP 0x04
56
57#define GENERIC_INFO_ELEM 0xdd
58#define RSN_INFO_ELEM 0x30
59
60
61
62typedef ULONGLONG NDIS_802_11_KEY_RSC;
63
64/*--------------------- Export Classes ----------------------------*/
65
66/*--------------------- Export Variables --------------------------*/
67
68/*--------------------- Export Functions --------------------------*/
69
70
71#ifdef __cplusplus
72extern "C" { /* Assume C declarations for C++ */
73#endif /* __cplusplus */
74
75int wpa_set_wpadev(PSDevice pDevice, int val);
76int wpa_ioctl(PSDevice pDevice, struct iw_point *p);
77int wpa_set_keys(PSDevice pDevice, void *ctx, BOOL fcpfkernel);
78
79#ifdef __cplusplus
80} /* End of extern "C" { */
81#endif /* __cplusplus */
82
83
84
85
86#endif // __WPACL_H__
87
88
89
diff --git a/drivers/staging/vt6655/wroute.c b/drivers/staging/vt6655/wroute.c
new file mode 100644
index 000000000000..219ae21654e2
--- /dev/null
+++ b/drivers/staging/vt6655/wroute.c
@@ -0,0 +1,211 @@
1/*
2 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
3 * All rights reserved.
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * File: wroute.c
20 *
21 * Purpose: handle WMAC frame relay & filterring
22 *
23 * Author: Lyndon Chen
24 *
25 * Date: May 20, 2003
26 *
27 * Functions:
28 * ROUTEbRelay - Relay packet
29 *
30 * Revision History:
31 *
32 */
33
34
35#if !defined(__MAC_H__)
36#include "mac.h"
37#endif
38#if !defined(__TCRC_H__)
39#include "tcrc.h"
40#endif
41#if !defined(__RXTX_H__)
42#include "rxtx.h"
43#endif
44#if !defined(__WROUTE_H__)
45#include "wroute.h"
46#endif
47#if !defined(__CARD_H__)
48#include "card.h"
49#endif
50#if !defined(__BASEBAND_H__)
51#include "baseband.h"
52#endif
53/*--------------------- Static Definitions -------------------------*/
54
55/*--------------------- Static Classes ----------------------------*/
56
57/*--------------------- Static Variables --------------------------*/
58static int msglevel =MSG_LEVEL_INFO;
59//static int msglevel =MSG_LEVEL_DEBUG;
60/*--------------------- Static Functions --------------------------*/
61
62/*--------------------- Export Variables --------------------------*/
63
64
65
66/*
67 * Description:
68 * Relay packet. Return TRUE if packet is copy to DMA1
69 *
70 * Parameters:
71 * In:
72 * pDevice -
73 * pbySkbData - rx packet skb data
74 * Out:
75 * TURE, FALSE
76 *
77 * Return Value: TRUE if packet duplicate; otherwise FALSE
78 *
79 */
80BOOL ROUTEbRelay (PSDevice pDevice, PBYTE pbySkbData, UINT uDataLen, UINT uNodeIndex)
81{
82 PSMgmtObject pMgmt = pDevice->pMgmt;
83 PSTxDesc pHeadTD, pLastTD;
84 UINT cbFrameBodySize;
85 UINT uMACfragNum;
86 BYTE byPktTyp;
87 BOOL bNeedEncryption = FALSE;
88 SKeyItem STempKey;
89 PSKeyItem pTransmitKey = NULL;
90 UINT cbHeaderSize;
91 UINT ii;
92 PBYTE pbyBSSID;
93
94
95
96
97 if (AVAIL_TD(pDevice, TYPE_AC0DMA)<=0) {
98 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Relay can't allocate TD1..\n");
99 return FALSE;
100 }
101
102 pHeadTD = pDevice->apCurrTD[TYPE_AC0DMA];
103
104 pHeadTD->m_td1TD1.byTCR = (TCR_EDP|TCR_STP);
105
106 memcpy(pDevice->sTxEthHeader.abyDstAddr, (PBYTE)pbySkbData, U_HEADER_LEN);
107
108 cbFrameBodySize = uDataLen - U_HEADER_LEN;
109
110 if (ntohs(pDevice->sTxEthHeader.wType) > MAX_DATA_LEN) {
111 cbFrameBodySize += 8;
112 }
113
114 if (pDevice->bEncryptionEnable == TRUE) {
115 bNeedEncryption = TRUE;
116
117 // get group key
118 pbyBSSID = pDevice->abyBroadcastAddr;
119 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == FALSE) {
120 pTransmitKey = NULL;
121 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"KEY is NULL. [%d]\n", pDevice->pMgmt->eCurrMode);
122 } else {
123 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"Get GTK.\n");
124 }
125 }
126
127 if (pDevice->bEnableHostWEP) {
128 if (uNodeIndex >= 0) {
129 pTransmitKey = &STempKey;
130 pTransmitKey->byCipherSuite = pMgmt->sNodeDBTable[uNodeIndex].byCipherSuite;
131 pTransmitKey->dwKeyIndex = pMgmt->sNodeDBTable[uNodeIndex].dwKeyIndex;
132 pTransmitKey->uKeyLength = pMgmt->sNodeDBTable[uNodeIndex].uWepKeyLength;
133 pTransmitKey->dwTSC47_16 = pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16;
134 pTransmitKey->wTSC15_0 = pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0;
135 memcpy(pTransmitKey->abyKey,
136 &pMgmt->sNodeDBTable[uNodeIndex].abyWepKey[0],
137 pTransmitKey->uKeyLength
138 );
139 }
140 }
141
142 uMACfragNum = cbGetFragCount(pDevice, pTransmitKey, cbFrameBodySize, &pDevice->sTxEthHeader);
143
144 if (uMACfragNum > AVAIL_TD(pDevice,TYPE_AC0DMA)) {
145 return FALSE;
146 }
147 byPktTyp = (BYTE)pDevice->byPacketType;
148
149 if (pDevice->bFixRate) {
150 if (pDevice->eCurrentPHYType == PHY_TYPE_11B) {
151 if (pDevice->uConnectionRate >= RATE_11M) {
152 pDevice->wCurrentRate = RATE_11M;
153 } else {
154 pDevice->wCurrentRate = (WORD)pDevice->uConnectionRate;
155 }
156 } else {
157 if ((pDevice->eCurrentPHYType == PHY_TYPE_11A) &&
158 (pDevice->uConnectionRate <= RATE_6M)) {
159 pDevice->wCurrentRate = RATE_6M;
160 } else {
161 if (pDevice->uConnectionRate >= RATE_54M)
162 pDevice->wCurrentRate = RATE_54M;
163 else
164 pDevice->wCurrentRate = (WORD)pDevice->uConnectionRate;
165 }
166 }
167 }
168 else {
169 pDevice->wCurrentRate = pDevice->pMgmt->sNodeDBTable[uNodeIndex].wTxDataRate;
170 }
171
172 if (pDevice->wCurrentRate <= RATE_11M)
173 byPktTyp = PK_TYPE_11B;
174
175 vGenerateFIFOHeader(pDevice, byPktTyp, pDevice->pbyTmpBuff, bNeedEncryption,
176 cbFrameBodySize, TYPE_AC0DMA, pHeadTD,
177 &pDevice->sTxEthHeader, pbySkbData, pTransmitKey, uNodeIndex,
178 &uMACfragNum,
179 &cbHeaderSize
180 );
181
182 if (MACbIsRegBitsOn(pDevice->PortOffset, MAC_REG_PSCTL, PSCTL_PS)) {
183 // Disable PS
184 MACbPSWakeup(pDevice->PortOffset);
185 }
186
187 pDevice->bPWBitOn = FALSE;
188
189 pLastTD = pHeadTD;
190 for (ii = 0; ii < uMACfragNum; ii++) {
191 // Poll Transmit the adapter
192 wmb();
193 pHeadTD->m_td0TD0.f1Owner=OWNED_BY_NIC;
194 wmb();
195 if (ii == (uMACfragNum - 1))
196 pLastTD = pHeadTD;
197 pHeadTD = pHeadTD->next;
198 }
199
200 pLastTD->pTDInfo->skb = 0;
201 pLastTD->pTDInfo->byFlags = 0;
202
203 pDevice->apCurrTD[TYPE_AC0DMA] = pHeadTD;
204
205 MACvTransmitAC0(pDevice->PortOffset);
206
207 return TRUE;
208}
209
210
211
diff --git a/drivers/staging/vt6655/wroute.h b/drivers/staging/vt6655/wroute.h
new file mode 100644
index 000000000000..ea5f5896e9ba
--- /dev/null
+++ b/drivers/staging/vt6655/wroute.h
@@ -0,0 +1,65 @@
1/*
2 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
3 * All rights reserved.
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * File: wroute.h
20 *
21 * Purpose:
22 *
23 * Author: Lyndon Chen
24 *
25 * Date: May 21, 2003
26 *
27 */
28
29
30#ifndef __WROUTE_H__
31#define __WROUTE_H__
32
33
34#if !defined(__DEVICE_H__)
35#include "device.h"
36#endif
37
38
39
40/*--------------------- Export Definitions -------------------------*/
41
42/*--------------------- Export Classes ----------------------------*/
43
44/*--------------------- Export Variables --------------------------*/
45
46/*--------------------- Export Functions --------------------------*/
47
48
49#ifdef __cplusplus
50extern "C" { /* Assume C declarations for C++ */
51#endif /* __cplusplus */
52
53BOOL ROUTEbRelay (PSDevice pDevice, PBYTE pbySkbData, UINT uDataLen, UINT uNodeIndex);
54
55#ifdef __cplusplus
56} /* End of extern "C" { */
57#endif /* __cplusplus */
58
59
60
61
62#endif // __WROUTE_H__
63
64
65