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 UCHAR CISCO_OUI[];
41 extern UCHAR WPA_OUI[];
42 extern UCHAR RSN_OUI[];
43 extern UCHAR WME_INFO_ELEM[];
44 extern UCHAR WME_PARM_ELEM[];
45 extern UCHAR Ccx2QosInfo[];
46 extern UCHAR RALINK_OUI[];
47 extern UCHAR BROADCOM_OUI[];
50 ==========================================================================
52 MLME message sanity check
54 TRUE if all parameters are OK, FALSE otherwise
55 ==========================================================================
57 BOOLEAN MlmeStartReqSanity(
64 MLME_START_REQ_STRUCT *Info;
66 Info = (MLME_START_REQ_STRUCT *)(Msg);
68 if (Info->SsidLen > MAX_LEN_OF_SSID)
70 DBGPRINT(RT_DEBUG_TRACE, ("MlmeStartReqSanity fail - wrong SSID length\n"));
74 *pSsidLen = Info->SsidLen;
75 NdisMoveMemory(Ssid, Info->Ssid, *pSsidLen);
81 ==========================================================================
83 MLME message sanity check
85 TRUE if all parameters are OK, FALSE otherwise
89 ==========================================================================
91 BOOLEAN PeerAssocRspSanity(
96 OUT USHORT *pCapabilityInfo,
100 OUT UCHAR *pSupRateLen,
102 OUT UCHAR *pExtRateLen,
103 OUT HT_CAPABILITY_IE *pHtCapability,
104 OUT ADD_HT_INFO_IE *pAddHtInfo, // AP might use this additional ht info IE
105 OUT UCHAR *pHtCapabilityLen,
106 OUT UCHAR *pAddHtInfoLen,
107 OUT UCHAR *pNewExtChannelOffset,
108 OUT PEDCA_PARM pEdcaParm,
109 OUT UCHAR *pCkipFlag)
112 PFRAME_802_11 pFrame = (PFRAME_802_11)pMsg;
116 *pNewExtChannelOffset = 0xff;
117 *pHtCapabilityLen = 0;
119 COPY_MAC_ADDR(pAddr2, pFrame->Hdr.Addr2);
121 Length += LENGTH_802_11;
123 NdisMoveMemory(pCapabilityInfo, &pFrame->Octet[0], 2);
125 NdisMoveMemory(pStatus, &pFrame->Octet[2], 2);
129 pEdcaParm->bValid = FALSE;
131 if (*pStatus != MLME_SUCCESS)
134 NdisMoveMemory(pAid, &pFrame->Octet[4], 2);
137 // Aid already swaped byte order in RTMPFrameEndianChange() for big endian platform
138 *pAid = (*pAid) & 0x3fff; // AID is low 14-bit
140 // -- get supported rates from payload and advance the pointer
141 IeType = pFrame->Octet[6];
142 *pSupRateLen = pFrame->Octet[7];
143 if ((IeType != IE_SUPP_RATES) || (*pSupRateLen > MAX_LEN_OF_SUPPORTED_RATES))
145 DBGPRINT(RT_DEBUG_TRACE, ("PeerAssocRspSanity fail - wrong SupportedRates IE\n"));
149 NdisMoveMemory(SupRate, &pFrame->Octet[8], *pSupRateLen);
151 Length = Length + 2 + *pSupRateLen;
153 // many AP implement proprietary IEs in non-standard order, we'd better
154 // tolerate mis-ordered IEs to get best compatibility
155 pEid = (PEID_STRUCT) &pFrame->Octet[8 + (*pSupRateLen)];
157 // get variable fields from payload and advance the pointer
158 while ((Length + 2 + pEid->Len) <= MsgLen)
162 case IE_EXT_SUPP_RATES:
163 if (pEid->Len <= MAX_LEN_OF_SUPPORTED_RATES)
165 NdisMoveMemory(ExtRate, pEid->Octet, pEid->Len);
166 *pExtRateLen = pEid->Len;
172 if (pEid->Len >= SIZE_HT_CAP_IE) //Note: allow extension.!!
174 NdisMoveMemory(pHtCapability, pEid->Octet, SIZE_HT_CAP_IE);
176 *(USHORT *)(&pHtCapability->HtCapInfo) = cpu2le16(*(USHORT *)(&pHtCapability->HtCapInfo));
177 *(USHORT *)(&pHtCapability->ExtHtCapInfo) = cpu2le16(*(USHORT *)(&pHtCapability->ExtHtCapInfo));
179 *pHtCapabilityLen = SIZE_HT_CAP_IE;
183 DBGPRINT(RT_DEBUG_WARN, ("PeerAssocRspSanity - wrong IE_HT_CAP. \n"));
187 #ifdef DOT11_N_SUPPORT
190 if (pEid->Len >= sizeof(ADD_HT_INFO_IE))
192 // This IE allows extension, but we can ignore extra bytes beyond our knowledge , so only
193 // copy first sizeof(ADD_HT_INFO_IE)
194 NdisMoveMemory(pAddHtInfo, pEid->Octet, sizeof(ADD_HT_INFO_IE));
196 *(USHORT *)(&pAddHtInfo->AddHtInfo2) = cpu2le16(*(USHORT *)(&pAddHtInfo->AddHtInfo2));
197 *(USHORT *)(&pAddHtInfo->AddHtInfo3) = cpu2le16(*(USHORT *)(&pAddHtInfo->AddHtInfo3));
199 *pAddHtInfoLen = SIZE_ADD_HT_INFO_IE;
203 DBGPRINT(RT_DEBUG_WARN, ("PeerAssocRspSanity - wrong IE_ADD_HT. \n"));
207 case IE_SECONDARY_CH_OFFSET:
210 *pNewExtChannelOffset = pEid->Octet[0];
214 DBGPRINT(RT_DEBUG_WARN, ("PeerAssocRspSanity - wrong IE_SECONDARY_CH_OFFSET. \n"));
216 #endif // DOT11_N_SUPPORT //
218 case IE_AIRONET_CKIP:
219 // 0. Check Aironet IE length, it must be larger or equal to 28
220 // Cisco's AP VxWork version(will not be supported) used this IE length as 28
221 // Cisco's AP IOS version used this IE length as 30
222 if (pEid->Len < (CKIP_NEGOTIATION_LENGTH - 2))
225 // 1. Copy CKIP flag byte to buffer for process
226 *pCkipFlag = *(pEid->Octet + 8);
229 case IE_AIRONET_IPADDRESS:
230 if (pEid->Len != 0x0A)
233 // Get Cisco Aironet IP information
234 if (NdisEqualMemory(pEid->Octet, CISCO_OUI, 3) == 1)
235 NdisMoveMemory(pAd->StaCfg.AironetIPAddress, pEid->Octet + 4, 4);
238 // CCX2, WMM use the same IE value
240 case IE_VENDOR_SPECIFIC:
241 // handle WME PARAMTER ELEMENT
242 if (NdisEqualMemory(pEid->Octet, WME_PARM_ELEM, 6) && (pEid->Len == 24))
247 // parsing EDCA parameters
248 pEdcaParm->bValid = TRUE;
249 pEdcaParm->bQAck = FALSE; // pEid->Octet[0] & 0x10;
250 pEdcaParm->bQueueRequest = FALSE; // pEid->Octet[0] & 0x20;
251 pEdcaParm->bTxopRequest = FALSE; // pEid->Octet[0] & 0x40;
252 //pEdcaParm->bMoreDataAck = FALSE; // pEid->Octet[0] & 0x80;
253 pEdcaParm->EdcaUpdateCount = pEid->Octet[6] & 0x0f;
254 pEdcaParm->bAPSDCapable = (pEid->Octet[6] & 0x80) ? 1 : 0;
255 ptr = &pEid->Octet[8];
258 UCHAR aci = (*ptr & 0x60) >> 5; // b5~6 is AC INDEX
259 pEdcaParm->bACM[aci] = (((*ptr) & 0x10) == 0x10); // b5 is ACM
260 pEdcaParm->Aifsn[aci] = (*ptr) & 0x0f; // b0~3 is AIFSN
261 pEdcaParm->Cwmin[aci] = *(ptr+1) & 0x0f; // b0~4 is Cwmin
262 pEdcaParm->Cwmax[aci] = *(ptr+1) >> 4; // b5~8 is Cwmax
263 pEdcaParm->Txop[aci] = *(ptr+2) + 256 * (*(ptr+3)); // in unit of 32-us
264 ptr += 4; // point to next AC
271 // 0. Check the size and CCX admin control
272 if (pAd->StaCfg.CCXControl.field.Enable == 0)
277 // Turn CCX2 if matched
278 if (NdisEqualMemory(pEid->Octet, Ccx2IeInfo, 5) == 1)
279 pAd->StaCfg.CCXEnable = TRUE;
285 DBGPRINT(RT_DEBUG_TRACE, ("PeerAssocRspSanity - ignore unrecognized EID = %d\n", pEid->Eid));
289 Length = Length + 2 + pEid->Len;
290 pEid = (PEID_STRUCT)((UCHAR*)pEid + 2 + pEid->Len);
293 // Force CCX2 enable to TRUE for those AP didn't replay CCX v2 IE, we still force it to be on
294 if (pAd->StaCfg.CCXControl.field.Enable == 1)
295 pAd->StaCfg.CCXEnable = TRUE;
301 ==========================================================================
303 MLME message sanity check
305 TRUE if all parameters are OK, FALSE otherwise
307 IRQL = DISPATCH_LEVEL
309 ==========================================================================
311 BOOLEAN PeerProbeReqSanity(
312 IN PRTMP_ADAPTER pAd,
322 PFRAME_802_11 pFrame = (PFRAME_802_11)Msg;
324 COPY_MAC_ADDR(pAddr2, pFrame->Hdr.Addr2);
326 if ((pFrame->Octet[0] != IE_SSID) || (pFrame->Octet[1] > MAX_LEN_OF_SSID))
328 DBGPRINT(RT_DEBUG_TRACE, ("PeerProbeReqSanity fail - wrong SSID IE(Type=%d,Len=%d)\n",pFrame->Octet[0],pFrame->Octet[1]));
332 *pSsidLen = pFrame->Octet[1];
333 NdisMoveMemory(Ssid, &pFrame->Octet[2], *pSsidLen);
337 // -- get supported rates from payload and advance the pointer
338 IeType = pFrame->Octet[Idx];
339 RateLen = pFrame->Octet[Idx + 1];
340 if (IeType != IE_SUPP_RATES)
342 DBGPRINT(RT_DEBUG_TRACE, ("PeerProbeReqSanity fail - wrong SupportRates IE(Type=%d,Len=%d)\n",pFrame->Octet[Idx],pFrame->Octet[Idx+1]));
347 if ((pAd->CommonCfg.PhyMode == PHY_11G) && (RateLen < 8))
355 ==========================================================================
358 IRQL = DISPATCH_LEVEL
360 ==========================================================================
366 OUT UCHAR *BcastFlag,
367 OUT UCHAR *DtimCount,
368 OUT UCHAR *DtimPeriod,
369 OUT UCHAR *MessageToMe)
371 UCHAR BitCntl, N1, N2, MyByte, MyBit;
379 // get DTIM Count from TIM element
381 *DtimCount = *IdxPtr;
383 // get DTIM Period from TIM element
385 *DtimPeriod = *IdxPtr;
387 // get Bitmap Control from TIM element
391 if ((*DtimCount == 0) && (BitCntl & 0x01))
396 // Parse Partial Virtual Bitmap from TIM element
397 N1 = BitCntl & 0xfe; // N1 is the first bitmap byte#
398 N2 = *TimLen - 4 + N1; // N2 is the last bitmap byte#
400 if ((Aid < (N1 << 3)) || (Aid >= ((N2 + 1) << 3)))
401 *MessageToMe = FALSE;
404 MyByte = (Aid >> 3) - N1; // my byte position in the bitmap byte-stream
405 MyBit = Aid % 16 - ((MyByte & 0x01)? 8:0);
407 IdxPtr += (MyByte + 1);
410 // DBGPRINT(RT_DEBUG_WARN, ("TIM bitmap = 0x%02x\n", *IdxPtr));
412 if (*IdxPtr & (0x01 << MyBit))
415 *MessageToMe = FALSE;