MOXA linux-2.6.x / linux-2.6.9-uc0 from sdlinux-moxaart.tgz
[linux-2.6.9-moxart.git] / drivers / usb / net / Zydas / zdsynch.c
blob9c7c38e50d60425222f7898faec8fb4d8cd43bb4
1 #ifndef __ZDSYNCH_C__
2 #define __ZDSYNCH_C__
4 #include "zd80211.h"
5 extern u8 LastMacMode;
6 extern u8 mMacMode;
7 //extern CurrScanCH;
8 extern const U16 dot11A_Channel[];
9 extern u8 LastSetChannel;
11 void zd_makeRateInfoMAP(U8 *pRates, U16 *basicRateMap, U16 *supRateMap)
13 int j;
14 U8 rate;
15 U8 eleLen = *(pRates+1);
17 for (j=0; j<eleLen; j++){
18 rate = *(pRates+2+j);
19 switch (rate & 0x7f){
20 case SR_1M:
21 *supRateMap |= BIT_0;
22 if (rate & 0x80)
23 *basicRateMap |= BIT_0;
24 break;
26 case SR_2M:
27 *supRateMap |= BIT_1;
28 if (rate & 0x80)
29 *basicRateMap |= BIT_1;
30 break;
32 case SR_5_5M:
33 *supRateMap |= BIT_2;
34 if (rate & 0x80)
35 *basicRateMap |= BIT_2;
36 break;
38 case SR_11M:
39 *supRateMap |= BIT_3;
40 if (rate & 0x80)
41 *basicRateMap |= BIT_3;
42 break;
44 case SR_6M:
45 *supRateMap |= BIT_4;
46 if (rate & 0x80)
47 *basicRateMap |= BIT_4;
48 break;
50 case SR_9M:
51 *supRateMap |= BIT_5;
52 if (rate & 0x80)
53 *basicRateMap |= BIT_5;
54 break;
56 case SR_12M:
57 *supRateMap |= BIT_6;
58 if (rate & 0x80)
59 *basicRateMap |= BIT_6;
60 break;
62 case SR_18M:
63 *supRateMap |= BIT_7;
64 if (rate & 0x80)
65 *basicRateMap |= BIT_7;
66 break;
68 case SR_24M:
69 *supRateMap |= BIT_8;
70 if (rate & 0x80)
71 *basicRateMap |= BIT_8;
72 break;
74 case SR_36M:
75 *supRateMap |= BIT_9;
76 if (rate & 0x80)
77 *basicRateMap |= BIT_9;
78 break;
80 case SR_48M:
81 *supRateMap |= BIT_10;
82 if (rate & 0x80)
83 *basicRateMap |= BIT_10;
84 break;
86 case SR_54M:
87 *supRateMap |= BIT_11;
88 if (rate & 0x80)
89 *basicRateMap |= BIT_11;
90 break;
92 #if 0
93 case SR_16_5M:
94 *supRateMap |= BIT_12;
95 if (rate & 0x80)
96 *basicRateMap |= BIT_12;
97 break;
99 case SR_27_5M:
100 *supRateMap |= BIT_13;
101 if (rate & 0x80)
102 *basicRateMap |= BIT_13;
103 break;
104 #endif
105 default:
107 break;
112 BOOLEAN Probe(Signal_t *signal)
114 FrmDesc_t *pfrmDesc;
115 Frame_t *rdu;
116 MacAddr_t sta;
117 Element rSsid;
118 Element *pWPA = NULL;
119 U8 vapId = 0;
120 Element *pExtRate = NULL;
122 ZDEBUG("Probe");
125 pfrmDesc = signal->frmInfo.frmDesc;
126 rdu = pfrmDesc->mpdu;
128 if (mBssType == INFRASTRUCTURE_BSS){
129 goto release;
132 if (!getElem(rdu, EID_SSID, &rSsid,1))
133 goto release;
135 if (mHiddenSSID){ //discard broadcast ssid
136 if (eLen(&rSsid) == 0){
137 goto release;
141 memcpy((U8*)&sta, (U8*)addr2(rdu), 6);
142 pExtRate = &mExtRates;
146 if (eLen(&rSsid) == 0){
147 //WPA
148 if (mDynKeyMode == DYN_KEY_TKIP || mDynKeyMode==DYN_KEY_AES)
149 pWPA = &mWPAIe;
152 mkProbeRspFrm(pfrmDesc, &sta, mBeaconPeriod, mCap, &dot11DesiredSsid, &mBrates, &mPhpm, pExtRate, (Element *)pWPA, vapId);
153 return sendMgtFrame(signal, pfrmDesc);
155 else{
156 if (memcmp(&rSsid, &dot11DesiredSsid, eLen(&dot11DesiredSsid)+2) == 0){
157 //WPA
158 if ((mDynKeyMode == DYN_KEY_TKIP) || (mDynKeyMode == DYN_KEY_AES))
159 pWPA = &mWPAIe;
161 mkProbeRspFrm(pfrmDesc, &sta, mBeaconPeriod, mCap, &dot11DesiredSsid, &mBrates, &mPhpm, pExtRate, (Element *)pWPA, vapId);
162 return sendMgtFrame(signal, pfrmDesc);
166 release:
167 ZDEBUG("goto release");
168 freeFdesc(pfrmDesc);
169 return TRUE;
172 BOOLEAN ProbeReq(Signal_t *signal)
174 FrmDesc_t *pfrmDesc;
175 Element BCSsid;
176 U8 vapId = 0;
177 Element *pSsid = NULL;
178 Element *pExtRate = NULL;
180 ZDEBUG("ProbeReq");
181 //FPRINT("ProbeReq");
183 pfrmDesc = allocFdesc();
184 if(!pfrmDesc){
185 sigEnque(pMgtQ, (signal));
186 return FALSE;
189 BCSsid.buf[0] = EID_SSID;
190 BCSsid.buf[1] = 0;
193 if (mProbeWithSsid){
194 //pSsid = &mSsid;
195 pSsid = &dot11DesiredSsid;
196 } else {
197 pSsid = &BCSsid;
200 pExtRate = &mExtRates;
202 mkProbeReqFrm(pfrmDesc, &dot11BCAddress, pSsid, &mBrates, pExtRate, NULL, vapId);
203 if (signal->vapId == 0)
204 pdot11Obj->StartTimer(SCAN_TIMEOUT, DO_SCAN);
205 //mProbeWithSsid = FALSE;
206 return sendMgtFrame(signal, pfrmDesc);
209 BOOLEAN ProbeRsp_Beacon(Signal_t *signal)
211 FrmDesc_t *pfrmDesc;
212 Frame_t *rdu;
213 MacAddr_t *pBssid = NULL;
214 //Element *pWPA = NULL;
215 U16 Cap = 0;
216 U16 BcnInterval = 0;
217 int i;
218 U8 FrmType;
219 BOOLEAN bUpdateInfo = FALSE;
220 U8 index;
221 U8 elemIdx=1;
222 #if ZDCONF_LP_SUPPORT == 1
223 Element tmpElement ;
224 #endif
225 #if ZDCONF_SES_SUPPORT == 1
226 U8 SES_OUI[] = { 0x00, 0x90, 0x4C };
227 #endif
228 u8 WPA_OUI[4]={0x00, 0x50, 0xF2, 0x01};
229 U16 loopCheck = 0;
230 U8 *pAddr2ForIBSS;
234 BssInfo_t *pCurrBssInfo;
236 ZDEBUG("ProbeRsp_Beacon");
237 pfrmDesc = signal->frmInfo.frmDesc;
238 rdu = pfrmDesc->mpdu;
240 FrmType = frmType(rdu);
242 if (pdot11Obj->ConfigFlag & ACTIVE_CHANNEL_SCAN_SET){
243 Cap = cap1(rdu);
244 //FPRINT_V("Cap", Cap);
245 BcnInterval = beaconInt(rdu);
247 pAddr2ForIBSS = (u8*) addr2(rdu);
248 if (Cap & CAP_IBSS){
249 pBssid = addr3(rdu);
251 else
252 pBssid = addr3(rdu);
254 index = mBssNum;
255 //The following if-statements is used to filter existing AP Info.
256 //The rule is:
257 //1. The bssid is seen before.
258 //2. The old Info.apMode equals to LastMacMode
259 //The meaning is if the incoming ap's bssid == old's bssid and
260 // ap's apMode(judged by LastMacMode) == old's apMode then Drop It.
261 for (i=0; i<mBssNum; i++){
262 if ((memcmp((U8 *)&mBssInfo[i].bssid, (U8 *)pBssid, 6) == 0) &&
263 ((PURE_A_AP==mBssInfo[i].apMode&& PURE_A_MODE==LastMacMode) ||
264 (PURE_A_AP!=mBssInfo[i].apMode&& PURE_A_MODE!=LastMacMode)
267 if (FrmType == ST_BEACON) {
268 goto release;
270 else {
271 bUpdateInfo = TRUE;
272 index = i;
277 pCurrBssInfo = &mBssInfo[index];
278 pCurrBssInfo->basicRateMap = 0;
279 pCurrBssInfo->supRateMap = 0;
281 /* Reset supRates, extRates */
282 memset(&pCurrBssInfo->supRates, 0, NUM_SUPPORTED_RATE);
283 memset(&pCurrBssInfo->extRates, 0, NUM_SUPPORTED_RATE);
284 #if ZDCONF_LP_SUPPORT == 1
285 memset(&pCurrBssInfo->zdIE_BURST,0, sizeof(Element));
286 memset(&pCurrBssInfo->zdIE_AMSDU,0, sizeof(Element));
287 memset(&tmpElement,0, sizeof(Element));
288 #endif
289 #if ZDCONF_SES_SUPPORT == 1
290 memset(&pCurrBssInfo->SES_Element,0, sizeof(Element));
291 pCurrBssInfo->SES_Element_Valid = FALSE;
292 #endif
294 //get bssid
295 memcpy((U8 *)&pCurrBssInfo->bssid, (U8 *)pBssid, 6);
297 //get beacon interval
298 pCurrBssInfo->bcnInterval = BcnInterval;
300 //get capability
301 pCurrBssInfo->cap = Cap;
303 if (!getElem(rdu, EID_SSID, &pCurrBssInfo->ssid,1)){
304 goto release;
307 if (!getElem(rdu, EID_SUPRATES, &pCurrBssInfo->supRates,1)){
308 goto release;
311 if (!getElem(rdu, EID_DSPARMS, &pCurrBssInfo->Phpm,1)){
312 pCurrBssInfo->Phpm.buf[0]=0x3;// DS Parameter Set
313 pCurrBssInfo->Phpm.buf[1]=1;
314 if (!(Cap & CAP_IBSS)) // In IBSS use the ch carried in Beacon/Rsp
315 pCurrBssInfo->Phpm.buf[2]=LastSetChannel;
316 //goto release;
318 #if ZDCONF_LP_SUPPORT == 1
319 elemIdx = 1;
320 while(getElem(rdu, EID_ZYDAS, &tmpElement,elemIdx))
322 //If elemIdx++ doesn't execute, there would be endless loop.
323 if(loopCheck++ > 100)
325 printk("infinite loop occurs in %s\n", __FUNCTION__);
326 loopCheck = 0;
327 break;
330 elemIdx++;
331 if(tmpElement.buf[2] == (U8)ZDOUI_AMSDU &&
332 tmpElement.buf[3] == (U8)(ZDOUI_AMSDU >> 8) &&
333 tmpElement.buf[4] == (U8)(ZDOUI_AMSDU >> 16) )
335 memcpy(&pCurrBssInfo->zdIE_AMSDU, &tmpElement, sizeof(Element));
337 else if(tmpElement.buf[2] == (U8)ZDOUI_BURST &&
338 tmpElement.buf[3] == (U8)(ZDOUI_BURST >> 8) &&
339 tmpElement.buf[4] == (U8)(ZDOUI_BURST >> 16) )
341 memcpy(&pCurrBssInfo->zdIE_BURST, &tmpElement, sizeof(Element));
344 #endif
345 #if ZDCONF_SES_SUPPORT
346 elemIdx=1;
347 while(getElem(rdu, EID_WPA, &(pCurrBssInfo->SES_Element), elemIdx))
349 //if elemIdx++ doesn't execute, endless loop occur
350 if(loopCheck++ > 100)
352 printk("infinite loop occurs in %s\n", __FUNCTION__);
353 loopCheck = 0;
354 break;
357 if(pCurrBssInfo->SES_Element.buf[1] >= 3)
359 if(memcmp(pCurrBssInfo->SES_Element.buf+2, SES_OUI, sizeof(SES_OUI)) == 0)
361 pCurrBssInfo->SES_Element_Valid = TRUE;
362 break;
365 elemIdx++;
367 #endif
369 //This is used to filter non-allowed channel beacons
370 if (!((1 << (pCurrBssInfo->Phpm.buf[2]-1)) & pdot11Obj->AllowedChannel)){
371 if(PURE_A_MODE != mMacMode)
372 goto release;
375 if (Cap & CAP_IBSS){
376 if (!getElem(rdu, EID_IBPARMS, &pCurrBssInfo->IbssParms,1)){
377 goto release;
381 if (getElem(rdu, EID_EXT_RATES, &pCurrBssInfo->extRates,1)){
382 //zd1205_dump_data("Ext Rates", &pCurrBssInfo->extRates.buf[2], pCurrBssInfo->extRates.buf[1]);
385 if (getElem(rdu, EID_ERP, &pCurrBssInfo->erp,1)){
386 //zd1205_dump_data("ERP Info", &pCurrBssInfo->erp.buf[2], pCurrBssInfo->erp.buf[1]);
388 getElem(rdu, EID_COUNTRY, &pCurrBssInfo->country,1);
390 zd_makeRateInfoMAP((U8 *)&pCurrBssInfo->supRates, &pCurrBssInfo->basicRateMap, &pCurrBssInfo->supRateMap);
391 zd_makeRateInfoMAP((U8 *)&pCurrBssInfo->extRates, &pCurrBssInfo->basicRateMap, &pCurrBssInfo->supRateMap);
392 //FPRINT_V("basicRateMap", pCurrBssInfo->basicRateMap);
393 //FPRINT_V("supRateMap", pCurrBssInfo->supRateMap);
395 if (LastMacMode != PURE_A_MODE && pCurrBssInfo->supRateMap > 0x0f){ //support rates include OFDM rates
396 if (pCurrBssInfo->basicRateMap & ~0xf){ // basic rates include OFDM rates
397 pCurrBssInfo->apMode = PURE_G_AP;
398 //FPRINT("PURE_G_AP");
400 else {
401 pCurrBssInfo->apMode = MIXED_AP;
402 //FPRINT("MIXED_AP");
405 else if(LastMacMode == PURE_A_MODE) {
406 pCurrBssInfo->apMode = PURE_A_AP;
408 else {
409 pCurrBssInfo->apMode = PURE_B_AP;
410 //FPRINT("PURE_B_AP");
413 /* Get WPA IE Information */
414 //getElem(rdu, EID_WPA, (Element *)&pCurrBssInfo->WPAIe);
416 memset(&pCurrBssInfo->WPAIe,0x00, sizeof(pCurrBssInfo->WPAIe));
417 elemIdx=1;
418 while(getElem(rdu, EID_WPA, (Element*)&pCurrBssInfo->WPAIe,elemIdx))
420 //if elemIdx++ doesn't execute, endless loop occur
421 if(loopCheck++ > 100)
423 printk("infinite loop occurs in %s\n", __FUNCTION__);
424 loopCheck = 0;
425 break;
428 if((memcmp(pCurrBssInfo->WPAIe+2,WPA_OUI, sizeof(WPA_OUI)) != 0) ||
429 (pCurrBssInfo->WPAIe[1] < 20) )
431 memset(&pCurrBssInfo->WPAIe,0x00, sizeof(pCurrBssInfo->WPAIe));
433 else
434 break;
436 elemIdx++;
439 memset(&pCurrBssInfo->RSNIe,0x00, sizeof(pCurrBssInfo->RSNIe));
440 getElem(rdu, EID_RSN, (Element*)&pCurrBssInfo->RSNIe,1);
443 #if 0
444 /* Dump WPA IE */
445 if(pCurrBssInfo->WPAIe[1] != 0) {
446 int ii;
447 u8 SSID[34];
449 memcpy(SSID, (u8 *)(&pCurrBssInfo->ssid.buf[2]), pCurrBssInfo->ssid.buf[1]);
450 SSID[pCurrBssInfo->ssid.buf[1]] = '\0';
452 printk(KERN_ERR "WPA IE found in site survey, SSID: %s\n", SSID);
454 for(ii = 0; ii < pCurrBssInfo->WPAIe[1]+2; ) {
455 printk(KERN_ERR "0x%02x ", pCurrBssInfo->WPAIe[ii]);
456 ii++;
459 printk(KERN_ERR "\n");
461 #endif
463 pCurrBssInfo->signalStrength = pfrmDesc->signalStrength;
464 pCurrBssInfo->signalQuality = pfrmDesc->signalQuality;
466 if (mBssNum < 63){
467 if (!bUpdateInfo)
468 mBssNum++;
472 release:
473 ZDEBUG("goto release");
474 freeFdesc(pfrmDesc);
475 return TRUE;
479 BOOLEAN SynchEntry(Signal_t *signal)
481 FrmDesc_t *pfrmDesc;
483 switch(signal->id){
484 case SIG_PROBE:
485 return Probe(signal);
487 case SIG_PROBE_REQ:
488 return ProbeReq(signal);
490 case SIQ_PROBE_RSP_BEACON:
491 return ProbeRsp_Beacon(signal);
493 default:
494 goto sync_discard;
497 sync_discard:
498 pfrmDesc = signal->frmInfo.frmDesc;
499 freeFdesc(pfrmDesc);
500 return TRUE;
502 #endif