wroute.c 5.1 KB

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