Btrfs: device_list_add() should not update list when mounted
[linux/fpc-iii.git] / drivers / staging / vt6655 / wroute.c
blob4da3fef139dcc8ab10657f9b16191867099c8768
1 /*
2 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
3 * All rights reserved.
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 * File: wroute.c
21 * Purpose: handle WMAC frame relay & filtering
23 * Author: Lyndon Chen
25 * Date: May 20, 2003
27 * Functions:
28 * ROUTEbRelay - Relay packet
30 * Revision History:
34 #include "mac.h"
35 #include "tcrc.h"
36 #include "rxtx.h"
37 #include "wroute.h"
38 #include "card.h"
39 #include "baseband.h"
41 /*--------------------- Static Definitions -------------------------*/
43 /*--------------------- Static Classes ----------------------------*/
45 /*--------------------- Static Variables --------------------------*/
46 static int msglevel = MSG_LEVEL_INFO;
47 /*--------------------- Static Functions --------------------------*/
49 /*--------------------- Export Variables --------------------------*/
52 * Description:
53 * Relay packet. Return true if packet is copy to DMA1
55 * Parameters:
56 * In:
57 * pDevice -
58 * pbySkbData - rx packet skb data
59 * Out:
60 * true, false
62 * Return Value: true if packet duplicate; otherwise false
65 bool ROUTEbRelay(PSDevice pDevice, unsigned char *pbySkbData,
66 unsigned int uDataLen, unsigned int uNodeIndex)
68 PSMgmtObject pMgmt = pDevice->pMgmt;
69 PSTxDesc pHeadTD, pLastTD;
70 unsigned int cbFrameBodySize;
71 unsigned int uMACfragNum;
72 unsigned char byPktType;
73 bool bNeedEncryption = false;
74 SKeyItem STempKey;
75 PSKeyItem pTransmitKey = NULL;
76 unsigned int cbHeaderSize;
77 unsigned int ii;
78 unsigned char *pbyBSSID;
80 if (AVAIL_TD(pDevice, TYPE_AC0DMA) <= 0) {
81 DBG_PRT(MSG_LEVEL_DEBUG,
82 KERN_INFO "Relay can't allocate TD1..\n");
83 return false;
86 pHeadTD = pDevice->apCurrTD[TYPE_AC0DMA];
88 pHeadTD->m_td1TD1.byTCR = (TCR_EDP | TCR_STP);
90 memcpy(pDevice->sTxEthHeader.abyDstAddr, pbySkbData, ETH_HLEN);
92 cbFrameBodySize = uDataLen - ETH_HLEN;
94 if (ntohs(pDevice->sTxEthHeader.wType) > ETH_DATA_LEN)
95 cbFrameBodySize += 8;
97 if (pDevice->bEncryptionEnable == true) {
98 bNeedEncryption = true;
100 // get group key
101 pbyBSSID = pDevice->abyBroadcastAddr;
102 if (KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID,
103 GROUP_KEY, &pTransmitKey) == false) {
104 pTransmitKey = NULL;
105 DBG_PRT(MSG_LEVEL_DEBUG,
106 KERN_DEBUG "KEY is NULL. [%d]\n",
107 pDevice->pMgmt->eCurrMode);
108 } else {
109 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG "Get GTK.\n");
113 if (pDevice->bEnableHostWEP) {
114 if (uNodeIndex < MAX_NODE_NUM + 1) {
115 pTransmitKey = &STempKey;
116 pTransmitKey->byCipherSuite = pMgmt->sNodeDBTable[uNodeIndex].byCipherSuite;
117 pTransmitKey->dwKeyIndex = pMgmt->sNodeDBTable[uNodeIndex].dwKeyIndex;
118 pTransmitKey->uKeyLength = pMgmt->sNodeDBTable[uNodeIndex].uWepKeyLength;
119 pTransmitKey->dwTSC47_16 = pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16;
120 pTransmitKey->wTSC15_0 = pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0;
121 memcpy(pTransmitKey->abyKey,
122 &pMgmt->sNodeDBTable[uNodeIndex].abyWepKey[0],
123 pTransmitKey->uKeyLength);
127 uMACfragNum = cbGetFragCount(pDevice, pTransmitKey,
128 cbFrameBodySize, &pDevice->sTxEthHeader);
130 if (uMACfragNum > AVAIL_TD(pDevice, TYPE_AC0DMA))
131 return false;
133 byPktType = pDevice->byPacketType;
135 if (pDevice->bFixRate) {
136 if (pDevice->eCurrentPHYType == PHY_TYPE_11B) {
137 if (pDevice->uConnectionRate >= RATE_11M)
138 pDevice->wCurrentRate = RATE_11M;
139 else
140 pDevice->wCurrentRate = pDevice->uConnectionRate;
141 } else {
142 if ((pDevice->eCurrentPHYType == PHY_TYPE_11A) &&
143 (pDevice->uConnectionRate <= RATE_6M)) {
144 pDevice->wCurrentRate = RATE_6M;
145 } else {
146 if (pDevice->uConnectionRate >= RATE_54M)
147 pDevice->wCurrentRate = RATE_54M;
148 else
149 pDevice->wCurrentRate = pDevice->uConnectionRate;
152 } else {
153 pDevice->wCurrentRate = pDevice->pMgmt->sNodeDBTable[uNodeIndex].wTxDataRate;
156 if (pDevice->wCurrentRate <= RATE_11M)
157 byPktType = PK_TYPE_11B;
159 vGenerateFIFOHeader(pDevice, byPktType, pDevice->pbyTmpBuff,
160 bNeedEncryption, cbFrameBodySize, TYPE_AC0DMA,
161 pHeadTD, &pDevice->sTxEthHeader, pbySkbData,
162 pTransmitKey, uNodeIndex, &uMACfragNum,
163 &cbHeaderSize);
165 if (MACbIsRegBitsOn(pDevice->PortOffset, MAC_REG_PSCTL, PSCTL_PS)) {
166 // Disable PS
167 MACbPSWakeup(pDevice->PortOffset);
170 pDevice->bPWBitOn = false;
172 pLastTD = pHeadTD;
173 for (ii = 0; ii < uMACfragNum; ii++) {
174 // Poll Transmit the adapter
175 wmb();
176 pHeadTD->m_td0TD0.f1Owner = OWNED_BY_NIC;
177 wmb();
178 if (ii == (uMACfragNum - 1))
179 pLastTD = pHeadTD;
180 pHeadTD = pHeadTD->next;
183 pLastTD->pTDInfo->skb = NULL;
184 pLastTD->pTDInfo->byFlags = 0;
186 pDevice->apCurrTD[TYPE_AC0DMA] = pHeadTD;
188 MACvTransmitAC0(pDevice->PortOffset);
190 return true;