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 #include <linux/skbuff.h>
34 #include "80211hdr.h"
35 #include "80211mgr.h"
36 #include "card.h"
37 #include "mib.h"
38 
39 /*---------------------  Export Definitions -------------------------*/
40 
41 #define MAX_NODE_NUM             64
42 #define MAX_BSS_NUM              42
43 #define LOST_BEACON_COUNT        10   /* 10 sec, XP defined */
44 #define MAX_PS_TX_BUF            32   // sta max power saving tx buf
45 #define ADHOC_LOST_BEACON_COUNT  30   // 30 sec, beacon lost for adhoc only
46 #define MAX_INACTIVE_COUNT       300  // 300 sec, inactive STA node refresh
47 
48 #define USE_PROTECT_PERIOD       10   // 10 sec, Use protect mode check period
49 #define ERP_RECOVER_COUNT        30   // 30 sec, ERP support callback check
50 #define BSS_CLEAR_COUNT           1
51 
52 #define RSSI_STAT_COUNT          10
53 #define MAX_CHECK_RSSI_COUNT     8
54 
55 // STA dwflags
56 #define WLAN_STA_AUTH            BIT0
57 #define WLAN_STA_ASSOC           BIT1
58 #define WLAN_STA_PS              BIT2
59 #define WLAN_STA_TIM             BIT3
60 // permanent; do not remove entry on expiration
61 #define WLAN_STA_PERM            BIT4
62 // If 802.1X is used, this flag is
63 // controlling whether STA is authorized to
64 // send and receive non-IEEE 802.1X frames
65 #define WLAN_STA_AUTHORIZED      BIT5
66 
67 //#define MAX_RATE            12
68 
69 #define MAX_WPA_IE_LEN      64
70 
71 
72 /*---------------------  Export Classes  ----------------------------*/
73 
74 /*---------------------  Export Variables  --------------------------*/
75 
76 
77 /*---------------------  Export Types  ------------------------------*/
78 
79 //
80 // IEEE 802.11 Structures and definitions
81 //
82 
83 typedef struct tagSERPObject {
84     BOOL    bERPExist;
85     BYTE    byERP;
86 } ERPObject, *PERPObject;
87 
88 
89 typedef struct tagSRSNCapObject {
90     BOOL    bRSNCapExist;
91     WORD    wRSNCap;
92 } SRSNCapObject, *PSRSNCapObject;
93 
94 // BSS info(AP)
95 typedef struct tagKnownBSS {
96     // BSS info
97     BOOL            bActive;
98     BYTE            abyBSSID[WLAN_BSSID_LEN];
99     unsigned int            uChannel;
100     BYTE            abySuppRates[WLAN_IEHDR_LEN + WLAN_RATES_MAXLEN + 1];
101     BYTE            abyExtSuppRates[WLAN_IEHDR_LEN + WLAN_RATES_MAXLEN + 1];
102     unsigned int            uRSSI;
103     BYTE            bySQ;
104     WORD            wBeaconInterval;
105     WORD            wCapInfo;
106     BYTE            abySSID[WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1];
107     BYTE            byRxRate;
108 
109 //    WORD            wATIMWindow;
110     BYTE            byRSSIStatCnt;
111     signed long            ldBmMAX;
112     signed long            ldBmAverage[RSSI_STAT_COUNT];
113     signed long            ldBmAverRange;
114     //For any BSSID selection improvment
115     BOOL            bSelected;
116 
117     //++ WPA informations
118     BOOL            bWPAValid;
119     BYTE            byGKType;
120     BYTE            abyPKType[4];
121     WORD            wPKCount;
122     BYTE            abyAuthType[4];
123     WORD            wAuthCount;
124     BYTE            byDefaultK_as_PK;
125     BYTE            byReplayIdx;
126     //--
127 
128     //++ WPA2 informations
129     BOOL            bWPA2Valid;
130     BYTE            byCSSGK;
131     WORD            wCSSPKCount;
132     BYTE            abyCSSPK[4];
133     WORD            wAKMSSAuthCount;
134     BYTE            abyAKMSSAuthType[4];
135 
136     //++  wpactl
137     BYTE            byWPAIE[MAX_WPA_IE_LEN];
138     BYTE            byRSNIE[MAX_WPA_IE_LEN];
139     WORD            wWPALen;
140     WORD            wRSNLen;
141 
142     // Clear count
143     unsigned int            uClearCount;
144 //    BYTE            abyIEs[WLAN_BEACON_FR_MAXLEN];
145     unsigned int            uIELength;
146     QWORD           qwBSSTimestamp;
147     QWORD           qwLocalTSF;     // local TSF timer
148 
149     CARD_PHY_TYPE   eNetworkTypeInUse;
150 
151     ERPObject       sERP;
152     SRSNCapObject   sRSNCapObj;
153     BYTE            abyIEs[1024];   // don't move this field !!
154 
155 } __attribute__ ((__packed__))
156 KnownBSS , *PKnownBSS;
157 
158 
159 
160 typedef enum tagNODE_STATE {
161     NODE_FREE,
162     NODE_AGED,
163     NODE_KNOWN,
164     NODE_AUTH,
165     NODE_ASSOC
166 } NODE_STATE, *PNODE_STATE;
167 
168 
169 // STA node info
170 typedef struct tagKnownNodeDB {
171     // STA info
172     BOOL            bActive;
173     BYTE            abyMACAddr[WLAN_ADDR_LEN];
174     BYTE            abyCurrSuppRates[WLAN_IEHDR_LEN + WLAN_RATES_MAXLEN];
175     BYTE            abyCurrExtSuppRates[WLAN_IEHDR_LEN + WLAN_RATES_MAXLEN];
176     WORD            wTxDataRate;
177     BOOL            bShortPreamble;
178     BOOL            bERPExist;
179     BOOL            bShortSlotTime;
180     unsigned int            uInActiveCount;
181     WORD            wMaxBasicRate;     //Get from byTopOFDMBasicRate or byTopCCKBasicRate which depends on packetTyp.
182     WORD            wMaxSuppRate;      //Records the highest supported rate getting from SuppRates IE and ExtSuppRates IE in Beacon.
183     WORD            wSuppRate;
184     BYTE            byTopOFDMBasicRate;//Records the highest basic rate in OFDM mode
185     BYTE            byTopCCKBasicRate; //Records the highest basic rate in CCK mode
186 
187     // For AP mode
188     struct sk_buff_head sTxPSQueue;
189     WORD            wCapInfo;
190     WORD            wListenInterval;
191     WORD            wAID;
192     NODE_STATE      eNodeState;
193     BOOL            bPSEnable;
194     BOOL            bRxPSPoll;
195     BYTE            byAuthSequence;
196     unsigned long           ulLastRxJiffer;
197     BYTE            bySuppRate;
198     DWORD           dwFlags;
199     WORD            wEnQueueCnt;
200 
201     BOOL            bOnFly;
202     unsigned long long       KeyRSC;
203     BYTE            byKeyIndex;
204     DWORD           dwKeyIndex;
205     BYTE            byCipherSuite;
206     DWORD           dwTSC47_16;
207     WORD            wTSC15_0;
208     unsigned int            uWepKeyLength;
209     BYTE            abyWepKey[WLAN_WEPMAX_KEYLEN];
210     //
211     // Auto rate fallback vars
212     BOOL            bIsInFallback;
213     unsigned int            uAverageRSSI;
214     unsigned int            uRateRecoveryTimeout;
215     unsigned int            uRatePollTimeout;
216     unsigned int            uTxFailures;
217     unsigned int            uTxAttempts;
218 
219     unsigned int            uTxRetry;
220     unsigned int            uFailureRatio;
221     unsigned int            uRetryRatio;
222     unsigned int            uTxOk[MAX_RATE+1];
223     unsigned int            uTxFail[MAX_RATE+1];
224     unsigned int            uTimeCount;
225 
226 } KnownNodeDB, *PKnownNodeDB;
227 
228 /*---------------------  Export Functions  --------------------------*/
229 
230 PKnownBSS BSSpSearchBSSList(void *hDeviceContext,
231 			    PBYTE pbyDesireBSSID,
232 			    PBYTE pbyDesireSSID,
233 			    CARD_PHY_TYPE ePhyType);
234 
235 PKnownBSS BSSpAddrIsInBSSList(void *hDeviceContext,
236 			      PBYTE abyBSSID,
237 			      PWLAN_IE_SSID pSSID);
238 
239 void BSSvClearBSSList(void *hDeviceContext, BOOL bKeepCurrBSSID);
240 
241 BOOL BSSbInsertToBSSList(void *hDeviceContext,
242 			 PBYTE abyBSSIDAddr,
243 			 QWORD qwTimestamp,
244 			 WORD wBeaconInterval,
245 			 WORD wCapInfo,
246 			 BYTE byCurrChannel,
247 			 PWLAN_IE_SSID pSSID,
248 			 PWLAN_IE_SUPP_RATES pSuppRates,
249 			 PWLAN_IE_SUPP_RATES pExtSuppRates,
250 			 PERPObject psERP,
251 			 PWLAN_IE_RSN pRSN,
252 			 PWLAN_IE_RSN_EXT pRSNWPA,
253 			 PWLAN_IE_COUNTRY pIE_Country,
254 			 PWLAN_IE_QUIET pIE_Quiet,
255 			 unsigned int uIELength,
256 			 PBYTE pbyIEs,
257 			 void *pRxPacketContext);
258 
259 BOOL BSSbUpdateToBSSList(void *hDeviceContext,
260 			 QWORD qwTimestamp,
261 			 WORD wBeaconInterval,
262 			 WORD wCapInfo,
263 			 BYTE byCurrChannel,
264 			 BOOL bChannelHit,
265 			 PWLAN_IE_SSID pSSID,
266 			 PWLAN_IE_SUPP_RATES pSuppRates,
267 			 PWLAN_IE_SUPP_RATES pExtSuppRates,
268 			 PERPObject psERP,
269 			 PWLAN_IE_RSN pRSN,
270 			 PWLAN_IE_RSN_EXT pRSNWPA,
271 			 PWLAN_IE_COUNTRY pIE_Country,
272 			 PWLAN_IE_QUIET pIE_Quiet,
273 			 PKnownBSS pBSSList,
274 			 unsigned int uIELength,
275 			 PBYTE pbyIEs,
276 			 void *pRxPacketContext);
277 
278 BOOL BSSbIsSTAInNodeDB(void *hDeviceContext,
279 		       PBYTE abyDstAddr,
280 		       unsigned int *puNodeIndex);
281 
282 void BSSvCreateOneNode(void *hDeviceContext, unsigned int *puNodeIndex);
283 
284 void BSSvUpdateAPNode(void *hDeviceContext,
285 		      PWORD pwCapInfo,
286 		      PWLAN_IE_SUPP_RATES pItemRates,
287 		      PWLAN_IE_SUPP_RATES pExtSuppRates);
288 
289 void BSSvSecondCallBack(void *hDeviceContext);
290 
291 void BSSvUpdateNodeTxCounter(void *hDeviceContext,
292 			     PSStatCounter pStatistic,
293 			     BYTE byTSR,
294 			     BYTE byPktNO);
295 
296 void BSSvRemoveOneNode(void *hDeviceContext,
297 		       unsigned int uNodeIndex);
298 
299 void BSSvAddMulticastNode(void *hDeviceContext);
300 
301 void BSSvClearNodeDBTable(void *hDeviceContext,
302 			  unsigned int uStartIndex);
303 
304 void BSSvClearAnyBSSJoinRecord(void *hDeviceContext);
305 
306 #endif /* __BSSDB_H__ */
307