Merge git://git.infradead.org/iommu-2.6
[linux-2.6] / drivers / staging / rt3070 / sta / auth_rsp.c
1 /*
2  *************************************************************************
3  * Ralink Tech Inc.
4  * 5F., No.36, Taiyuan St., Jhubei City,
5  * Hsinchu County 302,
6  * Taiwan, R.O.C.
7  *
8  * (c) Copyright 2002-2007, Ralink Technology, Inc.
9  *
10  * This program is free software; you can redistribute it and/or modify  *
11  * it under the terms of the GNU General Public License as published by  *
12  * the Free Software Foundation; either version 2 of the License, or     *
13  * (at your option) any later version.                                   *
14  *                                                                       *
15  * This program is distributed in the hope that it will be useful,       *
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of        *
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
18  * GNU General Public License for more details.                          *
19  *                                                                       *
20  * You should have received a copy of the GNU General Public License     *
21  * along with this program; if not, write to the                         *
22  * Free Software Foundation, Inc.,                                       *
23  * 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
24  *                                                                       *
25  *************************************************************************
26
27         Module Name:
28         auth_rsp.c
29
30         Abstract:
31
32         Revision History:
33         Who                     When                    What
34         --------        ----------              ----------------------------------------------
35         John            2004-10-1               copy from RT2560
36 */
37 #include "../rt_config.h"
38
39 /*
40     ==========================================================================
41     Description:
42         authentication state machine init procedure
43     Parameters:
44         Sm - the state machine
45
46         IRQL = PASSIVE_LEVEL
47
48     ==========================================================================
49  */
50 VOID AuthRspStateMachineInit(
51     IN PRTMP_ADAPTER pAd,
52     IN PSTATE_MACHINE Sm,
53     IN STATE_MACHINE_FUNC Trans[])
54 {
55     StateMachineInit(Sm, Trans, MAX_AUTH_RSP_STATE, MAX_AUTH_RSP_MSG, (STATE_MACHINE_FUNC)Drop, AUTH_RSP_IDLE, AUTH_RSP_MACHINE_BASE);
56
57     // column 1
58     StateMachineSetAction(Sm, AUTH_RSP_IDLE, MT2_PEER_DEAUTH, (STATE_MACHINE_FUNC)PeerDeauthAction);
59
60     // column 2
61     StateMachineSetAction(Sm, AUTH_RSP_WAIT_CHAL, MT2_PEER_DEAUTH, (STATE_MACHINE_FUNC)PeerDeauthAction);
62
63 }
64
65 /*
66     ==========================================================================
67     Description:
68
69         IRQL = DISPATCH_LEVEL
70
71     ==========================================================================
72 */
73 VOID PeerAuthSimpleRspGenAndSend(
74     IN PRTMP_ADAPTER pAd,
75     IN PHEADER_802_11 pHdr80211,
76     IN USHORT Alg,
77     IN USHORT Seq,
78     IN USHORT Reason,
79     IN USHORT Status)
80 {
81     HEADER_802_11     AuthHdr;
82     ULONG             FrameLen = 0;
83     PUCHAR            pOutBuffer = NULL;
84     NDIS_STATUS       NStatus;
85
86     if (Reason != MLME_SUCCESS)
87     {
88         DBGPRINT(RT_DEBUG_TRACE, ("Peer AUTH fail...\n"));
89         return;
90     }
91
92         //Get an unused nonpaged memory
93     NStatus = MlmeAllocateMemory(pAd, &pOutBuffer);
94     if (NStatus != NDIS_STATUS_SUCCESS)
95         return;
96
97     DBGPRINT(RT_DEBUG_TRACE, ("Send AUTH response (seq#2)...\n"));
98     MgtMacHeaderInit(pAd, &AuthHdr, SUBTYPE_AUTH, 0, pHdr80211->Addr2, pAd->MlmeAux.Bssid);
99     MakeOutgoingFrame(pOutBuffer,               &FrameLen,
100                       sizeof(HEADER_802_11),    &AuthHdr,
101                       2,                        &Alg,
102                       2,                        &Seq,
103                       2,                        &Reason,
104                       END_OF_ARGS);
105     MiniportMMRequest(pAd, 0, pOutBuffer, FrameLen);
106         MlmeFreeMemory(pAd, pOutBuffer);
107 }
108
109 /*
110     ==========================================================================
111     Description:
112
113         IRQL = DISPATCH_LEVEL
114
115     ==========================================================================
116 */
117 VOID PeerDeauthAction(
118     IN PRTMP_ADAPTER pAd,
119     IN PMLME_QUEUE_ELEM Elem)
120 {
121     UCHAR       Addr2[MAC_ADDR_LEN];
122     USHORT      Reason;
123
124     if (PeerDeauthSanity(pAd, Elem->Msg, Elem->MsgLen, Addr2, &Reason))
125     {
126         if (INFRA_ON(pAd) && MAC_ADDR_EQUAL(Addr2, pAd->CommonCfg.Bssid))
127         {
128             DBGPRINT(RT_DEBUG_TRACE,("AUTH_RSP - receive DE-AUTH from our AP (Reason=%d)\n", Reason));
129
130
131 #ifdef NATIVE_WPA_SUPPLICANT_SUPPORT
132             {
133                 union iwreq_data    wrqu;
134                 memset(wrqu.ap_addr.sa_data, 0, MAC_ADDR_LEN);
135                 wireless_send_event(pAd->net_dev, SIOCGIWAP, &wrqu, NULL);
136             }
137 #endif // NATIVE_WPA_SUPPLICANT_SUPPORT //
138
139
140                         // send wireless event - for deauthentication
141                         if (pAd->CommonCfg.bWirelessEvent)
142                                 RTMPSendWirelessEvent(pAd, IW_DEAUTH_EVENT_FLAG, pAd->MacTab.Content[BSSID_WCID].Addr, BSS0, 0);
143
144             LinkDown(pAd, TRUE);
145
146             // Authentication Mode Cisco_LEAP has start a timer
147             // We should cancel it if using LEAP
148 #ifdef LEAP_SUPPORT
149             if (pAd->StaCfg.LeapAuthMode == CISCO_AuthModeLEAP)
150             {
151                 RTMPCancelTimer(&pAd->StaCfg.LeapAuthTimer, &TimerCancelled);
152                 //Check is it mach the LEAP Authentication failed as possible a Rogue AP
153                 //on it's PortSecured not equal to WPA_802_1X_PORT_SECURED while process the Authenticaton.
154                 if ((pAd->StaCfg.PortSecured != WPA_802_1X_PORT_SECURED) && (pAd->Mlme.LeapMachine.CurrState != LEAP_IDLE))
155                 {
156                     RogueApTableSetEntry(pAd, &pAd->StaCfg.RogueApTab, Addr2, LEAP_REASON_AUTH_TIMEOUT);
157                 }
158             }
159 #endif // LEAP_SUPPORT //
160         }
161     }
162     else
163     {
164         DBGPRINT(RT_DEBUG_TRACE,("AUTH_RSP - PeerDeauthAction() sanity check fail\n"));
165     }
166 }
167