blob: 82e93cb820535a2d36fd5c8c39a00005cc999954 [file] [log] [blame]
Forest Bond5449c682009-04-25 10:30:44 -04001/*
2 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
3 * All rights reserved.
4 *
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.
9 *
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.
14 *
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.
18 *
19 * File: wroute.c
20 *
Justin P. Mattock789d1ae2012-08-20 08:43:13 -070021 * Purpose: handle WMAC frame relay & filtering
Forest Bond5449c682009-04-25 10:30:44 -040022 *
23 * Author: Lyndon Chen
24 *
25 * Date: May 20, 2003
26 *
27 * Functions:
28 * ROUTEbRelay - Relay packet
29 *
30 * Revision History:
31 *
32 */
33
Forest Bond5449c682009-04-25 10:30:44 -040034#include "mac.h"
Forest Bond5449c682009-04-25 10:30:44 -040035#include "tcrc.h"
Forest Bond5449c682009-04-25 10:30:44 -040036#include "rxtx.h"
Forest Bond5449c682009-04-25 10:30:44 -040037#include "wroute.h"
Forest Bond5449c682009-04-25 10:30:44 -040038#include "card.h"
Forest Bond5449c682009-04-25 10:30:44 -040039#include "baseband.h"
Jim Lieba7ad3222009-08-12 14:54:09 -070040
Forest Bond5449c682009-04-25 10:30:44 -040041/*--------------------- Static Definitions -------------------------*/
42
43/*--------------------- Static Classes ----------------------------*/
44
45/*--------------------- Static Variables --------------------------*/
46static int msglevel =MSG_LEVEL_INFO;
47//static int msglevel =MSG_LEVEL_DEBUG;
48/*--------------------- Static Functions --------------------------*/
49
50/*--------------------- Export Variables --------------------------*/
51
52
53
54/*
55 * Description:
Charles Clément1b120682010-08-01 17:15:48 +020056 * Relay packet. Return true if packet is copy to DMA1
Forest Bond5449c682009-04-25 10:30:44 -040057 *
58 * Parameters:
59 * In:
60 * pDevice -
61 * pbySkbData - rx packet skb data
62 * Out:
Charles Clément5a5a2a62010-08-01 17:15:49 +020063 * true, false
Forest Bond5449c682009-04-25 10:30:44 -040064 *
Charles Clément5a5a2a62010-08-01 17:15:49 +020065 * Return Value: true if packet duplicate; otherwise false
Forest Bond5449c682009-04-25 10:30:44 -040066 *
67 */
Charles Clément7b6a0012010-08-01 17:15:50 +020068bool ROUTEbRelay (PSDevice pDevice, unsigned char *pbySkbData, unsigned int uDataLen, unsigned int uNodeIndex)
Forest Bond5449c682009-04-25 10:30:44 -040069{
70 PSMgmtObject pMgmt = pDevice->pMgmt;
71 PSTxDesc pHeadTD, pLastTD;
Charles Clémentb6e95cd2010-06-02 09:52:01 -070072 unsigned int cbFrameBodySize;
73 unsigned int uMACfragNum;
Charles Clément3fc9b582010-06-24 11:02:27 -070074 unsigned char byPktType;
Charles Clément7b6a0012010-08-01 17:15:50 +020075 bool bNeedEncryption = false;
Forest Bond5449c682009-04-25 10:30:44 -040076 SKeyItem STempKey;
77 PSKeyItem pTransmitKey = NULL;
Charles Clémentb6e95cd2010-06-02 09:52:01 -070078 unsigned int cbHeaderSize;
79 unsigned int ii;
Charles Clément2989e962010-06-05 15:13:47 -070080 unsigned char *pbyBSSID;
Forest Bond5449c682009-04-25 10:30:44 -040081
82
83
84
85 if (AVAIL_TD(pDevice, TYPE_AC0DMA)<=0) {
Jim Lieb7e809a92009-07-30 10:27:21 -070086 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Relay can't allocate TD1..\n");
Charles Clément5a5a2a62010-08-01 17:15:49 +020087 return false;
Forest Bond5449c682009-04-25 10:30:44 -040088 }
89
90 pHeadTD = pDevice->apCurrTD[TYPE_AC0DMA];
91
92 pHeadTD->m_td1TD1.byTCR = (TCR_EDP|TCR_STP);
93
Charles Clément2989e962010-06-05 15:13:47 -070094 memcpy(pDevice->sTxEthHeader.abyDstAddr, (unsigned char *)pbySkbData, ETH_HLEN);
Forest Bond5449c682009-04-25 10:30:44 -040095
Charles Clément96fe9ee2010-05-14 19:37:33 -070096 cbFrameBodySize = uDataLen - ETH_HLEN;
Forest Bond5449c682009-04-25 10:30:44 -040097
Charles Clément31c21b72010-05-18 11:30:19 -070098 if (ntohs(pDevice->sTxEthHeader.wType) > ETH_DATA_LEN) {
Forest Bond5449c682009-04-25 10:30:44 -040099 cbFrameBodySize += 8;
100 }
101
Charles Clément1b120682010-08-01 17:15:48 +0200102 if (pDevice->bEncryptionEnable == true) {
103 bNeedEncryption = true;
Forest Bond5449c682009-04-25 10:30:44 -0400104
105 // get group key
106 pbyBSSID = pDevice->abyBroadcastAddr;
Charles Clément5a5a2a62010-08-01 17:15:49 +0200107 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == false) {
Forest Bond5449c682009-04-25 10:30:44 -0400108 pTransmitKey = NULL;
Jim Lieb7e809a92009-07-30 10:27:21 -0700109 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"KEY is NULL. [%d]\n", pDevice->pMgmt->eCurrMode);
Forest Bond5449c682009-04-25 10:30:44 -0400110 } else {
Jim Lieb7e809a92009-07-30 10:27:21 -0700111 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"Get GTK.\n");
Forest Bond5449c682009-04-25 10:30:44 -0400112 }
113 }
114
115 if (pDevice->bEnableHostWEP) {
Roel Kluinee93e192009-10-16 20:17:57 +0200116 if (uNodeIndex < MAX_NODE_NUM + 1) {
Forest Bond5449c682009-04-25 10:30:44 -0400117 pTransmitKey = &STempKey;
118 pTransmitKey->byCipherSuite = pMgmt->sNodeDBTable[uNodeIndex].byCipherSuite;
119 pTransmitKey->dwKeyIndex = pMgmt->sNodeDBTable[uNodeIndex].dwKeyIndex;
120 pTransmitKey->uKeyLength = pMgmt->sNodeDBTable[uNodeIndex].uWepKeyLength;
121 pTransmitKey->dwTSC47_16 = pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16;
122 pTransmitKey->wTSC15_0 = pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0;
123 memcpy(pTransmitKey->abyKey,
124 &pMgmt->sNodeDBTable[uNodeIndex].abyWepKey[0],
125 pTransmitKey->uKeyLength
126 );
127 }
128 }
129
130 uMACfragNum = cbGetFragCount(pDevice, pTransmitKey, cbFrameBodySize, &pDevice->sTxEthHeader);
131
132 if (uMACfragNum > AVAIL_TD(pDevice,TYPE_AC0DMA)) {
Charles Clément5a5a2a62010-08-01 17:15:49 +0200133 return false;
Forest Bond5449c682009-04-25 10:30:44 -0400134 }
Charles Clément3fc9b582010-06-24 11:02:27 -0700135 byPktType = (unsigned char)pDevice->byPacketType;
Forest Bond5449c682009-04-25 10:30:44 -0400136
137 if (pDevice->bFixRate) {
138 if (pDevice->eCurrentPHYType == PHY_TYPE_11B) {
139 if (pDevice->uConnectionRate >= RATE_11M) {
140 pDevice->wCurrentRate = RATE_11M;
141 } else {
Charles Clément2986db52010-06-24 11:02:26 -0700142 pDevice->wCurrentRate = (unsigned short)pDevice->uConnectionRate;
Forest Bond5449c682009-04-25 10:30:44 -0400143 }
144 } else {
145 if ((pDevice->eCurrentPHYType == PHY_TYPE_11A) &&
146 (pDevice->uConnectionRate <= RATE_6M)) {
147 pDevice->wCurrentRate = RATE_6M;
148 } else {
149 if (pDevice->uConnectionRate >= RATE_54M)
150 pDevice->wCurrentRate = RATE_54M;
151 else
Charles Clément2986db52010-06-24 11:02:26 -0700152 pDevice->wCurrentRate = (unsigned short)pDevice->uConnectionRate;
Forest Bond5449c682009-04-25 10:30:44 -0400153 }
154 }
155 }
156 else {
157 pDevice->wCurrentRate = pDevice->pMgmt->sNodeDBTable[uNodeIndex].wTxDataRate;
158 }
159
160 if (pDevice->wCurrentRate <= RATE_11M)
Jim Lieb7e809a92009-07-30 10:27:21 -0700161 byPktType = PK_TYPE_11B;
Forest Bond5449c682009-04-25 10:30:44 -0400162
Jim Lieb7e809a92009-07-30 10:27:21 -0700163 vGenerateFIFOHeader(pDevice, byPktType, pDevice->pbyTmpBuff, bNeedEncryption,
Forest Bond5449c682009-04-25 10:30:44 -0400164 cbFrameBodySize, TYPE_AC0DMA, pHeadTD,
165 &pDevice->sTxEthHeader, pbySkbData, pTransmitKey, uNodeIndex,
166 &uMACfragNum,
167 &cbHeaderSize
168 );
169
170 if (MACbIsRegBitsOn(pDevice->PortOffset, MAC_REG_PSCTL, PSCTL_PS)) {
171 // Disable PS
172 MACbPSWakeup(pDevice->PortOffset);
173 }
174
Charles Clément5a5a2a62010-08-01 17:15:49 +0200175 pDevice->bPWBitOn = false;
Forest Bond5449c682009-04-25 10:30:44 -0400176
177 pLastTD = pHeadTD;
178 for (ii = 0; ii < uMACfragNum; ii++) {
179 // Poll Transmit the adapter
180 wmb();
181 pHeadTD->m_td0TD0.f1Owner=OWNED_BY_NIC;
182 wmb();
183 if (ii == (uMACfragNum - 1))
184 pLastTD = pHeadTD;
185 pHeadTD = pHeadTD->next;
186 }
187
188 pLastTD->pTDInfo->skb = 0;
189 pLastTD->pTDInfo->byFlags = 0;
190
191 pDevice->apCurrTD[TYPE_AC0DMA] = pHeadTD;
192
193 MACvTransmitAC0(pDevice->PortOffset);
194
Charles Clément1b120682010-08-01 17:15:48 +0200195 return true;
Forest Bond5449c682009-04-25 10:30:44 -0400196}
197
198
199