2 *************************************************************************
4 * 5F., No.36, Taiyuan St., Jhubei City,
8 * (c) Copyright 2002-2007, Ralink Technology, Inc.
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. *
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. *
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. *
25 *************************************************************************
34 -------- ---------- ----------------------------------------------
35 John Chang 2004-09-01 add WMM support
37 #include "../rt_config.h"
39 extern u8 CISCO_OUI[];
43 extern u8 WME_INFO_ELEM[];
44 extern u8 WME_PARM_ELEM[];
45 extern u8 Ccx2QosInfo[];
46 extern u8 RALINK_OUI[];
47 extern u8 BROADCOM_OUI[];
50 ==========================================================================
52 MLME message sanity check
54 TRUE if all parameters are OK, FALSE otherwise
55 ==========================================================================
57 BOOLEAN MlmeStartReqSanity(struct rt_rtmp_adapter *pAd,
60 char Ssid[], u8 * pSsidLen)
62 struct rt_mlme_start_req *Info;
64 Info = (struct rt_mlme_start_req *)(Msg);
66 if (Info->SsidLen > MAX_LEN_OF_SSID) {
67 DBGPRINT(RT_DEBUG_TRACE,
68 ("MlmeStartReqSanity fail - wrong SSID length\n"));
72 *pSsidLen = Info->SsidLen;
73 NdisMoveMemory(Ssid, Info->Ssid, *pSsidLen);
79 ==========================================================================
81 MLME message sanity check
83 TRUE if all parameters are OK, FALSE otherwise
87 ==========================================================================
89 BOOLEAN PeerAssocRspSanity(struct rt_rtmp_adapter *pAd, void * pMsg, unsigned long MsgLen, u8 *pAddr2, u16 * pCapabilityInfo, u16 * pStatus, u16 * pAid, u8 SupRate[], u8 * pSupRateLen, u8 ExtRate[], u8 * pExtRateLen, struct rt_ht_capability_ie * pHtCapability, struct rt_add_ht_info_ie * pAddHtInfo, /* AP might use this additional ht info IE */
90 u8 * pHtCapabilityLen,
92 u8 * pNewExtChannelOffset,
93 struct rt_edca_parm *pEdcaParm, u8 * pCkipFlag)
96 struct rt_frame_802_11 * pFrame = (struct rt_frame_802_11 *) pMsg;
98 unsigned long Length = 0;
100 *pNewExtChannelOffset = 0xff;
101 *pHtCapabilityLen = 0;
103 COPY_MAC_ADDR(pAddr2, pFrame->Hdr.Addr2);
104 Ptr = (char *)pFrame->Octet;
105 Length += LENGTH_802_11;
107 NdisMoveMemory(pCapabilityInfo, &pFrame->Octet[0], 2);
109 NdisMoveMemory(pStatus, &pFrame->Octet[2], 2);
113 pEdcaParm->bValid = FALSE;
115 if (*pStatus != MLME_SUCCESS)
118 NdisMoveMemory(pAid, &pFrame->Octet[4], 2);
121 /* Aid already swaped byte order in RTMPFrameEndianChange() for big endian platform */
122 *pAid = (*pAid) & 0x3fff; /* AID is low 14-bit */
124 /* -- get supported rates from payload and advance the pointer */
125 IeType = pFrame->Octet[6];
126 *pSupRateLen = pFrame->Octet[7];
127 if ((IeType != IE_SUPP_RATES)
128 || (*pSupRateLen > MAX_LEN_OF_SUPPORTED_RATES)) {
129 DBGPRINT(RT_DEBUG_TRACE,
130 ("PeerAssocRspSanity fail - wrong SupportedRates IE\n"));
133 NdisMoveMemory(SupRate, &pFrame->Octet[8], *pSupRateLen);
135 Length = Length + 2 + *pSupRateLen;
137 /* many AP implement proprietary IEs in non-standard order, we'd better */
138 /* tolerate mis-ordered IEs to get best compatibility */
139 pEid = (struct rt_eid *) & pFrame->Octet[8 + (*pSupRateLen)];
141 /* get variable fields from payload and advance the pointer */
142 while ((Length + 2 + pEid->Len) <= MsgLen) {
144 case IE_EXT_SUPP_RATES:
145 if (pEid->Len <= MAX_LEN_OF_SUPPORTED_RATES) {
146 NdisMoveMemory(ExtRate, pEid->Octet, pEid->Len);
147 *pExtRateLen = pEid->Len;
153 if (pEid->Len >= SIZE_HT_CAP_IE) /*Note: allow extension! */
155 NdisMoveMemory(pHtCapability, pEid->Octet,
158 *(u16 *) (&pHtCapability->HtCapInfo) =
160 (&pHtCapability->HtCapInfo));
161 *(u16 *) (&pHtCapability->ExtHtCapInfo) =
163 (&pHtCapability->ExtHtCapInfo));
165 *pHtCapabilityLen = SIZE_HT_CAP_IE;
167 DBGPRINT(RT_DEBUG_WARN,
168 ("PeerAssocRspSanity - wrong IE_HT_CAP. \n"));
174 if (pEid->Len >= sizeof(struct rt_add_ht_info_ie)) {
175 /* This IE allows extension, but we can ignore extra bytes beyond our knowledge , so only */
176 /* copy first sizeof(struct rt_add_ht_info_ie) */
177 NdisMoveMemory(pAddHtInfo, pEid->Octet,
178 sizeof(struct rt_add_ht_info_ie));
180 *(u16 *) (&pAddHtInfo->AddHtInfo2) =
182 (&pAddHtInfo->AddHtInfo2));
183 *(u16 *) (&pAddHtInfo->AddHtInfo3) =
185 (&pAddHtInfo->AddHtInfo3));
187 *pAddHtInfoLen = SIZE_ADD_HT_INFO_IE;
189 DBGPRINT(RT_DEBUG_WARN,
190 ("PeerAssocRspSanity - wrong IE_ADD_HT. \n"));
194 case IE_SECONDARY_CH_OFFSET:
195 if (pEid->Len == 1) {
196 *pNewExtChannelOffset = pEid->Octet[0];
198 DBGPRINT(RT_DEBUG_WARN,
199 ("PeerAssocRspSanity - wrong IE_SECONDARY_CH_OFFSET. \n"));
203 case IE_VENDOR_SPECIFIC:
204 /* handle WME PARAMTER ELEMENT */
205 if (NdisEqualMemory(pEid->Octet, WME_PARM_ELEM, 6)
206 && (pEid->Len == 24)) {
210 /* parsing EDCA parameters */
211 pEdcaParm->bValid = TRUE;
212 pEdcaParm->bQAck = FALSE; /* pEid->Octet[0] & 0x10; */
213 pEdcaParm->bQueueRequest = FALSE; /* pEid->Octet[0] & 0x20; */
214 pEdcaParm->bTxopRequest = FALSE; /* pEid->Octet[0] & 0x40; */
215 /*pEdcaParm->bMoreDataAck = FALSE; // pEid->Octet[0] & 0x80; */
216 pEdcaParm->EdcaUpdateCount =
217 pEid->Octet[6] & 0x0f;
218 pEdcaParm->bAPSDCapable =
219 (pEid->Octet[6] & 0x80) ? 1 : 0;
220 ptr = (u8 *)& pEid->Octet[8];
221 for (i = 0; i < 4; i++) {
222 u8 aci = (*ptr & 0x60) >> 5; /* b5~6 is AC INDEX */
223 pEdcaParm->bACM[aci] = (((*ptr) & 0x10) == 0x10); /* b5 is ACM */
224 pEdcaParm->Aifsn[aci] = (*ptr) & 0x0f; /* b0~3 is AIFSN */
225 pEdcaParm->Cwmin[aci] = *(ptr + 1) & 0x0f; /* b0~4 is Cwmin */
226 pEdcaParm->Cwmax[aci] = *(ptr + 1) >> 4; /* b5~8 is Cwmax */
227 pEdcaParm->Txop[aci] = *(ptr + 2) + 256 * (*(ptr + 3)); /* in unit of 32-us */
228 ptr += 4; /* point to next AC */
233 DBGPRINT(RT_DEBUG_TRACE,
234 ("PeerAssocRspSanity - ignore unrecognized EID = %d\n",
239 Length = Length + 2 + pEid->Len;
240 pEid = (struct rt_eid *) ((u8 *) pEid + 2 + pEid->Len);
247 ==========================================================================
249 MLME message sanity check
251 TRUE if all parameters are OK, FALSE otherwise
253 IRQL = DISPATCH_LEVEL
255 ==========================================================================
257 BOOLEAN PeerProbeReqSanity(struct rt_rtmp_adapter *pAd,
259 unsigned long MsgLen,
261 char Ssid[], u8 * pSsidLen)
266 struct rt_frame_802_11 * pFrame = (struct rt_frame_802_11 *) Msg;
268 COPY_MAC_ADDR(pAddr2, pFrame->Hdr.Addr2);
270 if ((pFrame->Octet[0] != IE_SSID)
271 || (pFrame->Octet[1] > MAX_LEN_OF_SSID)) {
272 DBGPRINT(RT_DEBUG_TRACE,
273 ("PeerProbeReqSanity fail - wrong SSID IE(Type=%d,Len=%d)\n",
274 pFrame->Octet[0], pFrame->Octet[1]));
278 *pSsidLen = pFrame->Octet[1];
279 NdisMoveMemory(Ssid, &pFrame->Octet[2], *pSsidLen);
283 /* -- get supported rates from payload and advance the pointer */
284 IeType = pFrame->Octet[Idx];
285 RateLen = pFrame->Octet[Idx + 1];
286 if (IeType != IE_SUPP_RATES) {
287 DBGPRINT(RT_DEBUG_TRACE,
288 ("PeerProbeReqSanity fail - wrong SupportRates IE(Type=%d,Len=%d)\n",
289 pFrame->Octet[Idx], pFrame->Octet[Idx + 1]));
292 if ((pAd->CommonCfg.PhyMode == PHY_11G) && (RateLen < 8))
300 ==========================================================================
303 IRQL = DISPATCH_LEVEL
305 ==========================================================================
307 BOOLEAN GetTimBit(char * Ptr,
312 u8 * DtimPeriod, u8 * MessageToMe)
314 u8 BitCntl, N1, N2, MyByte, MyBit;
322 /* get DTIM Count from TIM element */
324 *DtimCount = *IdxPtr;
326 /* get DTIM Period from TIM element */
328 *DtimPeriod = *IdxPtr;
330 /* get Bitmap Control from TIM element */
334 if ((*DtimCount == 0) && (BitCntl & 0x01))
339 /* Parse Partial Virtual Bitmap from TIM element */
340 N1 = BitCntl & 0xfe; /* N1 is the first bitmap byte# */
341 N2 = *TimLen - 4 + N1; /* N2 is the last bitmap byte# */
343 if ((Aid < (N1 << 3)) || (Aid >= ((N2 + 1) << 3)))
344 *MessageToMe = FALSE;
346 MyByte = (Aid >> 3) - N1; /* my byte position in the bitmap byte-stream */
347 MyBit = Aid % 16 - ((MyByte & 0x01) ? 8 : 0);
349 IdxPtr += (MyByte + 1);
352 /* DBGPRINT(RT_DEBUG_WARN, ("TIM bitmap = 0x%02x\n", *IdxPtr)); */
354 if (*IdxPtr & (0x01 << MyBit))
357 *MessageToMe = FALSE;