]> git.karo-electronics.de Git - karo-tx-linux.git/blob - drivers/staging/vt6655/wroute.c
drm/imx: convert dev_dbg() to dev_err() for error message
[karo-tx-linux.git] / drivers / staging / vt6655 / wroute.c
1 /*
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  *
21  * Purpose: handle WMAC frame relay & filtering
22  *
23  * Author: Lyndon Chen
24  *
25  * Date: May 20, 2003
26  *
27  * Functions:
28  *      ROUTEbRelay - Relay packet
29  *
30  * Revision History:
31  *
32  */
33
34 #include "mac.h"
35 #include "tcrc.h"
36 #include "rxtx.h"
37 #include "wroute.h"
38 #include "card.h"
39 #include "baseband.h"
40
41 /*---------------------  Static Definitions -------------------------*/
42
43 /*---------------------  Static Classes  ----------------------------*/
44
45 /*---------------------  Static Variables  --------------------------*/
46 static int msglevel = MSG_LEVEL_INFO;
47 //static int          msglevel                =MSG_LEVEL_DEBUG;
48 /*---------------------  Static Functions  --------------------------*/
49
50 /*---------------------  Export Variables  --------------------------*/
51
52 /*
53  * Description:
54  *      Relay packet.  Return true if packet is copy to DMA1
55  *
56  * Parameters:
57  *  In:
58  *      pDevice             -
59  *      pbySkbData          - rx packet skb data
60  *  Out:
61  *      true, false
62  *
63  * Return Value: true if packet duplicate; otherwise false
64  *
65  */
66 bool ROUTEbRelay(PSDevice pDevice, unsigned char *pbySkbData, unsigned int uDataLen, unsigned int uNodeIndex)
67 {
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;
79
80         if (AVAIL_TD(pDevice, TYPE_AC0DMA) <= 0) {
81                 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Relay can't allocate TD1..\n");
82                 return false;
83         }
84
85         pHeadTD = pDevice->apCurrTD[TYPE_AC0DMA];
86
87         pHeadTD->m_td1TD1.byTCR = (TCR_EDP | TCR_STP);
88
89         memcpy(pDevice->sTxEthHeader.abyDstAddr, (unsigned char *)pbySkbData, ETH_HLEN);
90
91         cbFrameBodySize = uDataLen - ETH_HLEN;
92
93         if (ntohs(pDevice->sTxEthHeader.wType) > ETH_DATA_LEN) {
94                 cbFrameBodySize += 8;
95         }
96
97         if (pDevice->bEncryptionEnable == true) {
98                 bNeedEncryption = true;
99
100                 // get group key
101                 pbyBSSID = pDevice->abyBroadcastAddr;
102                 if (KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == false) {
103                         pTransmitKey = NULL;
104                         DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG "KEY is NULL. [%d]\n", pDevice->pMgmt->eCurrMode);
105                 } else {
106                         DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG "Get GTK.\n");
107                 }
108         }
109
110         if (pDevice->bEnableHostWEP) {
111                 if (uNodeIndex < MAX_NODE_NUM + 1) {
112                         pTransmitKey = &STempKey;
113                         pTransmitKey->byCipherSuite = pMgmt->sNodeDBTable[uNodeIndex].byCipherSuite;
114                         pTransmitKey->dwKeyIndex = pMgmt->sNodeDBTable[uNodeIndex].dwKeyIndex;
115                         pTransmitKey->uKeyLength = pMgmt->sNodeDBTable[uNodeIndex].uWepKeyLength;
116                         pTransmitKey->dwTSC47_16 = pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16;
117                         pTransmitKey->wTSC15_0 = pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0;
118                         memcpy(pTransmitKey->abyKey,
119                                &pMgmt->sNodeDBTable[uNodeIndex].abyWepKey[0],
120                                pTransmitKey->uKeyLength
121 );
122                 }
123         }
124
125         uMACfragNum = cbGetFragCount(pDevice, pTransmitKey, cbFrameBodySize, &pDevice->sTxEthHeader);
126
127         if (uMACfragNum > AVAIL_TD(pDevice, TYPE_AC0DMA)) {
128                 return false;
129         }
130         byPktType = (unsigned char)pDevice->byPacketType;
131
132         if (pDevice->bFixRate) {
133                 if (pDevice->eCurrentPHYType == PHY_TYPE_11B) {
134                         if (pDevice->uConnectionRate >= RATE_11M) {
135                                 pDevice->wCurrentRate = RATE_11M;
136                         } else {
137                                 pDevice->wCurrentRate = (unsigned short)pDevice->uConnectionRate;
138                         }
139                 } else {
140                         if ((pDevice->eCurrentPHYType == PHY_TYPE_11A) &&
141                             (pDevice->uConnectionRate <= RATE_6M)) {
142                                 pDevice->wCurrentRate = RATE_6M;
143                         } else {
144                                 if (pDevice->uConnectionRate >= RATE_54M)
145                                         pDevice->wCurrentRate = RATE_54M;
146                                 else
147                                         pDevice->wCurrentRate = (unsigned short)pDevice->uConnectionRate;
148                         }
149                 }
150         } else {
151                 pDevice->wCurrentRate = pDevice->pMgmt->sNodeDBTable[uNodeIndex].wTxDataRate;
152         }
153
154         if (pDevice->wCurrentRate <= RATE_11M)
155                 byPktType = PK_TYPE_11B;
156
157         vGenerateFIFOHeader(pDevice, byPktType, pDevice->pbyTmpBuff, bNeedEncryption,
158                             cbFrameBodySize, TYPE_AC0DMA, pHeadTD,
159                             &pDevice->sTxEthHeader, pbySkbData, pTransmitKey, uNodeIndex,
160                             &uMACfragNum,
161                             &cbHeaderSize
162 );
163
164         if (MACbIsRegBitsOn(pDevice->PortOffset, MAC_REG_PSCTL, PSCTL_PS)) {
165                 // Disable PS
166                 MACbPSWakeup(pDevice->PortOffset);
167         }
168
169         pDevice->bPWBitOn = false;
170
171         pLastTD = pHeadTD;
172         for (ii = 0; ii < uMACfragNum; ii++) {
173                 // Poll Transmit the adapter
174                 wmb();
175                 pHeadTD->m_td0TD0.f1Owner = OWNED_BY_NIC;
176                 wmb();
177                 if (ii == (uMACfragNum - 1))
178                         pLastTD = pHeadTD;
179                 pHeadTD = pHeadTD->next;
180         }
181
182         pLastTD->pTDInfo->skb = NULL;
183         pLastTD->pTDInfo->byFlags = 0;
184
185         pDevice->apCurrTD[TYPE_AC0DMA] = pHeadTD;
186
187         MACvTransmitAC0(pDevice->PortOffset);
188
189         return true;
190 }