📄 rxtx.c
字号:
/*
* Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
* All rights reserved.
*
* This software is copyrighted by and is the sole property of
* VIA Networking Technologies, Inc. This software may only be used
* in accordance with the corresponding license agreement. Any unauthorized
* use, duplication, transmission, distribution, or disclosure of this
* software is expressly forbidden.
*
* This software is provided by VIA Networking Technologies, Inc. "as is"
* and any express or implied warranties, including, but not limited to, the
* implied warranties of merchantability and fitness for a particular purpose
* are disclaimed. In no event shall VIA Networking Technologies, Inc.
* be liable for any direct, indirect, incidental, special, exemplary, or
* consequential damages.
*
* File: rxtx.c
*
* Purpose: handle WMAC/802.3/802.11 rx & tx functions
*
* Author: Lyndon Chen
*
* Date: May 20, 2003
*
* Functions:
* s_vGenerateTxParameter - Generate tx dma requried parameter.
* vGenerateMACHeader - Translate 802.3 to 802.11 header
* cbGetFragCount - Caculate fragement number count
* csBeacon_xmit - beacon tx function
* csMgmt_xmit - management tx function
* s_cbFillTxBufHead - fulfill tx dma buffer header
* s_uGetDataDuration - get tx data required duration
* s_uFillDataHead- fulfill tx data duration header
* s_uGetRTSCTSDuration- get rtx/cts requried duration
* s_uGetRTSCTSRsvTime- get rts/cts reserved time
* s_uGetTxRsvTime- get frame reserved time
* s_vFillCTSHead- fulfill CTS ctl header
* s_vFillFragParameter- Set fragement ctl parameter.
* s_vFillRTSHead- fulfill RTS ctl header
* s_vFillTxKey- fulfill tx encrypt key
* s_vSWencryption- Software encrypt header
* vDMA0_tx_80211- tx 802.11 frame via dma0
* vGenerateFIFOHeader- Generate tx FIFO ctl header
*
* Revision History:
*
*/
#if !defined(__DEVICE_H__)
#include "device.h"
#endif
#if !defined(__RXTX_H__)
#include "rxtx.h"
#endif
#if !defined(__TETHER_H__)
#include "tether.h"
#endif
#if !defined(__CARD_H__)
#include "card.h"
#endif
#if !defined(__BSSDB_H__)
#include "bssdb.h"
#endif
#if !defined(__MAC_H__)
#include "mac.h"
#endif
#if !defined(__BASEBAND_H__)
#include "baseband.h"
#endif
#if !defined(__UMEM_H__)
#include "umem.h"
#endif
#if !defined(__MICHAEL_H__)
#include "michael.h"
#endif
#if !defined(__TKIP_H__)
#include "tkip.h"
#endif
#if !defined(__TCRC_H__)
#include "tcrc.h"
#endif
#if !defined(__WCTL_H__)
#include "wctl.h"
#endif
#if !defined(__WROUTE_H__)
#include "wroute.h"
#endif
#if !defined(__TBIT_H__)
#include "tbit.h"
#endif
#if !defined(__HOSTAP_H__)
#include "hostap.h"
#endif
#if !defined(__RF_H__)
#include "rf.h"
#endif
/*--------------------- Static Definitions -------------------------*/
/*--------------------- Static Classes ----------------------------*/
/*--------------------- Static Variables --------------------------*/
//static int msglevel =MSG_LEVEL_DEBUG;
static int msglevel =MSG_LEVEL_INFO;
/*--------------------- Static Functions --------------------------*/
/*--------------------- Static Definitions -------------------------*/
#define CRITICAL_PACKET_LEN 256 // if packet size < 256 -> in-direct send
// packet size >= 256 -> direct send
const WORD wTimeStampOff[2][MAX_RATE] = {
{384, 288, 226, 209, 54, 43, 37, 31, 28, 25, 24, 23}, // Long Preamble
{384, 192, 130, 113, 54, 43, 37, 31, 28, 25, 24, 23}, // Short Preamble
};
const WORD wFB_Opt0[2][5] = {
{RATE_12M, RATE_18M, RATE_24M, RATE_36M, RATE_48M}, // fallback_rate0
{RATE_12M, RATE_12M, RATE_18M, RATE_24M, RATE_36M}, // fallback_rate1
};
const WORD wFB_Opt1[2][5] = {
{RATE_12M, RATE_18M, RATE_24M, RATE_24M, RATE_36M}, // fallback_rate0
{RATE_6M , RATE_6M, RATE_12M, RATE_12M, RATE_18M}, // fallback_rate1
};
#define RTSDUR_BB 0
#define RTSDUR_BA 1
#define RTSDUR_AA 2
#define CTSDUR_BA 3
#define RTSDUR_BA_F0 4
#define RTSDUR_AA_F0 5
#define RTSDUR_BA_F1 6
#define RTSDUR_AA_F1 7
#define CTSDUR_BA_F0 8
#define CTSDUR_BA_F1 9
#define DATADUR_B 10
#define DATADUR_A 11
#define DATADUR_A_F0 12
#define DATADUR_A_F1 13
/*--------------------- Static Functions --------------------------*/
static
VOID
s_vFillTxKey(
IN PSDevice pDevice,
IN PBYTE pbyBuf,
IN PBYTE pbyIVHead,
IN PSKeyItem pTransmitKey,
IN PBYTE pbyHdrBuf,
IN WORD wPayloadLen,
OUT PBYTE pMICHDR
);
static
VOID
s_vFillRTSHead(
IN PSDevice pDevice,
IN BYTE byPktTyp,
IN PVOID pvRTS,
IN UINT cbFrameLength,
IN BOOL bNeedAck,
IN BOOL bDisCRC,
IN PSEthernetHeader psEthHeader,
IN WORD wCurrentRate,
IN BYTE byFBOption
);
static
VOID
s_vGenerateTxParameter(
IN PSDevice pDevice,
IN BYTE byPktTyp,
IN PVOID pTxBufHead,
IN PVOID pvRrvTime,
IN PVOID pvRTS,
IN PVOID pvCTS,
IN UINT cbFrameSize,
IN BOOL bNeedACK,
IN UINT uDMAIdx,
IN PSEthernetHeader psEthHeader,
IN WORD wCurrentRate
);
static void s_vFillFragParameter(
IN PSDevice pDevice,
IN PBYTE pbyBuffer,
IN UINT uTxType,
IN PVOID pvtdCurr,
IN WORD wFragType,
IN UINT cbReqCount
);
static
UINT
s_cbFillTxBufHead (
IN PSDevice pDevice,
IN BYTE byPktTyp,
IN PBYTE pbyTxBufferAddr,
IN UINT cbFrameBodySize,
IN UINT uDMAIdx,
IN PSTxDesc pHeadTD,
IN PSEthernetHeader psEthHeader,
IN PBYTE pPacket,
IN BOOL bNeedEncrypt,
IN PSKeyItem pTransmitKey,
IN UINT uNodeIndex,
OUT PUINT puMACfragNum
);
static
UINT
s_uFillDataHead (
IN PSDevice pDevice,
IN BYTE byPktTyp,
IN PVOID pTxDataHead,
IN UINT cbFrameLength,
IN UINT uDMAIdx,
IN BOOL bNeedAck,
IN UINT uFragIdx,
IN UINT cbLastFragmentSize,
IN UINT uMACfragNum,
IN BYTE byFBOption,
IN WORD wCurrentRate
);
/*--------------------- Export Variables --------------------------*/
static
VOID
s_vFillTxKey (
IN PSDevice pDevice,
IN PBYTE pbyBuf,
IN PBYTE pbyIVHead,
IN PSKeyItem pTransmitKey,
IN PBYTE pbyHdrBuf,
IN WORD wPayloadLen,
OUT PBYTE pMICHDR
)
{
PDWORD pdwIV = (PDWORD) pbyIVHead;
PDWORD pdwExtIV = (PDWORD) ((PBYTE)pbyIVHead+4);
WORD wValue;
PS802_11Header pMACHeader = (PS802_11Header)pbyHdrBuf;
DWORD dwRevIVCounter;
BYTE byKeyIndex = 0;
//Fill TXKEY
if (pTransmitKey == NULL)
return;
dwRevIVCounter = cpu_to_le32(pDevice->dwIVCounter);
*pdwIV = pDevice->dwIVCounter;
byKeyIndex = pTransmitKey->dwKeyIndex & 0xf;
if (pTransmitKey->byCipherSuite == KEY_CTL_WEP) {
if (pTransmitKey->uKeyLength == WLAN_WEP232_KEYLEN ){
MEMvCopy(pDevice->abyPRNG, (PBYTE)&(dwRevIVCounter), 3);
MEMvCopy(pDevice->abyPRNG+3, pTransmitKey->abyKey, pTransmitKey->uKeyLength);
} else {
MEMvCopy(pbyBuf, (PBYTE)&(dwRevIVCounter), 3);
MEMvCopy(pbyBuf+3, pTransmitKey->abyKey, pTransmitKey->uKeyLength);
if(pTransmitKey->uKeyLength == WLAN_WEP40_KEYLEN) {
MEMvCopy(pbyBuf+8, (PBYTE)&(dwRevIVCounter), 3);
MEMvCopy(pbyBuf+11, pTransmitKey->abyKey, pTransmitKey->uKeyLength);
}
MEMvCopy(pDevice->abyPRNG, pbyBuf, 16);
}
// Append IV after Mac Header
*pdwIV &= WEP_IV_MASK;//00000000 11111111 11111111 11111111
*pdwIV |= (byKeyIndex << 30);
*pdwIV = cpu_to_le32(*pdwIV);
pDevice->dwIVCounter++;
if (pDevice->dwIVCounter > WEP_IV_MASK) {
pDevice->dwIVCounter = 0;
}
} else if (pTransmitKey->byCipherSuite == KEY_CTL_TKIP) {
pTransmitKey->wTSC15_0++;
if (pTransmitKey->wTSC15_0 == 0) {
pTransmitKey->dwTSC47_16++;
}
TKIPvMixKey(pTransmitKey->abyKey, pDevice->abyCurrentNetAddr,
pTransmitKey->wTSC15_0, pTransmitKey->dwTSC47_16, pDevice->abyPRNG);
MEMvCopy(pbyBuf, pDevice->abyPRNG, 16);
// Make IV
MEMvCopy(pdwIV, pDevice->abyPRNG, 3);
*(pbyIVHead+3) = (BYTE)(((byKeyIndex << 6) & 0xc0) | 0x20); // 0x20 is ExtIV
// Append IV&ExtIV after Mac Header
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -