MOXA linux-2.6.x / linux-2.6.9-uc0 from sdlinux-moxaart.tgz
[linux-2.6.9-moxart.git] / drivers / usb / net / Zydas / zdauthrsp.c
blob5a0fc40cf6b31e95ee41f62dbba7178b142c5a17
1 #ifndef __ZDAUTHRSP_C__
2 #define __ZDAUTHRSP_C__
4 #include "zd80211.h"
5 #include "zd1205.h"
7 U8 AuthRspState = STE_AUTH_RSP_IDLE;
8 static U8 arChalng[CHAL_TEXT_LEN]; //Challenge text
9 static MacAddr_t Sta2;
10 static MacAddr_t Sta;
11 extern struct net_device *g_dev;
13 BOOLEAN CheckAlg(U8 alg)
15 int i = 0;
17 for (i=0; i<3; i++){
18 if (i == 2)
19 return FALSE;
21 if (mAuthAlogrithms[i] == alg)
22 return TRUE;
24 return FALSE;
28 BOOLEAN AuthOdd_Idle(Signal_t *signal)
30 struct zd1205_private *macp=g_dev->priv;
31 FrmDesc_t *pfrmDesc;
32 Frame_t *rdu;
33 U16 arAlg;
34 U16 arSeq;
35 U16 arSC;
36 U8 vapId = 0;
38 ZDEBUG("AuthOdd_Idle");
39 pfrmDesc = signal->frmInfo.frmDesc;
40 rdu = pfrmDesc->mpdu;
41 arSeq = authSeqNum(rdu);
42 arAlg = authType(rdu);
43 memcpy((U8 *)&Sta, (U8 *)addr2(rdu), 6);
45 if (arSeq != 1){
46 arSC = SC_AUTH_OUT_OF_SEQ;
47 UpdateStaStatus(&Sta, STATION_STATE_NOT_AUTH, vapId);
48 mkAuthFrm(pfrmDesc, &Sta, arAlg, arSeq+1, arSC, NULL, vapId);
49 return sendMgtFrame(signal, pfrmDesc);
52 if (!CheckAlg(arAlg)){
53 arSC = SC_UNSUPT_ALG;
54 UpdateStaStatus(&Sta, STATION_STATE_NOT_AUTH, vapId);
55 mkAuthFrm(pfrmDesc, &Sta, arAlg, arSeq+1, arSC, NULL, vapId);
56 return sendMgtFrame(signal, pfrmDesc);
59 if (pdot11Obj->StatusNotify(STA_AUTH_REQ, (U8 *)&Sta)){ //Reject it
60 arSC = SC_UNSPEC_FAILURE;
61 UpdateStaStatus(&Sta, STATION_STATE_NOT_AUTH, vapId);
62 mkAuthFrm(pfrmDesc, &Sta, arAlg, arSeq+1, arSC, NULL, vapId);
63 return sendMgtFrame(signal, pfrmDesc);
66 if (arAlg == OPEN_SYSTEM){
67 if (UpdateStaStatus(&Sta, STATION_STATE_AUTH_OPEN, vapId))
68 arSC = SC_SUCCESSFUL;
69 else
70 arSC = SC_AP_FULL;
72 mkAuthFrm(pfrmDesc, &Sta, arAlg, arSeq+1, arSC, NULL, vapId);
73 return sendMgtFrame(signal, pfrmDesc);
76 if (arAlg == SHARE_KEY){
77 //WPA
78 if (macp->cardSetting.WPAIeLen){
79 //if ((mDynKeyMode == DYN_KEY_TKIP) || (mDynKeyMode == DYN_KEY_AES)){
80 arSC = SC_UNSUPT_ALG;
81 UpdateStaStatus(&Sta, STATION_STATE_NOT_AUTH, vapId);
82 mkAuthFrm(pfrmDesc, &Sta, arAlg, arSeq+1, arSC, NULL, vapId);
84 return sendMgtFrame(signal, pfrmDesc);
86 else{
87 if ((mCurrConnUser + 1) > mLimitedUser)
88 arSC = SC_AP_FULL;
89 else
90 arSC = SC_SUCCESSFUL;
92 mkAuthFrm(pfrmDesc, &Sta, arAlg, arSeq+1, arSC, arChalng, vapId);
93 if (arSC == SC_SUCCESSFUL){
94 pdot11Obj->StartTimer(512, DO_CHAL);
95 AuthRspState = STE_AUTH_RSP_WAIT_CRSP;
97 return sendMgtFrame(signal, pfrmDesc);
101 freeFdesc(pfrmDesc);
102 return TRUE;
106 BOOLEAN AuthOdd_WaitChalRsp(Signal_t *signal)
109 FrmDesc_t *pfrmDesc;
110 Frame_t *rdu;
111 U8 arAlg2;
112 U16 arSeq2;
113 U16 arSC;
114 U8 vapId = 0;
115 U8 ChalText[130];
117 ZDEBUG("AuthOdd_WaitChalRsp");
118 pfrmDesc = signal->frmInfo.frmDesc;
119 rdu = pfrmDesc->mpdu;
121 arSeq2 = authSeqNum(rdu);
122 arAlg2 = authType(rdu);
123 memcpy((U8 *)&Sta2, (U8 *)addr2(rdu), 6);
125 if(arSeq2 == 1){
126 if (memcmp(&Sta, &Sta2, 6) == 0){ // open system request from a different station
127 arSC = SC_UNSPEC_FAILURE;
128 goto fail_sta2;
131 if (arAlg2 == OPEN_SYSTEM){
132 arSC = SC_SUCCESSFUL;
133 UpdateStaStatus(&Sta, STATION_STATE_AUTH_OPEN, vapId);
134 mkAuthFrm(pfrmDesc, &Sta2, arAlg2, arSeq2+1, arSC, NULL, vapId);
136 return sendMgtFrame(signal, pfrmDesc);
138 else{
139 arSC = SC_UNSPEC_FAILURE;
140 goto fail_sta2;
143 else if(arSeq2 == 3){
144 if (memcmp(&Sta, &Sta2, 6) == 0){
145 pdot11Obj->StopTimer(DO_CHAL);
146 if (wepBit(rdu)){
147 if (!getElem(rdu, EID_CTEXT, (Element *)&ChalText[0],1)){
148 goto chal_failed;
150 else {
151 //zd1205_OctetDump("ChalText = ", &ChalText[0], CHAL_TEXT_LEN+2);
152 if (memcmp(&ChalText[2], arChalng, CHAL_TEXT_LEN) != 0){
153 goto chal_failed;
157 if (UpdateStaStatus(&Sta, STATION_STATE_AUTH_KEY, vapId))
158 arSC = SC_SUCCESSFUL;
159 else
160 arSC = SC_AP_FULL;
162 else{
163 chal_failed:
164 arSC = SC_CHAL_FAIL;
165 UpdateStaStatus(&Sta2, STATION_STATE_NOT_AUTH, vapId);
168 else{
169 arSC = SC_UNSPEC_FAILURE;
170 UpdateStaStatus(&Sta2, STATION_STATE_NOT_AUTH, vapId);
172 AuthRspState = STE_AUTH_RSP_IDLE;
173 mkAuthFrm(pfrmDesc, &Sta2, arAlg2, arSeq2+1, arSC, NULL, vapId);
174 return sendMgtFrame(signal, pfrmDesc);
176 else{
177 arSC = SC_UNSPEC_FAILURE;
178 goto fail_sta2;
181 fail_sta2:
182 UpdateStaStatus(&Sta2, STATION_STATE_NOT_AUTH, vapId);
183 mkAuthFrm(pfrmDesc, &Sta2, arAlg2, arSeq2+1, arSC, NULL, vapId);
184 return sendMgtFrame(signal, pfrmDesc);
188 BOOLEAN Tchal_WaitChalRsp(Signal_t *signal)
190 U8 vapId = 0;
192 ZDEBUG("Tchal_WaitChalRsp");
193 if (AuthRspState == STE_AUTH_RSP_WAIT_CRSP){
194 UpdateStaStatus(&Sta, STATION_STATE_NOT_AUTH, vapId);
195 AuthRspState = STE_AUTH_RSP_IDLE;
197 return FALSE;
201 BOOLEAN Deauth(Signal_t *signal)
203 FrmDesc_t *pfrmDesc;
204 Frame_t *rdu;
205 U8 vapId = 0;
207 ZDEBUG("Deauth");
208 pfrmDesc = signal->frmInfo.frmDesc;
209 rdu = pfrmDesc->mpdu;
210 UpdateStaStatus(addr2(rdu), STATION_STATE_NOT_AUTH, vapId);
211 if (memcmp(&mBssId, addr2(rdu), 6) == 0)
212 pdot11Obj->StatusNotify(STA_DEAUTHED, (U8 *)addr2(rdu));
214 if (mBssType == INFRASTRUCTURE_BSS){
215 //if (memcmp(&mBssId, addr2(rdu), 6) == 0){
216 FPRINT("Deauth");
217 mAssoc = FALSE;
218 memset((U8 *)&mBssId, 0, 6);
219 mRequestFlag |= DIS_CONNECT_SET;
223 //here to handle deauth ind.
224 freeFdesc(pfrmDesc);
225 return TRUE;
229 BOOLEAN AuthRspEntry(Signal_t *signal)
231 if (AuthRspState == STE_AUTH_RSP_IDLE){
232 switch(signal->id){
233 case SIG_AUTH_ODD:
234 return AuthOdd_Idle(signal);
236 case SIG_DEAUTH:
237 return Deauth(signal);
239 default:
240 return TRUE;
244 else if (AuthRspState == STE_AUTH_RSP_WAIT_CRSP){
245 switch(signal->id){
246 case SIG_AUTH_ODD:
247 return AuthOdd_WaitChalRsp(signal);
249 case SIG_DEAUTH:
250 return Deauth(signal);
252 case SIG_TO_CHAL:
253 return Tchal_WaitChalRsp(signal);
255 default:
256 return TRUE;
259 else
260 return TRUE;
263 #endif