wroute.c 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  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 & filterring
  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. #include "mac.h"
  34. #include "tcrc.h"
  35. #include "rxtx.h"
  36. #include "wroute.h"
  37. #include "card.h"
  38. #include "baseband.h"
  39. /*--------------------- Static Definitions -------------------------*/
  40. /*--------------------- Static Classes ----------------------------*/
  41. /*--------------------- Static Variables --------------------------*/
  42. static int msglevel =MSG_LEVEL_INFO;
  43. //static int msglevel =MSG_LEVEL_DEBUG;
  44. /*--------------------- Static Functions --------------------------*/
  45. /*--------------------- Export Variables --------------------------*/
  46. /*
  47. * Description:
  48. * Relay packet. Return true if packet is copy to DMA1
  49. *
  50. * Parameters:
  51. * In:
  52. * pDevice -
  53. * pbySkbData - rx packet skb data
  54. * Out:
  55. * true, false
  56. *
  57. * Return Value: true if packet duplicate; otherwise false
  58. *
  59. */
  60. bool ROUTEbRelay (PSDevice pDevice, unsigned char *pbySkbData, unsigned int uDataLen, unsigned int uNodeIndex)
  61. {
  62. PSMgmtObject pMgmt = pDevice->pMgmt;
  63. PSTxDesc pHeadTD, pLastTD;
  64. unsigned int cbFrameBodySize;
  65. unsigned int uMACfragNum;
  66. unsigned char byPktType;
  67. bool bNeedEncryption = false;
  68. SKeyItem STempKey;
  69. PSKeyItem pTransmitKey = NULL;
  70. unsigned int cbHeaderSize;
  71. unsigned int ii;
  72. unsigned char *pbyBSSID;
  73. if (AVAIL_TD(pDevice, TYPE_AC0DMA)<=0) {
  74. DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Relay can't allocate TD1..\n");
  75. return false;
  76. }
  77. pHeadTD = pDevice->apCurrTD[TYPE_AC0DMA];
  78. pHeadTD->m_td1TD1.byTCR = (TCR_EDP|TCR_STP);
  79. memcpy(pDevice->sTxEthHeader.abyDstAddr, (unsigned char *)pbySkbData, ETH_HLEN);
  80. cbFrameBodySize = uDataLen - ETH_HLEN;
  81. if (ntohs(pDevice->sTxEthHeader.wType) > ETH_DATA_LEN) {
  82. cbFrameBodySize += 8;
  83. }
  84. if (pDevice->bEncryptionEnable == true) {
  85. bNeedEncryption = true;
  86. // get group key
  87. pbyBSSID = pDevice->abyBroadcastAddr;
  88. if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == false) {
  89. pTransmitKey = NULL;
  90. DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"KEY is NULL. [%d]\n", pDevice->pMgmt->eCurrMode);
  91. } else {
  92. DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"Get GTK.\n");
  93. }
  94. }
  95. if (pDevice->bEnableHostWEP) {
  96. if (uNodeIndex < MAX_NODE_NUM + 1) {
  97. pTransmitKey = &STempKey;
  98. pTransmitKey->byCipherSuite = pMgmt->sNodeDBTable[uNodeIndex].byCipherSuite;
  99. pTransmitKey->dwKeyIndex = pMgmt->sNodeDBTable[uNodeIndex].dwKeyIndex;
  100. pTransmitKey->uKeyLength = pMgmt->sNodeDBTable[uNodeIndex].uWepKeyLength;
  101. pTransmitKey->dwTSC47_16 = pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16;
  102. pTransmitKey->wTSC15_0 = pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0;
  103. memcpy(pTransmitKey->abyKey,
  104. &pMgmt->sNodeDBTable[uNodeIndex].abyWepKey[0],
  105. pTransmitKey->uKeyLength
  106. );
  107. }
  108. }
  109. uMACfragNum = cbGetFragCount(pDevice, pTransmitKey, cbFrameBodySize, &pDevice->sTxEthHeader);
  110. if (uMACfragNum > AVAIL_TD(pDevice,TYPE_AC0DMA)) {
  111. return false;
  112. }
  113. byPktType = (unsigned char)pDevice->byPacketType;
  114. if (pDevice->bFixRate) {
  115. if (pDevice->eCurrentPHYType == PHY_TYPE_11B) {
  116. if (pDevice->uConnectionRate >= RATE_11M) {
  117. pDevice->wCurrentRate = RATE_11M;
  118. } else {
  119. pDevice->wCurrentRate = (unsigned short)pDevice->uConnectionRate;
  120. }
  121. } else {
  122. if ((pDevice->eCurrentPHYType == PHY_TYPE_11A) &&
  123. (pDevice->uConnectionRate <= RATE_6M)) {
  124. pDevice->wCurrentRate = RATE_6M;
  125. } else {
  126. if (pDevice->uConnectionRate >= RATE_54M)
  127. pDevice->wCurrentRate = RATE_54M;
  128. else
  129. pDevice->wCurrentRate = (unsigned short)pDevice->uConnectionRate;
  130. }
  131. }
  132. }
  133. else {
  134. pDevice->wCurrentRate = pDevice->pMgmt->sNodeDBTable[uNodeIndex].wTxDataRate;
  135. }
  136. if (pDevice->wCurrentRate <= RATE_11M)
  137. byPktType = PK_TYPE_11B;
  138. vGenerateFIFOHeader(pDevice, byPktType, pDevice->pbyTmpBuff, bNeedEncryption,
  139. cbFrameBodySize, TYPE_AC0DMA, pHeadTD,
  140. &pDevice->sTxEthHeader, pbySkbData, pTransmitKey, uNodeIndex,
  141. &uMACfragNum,
  142. &cbHeaderSize
  143. );
  144. if (MACbIsRegBitsOn(pDevice->PortOffset, MAC_REG_PSCTL, PSCTL_PS)) {
  145. // Disable PS
  146. MACbPSWakeup(pDevice->PortOffset);
  147. }
  148. pDevice->bPWBitOn = false;
  149. pLastTD = pHeadTD;
  150. for (ii = 0; ii < uMACfragNum; ii++) {
  151. // Poll Transmit the adapter
  152. wmb();
  153. pHeadTD->m_td0TD0.f1Owner=OWNED_BY_NIC;
  154. wmb();
  155. if (ii == (uMACfragNum - 1))
  156. pLastTD = pHeadTD;
  157. pHeadTD = pHeadTD->next;
  158. }
  159. pLastTD->pTDInfo->skb = 0;
  160. pLastTD->pTDInfo->byFlags = 0;
  161. pDevice->apCurrTD[TYPE_AC0DMA] = pHeadTD;
  162. MACvTransmitAC0(pDevice->PortOffset);
  163. return true;
  164. }