blob: 18723eab93d2b5bf1048c2b145ea9c72ac0c7309 [file] [log] [blame]
/*
* Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
* All rights reserved.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
*
* File: wmgr.c
*
* Purpose: Handles the 802.11 management functions
*
* Author: Lyndon Chen
*
* Date: May 8, 2002
*
* Functions:
* nsMgrObjectInitial - Initialize Management Objet data structure
* vMgrObjectReset - Reset Management Object data structure
* vMgrAssocBeginSta - Start associate function
* vMgrReAssocBeginSta - Start reassociate function
* vMgrDisassocBeginSta - Start disassociate function
* s_vMgrRxAssocRequest - Handle Rcv associate_request
* s_vMgrRxAssocResponse - Handle Rcv associate_response
* vMrgAuthenBeginSta - Start authentication function
* vMgrDeAuthenDeginSta - Start deauthentication function
* s_vMgrRxAuthentication - Handle Rcv authentication
* s_vMgrRxAuthenSequence_1 - Handle Rcv authentication sequence 1
* s_vMgrRxAuthenSequence_2 - Handle Rcv authentication sequence 2
* s_vMgrRxAuthenSequence_3 - Handle Rcv authentication sequence 3
* s_vMgrRxAuthenSequence_4 - Handle Rcv authentication sequence 4
* s_vMgrRxDisassociation - Handle Rcv disassociation
* s_vMgrRxBeacon - Handle Rcv Beacon
* vMgrCreateOwnIBSS - Create ad_hoc IBSS or AP BSS
* vMgrJoinBSSBegin - Join BSS function
* s_vMgrSynchBSS - Synch & adopt BSS parameters
* s_MgrMakeBeacon - Create Baecon frame
* s_MgrMakeProbeResponse - Create Probe Response frame
* s_MgrMakeAssocRequest - Create Associate Request frame
* s_MgrMakeReAssocRequest - Create ReAssociate Request frame
* s_vMgrRxProbeResponse - Handle Rcv probe_response
* s_vMrgRxProbeRequest - Handle Rcv probe_request
* bMgrPrepareBeaconToSend - Prepare Beacon frame
* s_vMgrLogStatus - Log 802.11 Status
* vMgrRxManagePacket - Rcv management frame dispatch function
* s_vMgrFormatTIM- Assembler TIM field of beacon
* vMgrTimerInit- Initial 1-sec and command call back funtions
*
* Revision History:
*
*/
#include "tmacro.h"
#include "desc.h"
#include "device.h"
#include "card.h"
#include "80211hdr.h"
#include "80211mgr.h"
#include "wmgr.h"
#include "wcmd.h"
#include "mac.h"
#include "bssdb.h"
#include "power.h"
#include "datarate.h"
#include "baseband.h"
#include "rxtx.h"
#include "wpa.h"
#include "rf.h"
#include "iowpa.h"
#include "usbpipe.h"
static int msglevel = MSG_LEVEL_INFO;
//static int msglevel =MSG_LEVEL_DEBUG;
static int ChannelExceedZoneType(struct vnt_private *, u8 byCurrChannel);
/* Association/diassociation functions */
static struct vnt_tx_mgmt *s_MgrMakeAssocRequest(struct vnt_private *,
struct vnt_manager *pMgmt, u8 *pDAddr, u16 wCurrCapInfo,
u16 wListenInterval, PWLAN_IE_SSID pCurrSSID,
PWLAN_IE_SUPP_RATES pCurrRates, PWLAN_IE_SUPP_RATES pCurrExtSuppRates);
static void s_vMgrRxAssocRequest(struct vnt_private *,
struct vnt_manager *pMgmt, struct vnt_rx_mgmt *pRxPacket,
u32 uNodeIndex);
static struct vnt_tx_mgmt *s_MgrMakeReAssocRequest(struct vnt_private *,
struct vnt_manager *pMgmt, u8 *pDAddr, u16 wCurrCapInfo,
u16 wListenInterval, PWLAN_IE_SSID pCurrSSID,
PWLAN_IE_SUPP_RATES pCurrRates, PWLAN_IE_SUPP_RATES pCurrExtSuppRates);
static void s_vMgrRxAssocResponse(struct vnt_private *,
struct vnt_manager *pMgmt, struct vnt_rx_mgmt *pRxPacket,
int bReAssocType);
static void s_vMgrRxDisassociation(struct vnt_private *,
struct vnt_manager *pMgmt, struct vnt_rx_mgmt *pRxPacket);
/* Authentication/deauthen functions */
static void s_vMgrRxAuthenSequence_1(struct vnt_private *,
struct vnt_manager *pMgmt, PWLAN_FR_AUTHEN pFrame);
static void s_vMgrRxAuthenSequence_2(struct vnt_private *,
struct vnt_manager *pMgmt, PWLAN_FR_AUTHEN pFrame);
static void s_vMgrRxAuthenSequence_3(struct vnt_private *,
struct vnt_manager *pMgmt, PWLAN_FR_AUTHEN pFrame);
static void s_vMgrRxAuthenSequence_4(struct vnt_private *,
struct vnt_manager *pMgmt, PWLAN_FR_AUTHEN pFrame);
static void s_vMgrRxAuthentication(struct vnt_private *,
struct vnt_manager *pMgmt, struct vnt_rx_mgmt *pRxPacket);
static void s_vMgrRxDeauthentication(struct vnt_private *,
struct vnt_manager *pMgmt, struct vnt_rx_mgmt *pRxPacket);
/* Scan functions
* probe request/response functions */
static void s_vMgrRxProbeRequest(struct vnt_private *,
struct vnt_manager *pMgmt, struct vnt_rx_mgmt *pRxPacket);
static void s_vMgrRxProbeResponse(struct vnt_private *,
struct vnt_manager *pMgmt, struct vnt_rx_mgmt *pRxPacket);
/* beacon functions */
static void s_vMgrRxBeacon(struct vnt_private *pDevice,
struct vnt_manager *pMgmt, struct vnt_rx_mgmt *pRxPacket,
int bInScan);
static void s_vMgrFormatTIM(struct vnt_manager *pMgmt, PWLAN_IE_TIM pTIM);
static struct vnt_tx_mgmt *s_MgrMakeBeacon(struct vnt_private *pDevice,
struct vnt_manager *pMgmt, u16 wCurrCapInfo, u16 wCurrBeaconPeriod,
u32 uCurrChannel, u16 wCurrATIMWinodw, PWLAN_IE_SSID pCurrSSID,
u8 *pCurrBSSID, PWLAN_IE_SUPP_RATES pCurrSuppRates,
PWLAN_IE_SUPP_RATES pCurrExtSuppRates);
/* Association response */
static struct vnt_tx_mgmt *s_MgrMakeAssocResponse(struct vnt_private *,
struct vnt_manager *pMgmt, u16 wCurrCapInfo, u16 wAssocStatus,
u16 wAssocAID, u8 *pDstAddr, PWLAN_IE_SUPP_RATES pCurrSuppRates,
PWLAN_IE_SUPP_RATES pCurrExtSuppRates);
/* ReAssociation response */
static struct vnt_tx_mgmt *s_MgrMakeReAssocResponse(struct vnt_private *,
struct vnt_manager *pMgmt, u16 wCurrCapInfo, u16 wAssocStatus,
u16 wAssocAID, u8 *pDstAddr, PWLAN_IE_SUPP_RATES pCurrSuppRates,
PWLAN_IE_SUPP_RATES pCurrExtSuppRates);
/* Probe response */
static struct vnt_tx_mgmt *s_MgrMakeProbeResponse(struct vnt_private *,
struct vnt_manager *pMgmt, u16 wCurrCapInfo, u16 wCurrBeaconPeriod,
u32 uCurrChannel, u16 wCurrATIMWinodw, u8 *pDstAddr,
PWLAN_IE_SSID pCurrSSID, u8 *pCurrBSSID,
PWLAN_IE_SUPP_RATES pCurrSuppRates,
PWLAN_IE_SUPP_RATES pCurrExtSuppRates, u8 byPHYType);
/* received status */
static void s_vMgrLogStatus(struct vnt_manager *pMgmt, u16 wStatus);
static void s_vMgrSynchBSS(struct vnt_private *, u32 uBSSMode,
PKnownBSS pCurr, PCMD_STATUS pStatus);
static bool
s_bCipherMatch (
PKnownBSS pBSSNode,
NDIS_802_11_ENCRYPTION_STATUS EncStatus,
u8 * pbyCCSPK,
u8 * pbyCCSGK
);
static void Encyption_Rebuild(struct vnt_private *, PKnownBSS pCurr);
/*+
*
* Routine Description:
* Allocates and initializes the Management object.
*
* Return Value:
* Ndis_staus.
*
-*/
void vMgrObjectInit(struct vnt_private *pDevice)
{
struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
int ii;
pMgmt->pbyPSPacketPool = &pMgmt->byPSPacketPool[0];
pMgmt->pbyMgmtPacketPool = &pMgmt->byMgmtPacketPool[0];
pMgmt->uCurrChannel = pDevice->uChannel;
for (ii = 0; ii < WLAN_BSSID_LEN; ii++)
pMgmt->abyDesireBSSID[ii] = 0xFF;
pMgmt->sAssocInfo.AssocInfo.Length = sizeof(NDIS_802_11_ASSOCIATION_INFORMATION);
//memset(pMgmt->abyDesireSSID, 0, WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN +1);
pMgmt->byCSSPK = KEY_CTL_NONE;
pMgmt->byCSSGK = KEY_CTL_NONE;
pMgmt->wIBSSBeaconPeriod = DEFAULT_IBSS_BI;
BSSvClearBSSList((void *) pDevice, false);
pDevice->cbFreeCmdQueue = CMD_Q_SIZE;
pDevice->uCmdDequeueIdx = 0;
pDevice->uCmdEnqueueIdx = 0;
pDevice->eCommandState = WLAN_CMD_IDLE;
pDevice->bCmdRunning = false;
pDevice->bCmdClear = false;
return;
}
/*+
*
* Routine Description:
* Start the station association procedure. Namely, send an
* association request frame to the AP.
*
* Return Value:
* None.
*
-*/
void vMgrAssocBeginSta(struct vnt_private *pDevice,
struct vnt_manager *pMgmt, PCMD_STATUS pStatus)
{
struct vnt_tx_mgmt *pTxPacket;
pMgmt->wCurrCapInfo = 0;
pMgmt->wCurrCapInfo |= WLAN_SET_CAP_INFO_ESS(1);
if (pDevice->bEncryptionEnable) {
pMgmt->wCurrCapInfo |= WLAN_SET_CAP_INFO_PRIVACY(1);
}
// always allow receive short preamble
//if (pDevice->byPreambleType == 1) {
// pMgmt->wCurrCapInfo |= WLAN_SET_CAP_INFO_SHORTPREAMBLE(1);
//}
pMgmt->wCurrCapInfo |= WLAN_SET_CAP_INFO_SHORTPREAMBLE(1);
if (pMgmt->wListenInterval == 0)
pMgmt->wListenInterval = 1; // at least one.
// ERP Phy (802.11g) should support short preamble.
if (pMgmt->eCurrentPHYMode == PHY_TYPE_11G) {
pMgmt->wCurrCapInfo |= WLAN_SET_CAP_INFO_SHORTPREAMBLE(1);
if (pDevice->bShortSlotTime == true)
pMgmt->wCurrCapInfo |= WLAN_SET_CAP_INFO_SHORTSLOTTIME(1);
} else if (pMgmt->eCurrentPHYMode == PHY_TYPE_11B) {
if (pDevice->byPreambleType == 1) {
pMgmt->wCurrCapInfo |= WLAN_SET_CAP_INFO_SHORTPREAMBLE(1);
}
}
if (pMgmt->b11hEnable == true)
pMgmt->wCurrCapInfo |= WLAN_SET_CAP_INFO_SPECTRUMMNG(1);
// build an assocreq frame and send it
pTxPacket = s_MgrMakeAssocRequest
(
pDevice,
pMgmt,
pMgmt->abyCurrBSSID,
pMgmt->wCurrCapInfo,
pMgmt->wListenInterval,
(PWLAN_IE_SSID)pMgmt->abyCurrSSID,
(PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates,
(PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates
);
if (pTxPacket != NULL ){
// send the frame
*pStatus = csMgmt_xmit(pDevice, pTxPacket);
if (*pStatus == CMD_STATUS_PENDING) {
pMgmt->eCurrState = WMAC_STATE_ASSOCPENDING;
*pStatus = CMD_STATUS_SUCCESS;
}
}
else
*pStatus = CMD_STATUS_RESOURCES;
return ;
}
/*+
*
* Routine Description:
* Start the station re-association procedure.
*
* Return Value:
* None.
*
-*/
void vMgrReAssocBeginSta(struct vnt_private *pDevice,
struct vnt_manager *pMgmt, PCMD_STATUS pStatus)
{
struct vnt_tx_mgmt *pTxPacket;
pMgmt->wCurrCapInfo = 0;
pMgmt->wCurrCapInfo |= WLAN_SET_CAP_INFO_ESS(1);
if (pDevice->bEncryptionEnable) {
pMgmt->wCurrCapInfo |= WLAN_SET_CAP_INFO_PRIVACY(1);
}
//if (pDevice->byPreambleType == 1) {
// pMgmt->wCurrCapInfo |= WLAN_SET_CAP_INFO_SHORTPREAMBLE(1);
//}
pMgmt->wCurrCapInfo |= WLAN_SET_CAP_INFO_SHORTPREAMBLE(1);
if (pMgmt->wListenInterval == 0)
pMgmt->wListenInterval = 1; // at least one.
// ERP Phy (802.11g) should support short preamble.
if (pMgmt->eCurrentPHYMode == PHY_TYPE_11G) {
pMgmt->wCurrCapInfo |= WLAN_SET_CAP_INFO_SHORTPREAMBLE(1);
if (pDevice->bShortSlotTime == true)
pMgmt->wCurrCapInfo |= WLAN_SET_CAP_INFO_SHORTSLOTTIME(1);
} else if (pMgmt->eCurrentPHYMode == PHY_TYPE_11B) {
if (pDevice->byPreambleType == 1) {
pMgmt->wCurrCapInfo |= WLAN_SET_CAP_INFO_SHORTPREAMBLE(1);
}
}
if (pMgmt->b11hEnable == true)
pMgmt->wCurrCapInfo |= WLAN_SET_CAP_INFO_SPECTRUMMNG(1);
pTxPacket = s_MgrMakeReAssocRequest
(
pDevice,
pMgmt,
pMgmt->abyCurrBSSID,
pMgmt->wCurrCapInfo,
pMgmt->wListenInterval,
(PWLAN_IE_SSID)pMgmt->abyCurrSSID,
(PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates,
(PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates
);
if (pTxPacket != NULL ){
// send the frame
*pStatus = csMgmt_xmit(pDevice, pTxPacket);
if (*pStatus != CMD_STATUS_PENDING) {
DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Mgt:Reassociation tx failed.\n");
}
else {
DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Mgt:Reassociation tx sending.\n");
}
}
return ;
}
/*+
*
* Routine Description:
* Send an dis-association request frame to the AP.
*
* Return Value:
* None.
*
-*/
void vMgrDisassocBeginSta(struct vnt_private *pDevice,
struct vnt_manager *pMgmt, u8 *abyDestAddress, u16 wReason,
PCMD_STATUS pStatus)
{
struct vnt_tx_mgmt *pTxPacket = NULL;
WLAN_FR_DISASSOC sFrame;
pTxPacket = (struct vnt_tx_mgmt *)pMgmt->pbyMgmtPacketPool;
memset(pTxPacket, 0, sizeof(struct vnt_tx_mgmt)
+ WLAN_DISASSOC_FR_MAXLEN);
pTxPacket->p80211Header = (PUWLAN_80211HDR)((u8 *)pTxPacket
+ sizeof(struct vnt_tx_mgmt));
// Setup the sFrame structure
sFrame.pBuf = (u8 *)pTxPacket->p80211Header;
sFrame.len = WLAN_DISASSOC_FR_MAXLEN;
// format fixed field frame structure
vMgrEncodeDisassociation(&sFrame);
// Setup the header
sFrame.pHdr->sA3.wFrameCtl = cpu_to_le16(
(
WLAN_SET_FC_FTYPE(WLAN_TYPE_MGR) |
WLAN_SET_FC_FSTYPE(WLAN_FSTYPE_DISASSOC)
));
memcpy( sFrame.pHdr->sA3.abyAddr1, abyDestAddress, WLAN_ADDR_LEN);
memcpy( sFrame.pHdr->sA3.abyAddr2, pMgmt->abyMACAddr, WLAN_ADDR_LEN);
memcpy( sFrame.pHdr->sA3.abyAddr3, pMgmt->abyCurrBSSID, WLAN_BSSID_LEN);
// Set reason code
*(sFrame.pwReason) = cpu_to_le16(wReason);
pTxPacket->cbMPDULen = sFrame.len;
pTxPacket->cbPayloadLen = sFrame.len - WLAN_HDR_ADDR3_LEN;
// send the frame
*pStatus = csMgmt_xmit(pDevice, pTxPacket);
if (*pStatus == CMD_STATUS_PENDING) {
pMgmt->eCurrState = WMAC_STATE_IDLE;
*pStatus = CMD_STATUS_SUCCESS;
}
return;
}
/*+
*
* Routine Description:(AP function)
* Handle incoming station association request frames.
*
* Return Value:
* None.
*
-*/
static void s_vMgrRxAssocRequest(struct vnt_private *pDevice,
struct vnt_manager *pMgmt, struct vnt_rx_mgmt *pRxPacket,
u32 uNodeIndex)
{
WLAN_FR_ASSOCREQ sFrame;
CMD_STATUS Status;
struct vnt_tx_mgmt *pTxPacket;
u16 wAssocStatus = 0;
u16 wAssocAID = 0;
u32 uRateLen = WLAN_RATES_MAXLEN;
u8 abyCurrSuppRates[WLAN_IEHDR_LEN + WLAN_RATES_MAXLEN + 1];
u8 abyCurrExtSuppRates[WLAN_IEHDR_LEN + WLAN_RATES_MAXLEN + 1];
if (pMgmt->eCurrMode != WMAC_MODE_ESS_AP)
return;
// node index not found
if (!uNodeIndex)
return;
//check if node is authenticated
//decode the frame
memset(&sFrame, 0, sizeof(WLAN_FR_ASSOCREQ));
memset(abyCurrSuppRates, 0, WLAN_IEHDR_LEN + WLAN_RATES_MAXLEN + 1);
memset(abyCurrExtSuppRates, 0, WLAN_IEHDR_LEN + WLAN_RATES_MAXLEN + 1);
sFrame.len = pRxPacket->cbMPDULen;
sFrame.pBuf = (u8 *)pRxPacket->p80211Header;
vMgrDecodeAssocRequest(&sFrame);
if (pMgmt->sNodeDBTable[uNodeIndex].eNodeState >= NODE_AUTH) {
pMgmt->sNodeDBTable[uNodeIndex].eNodeState = NODE_ASSOC;
pMgmt->sNodeDBTable[uNodeIndex].wCapInfo = cpu_to_le16(*sFrame.pwCapInfo);
pMgmt->sNodeDBTable[uNodeIndex].wListenInterval = cpu_to_le16(*sFrame.pwListenInterval);
pMgmt->sNodeDBTable[uNodeIndex].bPSEnable =
WLAN_GET_FC_PWRMGT(sFrame.pHdr->sA3.wFrameCtl) ? true : false;
// Todo: check sta basic rate, if ap can't support, set status code
if (pDevice->byBBType == BB_TYPE_11B) {
uRateLen = WLAN_RATES_MAXLEN_11B;
}
abyCurrSuppRates[0] = WLAN_EID_SUPP_RATES;
abyCurrSuppRates[1] = RATEuSetIE((PWLAN_IE_SUPP_RATES)sFrame.pSuppRates,
(PWLAN_IE_SUPP_RATES)abyCurrSuppRates,
uRateLen);
abyCurrExtSuppRates[0] = WLAN_EID_EXTSUPP_RATES;
if (pDevice->byBBType == BB_TYPE_11G) {
abyCurrExtSuppRates[1] = RATEuSetIE((PWLAN_IE_SUPP_RATES)sFrame.pExtSuppRates,
(PWLAN_IE_SUPP_RATES)abyCurrExtSuppRates,
uRateLen);
} else {
abyCurrExtSuppRates[1] = 0;
}
RATEvParseMaxRate((void *)pDevice,
(PWLAN_IE_SUPP_RATES)abyCurrSuppRates,
(PWLAN_IE_SUPP_RATES)abyCurrExtSuppRates,
false, // do not change our basic rate
&(pMgmt->sNodeDBTable[uNodeIndex].wMaxBasicRate),
&(pMgmt->sNodeDBTable[uNodeIndex].wMaxSuppRate),
&(pMgmt->sNodeDBTable[uNodeIndex].wSuppRate),
&(pMgmt->sNodeDBTable[uNodeIndex].byTopCCKBasicRate),
&(pMgmt->sNodeDBTable[uNodeIndex].byTopOFDMBasicRate)
);
// set max tx rate
pMgmt->sNodeDBTable[uNodeIndex].wTxDataRate =
pMgmt->sNodeDBTable[uNodeIndex].wMaxSuppRate;
// Todo: check sta preamble, if ap can't support, set status code
pMgmt->sNodeDBTable[uNodeIndex].bShortPreamble =
WLAN_GET_CAP_INFO_SHORTPREAMBLE(*sFrame.pwCapInfo);
pMgmt->sNodeDBTable[uNodeIndex].bShortSlotTime =
WLAN_GET_CAP_INFO_SHORTSLOTTIME(*sFrame.pwCapInfo);
pMgmt->sNodeDBTable[uNodeIndex].wAID = (u16)uNodeIndex;
wAssocStatus = WLAN_MGMT_STATUS_SUCCESS;
wAssocAID = (u16)uNodeIndex;
// check if ERP support
if(pMgmt->sNodeDBTable[uNodeIndex].wMaxSuppRate > RATE_11M)
pMgmt->sNodeDBTable[uNodeIndex].bERPExist = true;
if (pMgmt->sNodeDBTable[uNodeIndex].wMaxSuppRate <= RATE_11M) {
// B only STA join
pDevice->bProtectMode = true;
pDevice->bNonERPPresent = true;
}
if (pMgmt->sNodeDBTable[uNodeIndex].bShortPreamble == false) {
pDevice->bBarkerPreambleMd = true;
}
DBG_PRT(MSG_LEVEL_INFO, KERN_INFO "Associate AID= %d \n", wAssocAID);
DBG_PRT(MSG_LEVEL_INFO, KERN_INFO "MAC=%2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X \n",
sFrame.pHdr->sA3.abyAddr2[0],
sFrame.pHdr->sA3.abyAddr2[1],
sFrame.pHdr->sA3.abyAddr2[2],
sFrame.pHdr->sA3.abyAddr2[3],
sFrame.pHdr->sA3.abyAddr2[4],
sFrame.pHdr->sA3.abyAddr2[5]
) ;
DBG_PRT(MSG_LEVEL_INFO, KERN_INFO "Max Support rate = %d \n",
pMgmt->sNodeDBTable[uNodeIndex].wMaxSuppRate);
}
// assoc response reply..
pTxPacket = s_MgrMakeAssocResponse
(
pDevice,
pMgmt,
pMgmt->wCurrCapInfo,
wAssocStatus,
wAssocAID,
sFrame.pHdr->sA3.abyAddr2,
(PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates,
(PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates
);
if (pTxPacket != NULL ){
/* send the frame */
Status = csMgmt_xmit(pDevice, pTxPacket);
if (Status != CMD_STATUS_PENDING) {
DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Mgt:Assoc response tx failed\n");
}
else {
DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Mgt:Assoc response tx sending..\n");
}
}
return;
}
/*+
*
* Description:(AP function)
* Handle incoming station re-association request frames.
*
* Parameters:
* In:
* pMgmt - Management Object structure
* pRxPacket - Received Packet
* Out:
* none
*
* Return Value: None.
*
-*/
static void s_vMgrRxReAssocRequest(struct vnt_private *pDevice,
struct vnt_manager *pMgmt, struct vnt_rx_mgmt *pRxPacket,
u32 uNodeIndex)
{
WLAN_FR_REASSOCREQ sFrame;
CMD_STATUS Status;
struct vnt_tx_mgmt *pTxPacket;
u16 wAssocStatus = 0;
u16 wAssocAID = 0;
u32 uRateLen = WLAN_RATES_MAXLEN;
u8 abyCurrSuppRates[WLAN_IEHDR_LEN + WLAN_RATES_MAXLEN + 1];
u8 abyCurrExtSuppRates[WLAN_IEHDR_LEN + WLAN_RATES_MAXLEN + 1];
if (pMgmt->eCurrMode != WMAC_MODE_ESS_AP)
return;
// node index not found
if (!uNodeIndex)
return;
//check if node is authenticated
//decode the frame
memset(&sFrame, 0, sizeof(WLAN_FR_REASSOCREQ));
sFrame.len = pRxPacket->cbMPDULen;
sFrame.pBuf = (u8 *)pRxPacket->p80211Header;
vMgrDecodeReassocRequest(&sFrame);
if (pMgmt->sNodeDBTable[uNodeIndex].eNodeState >= NODE_AUTH) {
pMgmt->sNodeDBTable[uNodeIndex].eNodeState = NODE_ASSOC;
pMgmt->sNodeDBTable[uNodeIndex].wCapInfo = cpu_to_le16(*sFrame.pwCapInfo);
pMgmt->sNodeDBTable[uNodeIndex].wListenInterval = cpu_to_le16(*sFrame.pwListenInterval);
pMgmt->sNodeDBTable[uNodeIndex].bPSEnable =
WLAN_GET_FC_PWRMGT(sFrame.pHdr->sA3.wFrameCtl) ? true : false;
// Todo: check sta basic rate, if ap can't support, set status code
if (pDevice->byBBType == BB_TYPE_11B) {
uRateLen = WLAN_RATES_MAXLEN_11B;
}
abyCurrSuppRates[0] = WLAN_EID_SUPP_RATES;
abyCurrSuppRates[1] = RATEuSetIE((PWLAN_IE_SUPP_RATES)sFrame.pSuppRates,
(PWLAN_IE_SUPP_RATES)abyCurrSuppRates,
uRateLen);
abyCurrExtSuppRates[0] = WLAN_EID_EXTSUPP_RATES;
if (pDevice->byBBType == BB_TYPE_11G) {
abyCurrExtSuppRates[1] = RATEuSetIE((PWLAN_IE_SUPP_RATES)sFrame.pExtSuppRates,
(PWLAN_IE_SUPP_RATES)abyCurrExtSuppRates,
uRateLen);
} else {
abyCurrExtSuppRates[1] = 0;
}
RATEvParseMaxRate((void *)pDevice,
(PWLAN_IE_SUPP_RATES)abyCurrSuppRates,
(PWLAN_IE_SUPP_RATES)abyCurrExtSuppRates,
false, // do not change our basic rate
&(pMgmt->sNodeDBTable[uNodeIndex].wMaxBasicRate),
&(pMgmt->sNodeDBTable[uNodeIndex].wMaxSuppRate),
&(pMgmt->sNodeDBTable[uNodeIndex].wSuppRate),
&(pMgmt->sNodeDBTable[uNodeIndex].byTopCCKBasicRate),
&(pMgmt->sNodeDBTable[uNodeIndex].byTopOFDMBasicRate)
);
// set max tx rate
pMgmt->sNodeDBTable[uNodeIndex].wTxDataRate =
pMgmt->sNodeDBTable[uNodeIndex].wMaxSuppRate;
// Todo: check sta preamble, if ap can't support, set status code
pMgmt->sNodeDBTable[uNodeIndex].bShortPreamble =
WLAN_GET_CAP_INFO_SHORTPREAMBLE(*sFrame.pwCapInfo);
pMgmt->sNodeDBTable[uNodeIndex].bShortSlotTime =
WLAN_GET_CAP_INFO_SHORTSLOTTIME(*sFrame.pwCapInfo);
pMgmt->sNodeDBTable[uNodeIndex].wAID = (u16)uNodeIndex;
wAssocStatus = WLAN_MGMT_STATUS_SUCCESS;
wAssocAID = (u16)uNodeIndex;
// if suppurt ERP
if(pMgmt->sNodeDBTable[uNodeIndex].wMaxSuppRate > RATE_11M)
pMgmt->sNodeDBTable[uNodeIndex].bERPExist = true;
if (pMgmt->sNodeDBTable[uNodeIndex].wMaxSuppRate <= RATE_11M) {
// B only STA join
pDevice->bProtectMode = true;
pDevice->bNonERPPresent = true;
}
if (pMgmt->sNodeDBTable[uNodeIndex].bShortPreamble == false) {
pDevice->bBarkerPreambleMd = true;
}
DBG_PRT(MSG_LEVEL_INFO, KERN_INFO "Rx ReAssociate AID= %d \n", wAssocAID);
DBG_PRT(MSG_LEVEL_INFO, KERN_INFO "MAC=%2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X \n",
sFrame.pHdr->sA3.abyAddr2[0],
sFrame.pHdr->sA3.abyAddr2[1],
sFrame.pHdr->sA3.abyAddr2[2],
sFrame.pHdr->sA3.abyAddr2[3],
sFrame.pHdr->sA3.abyAddr2[4],
sFrame.pHdr->sA3.abyAddr2[5]
) ;
DBG_PRT(MSG_LEVEL_INFO, KERN_INFO "Max Support rate = %d \n",
pMgmt->sNodeDBTable[uNodeIndex].wMaxSuppRate);
}
// assoc response reply..
pTxPacket = s_MgrMakeReAssocResponse
(
pDevice,
pMgmt,
pMgmt->wCurrCapInfo,
wAssocStatus,
wAssocAID,
sFrame.pHdr->sA3.abyAddr2,
(PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates,
(PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates
);
if (pTxPacket != NULL ){
/* send the frame */
Status = csMgmt_xmit(pDevice, pTxPacket);
if (Status != CMD_STATUS_PENDING) {
DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Mgt:ReAssoc response tx failed\n");
}
else {
DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Mgt:ReAssoc response tx sending..\n");
}
}
return;
}
/*+
*
* Routine Description:
* Handle incoming association response frames.
*
* Return Value:
* None.
*
-*/
static void s_vMgrRxAssocResponse(struct vnt_private *pDevice,
struct vnt_manager *pMgmt, struct vnt_rx_mgmt *pRxPacket,
int bReAssocType)
{
WLAN_FR_ASSOCRESP sFrame;
PWLAN_IE_SSID pItemSSID;
u8 *pbyIEs;
if (pMgmt->eCurrState == WMAC_STATE_ASSOCPENDING ||
pMgmt->eCurrState == WMAC_STATE_ASSOC) {
sFrame.len = pRxPacket->cbMPDULen;
sFrame.pBuf = (u8 *)pRxPacket->p80211Header;
// decode the frame
vMgrDecodeAssocResponse(&sFrame);
if ((sFrame.pwCapInfo == NULL)
|| (sFrame.pwStatus == NULL)
|| (sFrame.pwAid == NULL)
|| (sFrame.pSuppRates == NULL)) {
return;
}
pMgmt->sAssocInfo.AssocInfo.ResponseFixedIEs.Capabilities = *(sFrame.pwCapInfo);
pMgmt->sAssocInfo.AssocInfo.ResponseFixedIEs.StatusCode = *(sFrame.pwStatus);
pMgmt->sAssocInfo.AssocInfo.ResponseFixedIEs.AssociationId = *(sFrame.pwAid);
pMgmt->sAssocInfo.AssocInfo.AvailableResponseFixedIEs |= 0x07;
pMgmt->sAssocInfo.AssocInfo.ResponseIELength = sFrame.len - 24 - 6;
pMgmt->sAssocInfo.AssocInfo.OffsetResponseIEs = pMgmt->sAssocInfo.AssocInfo.OffsetRequestIEs + pMgmt->sAssocInfo.AssocInfo.RequestIELength;
pbyIEs = pMgmt->sAssocInfo.abyIEs;
pbyIEs += pMgmt->sAssocInfo.AssocInfo.RequestIELength;
memcpy(pbyIEs, (sFrame.pBuf + 24 +6), pMgmt->sAssocInfo.AssocInfo.ResponseIELength);
// save values and set current BSS state
if (cpu_to_le16((*(sFrame.pwStatus))) == WLAN_MGMT_STATUS_SUCCESS ){
// set AID
pMgmt->wCurrAID = cpu_to_le16((*(sFrame.pwAid)));
if ( (pMgmt->wCurrAID >> 14) != (BIT0 | BIT1) )
{
DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "AID from AP, has two msb clear.\n");
}
DBG_PRT(MSG_LEVEL_INFO, KERN_INFO "Association Successful, AID=%d.\n", pMgmt->wCurrAID & ~(BIT14|BIT15));
pMgmt->eCurrState = WMAC_STATE_ASSOC;
BSSvUpdateAPNode((void *) pDevice,
sFrame.pwCapInfo,
sFrame.pSuppRates,
sFrame.pExtSuppRates);
pItemSSID = (PWLAN_IE_SSID)pMgmt->abyCurrSSID;
DBG_PRT(MSG_LEVEL_INFO, KERN_INFO "Link with AP(SSID): %s\n", pItemSSID->abySSID);
pDevice->bLinkPass = true;
vnt_mac_set_led(pDevice, LEDSTS_STS, LEDSTS_INTER);
//if(pDevice->bWPASuppWextEnabled == true)
{
u8 buf[512];
size_t len;
union iwreq_data wrqu;
int we_event;
memset(buf, 0, 512);
len = pMgmt->sAssocInfo.AssocInfo.RequestIELength;
if(len) {
memcpy(buf, pMgmt->sAssocInfo.abyIEs, len);
memset(&wrqu, 0, sizeof (wrqu));
wrqu.data.length = len;
we_event = IWEVASSOCREQIE;
PRINT_K("wireless_send_event--->IWEVASSOCREQIE\n");
wireless_send_event(pDevice->dev, we_event, &wrqu, buf);
}
memset(buf, 0, 512);
len = pMgmt->sAssocInfo.AssocInfo.ResponseIELength;
if(len) {
memcpy(buf, pbyIEs, len);
memset(&wrqu, 0, sizeof (wrqu));
wrqu.data.length = len;
we_event = IWEVASSOCRESPIE;
PRINT_K("wireless_send_event--->IWEVASSOCRESPIE\n");
wireless_send_event(pDevice->dev, we_event, &wrqu, buf);
}
memset(&wrqu, 0, sizeof (wrqu));
memcpy(wrqu.ap_addr.sa_data, &pMgmt->abyCurrBSSID[0], ETH_ALEN);
wrqu.ap_addr.sa_family = ARPHRD_ETHER;
PRINT_K("wireless_send_event--->SIOCGIWAP(associated)\n");
wireless_send_event(pDevice->dev, SIOCGIWAP, &wrqu, NULL);
}
}
else {
if (bReAssocType) {
pMgmt->eCurrState = WMAC_STATE_IDLE;
}
else {
// jump back to the auth state and indicate the error
pMgmt->eCurrState = WMAC_STATE_AUTH;
}
s_vMgrLogStatus(pMgmt,cpu_to_le16((*(sFrame.pwStatus))));
}
}
//need clear flags related to Networkmanager
pDevice->bwextstep0 = false;
pDevice->bwextstep1 = false;
pDevice->bwextstep2 = false;
pDevice->bwextstep3 = false;
pDevice->bWPASuppWextEnabled = false;
if (pMgmt->eCurrState == WMAC_STATE_ASSOC)
schedule_delayed_work(&pDevice->run_command_work, 0);
return;
}
/*+
*
* Routine Description:
* Start the station authentication procedure. Namely, send an
* authentication frame to the AP.
*
* Return Value:
* None.
*
-*/
void vMgrAuthenBeginSta(struct vnt_private *pDevice,
struct vnt_manager *pMgmt, PCMD_STATUS pStatus)
{
WLAN_FR_AUTHEN sFrame;
struct vnt_tx_mgmt *pTxPacket =
(struct vnt_tx_mgmt *)pMgmt->pbyMgmtPacketPool;
memset(pTxPacket, 0, sizeof(struct vnt_tx_mgmt)
+ WLAN_AUTHEN_FR_MAXLEN);
pTxPacket->p80211Header = (PUWLAN_80211HDR)((u8 *)pTxPacket
+ sizeof(struct vnt_tx_mgmt));
sFrame.pBuf = (u8 *)pTxPacket->p80211Header;
sFrame.len = WLAN_AUTHEN_FR_MAXLEN;
vMgrEncodeAuthen(&sFrame);
/* insert values */
sFrame.pHdr->sA3.wFrameCtl = cpu_to_le16(
(
WLAN_SET_FC_FTYPE(WLAN_TYPE_MGR) |
WLAN_SET_FC_FSTYPE(WLAN_FSTYPE_AUTHEN)
));
memcpy( sFrame.pHdr->sA3.abyAddr1, pMgmt->abyCurrBSSID, WLAN_ADDR_LEN);
memcpy( sFrame.pHdr->sA3.abyAddr2, pMgmt->abyMACAddr, WLAN_ADDR_LEN);
memcpy( sFrame.pHdr->sA3.abyAddr3, pMgmt->abyCurrBSSID, WLAN_BSSID_LEN);
if (pMgmt->bShareKeyAlgorithm)
*(sFrame.pwAuthAlgorithm) = cpu_to_le16(WLAN_AUTH_ALG_SHAREDKEY);
else
*(sFrame.pwAuthAlgorithm) = cpu_to_le16(WLAN_AUTH_ALG_OPENSYSTEM);
*(sFrame.pwAuthSequence) = cpu_to_le16(1);
/* Adjust the length fields */
pTxPacket->cbMPDULen = sFrame.len;
pTxPacket->cbPayloadLen = sFrame.len - WLAN_HDR_ADDR3_LEN;
*pStatus = csMgmt_xmit(pDevice, pTxPacket);
if (*pStatus == CMD_STATUS_PENDING){
pMgmt->eCurrState = WMAC_STATE_AUTHPENDING;
*pStatus = CMD_STATUS_SUCCESS;
}
return ;
}
/*+
*
* Routine Description:
* Start the station(AP) deauthentication procedure. Namely, send an
* deauthentication frame to the AP or Sta.
*
* Return Value:
* None.
*
-*/
void vMgrDeAuthenBeginSta(struct vnt_private *pDevice,
struct vnt_manager *pMgmt, u8 *abyDestAddress, u16 wReason,
PCMD_STATUS pStatus)
{
WLAN_FR_DEAUTHEN sFrame;
struct vnt_tx_mgmt *pTxPacket =
(struct vnt_tx_mgmt *)pMgmt->pbyMgmtPacketPool;
memset(pTxPacket, 0, sizeof(struct vnt_tx_mgmt)
+ WLAN_DEAUTHEN_FR_MAXLEN);
pTxPacket->p80211Header = (PUWLAN_80211HDR)((u8 *)pTxPacket
+ sizeof(struct vnt_tx_mgmt));
sFrame.pBuf = (u8 *)pTxPacket->p80211Header;
sFrame.len = WLAN_DEAUTHEN_FR_MAXLEN;
vMgrEncodeDeauthen(&sFrame);
/* insert values */
sFrame.pHdr->sA3.wFrameCtl = cpu_to_le16(
(
WLAN_SET_FC_FTYPE(WLAN_TYPE_MGR) |
WLAN_SET_FC_FSTYPE(WLAN_FSTYPE_DEAUTHEN)
));
memcpy( sFrame.pHdr->sA3.abyAddr1, abyDestAddress, WLAN_ADDR_LEN);
memcpy( sFrame.pHdr->sA3.abyAddr2, pMgmt->abyMACAddr, WLAN_ADDR_LEN);
memcpy( sFrame.pHdr->sA3.abyAddr3, pMgmt->abyCurrBSSID, WLAN_BSSID_LEN);
*(sFrame.pwReason) = cpu_to_le16(wReason); // deauthen. bcs left BSS
/* Adjust the length fields */
pTxPacket->cbMPDULen = sFrame.len;
pTxPacket->cbPayloadLen = sFrame.len - WLAN_HDR_ADDR3_LEN;
*pStatus = csMgmt_xmit(pDevice, pTxPacket);
if (*pStatus == CMD_STATUS_PENDING){
*pStatus = CMD_STATUS_SUCCESS;
}
return ;
}
/*+
*
* Routine Description:
* Handle incoming authentication frames.
*
* Return Value:
* None.
*
-*/
static void s_vMgrRxAuthentication(struct vnt_private *pDevice,
struct vnt_manager *pMgmt, struct vnt_rx_mgmt *pRxPacket)
{
WLAN_FR_AUTHEN sFrame;
// we better be an AP or a STA in AUTHPENDING otherwise ignore
if (!(pMgmt->eCurrMode == WMAC_MODE_ESS_AP ||
pMgmt->eCurrState == WMAC_STATE_AUTHPENDING)) {
return;
}
// decode the frame
sFrame.len = pRxPacket->cbMPDULen;
sFrame.pBuf = (u8 *)pRxPacket->p80211Header;
vMgrDecodeAuthen(&sFrame);
switch (cpu_to_le16((*(sFrame.pwAuthSequence )))){
case 1:
//AP funciton
s_vMgrRxAuthenSequence_1(pDevice,pMgmt, &sFrame);
break;
case 2:
s_vMgrRxAuthenSequence_2(pDevice, pMgmt, &sFrame);
break;
case 3:
//AP funciton
s_vMgrRxAuthenSequence_3(pDevice, pMgmt, &sFrame);
break;
case 4:
s_vMgrRxAuthenSequence_4(pDevice, pMgmt, &sFrame);
break;
default:
DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Auth Sequence error, seq = %d\n",
cpu_to_le16((*(sFrame.pwAuthSequence))));
break;
}
return;
}
/*+
*
* Routine Description:
* Handles incoming authen frames with sequence 1. Currently
* assumes we're an AP. So far, no one appears to use authentication
* in Ad-Hoc mode.
*
* Return Value:
* None.
*
-*/
static void s_vMgrRxAuthenSequence_1(struct vnt_private *pDevice,
struct vnt_manager *pMgmt, PWLAN_FR_AUTHEN pFrame)
{
struct vnt_tx_mgmt *pTxPacket = NULL;
u32 uNodeIndex;
WLAN_FR_AUTHEN sFrame;
PSKeyItem pTransmitKey;
/* Insert a Node entry */
if (!BSSbIsSTAInNodeDB(pDevice, pFrame->pHdr->sA3.abyAddr2,
&uNodeIndex)) {
BSSvCreateOneNode(pDevice, &uNodeIndex);
memcpy(pMgmt->sNodeDBTable[uNodeIndex].abyMACAddr,
pFrame->pHdr->sA3.abyAddr2, WLAN_ADDR_LEN);
}
if (pMgmt->bShareKeyAlgorithm) {
pMgmt->sNodeDBTable[uNodeIndex].eNodeState = NODE_KNOWN;
pMgmt->sNodeDBTable[uNodeIndex].byAuthSequence = 1;
}
else {
pMgmt->sNodeDBTable[uNodeIndex].eNodeState = NODE_AUTH;
}
// send auth reply
pTxPacket = (struct vnt_tx_mgmt *)pMgmt->pbyMgmtPacketPool;
memset(pTxPacket, 0, sizeof(struct vnt_tx_mgmt)
+ WLAN_AUTHEN_FR_MAXLEN);
pTxPacket->p80211Header = (PUWLAN_80211HDR)((u8 *)pTxPacket
+ sizeof(struct vnt_tx_mgmt));
sFrame.pBuf = (u8 *)pTxPacket->p80211Header;
sFrame.len = WLAN_AUTHEN_FR_MAXLEN;
// format buffer structure
vMgrEncodeAuthen(&sFrame);
// insert values
sFrame.pHdr->sA3.wFrameCtl = cpu_to_le16(
(
WLAN_SET_FC_FTYPE(WLAN_TYPE_MGR) |
WLAN_SET_FC_FSTYPE(WLAN_FSTYPE_AUTHEN)|
WLAN_SET_FC_ISWEP(0)
));
memcpy( sFrame.pHdr->sA3.abyAddr1, pFrame->pHdr->sA3.abyAddr2, WLAN_ADDR_LEN);
memcpy( sFrame.pHdr->sA3.abyAddr2, pMgmt->abyMACAddr, WLAN_ADDR_LEN);
memcpy( sFrame.pHdr->sA3.abyAddr3, pMgmt->abyCurrBSSID, WLAN_BSSID_LEN);
*(sFrame.pwAuthAlgorithm) = *(pFrame->pwAuthAlgorithm);
*(sFrame.pwAuthSequence) = cpu_to_le16(2);
if (cpu_to_le16(*(pFrame->pwAuthAlgorithm)) == WLAN_AUTH_ALG_SHAREDKEY) {
if (pMgmt->bShareKeyAlgorithm)
*(sFrame.pwStatus) = cpu_to_le16(WLAN_MGMT_STATUS_SUCCESS);
else
*(sFrame.pwStatus) = cpu_to_le16(WLAN_MGMT_STATUS_UNSUPPORTED_AUTHALG);
}
else {
if (pMgmt->bShareKeyAlgorithm)
*(sFrame.pwStatus) = cpu_to_le16(WLAN_MGMT_STATUS_UNSUPPORTED_AUTHALG);
else
*(sFrame.pwStatus) = cpu_to_le16(WLAN_MGMT_STATUS_SUCCESS);
}
if (pMgmt->bShareKeyAlgorithm &&
(cpu_to_le16(*(sFrame.pwStatus)) == WLAN_MGMT_STATUS_SUCCESS)) {
sFrame.pChallenge = (PWLAN_IE_CHALLENGE)(sFrame.pBuf + sFrame.len);
sFrame.len += WLAN_CHALLENGE_IE_LEN;
sFrame.pChallenge->byElementID = WLAN_EID_CHALLENGE;
sFrame.pChallenge->len = WLAN_CHALLENGE_LEN;
memset(pMgmt->abyChallenge, 0, WLAN_CHALLENGE_LEN);
// get group key
if(KeybGetTransmitKey(&(pDevice->sKey), pDevice->abyBroadcastAddr, GROUP_KEY, &pTransmitKey) == true) {
rc4_init(&pDevice->SBox, pDevice->abyPRNG, pTransmitKey->uKeyLength+3);
rc4_encrypt(&pDevice->SBox, pMgmt->abyChallenge, pMgmt->abyChallenge, WLAN_CHALLENGE_LEN);
}
memcpy(sFrame.pChallenge->abyChallenge, pMgmt->abyChallenge , WLAN_CHALLENGE_LEN);
}
/* Adjust the length fields */
pTxPacket->cbMPDULen = sFrame.len;
pTxPacket->cbPayloadLen = sFrame.len - WLAN_HDR_ADDR3_LEN;
// send the frame
DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Mgt:Authreq_reply sequence_1 tx.. \n");
if (csMgmt_xmit(pDevice, pTxPacket) != CMD_STATUS_PENDING) {
DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Mgt:Authreq_reply sequence_1 tx failed.\n");
}
return;
}
/*+
*
* Routine Description:
* Handles incoming auth frames with sequence number 2. Currently
* assumes we're a station.
*
*
* Return Value:
* None.
*
-*/
static void s_vMgrRxAuthenSequence_2(struct vnt_private *pDevice,
struct vnt_manager *pMgmt, PWLAN_FR_AUTHEN pFrame)
{
WLAN_FR_AUTHEN sFrame;
struct vnt_tx_mgmt *pTxPacket = NULL;
switch (cpu_to_le16((*(pFrame->pwAuthAlgorithm))))
{
case WLAN_AUTH_ALG_OPENSYSTEM:
if ( cpu_to_le16((*(pFrame->pwStatus))) == WLAN_MGMT_STATUS_SUCCESS ){
DBG_PRT(MSG_LEVEL_INFO, KERN_INFO "802.11 Authen (OPEN) Successful.\n");
pMgmt->eCurrState = WMAC_STATE_AUTH;
schedule_delayed_work(&pDevice->run_command_work, 0);
}
else {
DBG_PRT(MSG_LEVEL_INFO, KERN_INFO "802.11 Authen (OPEN) Failed.\n");
s_vMgrLogStatus(pMgmt, cpu_to_le16((*(pFrame->pwStatus))));
pMgmt->eCurrState = WMAC_STATE_IDLE;
}
if (pDevice->eCommandState == WLAN_AUTHENTICATE_WAIT) {
/* spin_unlock_irq(&pDevice->lock);
vCommandTimerWait((void *) pDevice, 0);
spin_lock_irq(&pDevice->lock); */
}
break;
case WLAN_AUTH_ALG_SHAREDKEY:
if (cpu_to_le16((*(pFrame->pwStatus))) == WLAN_MGMT_STATUS_SUCCESS) {
pTxPacket = (struct vnt_tx_mgmt *)
pMgmt->pbyMgmtPacketPool;
memset(pTxPacket, 0, sizeof(struct vnt_tx_mgmt)
+ WLAN_AUTHEN_FR_MAXLEN);
pTxPacket->p80211Header
= (PUWLAN_80211HDR)((u8 *)pTxPacket
+ sizeof(struct vnt_tx_mgmt));
sFrame.pBuf = (u8 *)pTxPacket->p80211Header;
sFrame.len = WLAN_AUTHEN_FR_MAXLEN;
// format buffer structure
vMgrEncodeAuthen(&sFrame);
// insert values
sFrame.pHdr->sA3.wFrameCtl = cpu_to_le16(
(
WLAN_SET_FC_FTYPE(WLAN_TYPE_MGR) |
WLAN_SET_FC_FSTYPE(WLAN_FSTYPE_AUTHEN)|
WLAN_SET_FC_ISWEP(1)
));
memcpy( sFrame.pHdr->sA3.abyAddr1, pMgmt->abyCurrBSSID, WLAN_BSSID_LEN);
memcpy( sFrame.pHdr->sA3.abyAddr2, pMgmt->abyMACAddr, WLAN_ADDR_LEN);
memcpy( sFrame.pHdr->sA3.abyAddr3, pMgmt->abyCurrBSSID, WLAN_BSSID_LEN);
*(sFrame.pwAuthAlgorithm) = *(pFrame->pwAuthAlgorithm);
*(sFrame.pwAuthSequence) = cpu_to_le16(3);
*(sFrame.pwStatus) = cpu_to_le16(WLAN_MGMT_STATUS_SUCCESS);
sFrame.pChallenge = (PWLAN_IE_CHALLENGE)(sFrame.pBuf + sFrame.len);
sFrame.len += WLAN_CHALLENGE_IE_LEN;
sFrame.pChallenge->byElementID = WLAN_EID_CHALLENGE;
sFrame.pChallenge->len = WLAN_CHALLENGE_LEN;
memcpy( sFrame.pChallenge->abyChallenge, pFrame->pChallenge->abyChallenge, WLAN_CHALLENGE_LEN);
// Adjust the length fields
pTxPacket->cbMPDULen = sFrame.len;
pTxPacket->cbPayloadLen = sFrame.len - WLAN_HDR_ADDR3_LEN;
// send the frame
if (csMgmt_xmit(pDevice, pTxPacket) != CMD_STATUS_PENDING) {
DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Mgt:Auth_reply sequence_2 tx failed.\n");
}
DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Mgt:Auth_reply sequence_2 tx ...\n");
}
else {
DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Mgt:rx Auth_reply sequence_2 status error ...\n");
if ( pDevice->eCommandState == WLAN_AUTHENTICATE_WAIT ) {
/* spin_unlock_irq(&pDevice->lock);
vCommandTimerWait((void *) pDevice, 0);
spin_lock_irq(&pDevice->lock); */
}
s_vMgrLogStatus(pMgmt, cpu_to_le16((*(pFrame->pwStatus))));
}
break;
default:
DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Mgt: rx auth.seq = 2 unknown AuthAlgorithm=%d\n", cpu_to_le16((*(pFrame->pwAuthAlgorithm))));
break;
}
return;
}
/*+
*
* Routine Description:
* Handles incoming authen frames with sequence 3. Currently
* assumes we're an AP. This function assumes the frame has
* already been successfully decrypted.
*
*
* Return Value:
* None.
*
-*/
static void s_vMgrRxAuthenSequence_3(struct vnt_private *pDevice,
struct vnt_manager *pMgmt, PWLAN_FR_AUTHEN pFrame)
{
struct vnt_tx_mgmt *pTxPacket = NULL;
u32 uStatusCode = 0 ;
u32 uNodeIndex = 0;
WLAN_FR_AUTHEN sFrame;
if (!WLAN_GET_FC_ISWEP(pFrame->pHdr->sA3.wFrameCtl)) {
uStatusCode = WLAN_MGMT_STATUS_CHALLENGE_FAIL;
goto reply;
}
if (BSSbIsSTAInNodeDB(pDevice, pFrame->pHdr->sA3.abyAddr2, &uNodeIndex)) {
if (pMgmt->sNodeDBTable[uNodeIndex].byAuthSequence != 1) {
uStatusCode = WLAN_MGMT_STATUS_RX_AUTH_NOSEQ;
goto reply;
}
if (memcmp(pMgmt->abyChallenge, pFrame->pChallenge->abyChallenge, WLAN_CHALLENGE_LEN) != 0) {
uStatusCode = WLAN_MGMT_STATUS_CHALLENGE_FAIL;
goto reply;
}
}
else {
uStatusCode = WLAN_MGMT_STATUS_UNSPEC_FAILURE;
goto reply;
}
if (uNodeIndex) {
pMgmt->sNodeDBTable[uNodeIndex].eNodeState = NODE_AUTH;
pMgmt->sNodeDBTable[uNodeIndex].byAuthSequence = 0;
}
uStatusCode = WLAN_MGMT_STATUS_SUCCESS;
DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Challenge text check ok..\n");
reply:
// send auth reply
pTxPacket = (struct vnt_tx_mgmt *)pMgmt->pbyMgmtPacketPool;
memset(pTxPacket, 0, sizeof(struct vnt_tx_mgmt)
+ WLAN_AUTHEN_FR_MAXLEN);
pTxPacket->p80211Header = (PUWLAN_80211HDR)((u8 *)pTxPacket
+ sizeof(struct vnt_tx_mgmt));
sFrame.pBuf = (u8 *)pTxPacket->p80211Header;
sFrame.len = WLAN_AUTHEN_FR_MAXLEN;
// format buffer structure
vMgrEncodeAuthen(&sFrame);
/* insert values */
sFrame.pHdr->sA3.wFrameCtl = cpu_to_le16(
(
WLAN_SET_FC_FTYPE(WLAN_TYPE_MGR) |
WLAN_SET_FC_FSTYPE(WLAN_FSTYPE_AUTHEN)|
WLAN_SET_FC_ISWEP(0)
));
memcpy( sFrame.pHdr->sA3.abyAddr1, pFrame->pHdr->sA3.abyAddr2, WLAN_ADDR_LEN);
memcpy( sFrame.pHdr->sA3.abyAddr2, pMgmt->abyMACAddr, WLAN_ADDR_LEN);
memcpy( sFrame.pHdr->sA3.abyAddr3, pMgmt->abyCurrBSSID, WLAN_BSSID_LEN);
*(sFrame.pwAuthAlgorithm) = *(pFrame->pwAuthAlgorithm);
*(sFrame.pwAuthSequence) = cpu_to_le16(4);
*(sFrame.pwStatus) = cpu_to_le16(uStatusCode);
/* Adjust the length fields */
pTxPacket->cbMPDULen = sFrame.len;
pTxPacket->cbPayloadLen = sFrame.len - WLAN_HDR_ADDR3_LEN;
// send the frame
if (csMgmt_xmit(pDevice, pTxPacket) != CMD_STATUS_PENDING) {
DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Mgt:Authreq_reply sequence_4 tx failed.\n");
}
return;
}
/*+
*
* Routine Description:
* Handles incoming authen frames with sequence 4
*
*
* Return Value:
* None.
*
-*/
static void s_vMgrRxAuthenSequence_4(struct vnt_private *pDevice,
struct vnt_manager *pMgmt, PWLAN_FR_AUTHEN pFrame)
{
if ( cpu_to_le16((*(pFrame->pwStatus))) == WLAN_MGMT_STATUS_SUCCESS ){
DBG_PRT(MSG_LEVEL_INFO, KERN_INFO "802.11 Authen (SHAREDKEY) Successful.\n");
pMgmt->eCurrState = WMAC_STATE_AUTH;
schedule_delayed_work(&pDevice->run_command_work, 0);
}
else{
DBG_PRT(MSG_LEVEL_INFO, KERN_INFO "802.11 Authen (SHAREDKEY) Failed.\n");
s_vMgrLogStatus(pMgmt, cpu_to_le16((*(pFrame->pwStatus))) );
pMgmt->eCurrState = WMAC_STATE_IDLE;
}
if ( pDevice->eCommandState == WLAN_AUTHENTICATE_WAIT ) {
/* spin_unlock_irq(&pDevice->lock);
vCommandTimerWait((void *) pDevice, 0);
spin_lock_irq(&pDevice->lock); */
}
}
/*+
*
* Routine Description:
* Handles incoming disassociation frames
*
*
* Return Value:
* None.
*
-*/
static void s_vMgrRxDisassociation(struct vnt_private *pDevice,
struct vnt_manager *pMgmt, struct vnt_rx_mgmt *pRxPacket)
{
WLAN_FR_DISASSOC sFrame;
u32 uNodeIndex = 0;
CMD_STATUS CmdStatus;
if ( pMgmt->eCurrMode == WMAC_MODE_ESS_AP ){
// if is acting an AP..
// a STA is leaving this BSS..
sFrame.len = pRxPacket->cbMPDULen;
sFrame.pBuf = (u8 *)pRxPacket->p80211Header;
if (BSSbIsSTAInNodeDB(pDevice, pRxPacket->p80211Header->sA3.abyAddr2, &uNodeIndex)) {
BSSvRemoveOneNode(pDevice, uNodeIndex);
}
else {
DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Rx disassoc, sta not found\n");
}
}
else if (pMgmt->eCurrMode == WMAC_MODE_ESS_STA ){
sFrame.len = pRxPacket->cbMPDULen;
sFrame.pBuf = (u8 *)pRxPacket->p80211Header;
vMgrDecodeDisassociation(&sFrame);
DBG_PRT(MSG_LEVEL_NOTICE, KERN_INFO "AP disassociated me, reason=%d.\n", cpu_to_le16(*(sFrame.pwReason)));
pDevice->fWPA_Authened = false;
//TODO: do something let upper layer know or
//try to send associate packet again because of inactivity timeout
if (pMgmt->eCurrState == WMAC_STATE_ASSOC) {
pDevice->bLinkPass = false;
pMgmt->sNodeDBTable[0].bActive = false;
pDevice->byReAssocCount = 0;
pMgmt->eCurrState = WMAC_STATE_AUTH; // jump back to the auth state!
pDevice->eCommandState = WLAN_ASSOCIATE_WAIT;
vMgrReAssocBeginSta(pDevice, pMgmt, &CmdStatus);
if(CmdStatus == CMD_STATUS_PENDING) {
pDevice->byReAssocCount ++;
return; //mike add: you'll retry for many times, so it cann't be regarded as disconnected!
}
}
// if(pDevice->bWPASuppWextEnabled == true)
{
union iwreq_data wrqu;
memset(&wrqu, 0, sizeof (wrqu));
wrqu.ap_addr.sa_family = ARPHRD_ETHER;
PRINT_K("wireless_send_event--->SIOCGIWAP(disassociated)\n");
wireless_send_event(pDevice->dev, SIOCGIWAP, &wrqu, NULL);
}
}
/* else, ignore it */
return;
}
/*+
*
* Routine Description:
* Handles incoming deauthentication frames
*
*
* Return Value:
* None.
*
-*/
static void s_vMgrRxDeauthentication(struct vnt_private *pDevice,
struct vnt_manager *pMgmt, struct vnt_rx_mgmt *pRxPacket)
{
WLAN_FR_DEAUTHEN sFrame;
u32 uNodeIndex = 0;
if (pMgmt->eCurrMode == WMAC_MODE_ESS_AP ){
//Todo:
// if is acting an AP..
// a STA is leaving this BSS..
sFrame.len = pRxPacket->cbMPDULen;
sFrame.pBuf = (u8 *)pRxPacket->p80211Header;
if (BSSbIsSTAInNodeDB(pDevice, pRxPacket->p80211Header->sA3.abyAddr2, &uNodeIndex)) {
BSSvRemoveOneNode(pDevice, uNodeIndex);
}
else {
DBG_PRT(MSG_LEVEL_NOTICE, KERN_INFO "Rx deauth, sta not found\n");
}
}
else {
if (pMgmt->eCurrMode == WMAC_MODE_ESS_STA ) {
sFrame.len = pRxPacket->cbMPDULen;
sFrame.pBuf = (u8 *)pRxPacket->p80211Header;
vMgrDecodeDeauthen(&sFrame);
pDevice->fWPA_Authened = false;
DBG_PRT(MSG_LEVEL_NOTICE, KERN_INFO "AP deauthed me, reason=%d.\n", cpu_to_le16((*(sFrame.pwReason))));
// TODO: update BSS list for specific BSSID if pre-authentication case
if (ether_addr_equal(sFrame.pHdr->sA3.abyAddr3,
pMgmt->abyCurrBSSID)) {
if (pMgmt->eCurrState >= WMAC_STATE_AUTHPENDING) {
pMgmt->sNodeDBTable[0].bActive = false;
pMgmt->eCurrMode = WMAC_MODE_STANDBY;
pMgmt->eCurrState = WMAC_STATE_IDLE;
netif_stop_queue(pDevice->dev);
pDevice->bLinkPass = false;
vnt_mac_set_led(pDevice, LEDSTS_STS, LEDSTS_SLOW);
}
}
// if(pDevice->bWPASuppWextEnabled == true)
{
union iwreq_data wrqu;
memset(&wrqu, 0, sizeof (wrqu));
wrqu.ap_addr.sa_family = ARPHRD_ETHER;
PRINT_K("wireless_send_event--->SIOCGIWAP(disauthen)\n");
wireless_send_event(pDevice->dev, SIOCGIWAP, &wrqu, NULL);
}
}
/* else, ignore it. TODO: IBSS authentication service
would be implemented here */
};
return;
}
/*+
*
* Routine Description:
* check if current channel is match ZoneType.
*for USA:1~11;
* Japan:1~13;
* Europe:1~13
* Return Value:
* True:exceed;
* False:normal case
-*/
static int ChannelExceedZoneType(struct vnt_private *pDevice, u8 byCurrChannel)
{
int exceed = false;
switch(pDevice->byZoneType) {
case 0x00: //USA:1~11
if((byCurrChannel<1) ||(byCurrChannel>11))
exceed = true;
break;
case 0x01: //Japan:1~13
case 0x02: //Europe:1~13
if((byCurrChannel<1) ||(byCurrChannel>13))
exceed = true;
break;
default: //reserve for other zonetype
break;
}
return exceed;
}
/*+
*
* Routine Description:
* Handles and analysis incoming beacon frames.
*
*
* Return Value:
* None.
*
-*/
static void s_vMgrRxBeacon(struct vnt_private *pDevice,
struct vnt_manager *pMgmt, struct vnt_rx_mgmt *pRxPacket,
int bInScan)
{
PKnownBSS pBSSList;
WLAN_FR_BEACON sFrame;
u64 qwTSFOffset;
int bIsBSSIDEqual = false;
int bIsSSIDEqual = false;
int bTSFLargeDiff = false;
int bTSFOffsetPostive = false;
int bUpdateTSF = false;
int bIsAPBeacon = false;
int bIsChannelEqual = false;
u32 uLocateByteIndex;
u8 byTIMBitOn = 0;
u16 wAIDNumber = 0;
u32 uNodeIndex;
u64 qwTimestamp, qwLocalTSF;
u64 qwCurrTSF;
u16 wStartIndex = 0;
u16 wAIDIndex = 0;
u8 byCurrChannel = pRxPacket->byRxChannel;
ERPObject sERP;
u32 uRateLen = WLAN_RATES_MAXLEN;
int bChannelHit = false;
u8 byOldPreambleType;
if (pMgmt->eCurrMode == WMAC_MODE_ESS_AP)
return;
memset(&sFrame, 0, sizeof(WLAN_FR_BEACON));
sFrame.len = pRxPacket->cbMPDULen;
sFrame.pBuf = (u8 *)pRxPacket->p80211Header;
// decode the beacon frame
vMgrDecodeBeacon(&sFrame);
if ((sFrame.pwBeaconInterval == NULL)
|| (sFrame.pwCapInfo == NULL)
|| (sFrame.pSSID == NULL)
|| (sFrame.pSuppRates == NULL)) {
DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Rx beacon frame error\n");
return;
}
if( byCurrChannel > CB_MAX_CHANNEL_24G )
{
if (sFrame.pDSParms != NULL) {
if (byCurrChannel == RFaby11aChannelIndex[sFrame.pDSParms->byCurrChannel-1])
bChannelHit = true;
byCurrChannel = RFaby11aChannelIndex[sFrame.pDSParms->byCurrChannel-1];
} else {
bChannelHit = true;
}
} else {
if (sFrame.pDSParms != NULL) {
if (byCurrChannel == sFrame.pDSParms->byCurrChannel)
bChannelHit = true;
byCurrChannel = sFrame.pDSParms->byCurrChannel;
} else {
bChannelHit = true;
}
}
if(ChannelExceedZoneType(pDevice,byCurrChannel)==true)
return;
if (sFrame.pERP != NULL) {
sERP.byERP = sFrame.pERP->byContext;
sERP.bERPExist = true;
} else {
sERP.bERPExist = false;
sERP.byERP = 0;
}
pBSSList = BSSpAddrIsInBSSList((void *) pDevice,
sFrame.pHdr->sA3.abyAddr3,
sFrame.pSSID);
if (pBSSList == NULL) {
DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Beacon/insert: RxChannel = : %d\n", byCurrChannel);
BSSbInsertToBSSList((void *) pDevice,
sFrame.pHdr->sA3.abyAddr3,
*sFrame.pqwTimestamp,
*sFrame.pwBeaconInterval,
*sFrame.pwCapInfo,
byCurrChannel,
sFrame.pSSID,
sFrame.pSuppRates,
sFrame.pExtSuppRates,
&sERP,
sFrame.pRSN,
sFrame.pRSNWPA,
sFrame.pIE_Country,
sFrame.pIE_Quiet,
sFrame.len - WLAN_HDR_ADDR3_LEN,
sFrame.pHdr->sA4.abyAddr4, // payload of beacon
(void *) pRxPacket);
}
else {
// DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"update bcn: RxChannel = : %d\n", byCurrChannel);
BSSbUpdateToBSSList((void *) pDevice,
*sFrame.pqwTimestamp,
*sFrame.pwBeaconInterval,
*sFrame.pwCapInfo,
byCurrChannel,
bChannelHit,
sFrame.pSSID,
sFrame.pSuppRates,
sFrame.pExtSuppRates,
&sERP,
sFrame.pRSN,
sFrame.pRSNWPA,
sFrame.pIE_Country,
sFrame.pIE_Quiet,
pBSSList,
sFrame.len - WLAN_HDR_ADDR3_LEN,
sFrame.pHdr->sA4.abyAddr4, // payload of probresponse
(void *) pRxPacket);
}
if (bInScan) {
return;
}
if(byCurrChannel == (u8)pMgmt->uCurrChannel)
bIsChannelEqual = true;
if (bIsChannelEqual && (pMgmt->eCurrMode == WMAC_MODE_ESS_AP)) {
// if rx beacon without ERP field
if (sERP.bERPExist) {
if (WLAN_GET_ERP_USE_PROTECTION(sERP.byERP)){
pDevice->byERPFlag |= WLAN_SET_ERP_USE_PROTECTION(1);
pDevice->wUseProtectCntDown = USE_PROTECT_PERIOD;
}
}
else {
pDevice->byERPFlag |= WLAN_SET_ERP_USE_PROTECTION(1);
pDevice->wUseProtectCntDown = USE_PROTECT_PERIOD;
}
if (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) {
if(!WLAN_GET_CAP_INFO_SHORTPREAMBLE(*sFrame.pwCapInfo))
pDevice->byERPFlag |= WLAN_SET_ERP_BARKER_MODE(1);
if(!sERP.bERPExist)
pDevice->byERPFlag |= WLAN_SET_ERP_NONERP_PRESENT(1);
}
}
// check if BSSID the same
if (memcmp(sFrame.pHdr->sA3.abyAddr3,
pMgmt->abyCurrBSSID,
WLAN_BSSID_LEN) == 0) {
bIsBSSIDEqual = true;
pDevice->uCurrRSSI = pRxPacket->uRSSI;
pDevice->byCurrSQ = pRxPacket->bySQ;
if (pMgmt->sNodeDBTable[0].uInActiveCount != 0) {
pMgmt->sNodeDBTable[0].uInActiveCount = 0;
//DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"BCN:Wake Count= [%d]\n", pMgmt->wCountToWakeUp);
}
}
// check if SSID the same
if (sFrame.pSSID->len == ((PWLAN_IE_SSID)pMgmt->abyCurrSSID)->len) {
if (memcmp(sFrame.pSSID->abySSID,
((PWLAN_IE_SSID)pMgmt->abyCurrSSID)->abySSID,
sFrame.pSSID->len
) == 0) {
bIsSSIDEqual = true;
}
}
if ((WLAN_GET_CAP_INFO_ESS(*sFrame.pwCapInfo)== true) &&
(bIsBSSIDEqual == true) &&
(bIsSSIDEqual == true) &&
(pMgmt->eCurrMode == WMAC_MODE_ESS_STA) &&
(pMgmt->eCurrState == WMAC_STATE_ASSOC)) {
// add state check to prevent reconnect fail since we'll receive Beacon
bIsAPBeacon = true;
if (pBSSList != NULL) {
// Sync ERP field
if ((pBSSList->sERP.bERPExist == true) && (pDevice->byBBType == BB_TYPE_11G)) {
if ((pBSSList->sERP.byERP & WLAN_EID_ERP_USE_PROTECTION) != pDevice->bProtectMode) {//0000 0010
pDevice->bProtectMode = (pBSSList->sERP.byERP & WLAN_EID_ERP_USE_PROTECTION);
if (pDevice->bProtectMode) {
MACvEnableProtectMD(pDevice);
} else {
MACvDisableProtectMD(pDevice);
}
vUpdateIFS(pDevice);
}
if ((pBSSList->sERP.byERP & WLAN_EID_ERP_NONERP_PRESENT) != pDevice->bNonERPPresent) {//0000 0001
pDevice->bNonERPPresent = (pBSSList->sERP.byERP & WLAN_EID_ERP_USE_PROTECTION);
}
if ((pBSSList->sERP.byERP & WLAN_EID_ERP_BARKER_MODE) != pDevice->bBarkerPreambleMd) {//0000 0100
pDevice->bBarkerPreambleMd = (pBSSList->sERP.byERP & WLAN_EID_ERP_BARKER_MODE);
//BarkerPreambleMd has higher priority than shortPreamble bit in Cap
if (pDevice->bBarkerPreambleMd) {
MACvEnableBarkerPreambleMd(pDevice);
} else {
MACvDisableBarkerPreambleMd(pDevice);
}
}
}
// Sync Short Slot Time
if (WLAN_GET_CAP_INFO_SHORTSLOTTIME(pBSSList->wCapInfo) != pDevice->bShortSlotTime) {
bool bShortSlotTime;
bShortSlotTime = WLAN_GET_CAP_INFO_SHORTSLOTTIME(pBSSList->wCapInfo);
//DBG_PRN_WLAN05(("Set Short Slot Time: %d\n", pDevice->bShortSlotTime));
//Kyle check if it is OK to set G.
if (pDevice->byBBType == BB_TYPE_11A) {
bShortSlotTime = true;
}
else if (pDevice->byBBType == BB_TYPE_11B) {
bShortSlotTime = false;
}
if (bShortSlotTime != pDevice->bShortSlotTime) {
pDevice->bShortSlotTime = bShortSlotTime;
BBvSetShortSlotTime(pDevice);
vUpdateIFS(pDevice);
}
}
//
// Preamble may change dynamically
//
byOldPreambleType = pDevice->byPreambleType;
if (WLAN_GET_CAP_INFO_SHORTPREAMBLE(pBSSList->wCapInfo)) {
pDevice->byPreambleType = pDevice->byShortPreamble;
}
else {
pDevice->byPreambleType = 0;
}
if (pDevice->byPreambleType != byOldPreambleType)
CARDvSetRSPINF(pDevice, (u8)pDevice->byBBType);
//
// Basic Rate Set may change dynamically
//
if (pBSSList->eNetworkTypeInUse == PHY_TYPE_11B) {
uRateLen = WLAN_RATES_MAXLEN_11B;
}
pMgmt->abyCurrSuppRates[1] = RATEuSetIE((PWLAN_IE_SUPP_RATES)pBSSList->abySuppRates,
(PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates,
uRateLen);
pMgmt->abyCurrExtSuppRates[1] = RATEuSetIE((PWLAN_IE_SUPP_RATES)pBSSList->abyExtSuppRates,
(PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates,
uRateLen);
RATEvParseMaxRate((void *)pDevice,
(PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates,
(PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates,
true,
&(pMgmt->sNodeDBTable[0].wMaxBasicRate),
&(pMgmt->sNodeDBTable[0].wMaxSuppRate),
&(pMgmt->sNodeDBTable[0].wSuppRate),
&(pMgmt->sNodeDBTable[0].byTopCCKBasicRate),
&(pMgmt->sNodeDBTable[0].byTopOFDMBasicRate)
);
}
}
// DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Beacon 2 \n");
// check if CF field exisit
if (WLAN_GET_CAP_INFO_ESS(*sFrame.pwCapInfo)) {
if (sFrame.pCFParms->wCFPDurRemaining > 0) {
// TODO: deal with CFP period to set NAV
}
}
qwTimestamp = cpu_to_le64(*sFrame.pqwTimestamp);
qwLocalTSF = pRxPacket->qwLocalTSF;
// check if beacon TSF larger or small than our local TSF
if (qwTimestamp >= qwLocalTSF)
bTSFOffsetPostive = true;
else
bTSFOffsetPostive = false;
if (bTSFOffsetPostive) {
qwTSFOffset = CARDqGetTSFOffset(pRxPacket->byRxRate, (qwTimestamp), (qwLocalTSF));
}
else {
qwTSFOffset = CARDqGetTSFOffset(pRxPacket->byRxRate, (qwLocalTSF), (qwTimestamp));
}
if (qwTSFOffset > TRIVIAL_SYNC_DIFFERENCE)
bTSFLargeDiff = true;
// if infra mode
if (bIsAPBeacon == true) {
// Infra mode: Local TSF always follow AP's TSF if Difference huge.
if (bTSFLargeDiff)
bUpdateTSF = true;
if ((pDevice->bEnablePSMode == true) && (sFrame.pTIM)) {
/* deal with DTIM, analysis TIM */
pMgmt->bMulticastTIM = WLAN_MGMT_IS_MULTICAST_TIM(sFrame.pTIM->byBitMapCtl) ? true : false ;
pMgmt->byDTIMCount = sFrame.pTIM->byDTIMCount;
pMgmt->byDTIMPeriod = sFrame.pTIM->byDTIMPeriod;
wAIDNumber = pMgmt->wCurrAID & ~(BIT14|BIT15);
// check if AID in TIM field bit on
// wStartIndex = N1
wStartIndex = WLAN_MGMT_GET_TIM_OFFSET(sFrame.pTIM->byBitMapCtl) << 1;
// AIDIndex = N2
wAIDIndex = (wAIDNumber >> 3);
if ((wAIDNumber > 0) && (wAIDIndex >= wStartIndex)) {
uLocateByteIndex = wAIDIndex - wStartIndex;
// len = byDTIMCount + byDTIMPeriod + byDTIMPeriod + byVirtBitMap[0~250]
if (sFrame.pTIM->len >= (uLocateByteIndex + 4)) {
byTIMBitOn = (0x01) << ((wAIDNumber) % 8);
pMgmt->bInTIM = sFrame.pTIM->byVirtBitMap[uLocateByteIndex] & byTIMBitOn ? true : false;
}
else {
pMgmt->bInTIM = false;
};
}
else {
pMgmt->bInTIM = false;
};
if (pMgmt->bInTIM ||
(pMgmt->bMulticastTIM && (pMgmt->byDTIMCount == 0))) {
pMgmt->bInTIMWake = true;
/* send out ps-poll packet */
if (pMgmt->bInTIM)
PSvSendPSPOLL(pDevice);
}
else {
pMgmt->bInTIMWake = false;
DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "BCN: Not In TIM..\n");
if (pDevice->bPWBitOn == false) {
DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "BCN: Send Null Packet\n");
if (PSbSendNullPacket(pDevice))
pDevice->bPWBitOn = true;
}
if(PSbConsiderPowerDown(pDevice, false, false)) {
DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "BCN: Power down now...\n");
}
}
}
}
// if adhoc mode
if ((pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) && !bIsAPBeacon && bIsChannelEqual) {
if (bIsBSSIDEqual) {
// Use sNodeDBTable[0].uInActiveCount as IBSS beacons received count.
if (pMgmt->sNodeDBTable[0].uInActiveCount != 0)
pMgmt->sNodeDBTable[0].uInActiveCount = 0;
// adhoc mode:TSF updated only when beacon larger then local TSF
if (bTSFLargeDiff && bTSFOffsetPostive &&
(pMgmt->eCurrState == WMAC_STATE_JOINTED))
bUpdateTSF = true;
// During dpc, already in spinlocked.
if (BSSbIsSTAInNodeDB(pDevice, sFrame.pHdr->sA3.abyAddr2, &uNodeIndex)) {
// Update the STA, (Technically the Beacons of all the IBSS nodes
// should be identical, but that's not happening in practice.
pMgmt->abyCurrSuppRates[1] = RATEuSetIE((PWLAN_IE_SUPP_RATES)sFrame.pSuppRates,
(PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates,
WLAN_RATES_MAXLEN_11B);
RATEvParseMaxRate((void *)pDevice,
(PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates,
NULL,
true,
&(pMgmt->sNodeDBTable[uNodeIndex].wMaxBasicRate),
&(pMgmt->sNodeDBTable[uNodeIndex].wMaxSuppRate),
&(pMgmt->sNodeDBTable[uNodeIndex].wSuppRate),
&(pMgmt->sNodeDBTable[uNodeIndex].byTopCCKBasicRate),
&(pMgmt->sNodeDBTable[uNodeIndex].byTopOFDMBasicRate)
);
pMgmt->sNodeDBTable[uNodeIndex].bShortPreamble = WLAN_GET_CAP_INFO_SHORTPREAMBLE(*sFrame.pwCapInfo);
pMgmt->sNodeDBTable[uNodeIndex].bShortSlotTime = WLAN_GET_CAP_INFO_SHORTSLOTTIME(*sFrame.pwCapInfo);
pMgmt->sNodeDBTable[uNodeIndex].uInActiveCount = 0;
}
else {
/* Todo, initial Node content */
BSSvCreateOneNode(pDevice, &uNodeIndex);
pMgmt->abyCurrSuppRates[1] = RATEuSetIE((PWLAN_IE_SUPP_RATES)sFrame.pSuppRates,
(PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates,
WLAN_RATES_MAXLEN_11B);
RATEvParseMaxRate((void *)pDevice,
(PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates,
NULL,
true,
&(pMgmt->sNodeDBTable[uNodeIndex].wMaxBasicRate),
&(pMgmt->sNodeDBTable[uNodeIndex].wMaxSuppRate),
&(pMgmt->sNodeDBTable[uNodeIndex].wSuppRate),
&(pMgmt->sNodeDBTable[uNodeIndex].byTopCCKBasicRate),
&(pMgmt->sNodeDBTable[uNodeIndex].byTopOFDMBasicRate)
);
memcpy(pMgmt->sNodeDBTable[uNodeIndex].abyMACAddr, sFrame.pHdr->sA3.abyAddr2, WLAN_ADDR_LEN);
pMgmt->sNodeDBTable[uNodeIndex].bShortPreamble = WLAN_GET_CAP_INFO_SHORTPREAMBLE(*sFrame.pwCapInfo);
pMgmt->sNodeDBTable[uNodeIndex].wTxDataRate = pMgmt->sNodeDBTable[uNodeIndex].wMaxSuppRate;
/*
pMgmt->sNodeDBTable[uNodeIndex].bShortSlotTime = WLAN_GET_CAP_INFO_SHORTSLOTTIME(*sFrame.pwCapInfo);
if(pMgmt->sNodeDBTable[uNodeIndex].wMaxSuppRate > RATE_11M)
pMgmt->sNodeDBTable[uNodeIndex].bERPExist = true;
*/
}
// if other stations jointed, indicate connect to upper layer..
if (pMgmt->eCurrState == WMAC_STATE_STARTED) {
DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Current IBSS State: [Started]........to: [Jointed] \n");
pMgmt->eCurrState = WMAC_STATE_JOINTED;
pDevice->bLinkPass = true;
vnt_mac_set_led(pDevice, LEDSTS_STS, LEDSTS_INTER);
if (netif_queue_stopped(pDevice->dev)){
netif_wake_queue(pDevice->dev);
}
pMgmt->sNodeDBTable[0].bActive = true;
pMgmt->sNodeDBTable[0].uInActiveCount = 0;
}
}
else if (bIsSSIDEqual) {
// See other adhoc sta with the same SSID but BSSID is different.
// adpot this vars only when TSF larger then us.
if (bTSFLargeDiff && bTSFOffsetPostive) {
// we don't support ATIM under adhoc mode
// if ( sFrame.pIBSSParms->wATIMWindow == 0) {
// adpot this vars
// TODO: check sFrame cap if privacy on, and support rate syn
memcpy(pMgmt->abyCurrBSSID, sFrame.pHdr->sA3.abyAddr3, WLAN_BSSID_LEN);
memcpy(pDevice->abyBSSID, pMgmt->abyCurrBSSID, WLAN_BSSID_LEN);
pMgmt->wCurrATIMWindow = cpu_to_le16(sFrame.pIBSSParms->wATIMWindow);
pMgmt->wCurrBeaconPeriod = cpu_to_le16(*sFrame.pwBeaconInterval);
pMgmt->abyCurrSuppRates[1] = RATEuSetIE((PWLAN_IE_SUPP_RATES)sFrame.pSuppRates,
(PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates,
WLAN_RATES_MAXLEN_11B);
// set HW beacon interval and re-synchronizing....
DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Rejoining to Other Adhoc group with same SSID........\n");
MACvWriteBeaconInterval(pDevice, pMgmt->wCurrBeaconPeriod);
CARDvAdjustTSF(pDevice, pRxPacket->byRxRate, qwTimestamp, pRxPacket->qwLocalTSF);
CARDvUpdateNextTBTT(pDevice, qwTimestamp, pMgmt->wCurrBeaconPeriod);
// Turn off bssid filter to avoid filter others adhoc station which bssid is different.
MACvWriteBSSIDAddress(pDevice, pMgmt->abyCurrBSSID);
byOldPreambleType = pDevice->byPreambleType;
if (WLAN_GET_CAP_INFO_SHORTPREAMBLE(*sFrame.pwCapInfo)) {
pDevice->byPreambleType = pDevice->byShortPreamble;
}
else {
pDevice->byPreambleType = 0;
}
if (pDevice->byPreambleType != byOldPreambleType)
CARDvSetRSPINF(pDevice, (u8)pDevice->byBBType);
// MACvRegBitsOff(pDevice->PortOffset, MAC_REG_RCR, RCR_BSSID);
// set highest basic rate
// s_vSetHighestBasicRate(pDevice, (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates);
// Prepare beacon frame
bMgrPrepareBeaconToSend((void *) pDevice, pMgmt);
// }
}
}
}
// endian issue ???
// Update TSF
if (bUpdateTSF) {
CARDbGetCurrentTSF(pDevice, &qwCurrTSF);
CARDvAdjustTSF(pDevice, pRxPacket->byRxRate, qwTimestamp , pRxPacket->qwLocalTSF);
CARDbGetCurrentTSF(pDevice, &qwCurrTSF);
CARDvUpdateNextTBTT(pDevice, qwTimestamp, pMgmt->wCurrBeaconPeriod);
}
return;
}
/*+
*
* Routine Description:
* Instructs the hw to create a bss using the supplied
* attributes. Note that this implementation only supports Ad-Hoc
* BSS creation.
*
*
* Return Value:
* CMD_STATUS
*
-*/
void vMgrCreateOwnIBSS(struct vnt_private *pDevice, PCMD_STATUS pStatus)
{
struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
u16 wMaxBasicRate;
u16 wMaxSuppRate;
u8 byTopCCKBasicRate;
u8 byTopOFDMBasicRate;
u64 qwCurrTSF = 0;
int ii;
u8 abyRATE[] = {0x82, 0x84, 0x8B, 0x96, 0x24, 0x30, 0x48, 0x6C, 0x0C,
0x12, 0x18, 0x60};
u8 abyCCK_RATE[] = {0x82, 0x84, 0x8B, 0x96};
u8 abyOFDM_RATE[] = {0x0C, 0x12, 0x18, 0x24, 0x30, 0x48, 0x60, 0x6C};
u16 wSuppRate;
DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Create Basic Service Set .......\n");
if (pMgmt->eConfigMode == WMAC_CONFIG_IBSS_STA) {
if ((pMgmt->eAuthenMode == WMAC_AUTH_WPANONE) &&
(pDevice->eEncryptionStatus != Ndis802_11Encryption2Enabled) &&
(pDevice->eEncryptionStatus != Ndis802_11Encryption3Enabled)) {
// encryption mode error
*pStatus = CMD_STATUS_FAILURE;
return;
}
}
pMgmt->abyCurrSuppRates[0] = WLAN_EID_SUPP_RATES;
pMgmt->abyCurrExtSuppRates[0] = WLAN_EID_EXTSUPP_RATES;
if (pMgmt->eConfigMode == WMAC_CONFIG_AP) {
pMgmt->eCurrentPHYMode = pMgmt->byAPBBType;
} else {
if (pDevice->byBBType == BB_TYPE_11G)
pMgmt->eCurrentPHYMode = PHY_TYPE_11G;
if (pDevice->byBBType == BB_TYPE_11B)
pMgmt->eCurrentPHYMode = PHY_TYPE_11B;
if (pDevice->byBBType == BB_TYPE_11A)
pMgmt->eCurrentPHYMode = PHY_TYPE_11A;
}
if (pMgmt->eCurrentPHYMode != PHY_TYPE_11A) {
pMgmt->abyCurrSuppRates[1] = WLAN_RATES_MAXLEN_11B;
pMgmt->abyCurrExtSuppRates[1] = 0;
for (ii = 0; ii < 4; ii++)
pMgmt->abyCurrSuppRates[2+ii] = abyRATE[ii];
} else {
pMgmt->abyCurrSuppRates[1] = 8;
pMgmt->abyCurrExtSuppRates[1] = 0;
for (ii = 0; ii < 8; ii++)
pMgmt->abyCurrSuppRates[2+ii] = abyRATE[ii];
}
if (pMgmt->eCurrentPHYMode == PHY_TYPE_11G) {
pMgmt->abyCurrSuppRates[1] = 8;
pMgmt->abyCurrExtSuppRates[1] = 4;
for (ii = 0; ii < 4; ii++)
pMgmt->abyCurrSuppRates[2+ii] = abyCCK_RATE[ii];
for (ii = 4; ii < 8; ii++)
pMgmt->abyCurrSuppRates[2+ii] = abyOFDM_RATE[ii-4];
for (ii = 0; ii < 4; ii++)
pMgmt->abyCurrExtSuppRates[2+ii] = abyOFDM_RATE[ii+4];
}
// Disable Protect Mode
pDevice->bProtectMode = 0;
MACvDisableProtectMD(pDevice);
pDevice->bBarkerPreambleMd = 0;
MACvDisableBarkerPreambleMd(pDevice);
// Kyle Test 2003.11.04
// set HW beacon interval
if (pMgmt->wIBSSBeaconPeriod == 0)
pMgmt->wIBSSBeaconPeriod = DEFAULT_IBSS_BI;
MACvWriteBeaconInterval(pDevice, pMgmt->wIBSSBeaconPeriod);
CARDbGetCurrentTSF(pDevice, &qwCurrTSF);
// clear TSF counter
CARDbClearCurrentTSF(pDevice);
// enable TSF counter
MACvRegBitsOn(pDevice,MAC_REG_TFTCTL,TFTCTL_TSFCNTREN);
// set Next TBTT
CARDvSetFirstNextTBTT(pDevice, pMgmt->wIBSSBeaconPeriod);
pMgmt->uIBSSChannel = pDevice->uChannel;
if (pMgmt->uIBSSChannel == 0)
pMgmt->uIBSSChannel = DEFAULT_IBSS_CHANNEL;
// set channel and clear NAV
CARDbSetMediaChannel(pDevice, pMgmt->uIBSSChannel);
pMgmt->uCurrChannel = pMgmt->uIBSSChannel;
pDevice->byPreambleType = pDevice->byShortPreamble;
// set basic rate
RATEvParseMaxRate((void *)pDevice,
(PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates,
(PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates, true,
&wMaxBasicRate, &wMaxSuppRate, &wSuppRate,
&byTopCCKBasicRate, &byTopOFDMBasicRate);
if (pDevice->byBBType == BB_TYPE_11A) {
pDevice->bShortSlotTime = true;
} else {
pDevice->bShortSlotTime = false;
}
BBvSetShortSlotTime(pDevice);
// vUpdateIFS() use pDevice->bShortSlotTime as parameter so it must be called
// after setting ShortSlotTime.
// CARDvSetBSSMode call vUpdateIFS()
CARDvSetBSSMode(pDevice);
if (pMgmt->eConfigMode == WMAC_CONFIG_AP) {
MACvRegBitsOn(pDevice, MAC_REG_HOSTCR, HOSTCR_AP);
pMgmt->eCurrMode = WMAC_MODE_ESS_AP;
}
if (pMgmt->eConfigMode == WMAC_CONFIG_IBSS_STA) {
MACvRegBitsOn(pDevice, MAC_REG_HOSTCR, HOSTCR_ADHOC);
pMgmt->eCurrMode = WMAC_MODE_IBSS_STA;
}
// Adopt pre-configured IBSS vars to current vars
pMgmt->eCurrState = WMAC_STATE_STARTED;
pMgmt->wCurrBeaconPeriod = pMgmt->wIBSSBeaconPeriod;
pMgmt->uCurrChannel = pMgmt->uIBSSChannel;
pMgmt->wCurrATIMWindow = pMgmt->wIBSSATIMWindow;
pDevice->uCurrRSSI = 0;
pDevice->byCurrSQ = 0;
memcpy(pMgmt->abyDesireSSID,pMgmt->abyAdHocSSID,
((PWLAN_IE_SSID)pMgmt->abyAdHocSSID)->len + WLAN_IEHDR_LEN);
memset(pMgmt->abyCurrSSID, 0, WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1);
memcpy(pMgmt->abyCurrSSID,
pMgmt->abyDesireSSID,
((PWLAN_IE_SSID)pMgmt->abyDesireSSID)->len + WLAN_IEHDR_LEN
);
if (pMgmt->eCurrMode == WMAC_MODE_ESS_AP) {
// AP mode BSSID = MAC addr
memcpy(pMgmt->abyCurrBSSID, pMgmt->abyMACAddr, WLAN_ADDR_LEN);
DBG_PRT(MSG_LEVEL_INFO, KERN_INFO"AP beacon created BSSID:"
"%pM\n", pMgmt->abyCurrBSSID);
}
if (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) {
// BSSID selected must be randomized as spec 11.1.3
pMgmt->abyCurrBSSID[5] = (u8)(qwCurrTSF & 0x000000ff);
pMgmt->abyCurrBSSID[4] = (u8)((qwCurrTSF & 0x0000ff00) >> 8);
pMgmt->abyCurrBSSID[3] = (u8)((qwCurrTSF & 0x00ff0000) >> 16);
pMgmt->abyCurrBSSID[2] = (u8)((qwCurrTSF & 0x00000ff0) >> 4);
pMgmt->abyCurrBSSID[1] = (u8)((qwCurrTSF & 0x000ff000) >> 12);
pMgmt->abyCurrBSSID[0] = (u8)((qwCurrTSF & 0x0ff00000) >> 20);
pMgmt->abyCurrBSSID[5] ^= pMgmt->abyMACAddr[0];
pMgmt->abyCurrBSSID[4] ^= pMgmt->abyMACAddr[1];
pMgmt->abyCurrBSSID[3] ^= pMgmt->abyMACAddr[2];
pMgmt->abyCurrBSSID[2] ^= pMgmt->abyMACAddr[3];
pMgmt->abyCurrBSSID[1] ^= pMgmt->abyMACAddr[4];
pMgmt->abyCurrBSSID[0] ^= pMgmt->abyMACAddr[5];
pMgmt->abyCurrBSSID[0] &= ~IEEE_ADDR_GROUP;
pMgmt->abyCurrBSSID[0] |= IEEE_ADDR_UNIVERSAL;
DBG_PRT(MSG_LEVEL_INFO, KERN_INFO"Adhoc beacon created bssid:"
"%pM\n", pMgmt->abyCurrBSSID);
}
// set BSSID filter
MACvWriteBSSIDAddress(pDevice, pMgmt->abyCurrBSSID);
memcpy(pDevice->abyBSSID, pMgmt->abyCurrBSSID, WLAN_ADDR_LEN);
MACvRegBitsOn(pDevice, MAC_REG_RCR, RCR_BSSID);
pDevice->byRxMode |= RCR_BSSID;
pMgmt->bCurrBSSIDFilterOn = true;
// Set Capability Info
pMgmt->wCurrCapInfo = 0;
if (pMgmt->eCurrMode == WMAC_MODE_ESS_AP) {
pMgmt->wCurrCapInfo |= WLAN_SET_CAP_INFO_ESS(1);
pMgmt->byDTIMPeriod = DEFAULT_DTIM_PERIOD;
pMgmt->byDTIMCount = pMgmt->byDTIMPeriod - 1;
pDevice->op_mode = NL80211_IFTYPE_AP;
}
if (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) {
pMgmt->wCurrCapInfo |= WLAN_SET_CAP_INFO_IBSS(1);
pDevice->op_mode = NL80211_IFTYPE_ADHOC;
}
if (pDevice->bEncryptionEnable) {
pMgmt->wCurrCapInfo |= WLAN_SET_CAP_INFO_PRIVACY(1);
if (pMgmt->eAuthenMode == WMAC_AUTH_WPANONE) {
if (pDevice->eEncryptionStatus == Ndis802_11Encryption3Enabled) {
pMgmt->byCSSPK = KEY_CTL_CCMP;
pMgmt->byCSSGK = KEY_CTL_CCMP;
} else if (pDevice->eEncryptionStatus == Ndis802_11Encryption2Enabled) {
pMgmt->byCSSPK = KEY_CTL_TKIP;
pMgmt->byCSSGK = KEY_CTL_TKIP;
} else {
pMgmt->byCSSPK = KEY_CTL_NONE;
pMgmt->byCSSGK = KEY_CTL_WEP;
}
} else {
pMgmt->byCSSPK = KEY_CTL_WEP;
pMgmt->byCSSGK = KEY_CTL_WEP;
}
}
pMgmt->byERPContext = 0;
if (pDevice->byPreambleType == 1) {
pMgmt->wCurrCapInfo |= WLAN_SET_CAP_INFO_SHORTPREAMBLE(1);
} else {
pMgmt->wCurrCapInfo &= (~WLAN_SET_CAP_INFO_SHORTPREAMBLE(1));
}
pMgmt->eCurrState = WMAC_STATE_STARTED;
// Prepare beacon to send
if (bMgrPrepareBeaconToSend((void *) pDevice, pMgmt))
*pStatus = CMD_STATUS_SUCCESS;
return;
}
/*+
*
* Routine Description:
* Instructs wmac to join a bss using the supplied attributes.
* The arguments may the BSSID or SSID and the rest of the
* attributes are obtained from the scan result of known bss list.
*
*
* Return Value:
* None.
*
-*/
void vMgrJoinBSSBegin(struct vnt_private *pDevice, PCMD_STATUS pStatus)
{
struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
PKnownBSS pCurr = NULL;
int ii, uu;
PWLAN_IE_SUPP_RATES pItemRates = NULL;
PWLAN_IE_SUPP_RATES pItemExtRates = NULL;
PWLAN_IE_SSID pItemSSID;
u32 uRateLen = WLAN_RATES_MAXLEN;
u16 wMaxBasicRate = RATE_1M;
u16 wMaxSuppRate = RATE_1M;
u16 wSuppRate;
u8 byTopCCKBasicRate = RATE_1M;
u8 byTopOFDMBasicRate = RATE_1M;
u8 bShortSlotTime = false;
for (ii = 0; ii < MAX_BSS_NUM; ii++) {
if (pMgmt->sBSSList[ii].bActive == true)
break;
}
if (ii == MAX_BSS_NUM) {
*pStatus = CMD_STATUS_RESOURCES;
DBG_PRT(MSG_LEVEL_NOTICE, KERN_INFO "BSS finding:BSS list is empty.\n");
return;
}
// memset(pMgmt->abyDesireBSSID, 0, WLAN_BSSID_LEN);
// Search known BSS list for prefer BSSID or SSID
pCurr = BSSpSearchBSSList(pDevice,
pMgmt->abyDesireBSSID,
pMgmt->abyDesireSSID,
pDevice->eConfigPHYMode
);
if (pCurr == NULL){
*pStatus = CMD_STATUS_RESOURCES;
pItemSSID = (PWLAN_IE_SSID)pMgmt->abyDesireSSID;
DBG_PRT(MSG_LEVEL_NOTICE, KERN_INFO "Scanning [%s] not found, disconnected !\n", pItemSSID->abySSID);
return;
}
DBG_PRT(MSG_LEVEL_NOTICE, KERN_INFO "AP(BSS) finding:Found a AP(BSS)..\n");
if (WLAN_GET_CAP_INFO_ESS(cpu_to_le16(pCurr->wCapInfo))){
if ((pMgmt->eAuthenMode == WMAC_AUTH_WPA) ||
(pMgmt->eAuthenMode == WMAC_AUTH_WPAPSK)) {
/*
if (pDevice->eEncryptionStatus == Ndis802_11Encryption2Enabled) {
if (WPA_SearchRSN(0, WPA_TKIP, pCurr) == false) {
DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"No match RSN info. ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n");
// encryption mode error
pMgmt->eCurrState = WMAC_STATE_IDLE;
return;
}
} else if (pDevice->eEncryptionStatus == Ndis802_11Encryption3Enabled) {
if (WPA_SearchRSN(0, WPA_AESCCMP, pCurr) == false) {
DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"No match RSN info. ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n");
// encryption mode error
pMgmt->eCurrState = WMAC_STATE_IDLE;
return;
}
}
*/
}
//if(pDevice->bWPASuppWextEnabled == true)
Encyption_Rebuild(pDevice, pCurr);
// Infrastructure BSS
s_vMgrSynchBSS(pDevice,
WMAC_MODE_ESS_STA,
pCurr,
pStatus
);
if (*pStatus == CMD_STATUS_SUCCESS){
// Adopt this BSS state vars in Mgmt Object
pMgmt->uCurrChannel = pCurr->uChannel;
memset(pMgmt->abyCurrSuppRates, 0 , WLAN_IEHDR_LEN + WLAN_RATES_MAXLEN + 1);
memset(pMgmt->abyCurrExtSuppRates, 0 , WLAN_IEHDR_LEN + WLAN_RATES_MAXLEN + 1);
if (pCurr->eNetworkTypeInUse == PHY_TYPE_11B) {
uRateLen = WLAN_RATES_MAXLEN_11B;
}
pItemRates = (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates;
pItemExtRates = (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates;
// Parse Support Rate IE
pItemRates->byElementID = WLAN_EID_SUPP_RATES;
pItemRates->len = RATEuSetIE((PWLAN_IE_SUPP_RATES)pCurr->abySuppRates,
pItemRates,
uRateLen);
// Parse Extension Support Rate IE
pItemExtRates->byElementID = WLAN_EID_EXTSUPP_RATES;
pItemExtRates->len = RATEuSetIE((PWLAN_IE_SUPP_RATES)pCurr->abyExtSuppRates,
pItemExtRates,
uRateLen);
// Stuffing Rate IE
if ((pItemExtRates->len > 0) && (pItemRates->len < 8)) {
for (ii = 0; ii < (unsigned int) (8 - pItemRates->len); ) {
pItemRates->abyRates[pItemRates->len + ii] =
pItemExtRates->abyRates[ii];
ii++;
if (pItemExtRates->len <= ii)
break;
}
pItemRates->len += (u8)ii;
if (pItemExtRates->len - ii > 0) {
pItemExtRates->len -= (u8)ii;
for (uu = 0; uu < pItemExtRates->len; uu ++) {
pItemExtRates->abyRates[uu] = pItemExtRates->abyRates[uu + ii];
}
} else {
pItemExtRates->len = 0;
}
}
RATEvParseMaxRate((void *)pDevice, pItemRates, pItemExtRates, true,
&wMaxBasicRate, &wMaxSuppRate, &wSuppRate,
&byTopCCKBasicRate, &byTopOFDMBasicRate);
vUpdateIFS(pDevice);
// TODO: deal with if wCapInfo the privacy is on, but station WEP is off
// TODO: deal with if wCapInfo the PS-Pollable is on.
pMgmt->wCurrBeaconPeriod = pCurr->wBeaconInterval;
memset(pMgmt->abyCurrSSID, 0, WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1);
memcpy(pMgmt->abyCurrBSSID, pCurr->abyBSSID, WLAN_BSSID_LEN);
memcpy(pMgmt->abyCurrSSID, pCurr->abySSID, WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1);
pMgmt->eCurrMode = WMAC_MODE_ESS_STA;
pMgmt->eCurrState = WMAC_STATE_JOINTED;
// Adopt BSS state in Adapter Device Object
pDevice->op_mode = NL80211_IFTYPE_STATION;
memcpy(pDevice->abyBSSID, pCurr->abyBSSID, WLAN_BSSID_LEN);
// Add current BSS to Candidate list
// This should only work for WPA2 BSS, and WPA2 BSS check must be done before.
if (pMgmt->eAuthenMode == WMAC_AUTH_WPA2) {
bool bResult = bAdd_PMKID_Candidate((void *) pDevice,
pMgmt->abyCurrBSSID,
&pCurr->sRSNCapObj);
DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"bAdd_PMKID_Candidate: 1(%d)\n", bResult);
if (bResult == false) {
vFlush_PMKID_Candidate((void *) pDevice);
DBG_PRT(MSG_LEVEL_DEBUG,
KERN_INFO "vFlush_PMKID_Candidate: 4\n");
bAdd_PMKID_Candidate((void *) pDevice,
pMgmt->abyCurrBSSID,
&pCurr->sRSNCapObj);
}
}
// Preamble type auto-switch: if AP can receive short-preamble cap,
// we can turn on too.
if (WLAN_GET_CAP_INFO_SHORTPREAMBLE(pCurr->wCapInfo)) {
pDevice->byPreambleType = pDevice->byShortPreamble;
}
else {
pDevice->byPreambleType = 0;
}
// Change PreambleType must set RSPINF again
CARDvSetRSPINF(pDevice, (u8)pDevice->byBBType);
DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Join ESS\n");
if (pCurr->eNetworkTypeInUse == PHY_TYPE_11G) {
if ((pCurr->sERP.byERP & WLAN_EID_ERP_USE_PROTECTION) != pDevice->bProtectMode) {//0000 0010
pDevice->bProtectMode = (pCurr->sERP.byERP & WLAN_EID_ERP_USE_PROTECTION);
if (pDevice->bProtectMode) {
MACvEnableProtectMD(pDevice);
} else {
MACvDisableProtectMD(pDevice);
}
vUpdateIFS(pDevice);
}
if ((pCurr->sERP.byERP & WLAN_EID_ERP_NONERP_PRESENT) != pDevice->bNonERPPresent) {//0000 0001
pDevice->bNonERPPresent = (pCurr->sERP.byERP & WLAN_EID_ERP_USE_PROTECTION);
}
if ((pCurr->sERP.byERP & WLAN_EID_ERP_BARKER_MODE) != pDevice->bBarkerPreambleMd) {//0000 0100
pDevice->bBarkerPreambleMd = (pCurr->sERP.byERP & WLAN_EID_ERP_BARKER_MODE);
//BarkerPreambleMd has higher priority than shortPreamble bit in Cap
if (pDevice->bBarkerPreambleMd) {
MACvEnableBarkerPreambleMd(pDevice);
} else {
MACvDisableBarkerPreambleMd(pDevice);
}
}
}
//DBG_PRN_WLAN05(("wCapInfo: %X\n", pCurr->wCapInfo));
if (WLAN_GET_CAP_INFO_SHORTSLOTTIME(pCurr->wCapInfo) != pDevice->bShortSlotTime) {
if (pDevice->byBBType == BB_TYPE_11A) {
bShortSlotTime = true;
}
else if (pDevice->byBBType == BB_TYPE_11B) {
bShortSlotTime = false;
}
else {
bShortSlotTime = WLAN_GET_CAP_INFO_SHORTSLOTTIME(pCurr->wCapInfo);
}
//DBG_PRN_WLAN05(("Set Short Slot Time: %d\n", pDevice->bShortSlotTime));
if (bShortSlotTime != pDevice->bShortSlotTime) {
pDevice->bShortSlotTime = bShortSlotTime;
BBvSetShortSlotTime(pDevice);
vUpdateIFS(pDevice);
}
}
DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"End of Join AP -- A/B/G Action\n");
}
else {
pMgmt->eCurrState = WMAC_STATE_IDLE;
};
}
else {
// ad-hoc mode BSS
if (pMgmt->eAuthenMode == WMAC_AUTH_WPANONE) {
if (pDevice->eEncryptionStatus == Ndis802_11Encryption2Enabled) {
/*
if (WPA_SearchRSN(0, WPA_TKIP, pCurr) == false) {
// encryption mode error
pMgmt->eCurrState = WMAC_STATE_IDLE;
return;
}
*/
} else if (pDevice->eEncryptionStatus == Ndis802_11Encryption3Enabled) {
/*
if (WPA_SearchRSN(0, WPA_AESCCMP, pCurr) == false) {
// encryption mode error
pMgmt->eCurrState = WMAC_STATE_IDLE;
return;
}
*/
} else {
// encryption mode error
pMgmt->eCurrState = WMAC_STATE_IDLE;
return;
}
}
s_vMgrSynchBSS(pDevice,
WMAC_MODE_IBSS_STA,
pCurr,
pStatus
);
if (*pStatus == CMD_STATUS_SUCCESS){
// Adopt this BSS state vars in Mgmt Object
// TODO: check if CapInfo privacy on, but we don't..
pMgmt->uCurrChannel = pCurr->uChannel;
// Parse Support Rate IE
pMgmt->abyCurrSuppRates[0] = WLAN_EID_SUPP_RATES;
pMgmt->abyCurrSuppRates[1] = RATEuSetIE((PWLAN_IE_SUPP_RATES)pCurr->abySuppRates,
(PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates,
WLAN_RATES_MAXLEN_11B);
// set basic rate
RATEvParseMaxRate((void *)pDevice,
(PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates,
NULL, true, &wMaxBasicRate, &wMaxSuppRate, &wSuppRate,
&byTopCCKBasicRate, &byTopOFDMBasicRate);
vUpdateIFS(pDevice);
pMgmt->wCurrCapInfo = pCurr->wCapInfo;
pMgmt->wCurrBeaconPeriod = pCurr->wBeaconInterval;
memset(pMgmt->abyCurrSSID, 0, WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN);
memcpy(pMgmt->abyCurrBSSID, pCurr->abyBSSID, WLAN_BSSID_LEN);
memcpy(pMgmt->abyCurrSSID, pCurr->abySSID, WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN);
// pMgmt->wCurrATIMWindow = pCurr->wATIMWindow;
pMgmt->eCurrMode = WMAC_MODE_IBSS_STA;
pMgmt->eCurrState = WMAC_STATE_STARTED;
// Adopt BSS state in Adapter Device Object
pDevice->op_mode = NL80211_IFTYPE_ADHOC;
pDevice->bLinkPass = true;
vnt_mac_set_led(pDevice, LEDSTS_STS, LEDSTS_INTER);
memcpy(pDevice->abyBSSID, pCurr->abyBSSID, WLAN_BSSID_LEN);
DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Join IBSS ok:%pM\n",
pMgmt->abyCurrBSSID);
// Preamble type auto-switch: if AP can receive short-preamble cap,
// and if registry setting is short preamble we can turn on too.
if (WLAN_GET_CAP_INFO_SHORTPREAMBLE(pCurr->wCapInfo)) {
pDevice->byPreambleType = pDevice->byShortPreamble;
}
else {
pDevice->byPreambleType = 0;
}
// Change PreambleType must set RSPINF again
CARDvSetRSPINF(pDevice, (u8)pDevice->byBBType);
// Prepare beacon
bMgrPrepareBeaconToSend((void *) pDevice, pMgmt);
}
else {
pMgmt->eCurrState = WMAC_STATE_IDLE;
};
};
return;
}
/*+
*
* Routine Description:
* Set HW to synchronize a specific BSS from known BSS list.
*
*
* Return Value:
* PCM_STATUS
*
-*/
static void s_vMgrSynchBSS(struct vnt_private *pDevice, u32 uBSSMode,
PKnownBSS pCurr, PCMD_STATUS pStatus)
{
struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
u8 abyCurrSuppRatesG[] = {WLAN_EID_SUPP_RATES,
8, 0x02, 0x04, 0x0B, 0x16, 0x24, 0x30, 0x48, 0x6C};
/* 1M, 2M, 5M, 11M, 18M, 24M, 36M, 54M*/
u8 abyCurrExtSuppRatesG[] = {WLAN_EID_EXTSUPP_RATES,
4, 0x0C, 0x12, 0x18, 0x60};
/* 6M, 9M, 12M, 48M*/
u8 abyCurrSuppRatesA[] = {WLAN_EID_SUPP_RATES,
8, 0x0C, 0x12, 0x18, 0x24, 0x30, 0x48, 0x60, 0x6C};
u8 abyCurrSuppRatesB[] = {WLAN_EID_SUPP_RATES,
4, 0x02, 0x04, 0x0B, 0x16};
*pStatus = CMD_STATUS_FAILURE;
if (s_bCipherMatch(pCurr,
pDevice->eEncryptionStatus,
&(pMgmt->byCSSPK),
&(pMgmt->byCSSGK)) == false) {
DBG_PRT(MSG_LEVEL_NOTICE, KERN_INFO "s_bCipherMatch Fail .......\n");
return;
}
pMgmt->pCurrBSS = pCurr;
// if previous mode is IBSS.
if(pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) {
MACvRegBitsOff(pDevice, MAC_REG_TCR, TCR_AUTOBCNTX);
}
// Init the BSS informations
pDevice->bProtectMode = false;
MACvDisableProtectMD(pDevice);
pDevice->bBarkerPreambleMd = false;
MACvDisableBarkerPreambleMd(pDevice);
pDevice->bNonERPPresent = false;
pDevice->byPreambleType = 0;
pDevice->wBasicRate = 0;
// Set Basic Rate
CARDbAddBasicRate((void *)pDevice, RATE_1M);
// calculate TSF offset
// TSF Offset = Received Timestamp TSF - Marked Local's TSF
CARDvAdjustTSF(pDevice, pCurr->byRxRate, pCurr->qwBSSTimestamp, pCurr->qwLocalTSF);
// set HW beacon interval
MACvWriteBeaconInterval(pDevice, pCurr->wBeaconInterval);
// set Next TBTT
// Next TBTT = ((local_current_TSF / beacon_interval) + 1 ) * beacon_interval
CARDvSetFirstNextTBTT(pDevice, pCurr->wBeaconInterval);
// set BSSID
MACvWriteBSSIDAddress(pDevice, pCurr->abyBSSID);
memcpy(pMgmt->abyCurrBSSID, pCurr->abyBSSID, 6);
DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Sync:set CurrBSSID address = "
"%pM\n", pMgmt->abyCurrBSSID);
if (pCurr->eNetworkTypeInUse == PHY_TYPE_11A) {
if ((pDevice->eConfigPHYMode == PHY_TYPE_11A) ||
(pDevice->eConfigPHYMode == PHY_TYPE_AUTO)) {
pDevice->byBBType = BB_TYPE_11A;
pMgmt->eCurrentPHYMode = PHY_TYPE_11A;
pDevice->bShortSlotTime = true;
BBvSetShortSlotTime(pDevice);
CARDvSetBSSMode(pDevice);
} else {
return;
}
} else if (pCurr->eNetworkTypeInUse == PHY_TYPE_11B) {
if ((pDevice->eConfigPHYMode == PHY_TYPE_11B) ||
(pDevice->eConfigPHYMode == PHY_TYPE_11G) ||
(pDevice->eConfigPHYMode == PHY_TYPE_AUTO)) {
pDevice->byBBType = BB_TYPE_11B;
pMgmt->eCurrentPHYMode = PHY_TYPE_11B;
pDevice->bShortSlotTime = false;
BBvSetShortSlotTime(pDevice);
CARDvSetBSSMode(pDevice);
} else {
return;
}
} else {
if ((pDevice->eConfigPHYMode == PHY_TYPE_11G) ||
(pDevice->eConfigPHYMode == PHY_TYPE_AUTO)) {
pDevice->byBBType = BB_TYPE_11G;
pMgmt->eCurrentPHYMode = PHY_TYPE_11G;
pDevice->bShortSlotTime = true;
BBvSetShortSlotTime(pDevice);
CARDvSetBSSMode(pDevice);
} else if (pDevice->eConfigPHYMode == PHY_TYPE_11B) {