rxtx.c 130 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190
  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: rxtx.c
  20. *
  21. * Purpose: handle WMAC/802.3/802.11 rx & tx functions
  22. *
  23. * Author: Lyndon Chen
  24. *
  25. * Date: May 20, 2003
  26. *
  27. * Functions:
  28. * s_vGenerateTxParameter - Generate tx dma required parameter.
  29. * vGenerateMACHeader - Translate 802.3 to 802.11 header
  30. * cbGetFragCount - Caculate fragment number count
  31. * csBeacon_xmit - beacon tx function
  32. * csMgmt_xmit - management tx function
  33. * s_cbFillTxBufHead - fulfill tx dma buffer header
  34. * s_uGetDataDuration - get tx data required duration
  35. * s_uFillDataHead- fulfill tx data duration header
  36. * s_uGetRTSCTSDuration- get rtx/cts required duration
  37. * s_uGetRTSCTSRsvTime- get rts/cts reserved time
  38. * s_uGetTxRsvTime- get frame reserved time
  39. * s_vFillCTSHead- fulfill CTS ctl header
  40. * s_vFillFragParameter- Set fragment ctl parameter.
  41. * s_vFillRTSHead- fulfill RTS ctl header
  42. * s_vFillTxKey- fulfill tx encrypt key
  43. * s_vSWencryption- Software encrypt header
  44. * vDMA0_tx_80211- tx 802.11 frame via dma0
  45. * vGenerateFIFOHeader- Generate tx FIFO ctl header
  46. *
  47. * Revision History:
  48. *
  49. */
  50. #include "device.h"
  51. #include "rxtx.h"
  52. #include "tether.h"
  53. #include "card.h"
  54. #include "bssdb.h"
  55. #include "mac.h"
  56. #include "baseband.h"
  57. #include "michael.h"
  58. #include "tkip.h"
  59. #include "tcrc.h"
  60. #include "wctl.h"
  61. #include "wroute.h"
  62. #include "hostap.h"
  63. #include "rf.h"
  64. /*--------------------- Static Definitions -------------------------*/
  65. /*--------------------- Static Classes ----------------------------*/
  66. /*--------------------- Static Variables --------------------------*/
  67. //static int msglevel =MSG_LEVEL_DEBUG;
  68. static int msglevel =MSG_LEVEL_INFO;
  69. #define PLICE_DEBUG
  70. /*--------------------- Static Functions --------------------------*/
  71. /*--------------------- Static Definitions -------------------------*/
  72. #define CRITICAL_PACKET_LEN 256 // if packet size < 256 -> in-direct send
  73. // packet size >= 256 -> direct send
  74. const unsigned short wTimeStampOff[2][MAX_RATE] = {
  75. {384, 288, 226, 209, 54, 43, 37, 31, 28, 25, 24, 23}, // Long Preamble
  76. {384, 192, 130, 113, 54, 43, 37, 31, 28, 25, 24, 23}, // Short Preamble
  77. };
  78. const unsigned short wFB_Opt0[2][5] = {
  79. {RATE_12M, RATE_18M, RATE_24M, RATE_36M, RATE_48M}, // fallback_rate0
  80. {RATE_12M, RATE_12M, RATE_18M, RATE_24M, RATE_36M}, // fallback_rate1
  81. };
  82. const unsigned short wFB_Opt1[2][5] = {
  83. {RATE_12M, RATE_18M, RATE_24M, RATE_24M, RATE_36M}, // fallback_rate0
  84. {RATE_6M , RATE_6M, RATE_12M, RATE_12M, RATE_18M}, // fallback_rate1
  85. };
  86. #define RTSDUR_BB 0
  87. #define RTSDUR_BA 1
  88. #define RTSDUR_AA 2
  89. #define CTSDUR_BA 3
  90. #define RTSDUR_BA_F0 4
  91. #define RTSDUR_AA_F0 5
  92. #define RTSDUR_BA_F1 6
  93. #define RTSDUR_AA_F1 7
  94. #define CTSDUR_BA_F0 8
  95. #define CTSDUR_BA_F1 9
  96. #define DATADUR_B 10
  97. #define DATADUR_A 11
  98. #define DATADUR_A_F0 12
  99. #define DATADUR_A_F1 13
  100. /*--------------------- Static Functions --------------------------*/
  101. static
  102. void
  103. s_vFillTxKey(
  104. PSDevice pDevice,
  105. unsigned char *pbyBuf,
  106. unsigned char *pbyIVHead,
  107. PSKeyItem pTransmitKey,
  108. unsigned char *pbyHdrBuf,
  109. unsigned short wPayloadLen,
  110. unsigned char *pMICHDR
  111. );
  112. static
  113. void
  114. s_vFillRTSHead(
  115. PSDevice pDevice,
  116. unsigned char byPktType,
  117. void * pvRTS,
  118. unsigned int cbFrameLength,
  119. bool bNeedAck,
  120. bool bDisCRC,
  121. PSEthernetHeader psEthHeader,
  122. unsigned short wCurrentRate,
  123. unsigned char byFBOption
  124. );
  125. static
  126. void
  127. s_vGenerateTxParameter(
  128. PSDevice pDevice,
  129. unsigned char byPktType,
  130. void * pTxBufHead,
  131. void * pvRrvTime,
  132. void * pvRTS,
  133. void * pvCTS,
  134. unsigned int cbFrameSize,
  135. bool bNeedACK,
  136. unsigned int uDMAIdx,
  137. PSEthernetHeader psEthHeader,
  138. unsigned short wCurrentRate
  139. );
  140. static void s_vFillFragParameter(
  141. PSDevice pDevice,
  142. unsigned char *pbyBuffer,
  143. unsigned int uTxType,
  144. void * pvtdCurr,
  145. unsigned short wFragType,
  146. unsigned int cbReqCount
  147. );
  148. static unsigned int
  149. s_cbFillTxBufHead(PSDevice pDevice, unsigned char byPktType, unsigned char *pbyTxBufferAddr,
  150. unsigned int cbFrameBodySize, unsigned int uDMAIdx, PSTxDesc pHeadTD,
  151. PSEthernetHeader psEthHeader, unsigned char *pPacket, bool bNeedEncrypt,
  152. PSKeyItem pTransmitKey, unsigned int uNodeIndex, unsigned int *puMACfragNum);
  153. static
  154. unsigned int
  155. s_uFillDataHead (
  156. PSDevice pDevice,
  157. unsigned char byPktType,
  158. void * pTxDataHead,
  159. unsigned int cbFrameLength,
  160. unsigned int uDMAIdx,
  161. bool bNeedAck,
  162. unsigned int uFragIdx,
  163. unsigned int cbLastFragmentSize,
  164. unsigned int uMACfragNum,
  165. unsigned char byFBOption,
  166. unsigned short wCurrentRate
  167. );
  168. /*--------------------- Export Variables --------------------------*/
  169. static
  170. void
  171. s_vFillTxKey (
  172. PSDevice pDevice,
  173. unsigned char *pbyBuf,
  174. unsigned char *pbyIVHead,
  175. PSKeyItem pTransmitKey,
  176. unsigned char *pbyHdrBuf,
  177. unsigned short wPayloadLen,
  178. unsigned char *pMICHDR
  179. )
  180. {
  181. unsigned long *pdwIV = (unsigned long *) pbyIVHead;
  182. unsigned long *pdwExtIV = (unsigned long *) ((unsigned char *)pbyIVHead+4);
  183. unsigned short wValue;
  184. PS802_11Header pMACHeader = (PS802_11Header)pbyHdrBuf;
  185. unsigned long dwRevIVCounter;
  186. unsigned char byKeyIndex = 0;
  187. //Fill TXKEY
  188. if (pTransmitKey == NULL)
  189. return;
  190. dwRevIVCounter = cpu_to_le32(pDevice->dwIVCounter);
  191. *pdwIV = pDevice->dwIVCounter;
  192. byKeyIndex = pTransmitKey->dwKeyIndex & 0xf;
  193. if (pTransmitKey->byCipherSuite == KEY_CTL_WEP) {
  194. if (pTransmitKey->uKeyLength == WLAN_WEP232_KEYLEN ){
  195. memcpy(pDevice->abyPRNG, (unsigned char *)&(dwRevIVCounter), 3);
  196. memcpy(pDevice->abyPRNG+3, pTransmitKey->abyKey, pTransmitKey->uKeyLength);
  197. } else {
  198. memcpy(pbyBuf, (unsigned char *)&(dwRevIVCounter), 3);
  199. memcpy(pbyBuf+3, pTransmitKey->abyKey, pTransmitKey->uKeyLength);
  200. if(pTransmitKey->uKeyLength == WLAN_WEP40_KEYLEN) {
  201. memcpy(pbyBuf+8, (unsigned char *)&(dwRevIVCounter), 3);
  202. memcpy(pbyBuf+11, pTransmitKey->abyKey, pTransmitKey->uKeyLength);
  203. }
  204. memcpy(pDevice->abyPRNG, pbyBuf, 16);
  205. }
  206. // Append IV after Mac Header
  207. *pdwIV &= WEP_IV_MASK;//00000000 11111111 11111111 11111111
  208. *pdwIV |= (byKeyIndex << 30);
  209. *pdwIV = cpu_to_le32(*pdwIV);
  210. pDevice->dwIVCounter++;
  211. if (pDevice->dwIVCounter > WEP_IV_MASK) {
  212. pDevice->dwIVCounter = 0;
  213. }
  214. } else if (pTransmitKey->byCipherSuite == KEY_CTL_TKIP) {
  215. pTransmitKey->wTSC15_0++;
  216. if (pTransmitKey->wTSC15_0 == 0) {
  217. pTransmitKey->dwTSC47_16++;
  218. }
  219. TKIPvMixKey(pTransmitKey->abyKey, pDevice->abyCurrentNetAddr,
  220. pTransmitKey->wTSC15_0, pTransmitKey->dwTSC47_16, pDevice->abyPRNG);
  221. memcpy(pbyBuf, pDevice->abyPRNG, 16);
  222. // Make IV
  223. memcpy(pdwIV, pDevice->abyPRNG, 3);
  224. *(pbyIVHead+3) = (unsigned char)(((byKeyIndex << 6) & 0xc0) | 0x20); // 0x20 is ExtIV
  225. // Append IV&ExtIV after Mac Header
  226. *pdwExtIV = cpu_to_le32(pTransmitKey->dwTSC47_16);
  227. DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"vFillTxKey()---- pdwExtIV: %lx\n", *pdwExtIV);
  228. } else if (pTransmitKey->byCipherSuite == KEY_CTL_CCMP) {
  229. pTransmitKey->wTSC15_0++;
  230. if (pTransmitKey->wTSC15_0 == 0) {
  231. pTransmitKey->dwTSC47_16++;
  232. }
  233. memcpy(pbyBuf, pTransmitKey->abyKey, 16);
  234. // Make IV
  235. *pdwIV = 0;
  236. *(pbyIVHead+3) = (unsigned char)(((byKeyIndex << 6) & 0xc0) | 0x20); // 0x20 is ExtIV
  237. *pdwIV |= cpu_to_le16((unsigned short)(pTransmitKey->wTSC15_0));
  238. //Append IV&ExtIV after Mac Header
  239. *pdwExtIV = cpu_to_le32(pTransmitKey->dwTSC47_16);
  240. //Fill MICHDR0
  241. *pMICHDR = 0x59;
  242. *((unsigned char *)(pMICHDR+1)) = 0; // TxPriority
  243. memcpy(pMICHDR+2, &(pMACHeader->abyAddr2[0]), 6);
  244. *((unsigned char *)(pMICHDR+8)) = HIBYTE(HIWORD(pTransmitKey->dwTSC47_16));
  245. *((unsigned char *)(pMICHDR+9)) = LOBYTE(HIWORD(pTransmitKey->dwTSC47_16));
  246. *((unsigned char *)(pMICHDR+10)) = HIBYTE(LOWORD(pTransmitKey->dwTSC47_16));
  247. *((unsigned char *)(pMICHDR+11)) = LOBYTE(LOWORD(pTransmitKey->dwTSC47_16));
  248. *((unsigned char *)(pMICHDR+12)) = HIBYTE(pTransmitKey->wTSC15_0);
  249. *((unsigned char *)(pMICHDR+13)) = LOBYTE(pTransmitKey->wTSC15_0);
  250. *((unsigned char *)(pMICHDR+14)) = HIBYTE(wPayloadLen);
  251. *((unsigned char *)(pMICHDR+15)) = LOBYTE(wPayloadLen);
  252. //Fill MICHDR1
  253. *((unsigned char *)(pMICHDR+16)) = 0; // HLEN[15:8]
  254. if (pDevice->bLongHeader) {
  255. *((unsigned char *)(pMICHDR+17)) = 28; // HLEN[7:0]
  256. } else {
  257. *((unsigned char *)(pMICHDR+17)) = 22; // HLEN[7:0]
  258. }
  259. wValue = cpu_to_le16(pMACHeader->wFrameCtl & 0xC78F);
  260. memcpy(pMICHDR+18, (unsigned char *)&wValue, 2); // MSKFRACTL
  261. memcpy(pMICHDR+20, &(pMACHeader->abyAddr1[0]), 6);
  262. memcpy(pMICHDR+26, &(pMACHeader->abyAddr2[0]), 6);
  263. //Fill MICHDR2
  264. memcpy(pMICHDR+32, &(pMACHeader->abyAddr3[0]), 6);
  265. wValue = pMACHeader->wSeqCtl;
  266. wValue &= 0x000F;
  267. wValue = cpu_to_le16(wValue);
  268. memcpy(pMICHDR+38, (unsigned char *)&wValue, 2); // MSKSEQCTL
  269. if (pDevice->bLongHeader) {
  270. memcpy(pMICHDR+40, &(pMACHeader->abyAddr4[0]), 6);
  271. }
  272. }
  273. }
  274. static
  275. void
  276. s_vSWencryption (
  277. PSDevice pDevice,
  278. PSKeyItem pTransmitKey,
  279. unsigned char *pbyPayloadHead,
  280. unsigned short wPayloadSize
  281. )
  282. {
  283. unsigned int cbICVlen = 4;
  284. unsigned long dwICV = 0xFFFFFFFFL;
  285. unsigned long *pdwICV;
  286. if (pTransmitKey == NULL)
  287. return;
  288. if (pTransmitKey->byCipherSuite == KEY_CTL_WEP) {
  289. //=======================================================================
  290. // Append ICV after payload
  291. dwICV = CRCdwGetCrc32Ex(pbyPayloadHead, wPayloadSize, dwICV);//ICV(Payload)
  292. pdwICV = (unsigned long *)(pbyPayloadHead + wPayloadSize);
  293. // finally, we must invert dwCRC to get the correct answer
  294. *pdwICV = cpu_to_le32(~dwICV);
  295. // RC4 encryption
  296. rc4_init(&pDevice->SBox, pDevice->abyPRNG, pTransmitKey->uKeyLength + 3);
  297. rc4_encrypt(&pDevice->SBox, pbyPayloadHead, pbyPayloadHead, wPayloadSize+cbICVlen);
  298. //=======================================================================
  299. } else if (pTransmitKey->byCipherSuite == KEY_CTL_TKIP) {
  300. //=======================================================================
  301. //Append ICV after payload
  302. dwICV = CRCdwGetCrc32Ex(pbyPayloadHead, wPayloadSize, dwICV);//ICV(Payload)
  303. pdwICV = (unsigned long *)(pbyPayloadHead + wPayloadSize);
  304. // finally, we must invert dwCRC to get the correct answer
  305. *pdwICV = cpu_to_le32(~dwICV);
  306. // RC4 encryption
  307. rc4_init(&pDevice->SBox, pDevice->abyPRNG, TKIP_KEY_LEN);
  308. rc4_encrypt(&pDevice->SBox, pbyPayloadHead, pbyPayloadHead, wPayloadSize+cbICVlen);
  309. //=======================================================================
  310. }
  311. }
  312. /*byPktType : PK_TYPE_11A 0
  313. PK_TYPE_11B 1
  314. PK_TYPE_11GB 2
  315. PK_TYPE_11GA 3
  316. */
  317. static
  318. unsigned int
  319. s_uGetTxRsvTime (
  320. PSDevice pDevice,
  321. unsigned char byPktType,
  322. unsigned int cbFrameLength,
  323. unsigned short wRate,
  324. bool bNeedAck
  325. )
  326. {
  327. unsigned int uDataTime, uAckTime;
  328. uDataTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, cbFrameLength, wRate);
  329. #ifdef PLICE_DEBUG
  330. //printk("s_uGetTxRsvTime is %d\n",uDataTime);
  331. #endif
  332. if (byPktType == PK_TYPE_11B) {//llb,CCK mode
  333. uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, (unsigned short)pDevice->byTopCCKBasicRate);
  334. } else {//11g 2.4G OFDM mode & 11a 5G OFDM mode
  335. uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, (unsigned short)pDevice->byTopOFDMBasicRate);
  336. }
  337. if (bNeedAck) {
  338. return (uDataTime + pDevice->uSIFS + uAckTime);
  339. }
  340. else {
  341. return uDataTime;
  342. }
  343. }
  344. //byFreqType: 0=>5GHZ 1=>2.4GHZ
  345. static
  346. unsigned int
  347. s_uGetRTSCTSRsvTime (
  348. PSDevice pDevice,
  349. unsigned char byRTSRsvType,
  350. unsigned char byPktType,
  351. unsigned int cbFrameLength,
  352. unsigned short wCurrentRate
  353. )
  354. {
  355. unsigned int uRrvTime , uRTSTime, uCTSTime, uAckTime, uDataTime;
  356. uRrvTime = uRTSTime = uCTSTime = uAckTime = uDataTime = 0;
  357. uDataTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, cbFrameLength, wCurrentRate);
  358. if (byRTSRsvType == 0) { //RTSTxRrvTime_bb
  359. uRTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 20, pDevice->byTopCCKBasicRate);
  360. uCTSTime = uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopCCKBasicRate);
  361. }
  362. else if (byRTSRsvType == 1){ //RTSTxRrvTime_ba, only in 2.4GHZ
  363. uRTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 20, pDevice->byTopCCKBasicRate);
  364. uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopCCKBasicRate);
  365. uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
  366. }
  367. else if (byRTSRsvType == 2) { //RTSTxRrvTime_aa
  368. uRTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 20, pDevice->byTopOFDMBasicRate);
  369. uCTSTime = uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
  370. }
  371. else if (byRTSRsvType == 3) { //CTSTxRrvTime_ba, only in 2.4GHZ
  372. uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopCCKBasicRate);
  373. uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
  374. uRrvTime = uCTSTime + uAckTime + uDataTime + 2*pDevice->uSIFS;
  375. return uRrvTime;
  376. }
  377. //RTSRrvTime
  378. uRrvTime = uRTSTime + uCTSTime + uAckTime + uDataTime + 3*pDevice->uSIFS;
  379. return uRrvTime;
  380. }
  381. //byFreqType 0: 5GHz, 1:2.4Ghz
  382. static
  383. unsigned int
  384. s_uGetDataDuration (
  385. PSDevice pDevice,
  386. unsigned char byDurType,
  387. unsigned int cbFrameLength,
  388. unsigned char byPktType,
  389. unsigned short wRate,
  390. bool bNeedAck,
  391. unsigned int uFragIdx,
  392. unsigned int cbLastFragmentSize,
  393. unsigned int uMACfragNum,
  394. unsigned char byFBOption
  395. )
  396. {
  397. bool bLastFrag = 0;
  398. unsigned int uAckTime =0, uNextPktTime = 0;
  399. if (uFragIdx == (uMACfragNum-1)) {
  400. bLastFrag = 1;
  401. }
  402. switch (byDurType) {
  403. case DATADUR_B: //DATADUR_B
  404. if (((uMACfragNum == 1)) || (bLastFrag == 1)) {//Non Frag or Last Frag
  405. if (bNeedAck) {
  406. uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopCCKBasicRate);
  407. return (pDevice->uSIFS + uAckTime);
  408. } else {
  409. return 0;
  410. }
  411. }
  412. else {//First Frag or Mid Frag
  413. if (uFragIdx == (uMACfragNum-2)) {
  414. uNextPktTime = s_uGetTxRsvTime(pDevice, byPktType, cbLastFragmentSize, wRate, bNeedAck);
  415. } else {
  416. uNextPktTime = s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wRate, bNeedAck);
  417. }
  418. if (bNeedAck) {
  419. uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopCCKBasicRate);
  420. return (pDevice->uSIFS + uAckTime + uNextPktTime);
  421. } else {
  422. return (pDevice->uSIFS + uNextPktTime);
  423. }
  424. }
  425. break;
  426. case DATADUR_A: //DATADUR_A
  427. if (((uMACfragNum==1)) || (bLastFrag==1)) {//Non Frag or Last Frag
  428. if(bNeedAck){
  429. uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
  430. return (pDevice->uSIFS + uAckTime);
  431. } else {
  432. return 0;
  433. }
  434. }
  435. else {//First Frag or Mid Frag
  436. if(uFragIdx == (uMACfragNum-2)){
  437. uNextPktTime = s_uGetTxRsvTime(pDevice, byPktType, cbLastFragmentSize, wRate, bNeedAck);
  438. } else {
  439. uNextPktTime = s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wRate, bNeedAck);
  440. }
  441. if(bNeedAck){
  442. uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
  443. return (pDevice->uSIFS + uAckTime + uNextPktTime);
  444. } else {
  445. return (pDevice->uSIFS + uNextPktTime);
  446. }
  447. }
  448. break;
  449. case DATADUR_A_F0: //DATADUR_A_F0
  450. if (((uMACfragNum==1)) || (bLastFrag==1)) {//Non Frag or Last Frag
  451. if(bNeedAck){
  452. uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
  453. return (pDevice->uSIFS + uAckTime);
  454. } else {
  455. return 0;
  456. }
  457. }
  458. else { //First Frag or Mid Frag
  459. if (byFBOption == AUTO_FB_0) {
  460. if (wRate < RATE_18M)
  461. wRate = RATE_18M;
  462. else if (wRate > RATE_54M)
  463. wRate = RATE_54M;
  464. if(uFragIdx == (uMACfragNum-2)){
  465. uNextPktTime = s_uGetTxRsvTime(pDevice, byPktType, cbLastFragmentSize, wFB_Opt0[FB_RATE0][wRate-RATE_18M], bNeedAck);
  466. } else {
  467. uNextPktTime = s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt0[FB_RATE0][wRate-RATE_18M], bNeedAck);
  468. }
  469. } else { // (byFBOption == AUTO_FB_1)
  470. if (wRate < RATE_18M)
  471. wRate = RATE_18M;
  472. else if (wRate > RATE_54M)
  473. wRate = RATE_54M;
  474. if(uFragIdx == (uMACfragNum-2)){
  475. uNextPktTime = s_uGetTxRsvTime(pDevice, byPktType, cbLastFragmentSize, wFB_Opt1[FB_RATE0][wRate-RATE_18M], bNeedAck);
  476. } else {
  477. uNextPktTime = s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt1[FB_RATE0][wRate-RATE_18M], bNeedAck);
  478. }
  479. }
  480. if(bNeedAck){
  481. uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
  482. return (pDevice->uSIFS + uAckTime + uNextPktTime);
  483. } else {
  484. return (pDevice->uSIFS + uNextPktTime);
  485. }
  486. }
  487. break;
  488. case DATADUR_A_F1: //DATADUR_A_F1
  489. if (((uMACfragNum==1)) || (bLastFrag==1)) {//Non Frag or Last Frag
  490. if(bNeedAck){
  491. uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
  492. return (pDevice->uSIFS + uAckTime);
  493. } else {
  494. return 0;
  495. }
  496. }
  497. else { //First Frag or Mid Frag
  498. if (byFBOption == AUTO_FB_0) {
  499. if (wRate < RATE_18M)
  500. wRate = RATE_18M;
  501. else if (wRate > RATE_54M)
  502. wRate = RATE_54M;
  503. if(uFragIdx == (uMACfragNum-2)){
  504. uNextPktTime = s_uGetTxRsvTime(pDevice, byPktType, cbLastFragmentSize, wFB_Opt0[FB_RATE1][wRate-RATE_18M], bNeedAck);
  505. } else {
  506. uNextPktTime = s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt0[FB_RATE1][wRate-RATE_18M], bNeedAck);
  507. }
  508. } else { // (byFBOption == AUTO_FB_1)
  509. if (wRate < RATE_18M)
  510. wRate = RATE_18M;
  511. else if (wRate > RATE_54M)
  512. wRate = RATE_54M;
  513. if(uFragIdx == (uMACfragNum-2)){
  514. uNextPktTime = s_uGetTxRsvTime(pDevice, byPktType, cbLastFragmentSize, wFB_Opt1[FB_RATE1][wRate-RATE_18M], bNeedAck);
  515. } else {
  516. uNextPktTime = s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt1[FB_RATE1][wRate-RATE_18M], bNeedAck);
  517. }
  518. }
  519. if(bNeedAck){
  520. uAckTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
  521. return (pDevice->uSIFS + uAckTime + uNextPktTime);
  522. } else {
  523. return (pDevice->uSIFS + uNextPktTime);
  524. }
  525. }
  526. break;
  527. default:
  528. break;
  529. }
  530. ASSERT(false);
  531. return 0;
  532. }
  533. //byFreqType: 0=>5GHZ 1=>2.4GHZ
  534. static
  535. unsigned int
  536. s_uGetRTSCTSDuration (
  537. PSDevice pDevice,
  538. unsigned char byDurType,
  539. unsigned int cbFrameLength,
  540. unsigned char byPktType,
  541. unsigned short wRate,
  542. bool bNeedAck,
  543. unsigned char byFBOption
  544. )
  545. {
  546. unsigned int uCTSTime = 0, uDurTime = 0;
  547. switch (byDurType) {
  548. case RTSDUR_BB: //RTSDuration_bb
  549. uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopCCKBasicRate);
  550. uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wRate, bNeedAck);
  551. break;
  552. case RTSDUR_BA: //RTSDuration_ba
  553. uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopCCKBasicRate);
  554. uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wRate, bNeedAck);
  555. break;
  556. case RTSDUR_AA: //RTSDuration_aa
  557. uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
  558. uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wRate, bNeedAck);
  559. break;
  560. case CTSDUR_BA: //CTSDuration_ba
  561. uDurTime = pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wRate, bNeedAck);
  562. break;
  563. case RTSDUR_BA_F0: //RTSDuration_ba_f0
  564. uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopCCKBasicRate);
  565. if ((byFBOption == AUTO_FB_0) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
  566. uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt0[FB_RATE0][wRate-RATE_18M], bNeedAck);
  567. } else if ((byFBOption == AUTO_FB_1) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
  568. uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt1[FB_RATE0][wRate-RATE_18M], bNeedAck);
  569. }
  570. break;
  571. case RTSDUR_AA_F0: //RTSDuration_aa_f0
  572. uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
  573. if ((byFBOption == AUTO_FB_0) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
  574. uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt0[FB_RATE0][wRate-RATE_18M], bNeedAck);
  575. } else if ((byFBOption == AUTO_FB_1) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
  576. uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt1[FB_RATE0][wRate-RATE_18M], bNeedAck);
  577. }
  578. break;
  579. case RTSDUR_BA_F1: //RTSDuration_ba_f1
  580. uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopCCKBasicRate);
  581. if ((byFBOption == AUTO_FB_0) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
  582. uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt0[FB_RATE1][wRate-RATE_18M], bNeedAck);
  583. } else if ((byFBOption == AUTO_FB_1) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
  584. uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt1[FB_RATE1][wRate-RATE_18M], bNeedAck);
  585. }
  586. break;
  587. case RTSDUR_AA_F1: //RTSDuration_aa_f1
  588. uCTSTime = BBuGetFrameTime(pDevice->byPreambleType, byPktType, 14, pDevice->byTopOFDMBasicRate);
  589. if ((byFBOption == AUTO_FB_0) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
  590. uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt0[FB_RATE1][wRate-RATE_18M], bNeedAck);
  591. } else if ((byFBOption == AUTO_FB_1) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
  592. uDurTime = uCTSTime + 2*pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt1[FB_RATE1][wRate-RATE_18M], bNeedAck);
  593. }
  594. break;
  595. case CTSDUR_BA_F0: //CTSDuration_ba_f0
  596. if ((byFBOption == AUTO_FB_0) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
  597. uDurTime = pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt0[FB_RATE0][wRate-RATE_18M], bNeedAck);
  598. } else if ((byFBOption == AUTO_FB_1) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
  599. uDurTime = pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt1[FB_RATE0][wRate-RATE_18M], bNeedAck);
  600. }
  601. break;
  602. case CTSDUR_BA_F1: //CTSDuration_ba_f1
  603. if ((byFBOption == AUTO_FB_0) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
  604. uDurTime = pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt0[FB_RATE1][wRate-RATE_18M], bNeedAck);
  605. } else if ((byFBOption == AUTO_FB_1) && (wRate >= RATE_18M) && (wRate <=RATE_54M)) {
  606. uDurTime = pDevice->uSIFS + s_uGetTxRsvTime(pDevice, byPktType, cbFrameLength, wFB_Opt1[FB_RATE1][wRate-RATE_18M], bNeedAck);
  607. }
  608. break;
  609. default:
  610. break;
  611. }
  612. return uDurTime;
  613. }
  614. static
  615. unsigned int
  616. s_uFillDataHead (
  617. PSDevice pDevice,
  618. unsigned char byPktType,
  619. void * pTxDataHead,
  620. unsigned int cbFrameLength,
  621. unsigned int uDMAIdx,
  622. bool bNeedAck,
  623. unsigned int uFragIdx,
  624. unsigned int cbLastFragmentSize,
  625. unsigned int uMACfragNum,
  626. unsigned char byFBOption,
  627. unsigned short wCurrentRate
  628. )
  629. {
  630. unsigned short wLen = 0x0000;
  631. if (pTxDataHead == NULL) {
  632. return 0;
  633. }
  634. if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {
  635. if (byFBOption == AUTO_FB_NONE) {
  636. PSTxDataHead_g pBuf = (PSTxDataHead_g)pTxDataHead;
  637. //Get SignalField,ServiceField,Length
  638. BBvCaculateParameter(pDevice, cbFrameLength, wCurrentRate, byPktType,
  639. (unsigned short *)&(wLen), (unsigned char *)&(pBuf->byServiceField_a), (unsigned char *)&(pBuf->bySignalField_a)
  640. );
  641. pBuf->wTransmitLength_a = cpu_to_le16(wLen);
  642. BBvCaculateParameter(pDevice, cbFrameLength, pDevice->byTopCCKBasicRate, PK_TYPE_11B,
  643. (unsigned short *)&(wLen), (unsigned char *)&(pBuf->byServiceField_b), (unsigned char *)&(pBuf->bySignalField_b)
  644. );
  645. pBuf->wTransmitLength_b = cpu_to_le16(wLen);
  646. //Get Duration and TimeStamp
  647. pBuf->wDuration_a = cpu_to_le16((unsigned short)s_uGetDataDuration(pDevice, DATADUR_A, cbFrameLength,
  648. byPktType, wCurrentRate, bNeedAck, uFragIdx,
  649. cbLastFragmentSize, uMACfragNum,
  650. byFBOption)); //1: 2.4GHz
  651. pBuf->wDuration_b = cpu_to_le16((unsigned short)s_uGetDataDuration(pDevice, DATADUR_B, cbFrameLength,
  652. PK_TYPE_11B, pDevice->byTopCCKBasicRate,
  653. bNeedAck, uFragIdx, cbLastFragmentSize,
  654. uMACfragNum, byFBOption)); //1: 2.4
  655. pBuf->wTimeStampOff_a = cpu_to_le16(wTimeStampOff[pDevice->byPreambleType%2][wCurrentRate%MAX_RATE]);
  656. pBuf->wTimeStampOff_b = cpu_to_le16(wTimeStampOff[pDevice->byPreambleType%2][pDevice->byTopCCKBasicRate%MAX_RATE]);
  657. return (pBuf->wDuration_a);
  658. } else {
  659. // Auto Fallback
  660. PSTxDataHead_g_FB pBuf = (PSTxDataHead_g_FB)pTxDataHead;
  661. //Get SignalField,ServiceField,Length
  662. BBvCaculateParameter(pDevice, cbFrameLength, wCurrentRate, byPktType,
  663. (unsigned short *)&(wLen), (unsigned char *)&(pBuf->byServiceField_a), (unsigned char *)&(pBuf->bySignalField_a)
  664. );
  665. pBuf->wTransmitLength_a = cpu_to_le16(wLen);
  666. BBvCaculateParameter(pDevice, cbFrameLength, pDevice->byTopCCKBasicRate, PK_TYPE_11B,
  667. (unsigned short *)&(wLen), (unsigned char *)&(pBuf->byServiceField_b), (unsigned char *)&(pBuf->bySignalField_b)
  668. );
  669. pBuf->wTransmitLength_b = cpu_to_le16(wLen);
  670. //Get Duration and TimeStamp
  671. pBuf->wDuration_a = cpu_to_le16((unsigned short)s_uGetDataDuration(pDevice, DATADUR_A, cbFrameLength, byPktType,
  672. wCurrentRate, bNeedAck, uFragIdx, cbLastFragmentSize, uMACfragNum, byFBOption)); //1: 2.4GHz
  673. pBuf->wDuration_b = cpu_to_le16((unsigned short)s_uGetDataDuration(pDevice, DATADUR_B, cbFrameLength, PK_TYPE_11B,
  674. pDevice->byTopCCKBasicRate, bNeedAck, uFragIdx, cbLastFragmentSize, uMACfragNum, byFBOption)); //1: 2.4GHz
  675. pBuf->wDuration_a_f0 = cpu_to_le16((unsigned short)s_uGetDataDuration(pDevice, DATADUR_A_F0, cbFrameLength, byPktType,
  676. wCurrentRate, bNeedAck, uFragIdx, cbLastFragmentSize, uMACfragNum, byFBOption)); //1: 2.4GHz
  677. pBuf->wDuration_a_f1 = cpu_to_le16((unsigned short)s_uGetDataDuration(pDevice, DATADUR_A_F1, cbFrameLength, byPktType,
  678. wCurrentRate, bNeedAck, uFragIdx, cbLastFragmentSize, uMACfragNum, byFBOption)); //1: 2.4GHz
  679. pBuf->wTimeStampOff_a = cpu_to_le16(wTimeStampOff[pDevice->byPreambleType%2][wCurrentRate%MAX_RATE]);
  680. pBuf->wTimeStampOff_b = cpu_to_le16(wTimeStampOff[pDevice->byPreambleType%2][pDevice->byTopCCKBasicRate%MAX_RATE]);
  681. return (pBuf->wDuration_a);
  682. } //if (byFBOption == AUTO_FB_NONE)
  683. }
  684. else if (byPktType == PK_TYPE_11A) {
  685. if ((byFBOption != AUTO_FB_NONE)) {
  686. // Auto Fallback
  687. PSTxDataHead_a_FB pBuf = (PSTxDataHead_a_FB)pTxDataHead;
  688. //Get SignalField,ServiceField,Length
  689. BBvCaculateParameter(pDevice, cbFrameLength, wCurrentRate, byPktType,
  690. (unsigned short *)&(wLen), (unsigned char *)&(pBuf->byServiceField), (unsigned char *)&(pBuf->bySignalField)
  691. );
  692. pBuf->wTransmitLength = cpu_to_le16(wLen);
  693. //Get Duration and TimeStampOff
  694. pBuf->wDuration = cpu_to_le16((unsigned short)s_uGetDataDuration(pDevice, DATADUR_A, cbFrameLength, byPktType,
  695. wCurrentRate, bNeedAck, uFragIdx, cbLastFragmentSize, uMACfragNum, byFBOption)); //0: 5GHz
  696. pBuf->wDuration_f0 = cpu_to_le16((unsigned short)s_uGetDataDuration(pDevice, DATADUR_A_F0, cbFrameLength, byPktType,
  697. wCurrentRate, bNeedAck, uFragIdx, cbLastFragmentSize, uMACfragNum, byFBOption)); //0: 5GHz
  698. pBuf->wDuration_f1 = cpu_to_le16((unsigned short)s_uGetDataDuration(pDevice, DATADUR_A_F1, cbFrameLength, byPktType,
  699. wCurrentRate, bNeedAck, uFragIdx, cbLastFragmentSize, uMACfragNum, byFBOption)); //0: 5GHz
  700. pBuf->wTimeStampOff = cpu_to_le16(wTimeStampOff[pDevice->byPreambleType%2][wCurrentRate%MAX_RATE]);
  701. return (pBuf->wDuration);
  702. } else {
  703. PSTxDataHead_ab pBuf = (PSTxDataHead_ab)pTxDataHead;
  704. //Get SignalField,ServiceField,Length
  705. BBvCaculateParameter(pDevice, cbFrameLength, wCurrentRate, byPktType,
  706. (unsigned short *)&(wLen), (unsigned char *)&(pBuf->byServiceField), (unsigned char *)&(pBuf->bySignalField)
  707. );
  708. pBuf->wTransmitLength = cpu_to_le16(wLen);
  709. //Get Duration and TimeStampOff
  710. pBuf->wDuration = cpu_to_le16((unsigned short)s_uGetDataDuration(pDevice, DATADUR_A, cbFrameLength, byPktType,
  711. wCurrentRate, bNeedAck, uFragIdx,
  712. cbLastFragmentSize, uMACfragNum,
  713. byFBOption));
  714. pBuf->wTimeStampOff = cpu_to_le16(wTimeStampOff[pDevice->byPreambleType%2][wCurrentRate%MAX_RATE]);
  715. return (pBuf->wDuration);
  716. }
  717. }
  718. else {
  719. PSTxDataHead_ab pBuf = (PSTxDataHead_ab)pTxDataHead;
  720. //Get SignalField,ServiceField,Length
  721. BBvCaculateParameter(pDevice, cbFrameLength, wCurrentRate, byPktType,
  722. (unsigned short *)&(wLen), (unsigned char *)&(pBuf->byServiceField), (unsigned char *)&(pBuf->bySignalField)
  723. );
  724. pBuf->wTransmitLength = cpu_to_le16(wLen);
  725. //Get Duration and TimeStampOff
  726. pBuf->wDuration = cpu_to_le16((unsigned short)s_uGetDataDuration(pDevice, DATADUR_B, cbFrameLength, byPktType,
  727. wCurrentRate, bNeedAck, uFragIdx,
  728. cbLastFragmentSize, uMACfragNum,
  729. byFBOption));
  730. pBuf->wTimeStampOff = cpu_to_le16(wTimeStampOff[pDevice->byPreambleType%2][wCurrentRate%MAX_RATE]);
  731. return (pBuf->wDuration);
  732. }
  733. return 0;
  734. }
  735. static
  736. void
  737. s_vFillRTSHead (
  738. PSDevice pDevice,
  739. unsigned char byPktType,
  740. void * pvRTS,
  741. unsigned int cbFrameLength,
  742. bool bNeedAck,
  743. bool bDisCRC,
  744. PSEthernetHeader psEthHeader,
  745. unsigned short wCurrentRate,
  746. unsigned char byFBOption
  747. )
  748. {
  749. unsigned int uRTSFrameLen = 20;
  750. unsigned short wLen = 0x0000;
  751. if (pvRTS == NULL)
  752. return;
  753. if (bDisCRC) {
  754. // When CRCDIS bit is on, H/W forgot to generate FCS for RTS frame,
  755. // in this case we need to decrease its length by 4.
  756. uRTSFrameLen -= 4;
  757. }
  758. // Note: So far RTSHead dosen't appear in ATIM & Beacom DMA, so we don't need to take them into account.
  759. // Otherwise, we need to modify codes for them.
  760. if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {
  761. if (byFBOption == AUTO_FB_NONE) {
  762. PSRTS_g pBuf = (PSRTS_g)pvRTS;
  763. //Get SignalField,ServiceField,Length
  764. BBvCaculateParameter(pDevice, uRTSFrameLen, pDevice->byTopCCKBasicRate, PK_TYPE_11B,
  765. (unsigned short *)&(wLen), (unsigned char *)&(pBuf->byServiceField_b), (unsigned char *)&(pBuf->bySignalField_b)
  766. );
  767. pBuf->wTransmitLength_b = cpu_to_le16(wLen);
  768. BBvCaculateParameter(pDevice, uRTSFrameLen, pDevice->byTopOFDMBasicRate, byPktType,
  769. (unsigned short *)&(wLen), (unsigned char *)&(pBuf->byServiceField_a), (unsigned char *)&(pBuf->bySignalField_a)
  770. );
  771. pBuf->wTransmitLength_a = cpu_to_le16(wLen);
  772. //Get Duration
  773. pBuf->wDuration_bb = cpu_to_le16((unsigned short)s_uGetRTSCTSDuration(pDevice, RTSDUR_BB, cbFrameLength, PK_TYPE_11B, pDevice->byTopCCKBasicRate, bNeedAck, byFBOption)); //0:RTSDuration_bb, 1:2.4G, 1:CCKData
  774. pBuf->wDuration_aa = cpu_to_le16((unsigned short)s_uGetRTSCTSDuration(pDevice, RTSDUR_AA, cbFrameLength, byPktType, wCurrentRate, bNeedAck, byFBOption)); //2:RTSDuration_aa, 1:2.4G, 2,3: 2.4G OFDMData
  775. pBuf->wDuration_ba = cpu_to_le16((unsigned short)s_uGetRTSCTSDuration(pDevice, RTSDUR_BA, cbFrameLength, byPktType, wCurrentRate, bNeedAck, byFBOption)); //1:RTSDuration_ba, 1:2.4G, 2,3:2.4G OFDM Data
  776. pBuf->Data.wDurationID = pBuf->wDuration_aa;
  777. //Get RTS Frame body
  778. pBuf->Data.wFrameControl = TYPE_CTL_RTS;//0x00B4
  779. if ((pDevice->eOPMode == OP_MODE_ADHOC) ||
  780. (pDevice->eOPMode == OP_MODE_AP)) {
  781. memcpy(&(pBuf->Data.abyRA[0]), &(psEthHeader->abyDstAddr[0]), ETH_ALEN);
  782. }
  783. else {
  784. memcpy(&(pBuf->Data.abyRA[0]), &(pDevice->abyBSSID[0]), ETH_ALEN);
  785. }
  786. if (pDevice->eOPMode == OP_MODE_AP) {
  787. memcpy(&(pBuf->Data.abyTA[0]), &(pDevice->abyBSSID[0]), ETH_ALEN);
  788. }
  789. else {
  790. memcpy(&(pBuf->Data.abyTA[0]), &(psEthHeader->abySrcAddr[0]), ETH_ALEN);
  791. }
  792. }
  793. else {
  794. PSRTS_g_FB pBuf = (PSRTS_g_FB)pvRTS;
  795. //Get SignalField,ServiceField,Length
  796. BBvCaculateParameter(pDevice, uRTSFrameLen, pDevice->byTopCCKBasicRate, PK_TYPE_11B,
  797. (unsigned short *)&(wLen), (unsigned char *)&(pBuf->byServiceField_b), (unsigned char *)&(pBuf->bySignalField_b)
  798. );
  799. pBuf->wTransmitLength_b = cpu_to_le16(wLen);
  800. BBvCaculateParameter(pDevice, uRTSFrameLen, pDevice->byTopOFDMBasicRate, byPktType,
  801. (unsigned short *)&(wLen), (unsigned char *)&(pBuf->byServiceField_a), (unsigned char *)&(pBuf->bySignalField_a)
  802. );
  803. pBuf->wTransmitLength_a = cpu_to_le16(wLen);
  804. //Get Duration
  805. pBuf->wDuration_bb = cpu_to_le16((unsigned short)s_uGetRTSCTSDuration(pDevice, RTSDUR_BB, cbFrameLength, PK_TYPE_11B, pDevice->byTopCCKBasicRate, bNeedAck, byFBOption)); //0:RTSDuration_bb, 1:2.4G, 1:CCKData
  806. pBuf->wDuration_aa = cpu_to_le16((unsigned short)s_uGetRTSCTSDuration(pDevice, RTSDUR_AA, cbFrameLength, byPktType, wCurrentRate, bNeedAck, byFBOption)); //2:RTSDuration_aa, 1:2.4G, 2,3:2.4G OFDMData
  807. pBuf->wDuration_ba = cpu_to_le16((unsigned short)s_uGetRTSCTSDuration(pDevice, RTSDUR_BA, cbFrameLength, byPktType, wCurrentRate, bNeedAck, byFBOption)); //1:RTSDuration_ba, 1:2.4G, 2,3:2.4G OFDMData
  808. pBuf->wRTSDuration_ba_f0 = cpu_to_le16((unsigned short)s_uGetRTSCTSDuration(pDevice, RTSDUR_BA_F0, cbFrameLength, byPktType, wCurrentRate, bNeedAck, byFBOption)); //4:wRTSDuration_ba_f0, 1:2.4G, 1:CCKData
  809. pBuf->wRTSDuration_aa_f0 = cpu_to_le16((unsigned short)s_uGetRTSCTSDuration(pDevice, RTSDUR_AA_F0, cbFrameLength, byPktType, wCurrentRate, bNeedAck, byFBOption)); //5:wRTSDuration_aa_f0, 1:2.4G, 1:CCKData
  810. pBuf->wRTSDuration_ba_f1 = cpu_to_le16((unsigned short)s_uGetRTSCTSDuration(pDevice, RTSDUR_BA_F1, cbFrameLength, byPktType, wCurrentRate, bNeedAck, byFBOption)); //6:wRTSDuration_ba_f1, 1:2.4G, 1:CCKData
  811. pBuf->wRTSDuration_aa_f1 = cpu_to_le16((unsigned short)s_uGetRTSCTSDuration(pDevice, RTSDUR_AA_F1, cbFrameLength, byPktType, wCurrentRate, bNeedAck, byFBOption)); //7:wRTSDuration_aa_f1, 1:2.4G, 1:CCKData
  812. pBuf->Data.wDurationID = pBuf->wDuration_aa;
  813. //Get RTS Frame body
  814. pBuf->Data.wFrameControl = TYPE_CTL_RTS;//0x00B4
  815. if ((pDevice->eOPMode == OP_MODE_ADHOC) ||
  816. (pDevice->eOPMode == OP_MODE_AP)) {
  817. memcpy(&(pBuf->Data.abyRA[0]), &(psEthHeader->abyDstAddr[0]), ETH_ALEN);
  818. }
  819. else {
  820. memcpy(&(pBuf->Data.abyRA[0]), &(pDevice->abyBSSID[0]), ETH_ALEN);
  821. }
  822. if (pDevice->eOPMode == OP_MODE_AP) {
  823. memcpy(&(pBuf->Data.abyTA[0]), &(pDevice->abyBSSID[0]), ETH_ALEN);
  824. }
  825. else {
  826. memcpy(&(pBuf->Data.abyTA[0]), &(psEthHeader->abySrcAddr[0]), ETH_ALEN);
  827. }
  828. } // if (byFBOption == AUTO_FB_NONE)
  829. }
  830. else if (byPktType == PK_TYPE_11A) {
  831. if (byFBOption == AUTO_FB_NONE) {
  832. PSRTS_ab pBuf = (PSRTS_ab)pvRTS;
  833. //Get SignalField,ServiceField,Length
  834. BBvCaculateParameter(pDevice, uRTSFrameLen, pDevice->byTopOFDMBasicRate, byPktType,
  835. (unsigned short *)&(wLen), (unsigned char *)&(pBuf->byServiceField), (unsigned char *)&(pBuf->bySignalField)
  836. );
  837. pBuf->wTransmitLength = cpu_to_le16(wLen);
  838. //Get Duration
  839. pBuf->wDuration = cpu_to_le16((unsigned short)s_uGetRTSCTSDuration(pDevice, RTSDUR_AA, cbFrameLength, byPktType, wCurrentRate, bNeedAck, byFBOption)); //0:RTSDuration_aa, 0:5G, 0: 5G OFDMData
  840. pBuf->Data.wDurationID = pBuf->wDuration;
  841. //Get RTS Frame body
  842. pBuf->Data.wFrameControl = TYPE_CTL_RTS;//0x00B4
  843. if ((pDevice->eOPMode == OP_MODE_ADHOC) ||
  844. (pDevice->eOPMode == OP_MODE_AP)) {
  845. memcpy(&(pBuf->Data.abyRA[0]), &(psEthHeader->abyDstAddr[0]), ETH_ALEN);
  846. }
  847. else {
  848. memcpy(&(pBuf->Data.abyRA[0]), &(pDevice->abyBSSID[0]), ETH_ALEN);
  849. }
  850. if (pDevice->eOPMode == OP_MODE_AP) {
  851. memcpy(&(pBuf->Data.abyTA[0]), &(pDevice->abyBSSID[0]), ETH_ALEN);
  852. }
  853. else {
  854. memcpy(&(pBuf->Data.abyTA[0]), &(psEthHeader->abySrcAddr[0]), ETH_ALEN);
  855. }
  856. }
  857. else {
  858. PSRTS_a_FB pBuf = (PSRTS_a_FB)pvRTS;
  859. //Get SignalField,ServiceField,Length
  860. BBvCaculateParameter(pDevice, uRTSFrameLen, pDevice->byTopOFDMBasicRate, byPktType,
  861. (unsigned short *)&(wLen), (unsigned char *)&(pBuf->byServiceField), (unsigned char *)&(pBuf->bySignalField)
  862. );
  863. pBuf->wTransmitLength = cpu_to_le16(wLen);
  864. //Get Duration
  865. pBuf->wDuration = cpu_to_le16((unsigned short)s_uGetRTSCTSDuration(pDevice, RTSDUR_AA, cbFrameLength, byPktType, wCurrentRate, bNeedAck, byFBOption)); //0:RTSDuration_aa, 0:5G, 0: 5G OFDMData
  866. pBuf->wRTSDuration_f0 = cpu_to_le16((unsigned short)s_uGetRTSCTSDuration(pDevice, RTSDUR_AA_F0, cbFrameLength, byPktType, wCurrentRate, bNeedAck, byFBOption)); //5:RTSDuration_aa_f0, 0:5G, 0: 5G OFDMData
  867. pBuf->wRTSDuration_f1 = cpu_to_le16((unsigned short)s_uGetRTSCTSDuration(pDevice, RTSDUR_AA_F1, cbFrameLength, byPktType, wCurrentRate, bNeedAck, byFBOption)); //7:RTSDuration_aa_f1, 0:5G, 0:
  868. pBuf->Data.wDurationID = pBuf->wDuration;
  869. //Get RTS Frame body
  870. pBuf->Data.wFrameControl = TYPE_CTL_RTS;//0x00B4
  871. if ((pDevice->eOPMode == OP_MODE_ADHOC) ||
  872. (pDevice->eOPMode == OP_MODE_AP)) {
  873. memcpy(&(pBuf->Data.abyRA[0]), &(psEthHeader->abyDstAddr[0]), ETH_ALEN);
  874. }
  875. else {
  876. memcpy(&(pBuf->Data.abyRA[0]), &(pDevice->abyBSSID[0]), ETH_ALEN);
  877. }
  878. if (pDevice->eOPMode == OP_MODE_AP) {
  879. memcpy(&(pBuf->Data.abyTA[0]), &(pDevice->abyBSSID[0]), ETH_ALEN);
  880. }
  881. else {
  882. memcpy(&(pBuf->Data.abyTA[0]), &(psEthHeader->abySrcAddr[0]), ETH_ALEN);
  883. }
  884. }
  885. }
  886. else if (byPktType == PK_TYPE_11B) {
  887. PSRTS_ab pBuf = (PSRTS_ab)pvRTS;
  888. //Get SignalField,ServiceField,Length
  889. BBvCaculateParameter(pDevice, uRTSFrameLen, pDevice->byTopCCKBasicRate, PK_TYPE_11B,
  890. (unsigned short *)&(wLen), (unsigned char *)&(pBuf->byServiceField), (unsigned char *)&(pBuf->bySignalField)
  891. );
  892. pBuf->wTransmitLength = cpu_to_le16(wLen);
  893. //Get Duration
  894. pBuf->wDuration = cpu_to_le16((unsigned short)s_uGetRTSCTSDuration(pDevice, RTSDUR_BB, cbFrameLength, byPktType, wCurrentRate, bNeedAck, byFBOption)); //0:RTSDuration_bb, 1:2.4G, 1:CCKData
  895. pBuf->Data.wDurationID = pBuf->wDuration;
  896. //Get RTS Frame body
  897. pBuf->Data.wFrameControl = TYPE_CTL_RTS;//0x00B4
  898. if ((pDevice->eOPMode == OP_MODE_ADHOC) ||
  899. (pDevice->eOPMode == OP_MODE_AP)) {
  900. memcpy(&(pBuf->Data.abyRA[0]), &(psEthHeader->abyDstAddr[0]), ETH_ALEN);
  901. }
  902. else {
  903. memcpy(&(pBuf->Data.abyRA[0]), &(pDevice->abyBSSID[0]), ETH_ALEN);
  904. }
  905. if (pDevice->eOPMode == OP_MODE_AP) {
  906. memcpy(&(pBuf->Data.abyTA[0]), &(pDevice->abyBSSID[0]), ETH_ALEN);
  907. }
  908. else {
  909. memcpy(&(pBuf->Data.abyTA[0]), &(psEthHeader->abySrcAddr[0]), ETH_ALEN);
  910. }
  911. }
  912. }
  913. static
  914. void
  915. s_vFillCTSHead (
  916. PSDevice pDevice,
  917. unsigned int uDMAIdx,
  918. unsigned char byPktType,
  919. void * pvCTS,
  920. unsigned int cbFrameLength,
  921. bool bNeedAck,
  922. bool bDisCRC,
  923. unsigned short wCurrentRate,
  924. unsigned char byFBOption
  925. )
  926. {
  927. unsigned int uCTSFrameLen = 14;
  928. unsigned short wLen = 0x0000;
  929. if (pvCTS == NULL) {
  930. return;
  931. }
  932. if (bDisCRC) {
  933. // When CRCDIS bit is on, H/W forgot to generate FCS for CTS frame,
  934. // in this case we need to decrease its length by 4.
  935. uCTSFrameLen -= 4;
  936. }
  937. if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {
  938. if (byFBOption != AUTO_FB_NONE && uDMAIdx != TYPE_ATIMDMA && uDMAIdx != TYPE_BEACONDMA) {
  939. // Auto Fall back
  940. PSCTS_FB pBuf = (PSCTS_FB)pvCTS;
  941. //Get SignalField,ServiceField,Length
  942. BBvCaculateParameter(pDevice, uCTSFrameLen, pDevice->byTopCCKBasicRate, PK_TYPE_11B,
  943. (unsigned short *)&(wLen), (unsigned char *)&(pBuf->byServiceField_b), (unsigned char *)&(pBuf->bySignalField_b)
  944. );
  945. pBuf->wTransmitLength_b = cpu_to_le16(wLen);
  946. pBuf->wDuration_ba = (unsigned short)s_uGetRTSCTSDuration(pDevice, CTSDUR_BA, cbFrameLength, byPktType, wCurrentRate, bNeedAck, byFBOption); //3:CTSDuration_ba, 1:2.4G, 2,3:2.4G OFDM Data
  947. pBuf->wDuration_ba += pDevice->wCTSDuration;
  948. pBuf->wDuration_ba = cpu_to_le16(pBuf->wDuration_ba);
  949. //Get CTSDuration_ba_f0
  950. pBuf->wCTSDuration_ba_f0 = (unsigned short)s_uGetRTSCTSDuration(pDevice, CTSDUR_BA_F0, cbFrameLength, byPktType, wCurrentRate, bNeedAck, byFBOption); //8:CTSDuration_ba_f0, 1:2.4G, 2,3:2.4G OFDM Data
  951. pBuf->wCTSDuration_ba_f0 += pDevice->wCTSDuration;
  952. pBuf->wCTSDuration_ba_f0 = cpu_to_le16(pBuf->wCTSDuration_ba_f0);
  953. //Get CTSDuration_ba_f1
  954. pBuf->wCTSDuration_ba_f1 = (unsigned short)s_uGetRTSCTSDuration(pDevice, CTSDUR_BA_F1, cbFrameLength, byPktType, wCurrentRate, bNeedAck, byFBOption); //9:CTSDuration_ba_f1, 1:2.4G, 2,3:2.4G OFDM Data
  955. pBuf->wCTSDuration_ba_f1 += pDevice->wCTSDuration;
  956. pBuf->wCTSDuration_ba_f1 = cpu_to_le16(pBuf->wCTSDuration_ba_f1);
  957. //Get CTS Frame body
  958. pBuf->Data.wDurationID = pBuf->wDuration_ba;
  959. pBuf->Data.wFrameControl = TYPE_CTL_CTS;//0x00C4
  960. pBuf->Data.wReserved = 0x0000;
  961. memcpy(&(pBuf->Data.abyRA[0]), &(pDevice->abyCurrentNetAddr[0]), ETH_ALEN);
  962. } else { //if (byFBOption != AUTO_FB_NONE && uDMAIdx != TYPE_ATIMDMA && uDMAIdx != TYPE_BEACONDMA)
  963. PSCTS pBuf = (PSCTS)pvCTS;
  964. //Get SignalField,ServiceField,Length
  965. BBvCaculateParameter(pDevice, uCTSFrameLen, pDevice->byTopCCKBasicRate, PK_TYPE_11B,
  966. (unsigned short *)&(wLen), (unsigned char *)&(pBuf->byServiceField_b), (unsigned char *)&(pBuf->bySignalField_b)
  967. );
  968. pBuf->wTransmitLength_b = cpu_to_le16(wLen);
  969. //Get CTSDuration_ba
  970. pBuf->wDuration_ba = cpu_to_le16((unsigned short)s_uGetRTSCTSDuration(pDevice, CTSDUR_BA, cbFrameLength, byPktType, wCurrentRate, bNeedAck, byFBOption)); //3:CTSDuration_ba, 1:2.4G, 2,3:2.4G OFDM Data
  971. pBuf->wDuration_ba += pDevice->wCTSDuration;
  972. pBuf->wDuration_ba = cpu_to_le16(pBuf->wDuration_ba);
  973. //Get CTS Frame body
  974. pBuf->Data.wDurationID = pBuf->wDuration_ba;
  975. pBuf->Data.wFrameControl = TYPE_CTL_CTS;//0x00C4
  976. pBuf->Data.wReserved = 0x0000;
  977. memcpy(&(pBuf->Data.abyRA[0]), &(pDevice->abyCurrentNetAddr[0]), ETH_ALEN);
  978. }
  979. }
  980. }
  981. /*+
  982. *
  983. * Description:
  984. * Generate FIFO control for MAC & Baseband controller
  985. *
  986. * Parameters:
  987. * In:
  988. * pDevice - Pointer to adapter
  989. * pTxDataHead - Transmit Data Buffer
  990. * pTxBufHead - pTxBufHead
  991. * pvRrvTime - pvRrvTime
  992. * pvRTS - RTS Buffer
  993. * pCTS - CTS Buffer
  994. * cbFrameSize - Transmit Data Length (Hdr+Payload+FCS)
  995. * bNeedACK - If need ACK
  996. * uDescIdx - Desc Index
  997. * Out:
  998. * none
  999. *
  1000. * Return Value: none
  1001. *
  1002. -*/
  1003. // unsigned int cbFrameSize,//Hdr+Payload+FCS
  1004. static
  1005. void
  1006. s_vGenerateTxParameter (
  1007. PSDevice pDevice,
  1008. unsigned char byPktType,
  1009. void * pTxBufHead,
  1010. void * pvRrvTime,
  1011. void * pvRTS,
  1012. void * pvCTS,
  1013. unsigned int cbFrameSize,
  1014. bool bNeedACK,
  1015. unsigned int uDMAIdx,
  1016. PSEthernetHeader psEthHeader,
  1017. unsigned short wCurrentRate
  1018. )
  1019. {
  1020. unsigned int cbMACHdLen = WLAN_HDR_ADDR3_LEN; //24
  1021. unsigned short wFifoCtl;
  1022. bool bDisCRC = false;
  1023. unsigned char byFBOption = AUTO_FB_NONE;
  1024. // unsigned short wCurrentRate = pDevice->wCurrentRate;
  1025. //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"s_vGenerateTxParameter...\n");
  1026. PSTxBufHead pFifoHead = (PSTxBufHead)pTxBufHead;
  1027. pFifoHead->wReserved = wCurrentRate;
  1028. wFifoCtl = pFifoHead->wFIFOCtl;
  1029. if (wFifoCtl & FIFOCTL_CRCDIS) {
  1030. bDisCRC = true;
  1031. }
  1032. if (wFifoCtl & FIFOCTL_AUTO_FB_0) {
  1033. byFBOption = AUTO_FB_0;
  1034. }
  1035. else if (wFifoCtl & FIFOCTL_AUTO_FB_1) {
  1036. byFBOption = AUTO_FB_1;
  1037. }
  1038. if (pDevice->bLongHeader)
  1039. cbMACHdLen = WLAN_HDR_ADDR3_LEN + 6;
  1040. if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {
  1041. if (pvRTS != NULL) { //RTS_need
  1042. //Fill RsvTime
  1043. if (pvRrvTime) {
  1044. PSRrvTime_gRTS pBuf = (PSRrvTime_gRTS)pvRrvTime;
  1045. pBuf->wRTSTxRrvTime_aa = cpu_to_le16((unsigned short)s_uGetRTSCTSRsvTime(pDevice, 2, byPktType, cbFrameSize, wCurrentRate));//2:RTSTxRrvTime_aa, 1:2.4GHz
  1046. pBuf->wRTSTxRrvTime_ba = cpu_to_le16((unsigned short)s_uGetRTSCTSRsvTime(pDevice, 1, byPktType, cbFrameSize, wCurrentRate));//1:RTSTxRrvTime_ba, 1:2.4GHz
  1047. pBuf->wRTSTxRrvTime_bb = cpu_to_le16((unsigned short)s_uGetRTSCTSRsvTime(pDevice, 0, byPktType, cbFrameSize, wCurrentRate));//0:RTSTxRrvTime_bb, 1:2.4GHz
  1048. pBuf->wTxRrvTime_a = cpu_to_le16((unsigned short) s_uGetTxRsvTime(pDevice, byPktType, cbFrameSize, wCurrentRate, bNeedACK));//2.4G OFDM
  1049. pBuf->wTxRrvTime_b = cpu_to_le16((unsigned short) s_uGetTxRsvTime(pDevice, PK_TYPE_11B, cbFrameSize, pDevice->byTopCCKBasicRate, bNeedACK));//1:CCK
  1050. }
  1051. //Fill RTS
  1052. s_vFillRTSHead(pDevice, byPktType, pvRTS, cbFrameSize, bNeedACK, bDisCRC, psEthHeader, wCurrentRate, byFBOption);
  1053. }
  1054. else {//RTS_needless, PCF mode
  1055. //Fill RsvTime
  1056. if (pvRrvTime) {
  1057. PSRrvTime_gCTS pBuf = (PSRrvTime_gCTS)pvRrvTime;
  1058. pBuf->wTxRrvTime_a = cpu_to_le16((unsigned short)s_uGetTxRsvTime(pDevice, byPktType, cbFrameSize, wCurrentRate, bNeedACK));//2.4G OFDM
  1059. pBuf->wTxRrvTime_b = cpu_to_le16((unsigned short)s_uGetTxRsvTime(pDevice, PK_TYPE_11B, cbFrameSize, pDevice->byTopCCKBasicRate, bNeedACK));//1:CCK
  1060. pBuf->wCTSTxRrvTime_ba = cpu_to_le16((unsigned short)s_uGetRTSCTSRsvTime(pDevice, 3, byPktType, cbFrameSize, wCurrentRate));//3:CTSTxRrvTime_Ba, 1:2.4GHz
  1061. }
  1062. //Fill CTS
  1063. s_vFillCTSHead(pDevice, uDMAIdx, byPktType, pvCTS, cbFrameSize, bNeedACK, bDisCRC, wCurrentRate, byFBOption);
  1064. }
  1065. }
  1066. else if (byPktType == PK_TYPE_11A) {
  1067. if (pvRTS != NULL) {//RTS_need, non PCF mode
  1068. //Fill RsvTime
  1069. if (pvRrvTime) {
  1070. PSRrvTime_ab pBuf = (PSRrvTime_ab)pvRrvTime;
  1071. pBuf->wRTSTxRrvTime = cpu_to_le16((unsigned short)s_uGetRTSCTSRsvTime(pDevice, 2, byPktType, cbFrameSize, wCurrentRate));//2:RTSTxRrvTime_aa, 0:5GHz
  1072. pBuf->wTxRrvTime = cpu_to_le16((unsigned short)s_uGetTxRsvTime(pDevice, byPktType, cbFrameSize, wCurrentRate, bNeedACK));//0:OFDM
  1073. }
  1074. //Fill RTS
  1075. s_vFillRTSHead(pDevice, byPktType, pvRTS, cbFrameSize, bNeedACK, bDisCRC, psEthHeader, wCurrentRate, byFBOption);
  1076. }
  1077. else if (pvRTS == NULL) {//RTS_needless, non PCF mode
  1078. //Fill RsvTime
  1079. if (pvRrvTime) {
  1080. PSRrvTime_ab pBuf = (PSRrvTime_ab)pvRrvTime;
  1081. pBuf->wTxRrvTime = cpu_to_le16((unsigned short)s_uGetTxRsvTime(pDevice, PK_TYPE_11A, cbFrameSize, wCurrentRate, bNeedACK)); //0:OFDM
  1082. }
  1083. }
  1084. }
  1085. else if (byPktType == PK_TYPE_11B) {
  1086. if ((pvRTS != NULL)) {//RTS_need, non PCF mode
  1087. //Fill RsvTime
  1088. if (pvRrvTime) {
  1089. PSRrvTime_ab pBuf = (PSRrvTime_ab)pvRrvTime;
  1090. pBuf->wRTSTxRrvTime = cpu_to_le16((unsigned short)s_uGetRTSCTSRsvTime(pDevice, 0, byPktType, cbFrameSize, wCurrentRate));//0:RTSTxRrvTime_bb, 1:2.4GHz
  1091. pBuf->wTxRrvTime = cpu_to_le16((unsigned short)s_uGetTxRsvTime(pDevice, PK_TYPE_11B, cbFrameSize, wCurrentRate, bNeedACK));//1:CCK
  1092. }
  1093. //Fill RTS
  1094. s_vFillRTSHead(pDevice, byPktType, pvRTS, cbFrameSize, bNeedACK, bDisCRC, psEthHeader, wCurrentRate, byFBOption);
  1095. }
  1096. else { //RTS_needless, non PCF mode
  1097. //Fill RsvTime
  1098. if (pvRrvTime) {
  1099. PSRrvTime_ab pBuf = (PSRrvTime_ab)pvRrvTime;
  1100. pBuf->wTxRrvTime = cpu_to_le16((unsigned short)s_uGetTxRsvTime(pDevice, PK_TYPE_11B, cbFrameSize, wCurrentRate, bNeedACK)); //1:CCK
  1101. }
  1102. }
  1103. }
  1104. //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"s_vGenerateTxParameter END.\n");
  1105. }
  1106. /*
  1107. unsigned char *pbyBuffer,//point to pTxBufHead
  1108. unsigned short wFragType,//00:Non-Frag, 01:Start, 02:Mid, 03:Last
  1109. unsigned int cbFragmentSize,//Hdr+payoad+FCS
  1110. */
  1111. static
  1112. void
  1113. s_vFillFragParameter(
  1114. PSDevice pDevice,
  1115. unsigned char *pbyBuffer,
  1116. unsigned int uTxType,
  1117. void * pvtdCurr,
  1118. unsigned short wFragType,
  1119. unsigned int cbReqCount
  1120. )
  1121. {
  1122. PSTxBufHead pTxBufHead = (PSTxBufHead) pbyBuffer;
  1123. //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"s_vFillFragParameter...\n");
  1124. if (uTxType == TYPE_SYNCDMA) {
  1125. //PSTxSyncDesc ptdCurr = (PSTxSyncDesc)s_pvGetTxDescHead(pDevice, uTxType, uCurIdx);
  1126. PSTxSyncDesc ptdCurr = (PSTxSyncDesc)pvtdCurr;
  1127. //Set FIFOCtl & TimeStamp in TxSyncDesc
  1128. ptdCurr->m_wFIFOCtl = pTxBufHead->wFIFOCtl;
  1129. ptdCurr->m_wTimeStamp = pTxBufHead->wTimeStamp;
  1130. //Set TSR1 & ReqCount in TxDescHead
  1131. ptdCurr->m_td1TD1.wReqCount = cpu_to_le16((unsigned short)(cbReqCount));
  1132. if (wFragType == FRAGCTL_ENDFRAG) { //Last Fragmentation
  1133. ptdCurr->m_td1TD1.byTCR |= (TCR_STP | TCR_EDP | EDMSDU);
  1134. }
  1135. else {
  1136. ptdCurr->m_td1TD1.byTCR |= (TCR_STP | TCR_EDP);
  1137. }
  1138. }
  1139. else {
  1140. //PSTxDesc ptdCurr = (PSTxDesc)s_pvGetTxDescHead(pDevice, uTxType, uCurIdx);
  1141. PSTxDesc ptdCurr = (PSTxDesc)pvtdCurr;
  1142. //Set TSR1 & ReqCount in TxDescHead
  1143. ptdCurr->m_td1TD1.wReqCount = cpu_to_le16((unsigned short)(cbReqCount));
  1144. if (wFragType == FRAGCTL_ENDFRAG) { //Last Fragmentation
  1145. ptdCurr->m_td1TD1.byTCR |= (TCR_STP | TCR_EDP | EDMSDU);
  1146. }
  1147. else {
  1148. ptdCurr->m_td1TD1.byTCR |= (TCR_STP | TCR_EDP);
  1149. }
  1150. }
  1151. pTxBufHead->wFragCtl |= (unsigned short)wFragType;//0x0001; //0000 0000 0000 0001
  1152. //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"s_vFillFragParameter END\n");
  1153. }
  1154. static unsigned int
  1155. s_cbFillTxBufHead(PSDevice pDevice, unsigned char byPktType, unsigned char *pbyTxBufferAddr,
  1156. unsigned int cbFrameBodySize, unsigned int uDMAIdx, PSTxDesc pHeadTD,
  1157. PSEthernetHeader psEthHeader, unsigned char *pPacket, bool bNeedEncrypt,
  1158. PSKeyItem pTransmitKey, unsigned int uNodeIndex, unsigned int *puMACfragNum)
  1159. {
  1160. unsigned int cbMACHdLen;
  1161. unsigned int cbFrameSize;
  1162. unsigned int cbFragmentSize; //Hdr+(IV)+payoad+(MIC)+(ICV)+FCS
  1163. unsigned int cbFragPayloadSize;
  1164. unsigned int cbLastFragmentSize; //Hdr+(IV)+payoad+(MIC)+(ICV)+FCS
  1165. unsigned int cbLastFragPayloadSize;
  1166. unsigned int uFragIdx;
  1167. unsigned char *pbyPayloadHead;
  1168. unsigned char *pbyIVHead;
  1169. unsigned char *pbyMacHdr;
  1170. unsigned short wFragType; //00:Non-Frag, 01:Start, 10:Mid, 11:Last
  1171. unsigned int uDuration;
  1172. unsigned char *pbyBuffer;
  1173. // unsigned int uKeyEntryIdx = NUM_KEY_ENTRY+1;
  1174. // unsigned char byKeySel = 0xFF;
  1175. unsigned int cbIVlen = 0;
  1176. unsigned int cbICVlen = 0;
  1177. unsigned int cbMIClen = 0;
  1178. unsigned int cbFCSlen = 4;
  1179. unsigned int cb802_1_H_len = 0;
  1180. unsigned int uLength = 0;
  1181. unsigned int uTmpLen = 0;
  1182. // unsigned char abyTmp[8];
  1183. // unsigned long dwCRC;
  1184. unsigned int cbMICHDR = 0;
  1185. unsigned long dwMICKey0, dwMICKey1;
  1186. unsigned long dwMIC_Priority;
  1187. unsigned long *pdwMIC_L;
  1188. unsigned long *pdwMIC_R;
  1189. unsigned long dwSafeMIC_L, dwSafeMIC_R; //Fix "Last Frag Size" < "MIC length".
  1190. bool bMIC2Frag = false;
  1191. unsigned int uMICFragLen = 0;
  1192. unsigned int uMACfragNum = 1;
  1193. unsigned int uPadding = 0;
  1194. unsigned int cbReqCount = 0;
  1195. bool bNeedACK;
  1196. bool bRTS;
  1197. bool bIsAdhoc;
  1198. unsigned char *pbyType;
  1199. PSTxDesc ptdCurr;
  1200. PSTxBufHead psTxBufHd = (PSTxBufHead) pbyTxBufferAddr;
  1201. // unsigned int tmpDescIdx;
  1202. unsigned int cbHeaderLength = 0;
  1203. void * pvRrvTime;
  1204. PSMICHDRHead pMICHDR;
  1205. void * pvRTS;
  1206. void * pvCTS;
  1207. void * pvTxDataHd;
  1208. unsigned short wTxBufSize; // FFinfo size
  1209. unsigned int uTotalCopyLength = 0;
  1210. unsigned char byFBOption = AUTO_FB_NONE;
  1211. bool bIsWEP256 = false;
  1212. PSMgmtObject pMgmt = pDevice->pMgmt;
  1213. pvRrvTime = pMICHDR = pvRTS = pvCTS = pvTxDataHd = NULL;
  1214. //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"s_cbFillTxBufHead...\n");
  1215. if ((pDevice->eOPMode == OP_MODE_ADHOC) ||
  1216. (pDevice->eOPMode == OP_MODE_AP)) {
  1217. if (is_multicast_ether_addr(&(psEthHeader->abyDstAddr[0])))
  1218. bNeedACK = false;
  1219. else
  1220. bNeedACK = true;
  1221. bIsAdhoc = true;
  1222. }
  1223. else {
  1224. // MSDUs in Infra mode always need ACK
  1225. bNeedACK = true;
  1226. bIsAdhoc = false;
  1227. }
  1228. if (pDevice->bLongHeader)
  1229. cbMACHdLen = WLAN_HDR_ADDR3_LEN + 6;
  1230. else
  1231. cbMACHdLen = WLAN_HDR_ADDR3_LEN;
  1232. if ((bNeedEncrypt == true) && (pTransmitKey != NULL)) {
  1233. if (pTransmitKey->byCipherSuite == KEY_CTL_WEP) {
  1234. cbIVlen = 4;
  1235. cbICVlen = 4;
  1236. if (pTransmitKey->uKeyLength == WLAN_WEP232_KEYLEN) {
  1237. bIsWEP256 = true;
  1238. }
  1239. }
  1240. if (pTransmitKey->byCipherSuite == KEY_CTL_TKIP) {
  1241. cbIVlen = 8;//IV+ExtIV
  1242. cbMIClen = 8;
  1243. cbICVlen = 4;
  1244. }
  1245. if (pTransmitKey->byCipherSuite == KEY_CTL_CCMP) {
  1246. cbIVlen = 8;//RSN Header
  1247. cbICVlen = 8;//MIC
  1248. cbMICHDR = sizeof(SMICHDRHead);
  1249. }
  1250. if (pDevice->byLocalID > REV_ID_VT3253_A1) {
  1251. //MAC Header should be padding 0 to DW alignment.
  1252. uPadding = 4 - (cbMACHdLen%4);
  1253. uPadding %= 4;
  1254. }
  1255. }
  1256. cbFrameSize = cbMACHdLen + cbIVlen + (cbFrameBodySize + cbMIClen) + cbICVlen + cbFCSlen;
  1257. if ((bNeedACK == false) ||
  1258. (cbFrameSize < pDevice->wRTSThreshold) ||
  1259. ((cbFrameSize >= pDevice->wFragmentationThreshold) && (pDevice->wFragmentationThreshold <= pDevice->wRTSThreshold))
  1260. ) {
  1261. bRTS = false;
  1262. }
  1263. else {
  1264. bRTS = true;
  1265. psTxBufHd->wFIFOCtl |= (FIFOCTL_RTS | FIFOCTL_LRETRY);
  1266. }
  1267. //
  1268. // Use for AUTO FALL BACK
  1269. //
  1270. if (psTxBufHd->wFIFOCtl & FIFOCTL_AUTO_FB_0) {
  1271. byFBOption = AUTO_FB_0;
  1272. }
  1273. else if (psTxBufHd->wFIFOCtl & FIFOCTL_AUTO_FB_1) {
  1274. byFBOption = AUTO_FB_1;
  1275. }
  1276. //////////////////////////////////////////////////////
  1277. //Set RrvTime/RTS/CTS Buffer
  1278. wTxBufSize = sizeof(STxBufHead);
  1279. if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {//802.11g packet
  1280. if (byFBOption == AUTO_FB_NONE) {
  1281. if (bRTS == true) {//RTS_need
  1282. pvRrvTime = (PSRrvTime_gRTS) (pbyTxBufferAddr + wTxBufSize);
  1283. pMICHDR = (PSMICHDRHead) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_gRTS));
  1284. pvRTS = (PSRTS_g) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_gRTS) + cbMICHDR);
  1285. pvCTS = NULL;
  1286. pvTxDataHd = (PSTxDataHead_g) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_gRTS) + cbMICHDR + sizeof(SRTS_g));
  1287. cbHeaderLength = wTxBufSize + sizeof(SRrvTime_gRTS) + cbMICHDR + sizeof(SRTS_g) + sizeof(STxDataHead_g);
  1288. }
  1289. else { //RTS_needless
  1290. pvRrvTime = (PSRrvTime_gCTS) (pbyTxBufferAddr + wTxBufSize);
  1291. pMICHDR = (PSMICHDRHead) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_gCTS));
  1292. pvRTS = NULL;
  1293. pvCTS = (PSCTS) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_gCTS) + cbMICHDR);
  1294. pvTxDataHd = (PSTxDataHead_g) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_gCTS) + cbMICHDR + sizeof(SCTS));
  1295. cbHeaderLength = wTxBufSize + sizeof(SRrvTime_gCTS) + cbMICHDR + sizeof(SCTS) + sizeof(STxDataHead_g);
  1296. }
  1297. } else {
  1298. // Auto Fall Back
  1299. if (bRTS == true) {//RTS_need
  1300. pvRrvTime = (PSRrvTime_gRTS) (pbyTxBufferAddr + wTxBufSize);
  1301. pMICHDR = (PSMICHDRHead) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_gRTS));
  1302. pvRTS = (PSRTS_g_FB) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_gRTS) + cbMICHDR);
  1303. pvCTS = NULL;
  1304. pvTxDataHd = (PSTxDataHead_g_FB) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_gRTS) + cbMICHDR + sizeof(SRTS_g_FB));
  1305. cbHeaderLength = wTxBufSize + sizeof(SRrvTime_gRTS) + cbMICHDR + sizeof(SRTS_g_FB) + sizeof(STxDataHead_g_FB);
  1306. }
  1307. else { //RTS_needless
  1308. pvRrvTime = (PSRrvTime_gCTS) (pbyTxBufferAddr + wTxBufSize);
  1309. pMICHDR = (PSMICHDRHead) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_gCTS));
  1310. pvRTS = NULL;
  1311. pvCTS = (PSCTS_FB) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_gCTS) + cbMICHDR);
  1312. pvTxDataHd = (PSTxDataHead_g_FB) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_gCTS) + cbMICHDR + sizeof(SCTS_FB));
  1313. cbHeaderLength = wTxBufSize + sizeof(SRrvTime_gCTS) + cbMICHDR + sizeof(SCTS_FB) + sizeof(STxDataHead_g_FB);
  1314. }
  1315. } // Auto Fall Back
  1316. }
  1317. else {//802.11a/b packet
  1318. if (byFBOption == AUTO_FB_NONE) {
  1319. if (bRTS == true) {
  1320. pvRrvTime = (PSRrvTime_ab) (pbyTxBufferAddr + wTxBufSize);
  1321. pMICHDR = (PSMICHDRHead) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_ab));
  1322. pvRTS = (PSRTS_ab) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_ab) + cbMICHDR);
  1323. pvCTS = NULL;
  1324. pvTxDataHd = (PSTxDataHead_ab) (pbyTxBufferAddr + wTxBufSize + sizeof(PSRrvTime_ab) + cbMICHDR + sizeof(SRTS_ab));
  1325. cbHeaderLength = wTxBufSize + sizeof(PSRrvTime_ab) + cbMICHDR + sizeof(SRTS_ab) + sizeof(STxDataHead_ab);
  1326. }
  1327. else { //RTS_needless, need MICHDR
  1328. pvRrvTime = (PSRrvTime_ab) (pbyTxBufferAddr + wTxBufSize);
  1329. pMICHDR = (PSMICHDRHead) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_ab));
  1330. pvRTS = NULL;
  1331. pvCTS = NULL;
  1332. pvTxDataHd = (PSTxDataHead_ab) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_ab) + cbMICHDR);
  1333. cbHeaderLength = wTxBufSize + sizeof(SRrvTime_ab) + cbMICHDR + sizeof(STxDataHead_ab);
  1334. }
  1335. } else {
  1336. // Auto Fall Back
  1337. if (bRTS == true) {//RTS_need
  1338. pvRrvTime = (PSRrvTime_ab) (pbyTxBufferAddr + wTxBufSize);
  1339. pMICHDR = (PSMICHDRHead) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_ab));
  1340. pvRTS = (PSRTS_a_FB) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_ab) + cbMICHDR);
  1341. pvCTS = NULL;
  1342. pvTxDataHd = (PSTxDataHead_a_FB) (pbyTxBufferAddr + wTxBufSize + sizeof(PSRrvTime_ab) + cbMICHDR + sizeof(SRTS_a_FB));
  1343. cbHeaderLength = wTxBufSize + sizeof(PSRrvTime_ab) + cbMICHDR + sizeof(SRTS_a_FB) + sizeof(STxDataHead_a_FB);
  1344. }
  1345. else { //RTS_needless
  1346. pvRrvTime = (PSRrvTime_ab) (pbyTxBufferAddr + wTxBufSize);
  1347. pMICHDR = (PSMICHDRHead) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_ab));
  1348. pvRTS = NULL;
  1349. pvCTS = NULL;
  1350. pvTxDataHd = (PSTxDataHead_a_FB) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_ab) + cbMICHDR);
  1351. cbHeaderLength = wTxBufSize + sizeof(SRrvTime_ab) + cbMICHDR + sizeof(STxDataHead_a_FB);
  1352. }
  1353. } // Auto Fall Back
  1354. }
  1355. memset((void *)(pbyTxBufferAddr + wTxBufSize), 0, (cbHeaderLength - wTxBufSize));
  1356. //////////////////////////////////////////////////////////////////
  1357. if ((bNeedEncrypt == true) && (pTransmitKey != NULL) && (pTransmitKey->byCipherSuite == KEY_CTL_TKIP)) {
  1358. if (pDevice->pMgmt->eAuthenMode == WMAC_AUTH_WPANONE) {
  1359. dwMICKey0 = *(unsigned long *)(&pTransmitKey->abyKey[16]);
  1360. dwMICKey1 = *(unsigned long *)(&pTransmitKey->abyKey[20]);
  1361. }
  1362. else if ((pTransmitKey->dwKeyIndex & AUTHENTICATOR_KEY) != 0) {
  1363. dwMICKey0 = *(unsigned long *)(&pTransmitKey->abyKey[16]);
  1364. dwMICKey1 = *(unsigned long *)(&pTransmitKey->abyKey[20]);
  1365. }
  1366. else {
  1367. dwMICKey0 = *(unsigned long *)(&pTransmitKey->abyKey[24]);
  1368. dwMICKey1 = *(unsigned long *)(&pTransmitKey->abyKey[28]);
  1369. }
  1370. // DO Software Michael
  1371. MIC_vInit(dwMICKey0, dwMICKey1);
  1372. MIC_vAppend((unsigned char *)&(psEthHeader->abyDstAddr[0]), 12);
  1373. dwMIC_Priority = 0;
  1374. MIC_vAppend((unsigned char *)&dwMIC_Priority, 4);
  1375. DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"MIC KEY: %lX, %lX\n", dwMICKey0, dwMICKey1);
  1376. }
  1377. ///////////////////////////////////////////////////////////////////
  1378. pbyMacHdr = (unsigned char *)(pbyTxBufferAddr + cbHeaderLength);
  1379. pbyPayloadHead = (unsigned char *)(pbyMacHdr + cbMACHdLen + uPadding + cbIVlen);
  1380. pbyIVHead = (unsigned char *)(pbyMacHdr + cbMACHdLen + uPadding);
  1381. if ((cbFrameSize > pDevice->wFragmentationThreshold) && (bNeedACK == true) && (bIsWEP256 == false)) {
  1382. // Fragmentation
  1383. // FragThreshold = Fragment size(Hdr+(IV)+fragment payload+(MIC)+(ICV)+FCS)
  1384. cbFragmentSize = pDevice->wFragmentationThreshold;
  1385. cbFragPayloadSize = cbFragmentSize - cbMACHdLen - cbIVlen - cbICVlen - cbFCSlen;
  1386. //FragNum = (FrameSize-(Hdr+FCS))/(Fragment Size -(Hrd+FCS)))
  1387. uMACfragNum = (unsigned short) ((cbFrameBodySize + cbMIClen) / cbFragPayloadSize);
  1388. cbLastFragPayloadSize = (cbFrameBodySize + cbMIClen) % cbFragPayloadSize;
  1389. if (cbLastFragPayloadSize == 0) {
  1390. cbLastFragPayloadSize = cbFragPayloadSize;
  1391. } else {
  1392. uMACfragNum++;
  1393. }
  1394. //[Hdr+(IV)+last fragment payload+(MIC)+(ICV)+FCS]
  1395. cbLastFragmentSize = cbMACHdLen + cbLastFragPayloadSize + cbIVlen + cbICVlen + cbFCSlen;
  1396. for (uFragIdx = 0; uFragIdx < uMACfragNum; uFragIdx ++) {
  1397. if (uFragIdx == 0) {
  1398. //=========================
  1399. // Start Fragmentation
  1400. //=========================
  1401. DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Start Fragmentation...\n");
  1402. wFragType = FRAGCTL_STAFRAG;
  1403. //Fill FIFO,RrvTime,RTS,and CTS
  1404. s_vGenerateTxParameter(pDevice, byPktType, (void *)psTxBufHd, pvRrvTime, pvRTS, pvCTS,
  1405. cbFragmentSize, bNeedACK, uDMAIdx, psEthHeader, pDevice->wCurrentRate);
  1406. //Fill DataHead
  1407. uDuration = s_uFillDataHead(pDevice, byPktType, pvTxDataHd, cbFragmentSize, uDMAIdx, bNeedACK,
  1408. uFragIdx, cbLastFragmentSize, uMACfragNum, byFBOption, pDevice->wCurrentRate);
  1409. // Generate TX MAC Header
  1410. vGenerateMACHeader(pDevice, pbyMacHdr, (unsigned short)uDuration, psEthHeader, bNeedEncrypt,
  1411. wFragType, uDMAIdx, uFragIdx);
  1412. if (bNeedEncrypt == true) {
  1413. //Fill TXKEY
  1414. s_vFillTxKey(pDevice, (unsigned char *)(psTxBufHd->adwTxKey), pbyIVHead, pTransmitKey,
  1415. pbyMacHdr, (unsigned short)cbFragPayloadSize, (unsigned char *)pMICHDR);
  1416. //Fill IV(ExtIV,RSNHDR)
  1417. if (pDevice->bEnableHostWEP) {
  1418. pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16 = pTransmitKey->dwTSC47_16;
  1419. pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0 = pTransmitKey->wTSC15_0;
  1420. }
  1421. }
  1422. // 802.1H
  1423. if (ntohs(psEthHeader->wType) > ETH_DATA_LEN) {
  1424. if ((psEthHeader->wType == TYPE_PKT_IPX) ||
  1425. (psEthHeader->wType == cpu_to_le16(0xF380))) {
  1426. memcpy((unsigned char *) (pbyPayloadHead), &pDevice->abySNAP_Bridgetunnel[0], 6);
  1427. }
  1428. else {
  1429. memcpy((unsigned char *) (pbyPayloadHead), &pDevice->abySNAP_RFC1042[0], 6);
  1430. }
  1431. pbyType = (unsigned char *) (pbyPayloadHead + 6);
  1432. memcpy(pbyType, &(psEthHeader->wType), sizeof(unsigned short));
  1433. cb802_1_H_len = 8;
  1434. }
  1435. cbReqCount = cbHeaderLength + cbMACHdLen + uPadding + cbIVlen + cbFragPayloadSize;
  1436. //---------------------------
  1437. // S/W or H/W Encryption
  1438. //---------------------------
  1439. //Fill MICHDR
  1440. //if (pDevice->bAES) {
  1441. // s_vFillMICHDR(pDevice, (unsigned char *)pMICHDR, pbyMacHdr, (unsigned short)cbFragPayloadSize);
  1442. //}
  1443. //cbReqCount += s_uDoEncryption(pDevice, psEthHeader, (void *)psTxBufHd, byKeySel,
  1444. // pbyPayloadHead, (unsigned short)cbFragPayloadSize, uDMAIdx);
  1445. //pbyBuffer = (unsigned char *)pDevice->aamTxBuf[uDMAIdx][uDescIdx].pbyVAddr;
  1446. pbyBuffer = (unsigned char *)pHeadTD->pTDInfo->buf;
  1447. uLength = cbHeaderLength + cbMACHdLen + uPadding + cbIVlen + cb802_1_H_len;
  1448. //copy TxBufferHeader + MacHeader to desc
  1449. memcpy(pbyBuffer, (void *)psTxBufHd, uLength);
  1450. // Copy the Packet into a tx Buffer
  1451. memcpy((pbyBuffer + uLength), (pPacket + 14), (cbFragPayloadSize - cb802_1_H_len));
  1452. uTotalCopyLength += cbFragPayloadSize - cb802_1_H_len;
  1453. if ((bNeedEncrypt == true) && (pTransmitKey != NULL) && (pTransmitKey->byCipherSuite == KEY_CTL_TKIP)) {
  1454. DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Start MIC: %d\n", cbFragPayloadSize);
  1455. MIC_vAppend((pbyBuffer + uLength - cb802_1_H_len), cbFragPayloadSize);
  1456. }
  1457. //---------------------------
  1458. // S/W Encryption
  1459. //---------------------------
  1460. if ((pDevice->byLocalID <= REV_ID_VT3253_A1)) {
  1461. if (bNeedEncrypt) {
  1462. s_vSWencryption(pDevice, pTransmitKey, (pbyBuffer + uLength - cb802_1_H_len), (unsigned short)cbFragPayloadSize);
  1463. cbReqCount += cbICVlen;
  1464. }
  1465. }
  1466. ptdCurr = (PSTxDesc)pHeadTD;
  1467. //--------------------
  1468. //1.Set TSR1 & ReqCount in TxDescHead
  1469. //2.Set FragCtl in TxBufferHead
  1470. //3.Set Frame Control
  1471. //4.Set Sequence Control
  1472. //5.Get S/W generate FCS
  1473. //--------------------
  1474. s_vFillFragParameter(pDevice, pbyBuffer, uDMAIdx, (void *)ptdCurr, wFragType, cbReqCount);
  1475. ptdCurr->pTDInfo->dwReqCount = cbReqCount - uPadding;
  1476. ptdCurr->pTDInfo->dwHeaderLength = cbHeaderLength;
  1477. ptdCurr->pTDInfo->skb_dma = ptdCurr->pTDInfo->buf_dma;
  1478. ptdCurr->buff_addr = cpu_to_le32(ptdCurr->pTDInfo->skb_dma);
  1479. pDevice->iTDUsed[uDMAIdx]++;
  1480. pHeadTD = ptdCurr->next;
  1481. }
  1482. else if (uFragIdx == (uMACfragNum-1)) {
  1483. //=========================
  1484. // Last Fragmentation
  1485. //=========================
  1486. DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Last Fragmentation...\n");
  1487. //tmpDescIdx = (uDescIdx + uFragIdx) % pDevice->cbTD[uDMAIdx];
  1488. wFragType = FRAGCTL_ENDFRAG;
  1489. //Fill FIFO,RrvTime,RTS,and CTS
  1490. s_vGenerateTxParameter(pDevice, byPktType, (void *)psTxBufHd, pvRrvTime, pvRTS, pvCTS,
  1491. cbLastFragmentSize, bNeedACK, uDMAIdx, psEthHeader, pDevice->wCurrentRate);
  1492. //Fill DataHead
  1493. uDuration = s_uFillDataHead(pDevice, byPktType, pvTxDataHd, cbLastFragmentSize, uDMAIdx, bNeedACK,
  1494. uFragIdx, cbLastFragmentSize, uMACfragNum, byFBOption, pDevice->wCurrentRate);
  1495. // Generate TX MAC Header
  1496. vGenerateMACHeader(pDevice, pbyMacHdr, (unsigned short)uDuration, psEthHeader, bNeedEncrypt,
  1497. wFragType, uDMAIdx, uFragIdx);
  1498. if (bNeedEncrypt == true) {
  1499. //Fill TXKEY
  1500. s_vFillTxKey(pDevice, (unsigned char *)(psTxBufHd->adwTxKey), pbyIVHead, pTransmitKey,
  1501. pbyMacHdr, (unsigned short)cbLastFragPayloadSize, (unsigned char *)pMICHDR);
  1502. if (pDevice->bEnableHostWEP) {
  1503. pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16 = pTransmitKey->dwTSC47_16;
  1504. pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0 = pTransmitKey->wTSC15_0;
  1505. }
  1506. }
  1507. cbReqCount = cbHeaderLength + cbMACHdLen + uPadding + cbIVlen + cbLastFragPayloadSize;
  1508. //---------------------------
  1509. // S/W or H/W Encryption
  1510. //---------------------------
  1511. pbyBuffer = (unsigned char *)pHeadTD->pTDInfo->buf;
  1512. //pbyBuffer = (unsigned char *)pDevice->aamTxBuf[uDMAIdx][tmpDescIdx].pbyVAddr;
  1513. uLength = cbHeaderLength + cbMACHdLen + uPadding + cbIVlen;
  1514. //copy TxBufferHeader + MacHeader to desc
  1515. memcpy(pbyBuffer, (void *)psTxBufHd, uLength);
  1516. // Copy the Packet into a tx Buffer
  1517. if (bMIC2Frag == false) {
  1518. memcpy((pbyBuffer + uLength),
  1519. (pPacket + 14 + uTotalCopyLength),
  1520. (cbLastFragPayloadSize - cbMIClen)
  1521. );
  1522. //TODO check uTmpLen !
  1523. uTmpLen = cbLastFragPayloadSize - cbMIClen;
  1524. }
  1525. if ((bNeedEncrypt == true) && (pTransmitKey != NULL) && (pTransmitKey->byCipherSuite == KEY_CTL_TKIP)) {
  1526. DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"LAST: uMICFragLen:%d, cbLastFragPayloadSize:%d, uTmpLen:%d\n",
  1527. uMICFragLen, cbLastFragPayloadSize, uTmpLen);
  1528. if (bMIC2Frag == false) {
  1529. if (uTmpLen != 0)
  1530. MIC_vAppend((pbyBuffer + uLength), uTmpLen);
  1531. pdwMIC_L = (unsigned long *)(pbyBuffer + uLength + uTmpLen);
  1532. pdwMIC_R = (unsigned long *)(pbyBuffer + uLength + uTmpLen + 4);
  1533. MIC_vGetMIC(pdwMIC_L, pdwMIC_R);
  1534. DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Last MIC:%lX, %lX\n", *pdwMIC_L, *pdwMIC_R);
  1535. } else {
  1536. if (uMICFragLen >= 4) {
  1537. memcpy((pbyBuffer + uLength), ((unsigned char *)&dwSafeMIC_R + (uMICFragLen - 4)),
  1538. (cbMIClen - uMICFragLen));
  1539. DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"LAST: uMICFragLen >= 4: %X, %d\n",
  1540. *(unsigned char *)((unsigned char *)&dwSafeMIC_R + (uMICFragLen - 4)),
  1541. (cbMIClen - uMICFragLen));
  1542. } else {
  1543. memcpy((pbyBuffer + uLength), ((unsigned char *)&dwSafeMIC_L + uMICFragLen),
  1544. (4 - uMICFragLen));
  1545. memcpy((pbyBuffer + uLength + (4 - uMICFragLen)), &dwSafeMIC_R, 4);
  1546. DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"LAST: uMICFragLen < 4: %X, %d\n",
  1547. *(unsigned char *)((unsigned char *)&dwSafeMIC_R + uMICFragLen - 4),
  1548. (cbMIClen - uMICFragLen));
  1549. }
  1550. /*
  1551. for (ii = 0; ii < cbLastFragPayloadSize + 8 + 24; ii++) {
  1552. DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"%02x ", *((unsigned char *)((pbyBuffer + uLength) + ii - 8 - 24)));
  1553. }
  1554. DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"\n\n");
  1555. */
  1556. }
  1557. MIC_vUnInit();
  1558. } else {
  1559. ASSERT(uTmpLen == (cbLastFragPayloadSize - cbMIClen));
  1560. }
  1561. //---------------------------
  1562. // S/W Encryption
  1563. //---------------------------
  1564. if ((pDevice->byLocalID <= REV_ID_VT3253_A1)) {
  1565. if (bNeedEncrypt) {
  1566. s_vSWencryption(pDevice, pTransmitKey, (pbyBuffer + uLength), (unsigned short)cbLastFragPayloadSize);
  1567. cbReqCount += cbICVlen;
  1568. }
  1569. }
  1570. ptdCurr = (PSTxDesc)pHeadTD;
  1571. //--------------------
  1572. //1.Set TSR1 & ReqCount in TxDescHead
  1573. //2.Set FragCtl in TxBufferHead
  1574. //3.Set Frame Control
  1575. //4.Set Sequence Control
  1576. //5.Get S/W generate FCS
  1577. //--------------------
  1578. s_vFillFragParameter(pDevice, pbyBuffer, uDMAIdx, (void *)ptdCurr, wFragType, cbReqCount);
  1579. ptdCurr->pTDInfo->dwReqCount = cbReqCount - uPadding;
  1580. ptdCurr->pTDInfo->dwHeaderLength = cbHeaderLength;
  1581. ptdCurr->pTDInfo->skb_dma = ptdCurr->pTDInfo->buf_dma;
  1582. ptdCurr->buff_addr = cpu_to_le32(ptdCurr->pTDInfo->skb_dma);
  1583. pDevice->iTDUsed[uDMAIdx]++;
  1584. pHeadTD = ptdCurr->next;
  1585. }
  1586. else {
  1587. //=========================
  1588. // Middle Fragmentation
  1589. //=========================
  1590. DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Middle Fragmentation...\n");
  1591. //tmpDescIdx = (uDescIdx + uFragIdx) % pDevice->cbTD[uDMAIdx];
  1592. wFragType = FRAGCTL_MIDFRAG;
  1593. //Fill FIFO,RrvTime,RTS,and CTS
  1594. s_vGenerateTxParameter(pDevice, byPktType, (void *)psTxBufHd, pvRrvTime, pvRTS, pvCTS,
  1595. cbFragmentSize, bNeedACK, uDMAIdx, psEthHeader, pDevice->wCurrentRate);
  1596. //Fill DataHead
  1597. uDuration = s_uFillDataHead(pDevice, byPktType, pvTxDataHd, cbFragmentSize, uDMAIdx, bNeedACK,
  1598. uFragIdx, cbLastFragmentSize, uMACfragNum, byFBOption, pDevice->wCurrentRate);
  1599. // Generate TX MAC Header
  1600. vGenerateMACHeader(pDevice, pbyMacHdr, (unsigned short)uDuration, psEthHeader, bNeedEncrypt,
  1601. wFragType, uDMAIdx, uFragIdx);
  1602. if (bNeedEncrypt == true) {
  1603. //Fill TXKEY
  1604. s_vFillTxKey(pDevice, (unsigned char *)(psTxBufHd->adwTxKey), pbyIVHead, pTransmitKey,
  1605. pbyMacHdr, (unsigned short)cbFragPayloadSize, (unsigned char *)pMICHDR);
  1606. if (pDevice->bEnableHostWEP) {
  1607. pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16 = pTransmitKey->dwTSC47_16;
  1608. pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0 = pTransmitKey->wTSC15_0;
  1609. }
  1610. }
  1611. cbReqCount = cbHeaderLength + cbMACHdLen + uPadding + cbIVlen + cbFragPayloadSize;
  1612. //---------------------------
  1613. // S/W or H/W Encryption
  1614. //---------------------------
  1615. //Fill MICHDR
  1616. //if (pDevice->bAES) {
  1617. // s_vFillMICHDR(pDevice, (unsigned char *)pMICHDR, pbyMacHdr, (unsigned short)cbFragPayloadSize);
  1618. //}
  1619. //cbReqCount += s_uDoEncryption(pDevice, psEthHeader, (void *)psTxBufHd, byKeySel,
  1620. // pbyPayloadHead, (unsigned short)cbFragPayloadSize, uDMAIdx);
  1621. pbyBuffer = (unsigned char *)pHeadTD->pTDInfo->buf;
  1622. //pbyBuffer = (unsigned char *)pDevice->aamTxBuf[uDMAIdx][tmpDescIdx].pbyVAddr;
  1623. uLength = cbHeaderLength + cbMACHdLen + uPadding + cbIVlen;
  1624. //copy TxBufferHeader + MacHeader to desc
  1625. memcpy(pbyBuffer, (void *)psTxBufHd, uLength);
  1626. // Copy the Packet into a tx Buffer
  1627. memcpy((pbyBuffer + uLength),
  1628. (pPacket + 14 + uTotalCopyLength),
  1629. cbFragPayloadSize
  1630. );
  1631. uTmpLen = cbFragPayloadSize;
  1632. uTotalCopyLength += uTmpLen;
  1633. if ((bNeedEncrypt == true) && (pTransmitKey != NULL) && (pTransmitKey->byCipherSuite == KEY_CTL_TKIP)) {
  1634. MIC_vAppend((pbyBuffer + uLength), uTmpLen);
  1635. if (uTmpLen < cbFragPayloadSize) {
  1636. bMIC2Frag = true;
  1637. uMICFragLen = cbFragPayloadSize - uTmpLen;
  1638. ASSERT(uMICFragLen < cbMIClen);
  1639. pdwMIC_L = (unsigned long *)(pbyBuffer + uLength + uTmpLen);
  1640. pdwMIC_R = (unsigned long *)(pbyBuffer + uLength + uTmpLen + 4);
  1641. MIC_vGetMIC(pdwMIC_L, pdwMIC_R);
  1642. dwSafeMIC_L = *pdwMIC_L;
  1643. dwSafeMIC_R = *pdwMIC_R;
  1644. DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"MIDDLE: uMICFragLen:%d, cbFragPayloadSize:%d, uTmpLen:%d\n",
  1645. uMICFragLen, cbFragPayloadSize, uTmpLen);
  1646. DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Fill MIC in Middle frag [%d]\n", uMICFragLen);
  1647. /*
  1648. for (ii = 0; ii < uMICFragLen; ii++) {
  1649. DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"%02x ", *((unsigned char *)((pbyBuffer + uLength + uTmpLen) + ii)));
  1650. }
  1651. DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"\n");
  1652. */
  1653. DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Get MIC:%lX, %lX\n", *pdwMIC_L, *pdwMIC_R);
  1654. }
  1655. DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Middle frag len: %d\n", uTmpLen);
  1656. /*
  1657. for (ii = 0; ii < uTmpLen; ii++) {
  1658. DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"%02x ", *((unsigned char *)((pbyBuffer + uLength) + ii)));
  1659. }
  1660. DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"\n\n");
  1661. */
  1662. } else {
  1663. ASSERT(uTmpLen == (cbFragPayloadSize));
  1664. }
  1665. if ((pDevice->byLocalID <= REV_ID_VT3253_A1)) {
  1666. if (bNeedEncrypt) {
  1667. s_vSWencryption(pDevice, pTransmitKey, (pbyBuffer + uLength), (unsigned short)cbFragPayloadSize);
  1668. cbReqCount += cbICVlen;
  1669. }
  1670. }
  1671. ptdCurr = (PSTxDesc)pHeadTD;
  1672. //--------------------
  1673. //1.Set TSR1 & ReqCount in TxDescHead
  1674. //2.Set FragCtl in TxBufferHead
  1675. //3.Set Frame Control
  1676. //4.Set Sequence Control
  1677. //5.Get S/W generate FCS
  1678. //--------------------
  1679. s_vFillFragParameter(pDevice, pbyBuffer, uDMAIdx, (void *)ptdCurr, wFragType, cbReqCount);
  1680. ptdCurr->pTDInfo->dwReqCount = cbReqCount - uPadding;
  1681. ptdCurr->pTDInfo->dwHeaderLength = cbHeaderLength;
  1682. ptdCurr->pTDInfo->skb_dma = ptdCurr->pTDInfo->buf_dma;
  1683. ptdCurr->buff_addr = cpu_to_le32(ptdCurr->pTDInfo->skb_dma);
  1684. pDevice->iTDUsed[uDMAIdx]++;
  1685. pHeadTD = ptdCurr->next;
  1686. }
  1687. } // for (uMACfragNum)
  1688. }
  1689. else {
  1690. //=========================
  1691. // No Fragmentation
  1692. //=========================
  1693. //DBG_PRTGRP03(("No Fragmentation...\n"));
  1694. //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"No Fragmentation...\n");
  1695. wFragType = FRAGCTL_NONFRAG;
  1696. //Set FragCtl in TxBufferHead
  1697. psTxBufHd->wFragCtl |= (unsigned short)wFragType;
  1698. //Fill FIFO,RrvTime,RTS,and CTS
  1699. s_vGenerateTxParameter(pDevice, byPktType, (void *)psTxBufHd, pvRrvTime, pvRTS, pvCTS,
  1700. cbFrameSize, bNeedACK, uDMAIdx, psEthHeader, pDevice->wCurrentRate);
  1701. //Fill DataHead
  1702. uDuration = s_uFillDataHead(pDevice, byPktType, pvTxDataHd, cbFrameSize, uDMAIdx, bNeedACK,
  1703. 0, 0, uMACfragNum, byFBOption, pDevice->wCurrentRate);
  1704. // Generate TX MAC Header
  1705. vGenerateMACHeader(pDevice, pbyMacHdr, (unsigned short)uDuration, psEthHeader, bNeedEncrypt,
  1706. wFragType, uDMAIdx, 0);
  1707. if (bNeedEncrypt == true) {
  1708. //Fill TXKEY
  1709. s_vFillTxKey(pDevice, (unsigned char *)(psTxBufHd->adwTxKey), pbyIVHead, pTransmitKey,
  1710. pbyMacHdr, (unsigned short)cbFrameBodySize, (unsigned char *)pMICHDR);
  1711. if (pDevice->bEnableHostWEP) {
  1712. pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16 = pTransmitKey->dwTSC47_16;
  1713. pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0 = pTransmitKey->wTSC15_0;
  1714. }
  1715. }
  1716. // 802.1H
  1717. if (ntohs(psEthHeader->wType) > ETH_DATA_LEN) {
  1718. if ((psEthHeader->wType == TYPE_PKT_IPX) ||
  1719. (psEthHeader->wType == cpu_to_le16(0xF380))) {
  1720. memcpy((unsigned char *) (pbyPayloadHead), &pDevice->abySNAP_Bridgetunnel[0], 6);
  1721. }
  1722. else {
  1723. memcpy((unsigned char *) (pbyPayloadHead), &pDevice->abySNAP_RFC1042[0], 6);
  1724. }
  1725. pbyType = (unsigned char *) (pbyPayloadHead + 6);
  1726. memcpy(pbyType, &(psEthHeader->wType), sizeof(unsigned short));
  1727. cb802_1_H_len = 8;
  1728. }
  1729. cbReqCount = cbHeaderLength + cbMACHdLen + uPadding + cbIVlen + (cbFrameBodySize + cbMIClen);
  1730. //---------------------------
  1731. // S/W or H/W Encryption
  1732. //---------------------------
  1733. //Fill MICHDR
  1734. //if (pDevice->bAES) {
  1735. // DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Fill MICHDR...\n");
  1736. // s_vFillMICHDR(pDevice, (unsigned char *)pMICHDR, pbyMacHdr, (unsigned short)cbFrameBodySize);
  1737. //}
  1738. pbyBuffer = (unsigned char *)pHeadTD->pTDInfo->buf;
  1739. //pbyBuffer = (unsigned char *)pDevice->aamTxBuf[uDMAIdx][uDescIdx].pbyVAddr;
  1740. uLength = cbHeaderLength + cbMACHdLen + uPadding + cbIVlen + cb802_1_H_len;
  1741. //copy TxBufferHeader + MacHeader to desc
  1742. memcpy(pbyBuffer, (void *)psTxBufHd, uLength);
  1743. // Copy the Packet into a tx Buffer
  1744. memcpy((pbyBuffer + uLength),
  1745. (pPacket + 14),
  1746. cbFrameBodySize - cb802_1_H_len
  1747. );
  1748. if ((bNeedEncrypt == true) && (pTransmitKey != NULL) && (pTransmitKey->byCipherSuite == KEY_CTL_TKIP)){
  1749. DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Length:%d, %d\n", cbFrameBodySize - cb802_1_H_len, uLength);
  1750. /*
  1751. for (ii = 0; ii < (cbFrameBodySize - cb802_1_H_len); ii++) {
  1752. DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"%02x ", *((unsigned char *)((pbyBuffer + uLength) + ii)));
  1753. }
  1754. DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"\n");
  1755. */
  1756. MIC_vAppend((pbyBuffer + uLength - cb802_1_H_len), cbFrameBodySize);
  1757. pdwMIC_L = (unsigned long *)(pbyBuffer + uLength - cb802_1_H_len + cbFrameBodySize);
  1758. pdwMIC_R = (unsigned long *)(pbyBuffer + uLength - cb802_1_H_len + cbFrameBodySize + 4);
  1759. MIC_vGetMIC(pdwMIC_L, pdwMIC_R);
  1760. MIC_vUnInit();
  1761. if (pDevice->bTxMICFail == true) {
  1762. *pdwMIC_L = 0;
  1763. *pdwMIC_R = 0;
  1764. pDevice->bTxMICFail = false;
  1765. }
  1766. DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"uLength: %d, %d\n", uLength, cbFrameBodySize);
  1767. DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"cbReqCount:%d, %d, %d, %d\n", cbReqCount, cbHeaderLength, uPadding, cbIVlen);
  1768. DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"MIC:%lx, %lx\n", *pdwMIC_L, *pdwMIC_R);
  1769. /*
  1770. for (ii = 0; ii < 8; ii++) {
  1771. DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"%02x ", *(((unsigned char *)(pdwMIC_L) + ii)));
  1772. }
  1773. DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"\n");
  1774. */
  1775. }
  1776. if ((pDevice->byLocalID <= REV_ID_VT3253_A1)){
  1777. if (bNeedEncrypt) {
  1778. s_vSWencryption(pDevice, pTransmitKey, (pbyBuffer + uLength - cb802_1_H_len),
  1779. (unsigned short)(cbFrameBodySize + cbMIClen));
  1780. cbReqCount += cbICVlen;
  1781. }
  1782. }
  1783. ptdCurr = (PSTxDesc)pHeadTD;
  1784. ptdCurr->pTDInfo->dwReqCount = cbReqCount - uPadding;
  1785. ptdCurr->pTDInfo->dwHeaderLength = cbHeaderLength;
  1786. ptdCurr->pTDInfo->skb_dma = ptdCurr->pTDInfo->buf_dma;
  1787. ptdCurr->buff_addr = cpu_to_le32(ptdCurr->pTDInfo->skb_dma);
  1788. //Set TSR1 & ReqCount in TxDescHead
  1789. ptdCurr->m_td1TD1.byTCR |= (TCR_STP | TCR_EDP | EDMSDU);
  1790. ptdCurr->m_td1TD1.wReqCount = cpu_to_le16((unsigned short)(cbReqCount));
  1791. pDevice->iTDUsed[uDMAIdx]++;
  1792. // DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO" ptdCurr->m_dwReserved0[%d] ptdCurr->m_dwReserved1[%d].\n", ptdCurr->pTDInfo->dwReqCount, ptdCurr->pTDInfo->dwHeaderLength);
  1793. // DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO" cbHeaderLength[%d]\n", cbHeaderLength);
  1794. }
  1795. *puMACfragNum = uMACfragNum;
  1796. //DBG_PRTGRP03(("s_cbFillTxBufHead END\n"));
  1797. return cbHeaderLength;
  1798. }
  1799. void
  1800. vGenerateFIFOHeader(PSDevice pDevice, unsigned char byPktType, unsigned char *pbyTxBufferAddr,
  1801. bool bNeedEncrypt, unsigned int cbPayloadSize, unsigned int uDMAIdx,
  1802. PSTxDesc pHeadTD, PSEthernetHeader psEthHeader, unsigned char *pPacket,
  1803. PSKeyItem pTransmitKey, unsigned int uNodeIndex, unsigned int *puMACfragNum,
  1804. unsigned int *pcbHeaderSize)
  1805. {
  1806. unsigned int wTxBufSize; // FFinfo size
  1807. bool bNeedACK;
  1808. bool bIsAdhoc;
  1809. unsigned short cbMacHdLen;
  1810. PSTxBufHead pTxBufHead = (PSTxBufHead) pbyTxBufferAddr;
  1811. wTxBufSize = sizeof(STxBufHead);
  1812. memset(pTxBufHead, 0, wTxBufSize);
  1813. //Set FIFOCTL_NEEDACK
  1814. if ((pDevice->eOPMode == OP_MODE_ADHOC) ||
  1815. (pDevice->eOPMode == OP_MODE_AP)) {
  1816. if (is_multicast_ether_addr(&(psEthHeader->abyDstAddr[0]))) {
  1817. bNeedACK = false;
  1818. pTxBufHead->wFIFOCtl = pTxBufHead->wFIFOCtl & (~FIFOCTL_NEEDACK);
  1819. }
  1820. else {
  1821. bNeedACK = true;
  1822. pTxBufHead->wFIFOCtl |= FIFOCTL_NEEDACK;
  1823. }
  1824. bIsAdhoc = true;
  1825. }
  1826. else {
  1827. // MSDUs in Infra mode always need ACK
  1828. bNeedACK = true;
  1829. pTxBufHead->wFIFOCtl |= FIFOCTL_NEEDACK;
  1830. bIsAdhoc = false;
  1831. }
  1832. pTxBufHead->wFIFOCtl |= FIFOCTL_TMOEN;
  1833. pTxBufHead->wTimeStamp = cpu_to_le16(DEFAULT_MSDU_LIFETIME_RES_64us);
  1834. //Set FIFOCTL_LHEAD
  1835. if (pDevice->bLongHeader)
  1836. pTxBufHead->wFIFOCtl |= FIFOCTL_LHEAD;
  1837. //Set FIFOCTL_GENINT
  1838. pTxBufHead->wFIFOCtl |= FIFOCTL_GENINT;
  1839. //Set FIFOCTL_ISDMA0
  1840. if (TYPE_TXDMA0 == uDMAIdx) {
  1841. pTxBufHead->wFIFOCtl |= FIFOCTL_ISDMA0;
  1842. }
  1843. //Set FRAGCTL_MACHDCNT
  1844. if (pDevice->bLongHeader) {
  1845. cbMacHdLen = WLAN_HDR_ADDR3_LEN + 6;
  1846. } else {
  1847. cbMacHdLen = WLAN_HDR_ADDR3_LEN;
  1848. }
  1849. pTxBufHead->wFragCtl |= cpu_to_le16((unsigned short)(cbMacHdLen << 10));
  1850. //Set packet type
  1851. if (byPktType == PK_TYPE_11A) {//0000 0000 0000 0000
  1852. ;
  1853. }
  1854. else if (byPktType == PK_TYPE_11B) {//0000 0001 0000 0000
  1855. pTxBufHead->wFIFOCtl |= FIFOCTL_11B;
  1856. }
  1857. else if (byPktType == PK_TYPE_11GB) {//0000 0010 0000 0000
  1858. pTxBufHead->wFIFOCtl |= FIFOCTL_11GB;
  1859. }
  1860. else if (byPktType == PK_TYPE_11GA) {//0000 0011 0000 0000
  1861. pTxBufHead->wFIFOCtl |= FIFOCTL_11GA;
  1862. }
  1863. //Set FIFOCTL_GrpAckPolicy
  1864. if (pDevice->bGrpAckPolicy == true) {//0000 0100 0000 0000
  1865. pTxBufHead->wFIFOCtl |= FIFOCTL_GRPACK;
  1866. }
  1867. //Set Auto Fallback Ctl
  1868. if (pDevice->wCurrentRate >= RATE_18M) {
  1869. if (pDevice->byAutoFBCtrl == AUTO_FB_0) {
  1870. pTxBufHead->wFIFOCtl |= FIFOCTL_AUTO_FB_0;
  1871. } else if (pDevice->byAutoFBCtrl == AUTO_FB_1) {
  1872. pTxBufHead->wFIFOCtl |= FIFOCTL_AUTO_FB_1;
  1873. }
  1874. }
  1875. //Set FRAGCTL_WEPTYP
  1876. pDevice->bAES = false;
  1877. //Set FRAGCTL_WEPTYP
  1878. if (pDevice->byLocalID > REV_ID_VT3253_A1) {
  1879. if ((bNeedEncrypt) && (pTransmitKey != NULL)) { //WEP enabled
  1880. if (pTransmitKey->byCipherSuite == KEY_CTL_TKIP) {
  1881. pTxBufHead->wFragCtl |= FRAGCTL_TKIP;
  1882. }
  1883. else if (pTransmitKey->byCipherSuite == KEY_CTL_WEP) { //WEP40 or WEP104
  1884. if (pTransmitKey->uKeyLength != WLAN_WEP232_KEYLEN)
  1885. pTxBufHead->wFragCtl |= FRAGCTL_LEGACY;
  1886. }
  1887. else if (pTransmitKey->byCipherSuite == KEY_CTL_CCMP) { //CCMP
  1888. pTxBufHead->wFragCtl |= FRAGCTL_AES;
  1889. }
  1890. }
  1891. }
  1892. #ifdef PLICE_DEBUG
  1893. //printk("Func:vGenerateFIFOHeader:TxDataRate is %d,TxPower is %d\n",pDevice->wCurrentRate,pDevice->byCurPwr);
  1894. //if (pDevice->wCurrentRate <= 3)
  1895. //{
  1896. // RFbRawSetPower(pDevice,36,pDevice->wCurrentRate);
  1897. //}
  1898. //else
  1899. RFbSetPower(pDevice, pDevice->wCurrentRate, pDevice->byCurrentCh);
  1900. #endif
  1901. //if (pDevice->wCurrentRate == 3)
  1902. //pDevice->byCurPwr = 46;
  1903. pTxBufHead->byTxPower = pDevice->byCurPwr;
  1904. /*
  1905. if(pDevice->bEnableHostWEP)
  1906. pTxBufHead->wFragCtl &= ~(FRAGCTL_TKIP | FRAGCTL_LEGACY |FRAGCTL_AES);
  1907. */
  1908. *pcbHeaderSize = s_cbFillTxBufHead(pDevice, byPktType, pbyTxBufferAddr, cbPayloadSize,
  1909. uDMAIdx, pHeadTD, psEthHeader, pPacket, bNeedEncrypt,
  1910. pTransmitKey, uNodeIndex, puMACfragNum);
  1911. return;
  1912. }
  1913. /*+
  1914. *
  1915. * Description:
  1916. * Translate 802.3 to 802.11 header
  1917. *
  1918. * Parameters:
  1919. * In:
  1920. * pDevice - Pointer to adapter
  1921. * dwTxBufferAddr - Transmit Buffer
  1922. * pPacket - Packet from upper layer
  1923. * cbPacketSize - Transmit Data Length
  1924. * Out:
  1925. * pcbHeadSize - Header size of MAC&Baseband control and 802.11 Header
  1926. * pcbAppendPayload - size of append payload for 802.1H translation
  1927. *
  1928. * Return Value: none
  1929. *
  1930. -*/
  1931. void
  1932. vGenerateMACHeader (
  1933. PSDevice pDevice,
  1934. unsigned char *pbyBufferAddr,
  1935. unsigned short wDuration,
  1936. PSEthernetHeader psEthHeader,
  1937. bool bNeedEncrypt,
  1938. unsigned short wFragType,
  1939. unsigned int uDMAIdx,
  1940. unsigned int uFragIdx
  1941. )
  1942. {
  1943. PS802_11Header pMACHeader = (PS802_11Header)pbyBufferAddr;
  1944. memset(pMACHeader, 0, (sizeof(S802_11Header))); //- sizeof(pMACHeader->dwIV)));
  1945. if (uDMAIdx == TYPE_ATIMDMA) {
  1946. pMACHeader->wFrameCtl = TYPE_802_11_ATIM;
  1947. } else {
  1948. pMACHeader->wFrameCtl = TYPE_802_11_DATA;
  1949. }
  1950. if (pDevice->eOPMode == OP_MODE_AP) {
  1951. memcpy(&(pMACHeader->abyAddr1[0]), &(psEthHeader->abyDstAddr[0]), ETH_ALEN);
  1952. memcpy(&(pMACHeader->abyAddr2[0]), &(pDevice->abyBSSID[0]), ETH_ALEN);
  1953. memcpy(&(pMACHeader->abyAddr3[0]), &(psEthHeader->abySrcAddr[0]), ETH_ALEN);
  1954. pMACHeader->wFrameCtl |= FC_FROMDS;
  1955. }
  1956. else {
  1957. if (pDevice->eOPMode == OP_MODE_ADHOC) {
  1958. memcpy(&(pMACHeader->abyAddr1[0]), &(psEthHeader->abyDstAddr[0]), ETH_ALEN);
  1959. memcpy(&(pMACHeader->abyAddr2[0]), &(psEthHeader->abySrcAddr[0]), ETH_ALEN);
  1960. memcpy(&(pMACHeader->abyAddr3[0]), &(pDevice->abyBSSID[0]), ETH_ALEN);
  1961. }
  1962. else {
  1963. memcpy(&(pMACHeader->abyAddr3[0]), &(psEthHeader->abyDstAddr[0]), ETH_ALEN);
  1964. memcpy(&(pMACHeader->abyAddr2[0]), &(psEthHeader->abySrcAddr[0]), ETH_ALEN);
  1965. memcpy(&(pMACHeader->abyAddr1[0]), &(pDevice->abyBSSID[0]), ETH_ALEN);
  1966. pMACHeader->wFrameCtl |= FC_TODS;
  1967. }
  1968. }
  1969. if (bNeedEncrypt)
  1970. pMACHeader->wFrameCtl |= cpu_to_le16((unsigned short)WLAN_SET_FC_ISWEP(1));
  1971. pMACHeader->wDurationID = cpu_to_le16(wDuration);
  1972. if (pDevice->bLongHeader) {
  1973. PWLAN_80211HDR_A4 pMACA4Header = (PWLAN_80211HDR_A4) pbyBufferAddr;
  1974. pMACHeader->wFrameCtl |= (FC_TODS | FC_FROMDS);
  1975. memcpy(pMACA4Header->abyAddr4, pDevice->abyBSSID, WLAN_ADDR_LEN);
  1976. }
  1977. pMACHeader->wSeqCtl = cpu_to_le16(pDevice->wSeqCounter << 4);
  1978. //Set FragNumber in Sequence Control
  1979. pMACHeader->wSeqCtl |= cpu_to_le16((unsigned short)uFragIdx);
  1980. if ((wFragType == FRAGCTL_ENDFRAG) || (wFragType == FRAGCTL_NONFRAG)) {
  1981. pDevice->wSeqCounter++;
  1982. if (pDevice->wSeqCounter > 0x0fff)
  1983. pDevice->wSeqCounter = 0;
  1984. }
  1985. if ((wFragType == FRAGCTL_STAFRAG) || (wFragType == FRAGCTL_MIDFRAG)) { //StartFrag or MidFrag
  1986. pMACHeader->wFrameCtl |= FC_MOREFRAG;
  1987. }
  1988. }
  1989. CMD_STATUS csMgmt_xmit(PSDevice pDevice, PSTxMgmtPacket pPacket) {
  1990. PSTxDesc pFrstTD;
  1991. unsigned char byPktType;
  1992. unsigned char *pbyTxBufferAddr;
  1993. void * pvRTS;
  1994. PSCTS pCTS;
  1995. void * pvTxDataHd;
  1996. unsigned int uDuration;
  1997. unsigned int cbReqCount;
  1998. PS802_11Header pMACHeader;
  1999. unsigned int cbHeaderSize;
  2000. unsigned int cbFrameBodySize;
  2001. bool bNeedACK;
  2002. bool bIsPSPOLL = false;
  2003. PSTxBufHead pTxBufHead;
  2004. unsigned int cbFrameSize;
  2005. unsigned int cbIVlen = 0;
  2006. unsigned int cbICVlen = 0;
  2007. unsigned int cbMIClen = 0;
  2008. unsigned int cbFCSlen = 4;
  2009. unsigned int uPadding = 0;
  2010. unsigned short wTxBufSize;
  2011. unsigned int cbMacHdLen;
  2012. SEthernetHeader sEthHeader;
  2013. void * pvRrvTime;
  2014. void * pMICHDR;
  2015. PSMgmtObject pMgmt = pDevice->pMgmt;
  2016. unsigned short wCurrentRate = RATE_1M;
  2017. if (AVAIL_TD(pDevice, TYPE_TXDMA0) <= 0) {
  2018. return CMD_STATUS_RESOURCES;
  2019. }
  2020. pFrstTD = pDevice->apCurrTD[TYPE_TXDMA0];
  2021. pbyTxBufferAddr = (unsigned char *)pFrstTD->pTDInfo->buf;
  2022. cbFrameBodySize = pPacket->cbPayloadLen;
  2023. pTxBufHead = (PSTxBufHead) pbyTxBufferAddr;
  2024. wTxBufSize = sizeof(STxBufHead);
  2025. memset(pTxBufHead, 0, wTxBufSize);
  2026. if (pDevice->eCurrentPHYType == PHY_TYPE_11A) {
  2027. wCurrentRate = RATE_6M;
  2028. byPktType = PK_TYPE_11A;
  2029. } else {
  2030. wCurrentRate = RATE_1M;
  2031. byPktType = PK_TYPE_11B;
  2032. }
  2033. // SetPower will cause error power TX state for OFDM Date packet in TX buffer.
  2034. // 2004.11.11 Kyle -- Using OFDM power to tx MngPkt will decrease the connection capability.
  2035. // And cmd timer will wait data pkt TX finish before scanning so it's OK
  2036. // to set power here.
  2037. if (pDevice->pMgmt->eScanState != WMAC_NO_SCANNING) {
  2038. RFbSetPower(pDevice, wCurrentRate, pDevice->byCurrentCh);
  2039. } else {
  2040. RFbSetPower(pDevice, wCurrentRate, pMgmt->uCurrChannel);
  2041. }
  2042. pTxBufHead->byTxPower = pDevice->byCurPwr;
  2043. //+++++++++++++++++++++ Patch VT3253 A1 performance +++++++++++++++++++++++++++
  2044. if (pDevice->byFOETuning) {
  2045. if ((pPacket->p80211Header->sA3.wFrameCtl & TYPE_DATE_NULL) == TYPE_DATE_NULL) {
  2046. wCurrentRate = RATE_24M;
  2047. byPktType = PK_TYPE_11GA;
  2048. }
  2049. }
  2050. //Set packet type
  2051. if (byPktType == PK_TYPE_11A) {//0000 0000 0000 0000
  2052. pTxBufHead->wFIFOCtl = 0;
  2053. }
  2054. else if (byPktType == PK_TYPE_11B) {//0000 0001 0000 0000
  2055. pTxBufHead->wFIFOCtl |= FIFOCTL_11B;
  2056. }
  2057. else if (byPktType == PK_TYPE_11GB) {//0000 0010 0000 0000
  2058. pTxBufHead->wFIFOCtl |= FIFOCTL_11GB;
  2059. }
  2060. else if (byPktType == PK_TYPE_11GA) {//0000 0011 0000 0000
  2061. pTxBufHead->wFIFOCtl |= FIFOCTL_11GA;
  2062. }
  2063. pTxBufHead->wFIFOCtl |= FIFOCTL_TMOEN;
  2064. pTxBufHead->wTimeStamp = cpu_to_le16(DEFAULT_MGN_LIFETIME_RES_64us);
  2065. if (is_multicast_ether_addr(&(pPacket->p80211Header->sA3.abyAddr1[0])))
  2066. bNeedACK = false;
  2067. else {
  2068. bNeedACK = true;
  2069. pTxBufHead->wFIFOCtl |= FIFOCTL_NEEDACK;
  2070. };
  2071. if ((pMgmt->eCurrMode == WMAC_MODE_ESS_AP) ||
  2072. (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) ) {
  2073. pTxBufHead->wFIFOCtl |= FIFOCTL_LRETRY;
  2074. //Set Preamble type always long
  2075. //pDevice->byPreambleType = PREAMBLE_LONG;
  2076. // probe-response don't retry
  2077. //if ((pPacket->p80211Header->sA4.wFrameCtl & TYPE_SUBTYPE_MASK) == TYPE_MGMT_PROBE_RSP) {
  2078. // bNeedACK = false;
  2079. // pTxBufHead->wFIFOCtl &= (~FIFOCTL_NEEDACK);
  2080. //}
  2081. }
  2082. pTxBufHead->wFIFOCtl |= (FIFOCTL_GENINT | FIFOCTL_ISDMA0);
  2083. if ((pPacket->p80211Header->sA4.wFrameCtl & TYPE_SUBTYPE_MASK) == TYPE_CTL_PSPOLL) {
  2084. bIsPSPOLL = true;
  2085. cbMacHdLen = WLAN_HDR_ADDR2_LEN;
  2086. } else {
  2087. cbMacHdLen = WLAN_HDR_ADDR3_LEN;
  2088. }
  2089. //Set FRAGCTL_MACHDCNT
  2090. pTxBufHead->wFragCtl |= cpu_to_le16((unsigned short)(cbMacHdLen << 10));
  2091. // Notes:
  2092. // Although spec says MMPDU can be fragmented; In most case,
  2093. // no one will send a MMPDU under fragmentation. With RTS may occur.
  2094. pDevice->bAES = false; //Set FRAGCTL_WEPTYP
  2095. if (WLAN_GET_FC_ISWEP(pPacket->p80211Header->sA4.wFrameCtl) != 0) {
  2096. if (pDevice->eEncryptionStatus == Ndis802_11Encryption1Enabled) {
  2097. cbIVlen = 4;
  2098. cbICVlen = 4;
  2099. pTxBufHead->wFragCtl |= FRAGCTL_LEGACY;
  2100. }
  2101. else if (pDevice->eEncryptionStatus == Ndis802_11Encryption2Enabled) {
  2102. cbIVlen = 8;//IV+ExtIV
  2103. cbMIClen = 8;
  2104. cbICVlen = 4;
  2105. pTxBufHead->wFragCtl |= FRAGCTL_TKIP;
  2106. //We need to get seed here for filling TxKey entry.
  2107. //TKIPvMixKey(pTransmitKey->abyKey, pDevice->abyCurrentNetAddr,
  2108. // pTransmitKey->wTSC15_0, pTransmitKey->dwTSC47_16, pDevice->abyPRNG);
  2109. }
  2110. else if (pDevice->eEncryptionStatus == Ndis802_11Encryption3Enabled) {
  2111. cbIVlen = 8;//RSN Header
  2112. cbICVlen = 8;//MIC
  2113. pTxBufHead->wFragCtl |= FRAGCTL_AES;
  2114. pDevice->bAES = true;
  2115. }
  2116. //MAC Header should be padding 0 to DW alignment.
  2117. uPadding = 4 - (cbMacHdLen%4);
  2118. uPadding %= 4;
  2119. }
  2120. cbFrameSize = cbMacHdLen + cbFrameBodySize + cbIVlen + cbMIClen + cbICVlen + cbFCSlen;
  2121. //Set FIFOCTL_GrpAckPolicy
  2122. if (pDevice->bGrpAckPolicy == true) {//0000 0100 0000 0000
  2123. pTxBufHead->wFIFOCtl |= FIFOCTL_GRPACK;
  2124. }
  2125. //the rest of pTxBufHead->wFragCtl:FragTyp will be set later in s_vFillFragParameter()
  2126. //Set RrvTime/RTS/CTS Buffer
  2127. if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {//802.11g packet
  2128. pvRrvTime = (PSRrvTime_gCTS) (pbyTxBufferAddr + wTxBufSize);
  2129. pMICHDR = NULL;
  2130. pvRTS = NULL;
  2131. pCTS = (PSCTS) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_gCTS));
  2132. pvTxDataHd = (PSTxDataHead_g) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_gCTS) + sizeof(SCTS));
  2133. cbHeaderSize = wTxBufSize + sizeof(SRrvTime_gCTS) + sizeof(SCTS) + sizeof(STxDataHead_g);
  2134. }
  2135. else { // 802.11a/b packet
  2136. pvRrvTime = (PSRrvTime_ab) (pbyTxBufferAddr + wTxBufSize);
  2137. pMICHDR = NULL;
  2138. pvRTS = NULL;
  2139. pCTS = NULL;
  2140. pvTxDataHd = (PSTxDataHead_ab) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_ab));
  2141. cbHeaderSize = wTxBufSize + sizeof(SRrvTime_ab) + sizeof(STxDataHead_ab);
  2142. }
  2143. memset((void *)(pbyTxBufferAddr + wTxBufSize), 0, (cbHeaderSize - wTxBufSize));
  2144. memcpy(&(sEthHeader.abyDstAddr[0]), &(pPacket->p80211Header->sA3.abyAddr1[0]), ETH_ALEN);
  2145. memcpy(&(sEthHeader.abySrcAddr[0]), &(pPacket->p80211Header->sA3.abyAddr2[0]), ETH_ALEN);
  2146. //=========================
  2147. // No Fragmentation
  2148. //=========================
  2149. pTxBufHead->wFragCtl |= (unsigned short)FRAGCTL_NONFRAG;
  2150. //Fill FIFO,RrvTime,RTS,and CTS
  2151. s_vGenerateTxParameter(pDevice, byPktType, pbyTxBufferAddr, pvRrvTime, pvRTS, pCTS,
  2152. cbFrameSize, bNeedACK, TYPE_TXDMA0, &sEthHeader, wCurrentRate);
  2153. //Fill DataHead
  2154. uDuration = s_uFillDataHead(pDevice, byPktType, pvTxDataHd, cbFrameSize, TYPE_TXDMA0, bNeedACK,
  2155. 0, 0, 1, AUTO_FB_NONE, wCurrentRate);
  2156. pMACHeader = (PS802_11Header) (pbyTxBufferAddr + cbHeaderSize);
  2157. cbReqCount = cbHeaderSize + cbMacHdLen + uPadding + cbIVlen + cbFrameBodySize;
  2158. if (WLAN_GET_FC_ISWEP(pPacket->p80211Header->sA4.wFrameCtl) != 0) {
  2159. unsigned char *pbyIVHead;
  2160. unsigned char *pbyPayloadHead;
  2161. unsigned char *pbyBSSID;
  2162. PSKeyItem pTransmitKey = NULL;
  2163. pbyIVHead = (unsigned char *)(pbyTxBufferAddr + cbHeaderSize + cbMacHdLen + uPadding);
  2164. pbyPayloadHead = (unsigned char *)(pbyTxBufferAddr + cbHeaderSize + cbMacHdLen + uPadding + cbIVlen);
  2165. //Fill TXKEY
  2166. //Kyle: Need fix: TKIP and AES did't encryt Mnt Packet.
  2167. //s_vFillTxKey(pDevice, (unsigned char *)pTxBufHead->adwTxKey, NULL);
  2168. //Fill IV(ExtIV,RSNHDR)
  2169. //s_vFillPrePayload(pDevice, pbyIVHead, NULL);
  2170. //---------------------------
  2171. // S/W or H/W Encryption
  2172. //---------------------------
  2173. //Fill MICHDR
  2174. //if (pDevice->bAES) {
  2175. // s_vFillMICHDR(pDevice, (unsigned char *)pMICHDR, (unsigned char *)pMACHeader, (unsigned short)cbFrameBodySize);
  2176. //}
  2177. do {
  2178. if ((pDevice->eOPMode == OP_MODE_INFRASTRUCTURE) &&
  2179. (pDevice->bLinkPass == true)) {
  2180. pbyBSSID = pDevice->abyBSSID;
  2181. // get pairwise key
  2182. if (KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, PAIRWISE_KEY, &pTransmitKey) == false) {
  2183. // get group key
  2184. if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == true) {
  2185. DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Get GTK.\n");
  2186. break;
  2187. }
  2188. } else {
  2189. DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Get PTK.\n");
  2190. break;
  2191. }
  2192. }
  2193. // get group key
  2194. pbyBSSID = pDevice->abyBroadcastAddr;
  2195. if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == false) {
  2196. pTransmitKey = NULL;
  2197. DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"KEY is NULL. OP Mode[%d]\n", pDevice->eOPMode);
  2198. } else {
  2199. DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Get GTK.\n");
  2200. }
  2201. } while(false);
  2202. //Fill TXKEY
  2203. s_vFillTxKey(pDevice, (unsigned char *)(pTxBufHead->adwTxKey), pbyIVHead, pTransmitKey,
  2204. (unsigned char *)pMACHeader, (unsigned short)cbFrameBodySize, NULL);
  2205. memcpy(pMACHeader, pPacket->p80211Header, cbMacHdLen);
  2206. memcpy(pbyPayloadHead, ((unsigned char *)(pPacket->p80211Header) + cbMacHdLen),
  2207. cbFrameBodySize);
  2208. }
  2209. else {
  2210. // Copy the Packet into a tx Buffer
  2211. memcpy(pMACHeader, pPacket->p80211Header, pPacket->cbMPDULen);
  2212. }
  2213. pMACHeader->wSeqCtl = cpu_to_le16(pDevice->wSeqCounter << 4);
  2214. pDevice->wSeqCounter++ ;
  2215. if (pDevice->wSeqCounter > 0x0fff)
  2216. pDevice->wSeqCounter = 0;
  2217. if (bIsPSPOLL) {
  2218. // The MAC will automatically replace the Duration-field of MAC header by Duration-field
  2219. // of FIFO control header.
  2220. // This will cause AID-field of PS-POLL packet be incorrect (Because PS-POLL's AID field is
  2221. // in the same place of other packet's Duration-field).
  2222. // And it will cause Cisco-AP to issue Disassociation-packet
  2223. if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {
  2224. ((PSTxDataHead_g)pvTxDataHd)->wDuration_a = cpu_to_le16(pPacket->p80211Header->sA2.wDurationID);
  2225. ((PSTxDataHead_g)pvTxDataHd)->wDuration_b = cpu_to_le16(pPacket->p80211Header->sA2.wDurationID);
  2226. } else {
  2227. ((PSTxDataHead_ab)pvTxDataHd)->wDuration = cpu_to_le16(pPacket->p80211Header->sA2.wDurationID);
  2228. }
  2229. }
  2230. // first TD is the only TD
  2231. //Set TSR1 & ReqCount in TxDescHead
  2232. pFrstTD->m_td1TD1.byTCR = (TCR_STP | TCR_EDP | EDMSDU);
  2233. pFrstTD->pTDInfo->skb_dma = pFrstTD->pTDInfo->buf_dma;
  2234. pFrstTD->m_td1TD1.wReqCount = cpu_to_le16((unsigned short)(cbReqCount));
  2235. pFrstTD->buff_addr = cpu_to_le32(pFrstTD->pTDInfo->skb_dma);
  2236. pFrstTD->pTDInfo->byFlags = 0;
  2237. if (MACbIsRegBitsOn(pDevice->PortOffset, MAC_REG_PSCTL, PSCTL_PS)) {
  2238. // Disable PS
  2239. MACbPSWakeup(pDevice->PortOffset);
  2240. }
  2241. pDevice->bPWBitOn = false;
  2242. wmb();
  2243. pFrstTD->m_td0TD0.f1Owner = OWNED_BY_NIC;
  2244. wmb();
  2245. pDevice->iTDUsed[TYPE_TXDMA0]++;
  2246. if (AVAIL_TD(pDevice, TYPE_TXDMA0) <= 1) {
  2247. DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " available td0 <= 1\n");
  2248. }
  2249. pDevice->apCurrTD[TYPE_TXDMA0] = pFrstTD->next;
  2250. #ifdef PLICE_DEBUG
  2251. //printk("SCAN:CurrentRate is %d,TxPower is %d\n",wCurrentRate,pTxBufHead->byTxPower);
  2252. #endif
  2253. #ifdef TxInSleep
  2254. pDevice->nTxDataTimeCout=0; //2008-8-21 chester <add> for send null packet
  2255. #endif
  2256. // Poll Transmit the adapter
  2257. MACvTransmit0(pDevice->PortOffset);
  2258. return CMD_STATUS_PENDING;
  2259. }
  2260. CMD_STATUS csBeacon_xmit(PSDevice pDevice, PSTxMgmtPacket pPacket) {
  2261. unsigned char byPktType;
  2262. unsigned char *pbyBuffer = (unsigned char *)pDevice->tx_beacon_bufs;
  2263. unsigned int cbFrameSize = pPacket->cbMPDULen + WLAN_FCS_LEN;
  2264. unsigned int cbHeaderSize = 0;
  2265. unsigned short wTxBufSize = sizeof(STxShortBufHead);
  2266. PSTxShortBufHead pTxBufHead = (PSTxShortBufHead) pbyBuffer;
  2267. PSTxDataHead_ab pTxDataHead = (PSTxDataHead_ab) (pbyBuffer + wTxBufSize);
  2268. PS802_11Header pMACHeader;
  2269. unsigned short wCurrentRate;
  2270. unsigned short wLen = 0x0000;
  2271. memset(pTxBufHead, 0, wTxBufSize);
  2272. if (pDevice->eCurrentPHYType == PHY_TYPE_11A) {
  2273. wCurrentRate = RATE_6M;
  2274. byPktType = PK_TYPE_11A;
  2275. } else {
  2276. wCurrentRate = RATE_2M;
  2277. byPktType = PK_TYPE_11B;
  2278. }
  2279. //Set Preamble type always long
  2280. pDevice->byPreambleType = PREAMBLE_LONG;
  2281. //Set FIFOCTL_GENINT
  2282. pTxBufHead->wFIFOCtl |= FIFOCTL_GENINT;
  2283. //Set packet type & Get Duration
  2284. if (byPktType == PK_TYPE_11A) {//0000 0000 0000 0000
  2285. pTxDataHead->wDuration = cpu_to_le16((unsigned short)s_uGetDataDuration(pDevice, DATADUR_A, cbFrameSize, byPktType,
  2286. wCurrentRate, false, 0, 0, 1, AUTO_FB_NONE));
  2287. }
  2288. else if (byPktType == PK_TYPE_11B) {//0000 0001 0000 0000
  2289. pTxBufHead->wFIFOCtl |= FIFOCTL_11B;
  2290. pTxDataHead->wDuration = cpu_to_le16((unsigned short)s_uGetDataDuration(pDevice, DATADUR_B, cbFrameSize, byPktType,
  2291. wCurrentRate, false, 0, 0, 1, AUTO_FB_NONE));
  2292. }
  2293. BBvCaculateParameter(pDevice, cbFrameSize, wCurrentRate, byPktType,
  2294. (unsigned short *)&(wLen), (unsigned char *)&(pTxDataHead->byServiceField), (unsigned char *)&(pTxDataHead->bySignalField)
  2295. );
  2296. pTxDataHead->wTransmitLength = cpu_to_le16(wLen);
  2297. //Get TimeStampOff
  2298. pTxDataHead->wTimeStampOff = cpu_to_le16(wTimeStampOff[pDevice->byPreambleType%2][wCurrentRate%MAX_RATE]);
  2299. cbHeaderSize = wTxBufSize + sizeof(STxDataHead_ab);
  2300. //Generate Beacon Header
  2301. pMACHeader = (PS802_11Header)(pbyBuffer + cbHeaderSize);
  2302. memcpy(pMACHeader, pPacket->p80211Header, pPacket->cbMPDULen);
  2303. pMACHeader->wDurationID = 0;
  2304. pMACHeader->wSeqCtl = cpu_to_le16(pDevice->wSeqCounter << 4);
  2305. pDevice->wSeqCounter++ ;
  2306. if (pDevice->wSeqCounter > 0x0fff)
  2307. pDevice->wSeqCounter = 0;
  2308. // Set Beacon buffer length
  2309. pDevice->wBCNBufLen = pPacket->cbMPDULen + cbHeaderSize;
  2310. MACvSetCurrBCNTxDescAddr(pDevice->PortOffset, (pDevice->tx_beacon_dma));
  2311. MACvSetCurrBCNLength(pDevice->PortOffset, pDevice->wBCNBufLen);
  2312. // Set auto Transmit on
  2313. MACvRegBitsOn(pDevice->PortOffset, MAC_REG_TCR, TCR_AUTOBCNTX);
  2314. // Poll Transmit the adapter
  2315. MACvTransmitBCN(pDevice->PortOffset);
  2316. return CMD_STATUS_PENDING;
  2317. }
  2318. unsigned int
  2319. cbGetFragCount (
  2320. PSDevice pDevice,
  2321. PSKeyItem pTransmitKey,
  2322. unsigned int cbFrameBodySize,
  2323. PSEthernetHeader psEthHeader
  2324. )
  2325. {
  2326. unsigned int cbMACHdLen;
  2327. unsigned int cbFrameSize;
  2328. unsigned int cbFragmentSize; //Hdr+(IV)+payoad+(MIC)+(ICV)+FCS
  2329. unsigned int cbFragPayloadSize;
  2330. unsigned int cbLastFragPayloadSize;
  2331. unsigned int cbIVlen = 0;
  2332. unsigned int cbICVlen = 0;
  2333. unsigned int cbMIClen = 0;
  2334. unsigned int cbFCSlen = 4;
  2335. unsigned int uMACfragNum = 1;
  2336. bool bNeedACK;
  2337. if ((pDevice->eOPMode == OP_MODE_ADHOC) ||
  2338. (pDevice->eOPMode == OP_MODE_AP)) {
  2339. if (is_multicast_ether_addr(&(psEthHeader->abyDstAddr[0])))
  2340. bNeedACK = false;
  2341. else
  2342. bNeedACK = true;
  2343. }
  2344. else {
  2345. // MSDUs in Infra mode always need ACK
  2346. bNeedACK = true;
  2347. }
  2348. if (pDevice->bLongHeader)
  2349. cbMACHdLen = WLAN_HDR_ADDR3_LEN + 6;
  2350. else
  2351. cbMACHdLen = WLAN_HDR_ADDR3_LEN;
  2352. if (pDevice->bEncryptionEnable == true) {
  2353. if (pTransmitKey == NULL) {
  2354. if ((pDevice->eEncryptionStatus == Ndis802_11Encryption1Enabled) ||
  2355. (pDevice->pMgmt->eAuthenMode < WMAC_AUTH_WPA)) {
  2356. cbIVlen = 4;
  2357. cbICVlen = 4;
  2358. } else if (pDevice->eEncryptionStatus == Ndis802_11Encryption2Enabled) {
  2359. cbIVlen = 8;//IV+ExtIV
  2360. cbMIClen = 8;
  2361. cbICVlen = 4;
  2362. } else if (pDevice->eEncryptionStatus == Ndis802_11Encryption3Enabled) {
  2363. cbIVlen = 8;//RSN Header
  2364. cbICVlen = 8;//MIC
  2365. }
  2366. } else if (pTransmitKey->byCipherSuite == KEY_CTL_WEP) {
  2367. cbIVlen = 4;
  2368. cbICVlen = 4;
  2369. } else if (pTransmitKey->byCipherSuite == KEY_CTL_TKIP) {
  2370. cbIVlen = 8;//IV+ExtIV
  2371. cbMIClen = 8;
  2372. cbICVlen = 4;
  2373. } else if (pTransmitKey->byCipherSuite == KEY_CTL_CCMP) {
  2374. cbIVlen = 8;//RSN Header
  2375. cbICVlen = 8;//MIC
  2376. }
  2377. }
  2378. cbFrameSize = cbMACHdLen + cbIVlen + (cbFrameBodySize + cbMIClen) + cbICVlen + cbFCSlen;
  2379. if ((cbFrameSize > pDevice->wFragmentationThreshold) && (bNeedACK == true)) {
  2380. // Fragmentation
  2381. cbFragmentSize = pDevice->wFragmentationThreshold;
  2382. cbFragPayloadSize = cbFragmentSize - cbMACHdLen - cbIVlen - cbICVlen - cbFCSlen;
  2383. uMACfragNum = (unsigned short) ((cbFrameBodySize + cbMIClen) / cbFragPayloadSize);
  2384. cbLastFragPayloadSize = (cbFrameBodySize + cbMIClen) % cbFragPayloadSize;
  2385. if (cbLastFragPayloadSize == 0) {
  2386. cbLastFragPayloadSize = cbFragPayloadSize;
  2387. } else {
  2388. uMACfragNum++;
  2389. }
  2390. }
  2391. return uMACfragNum;
  2392. }
  2393. void
  2394. vDMA0_tx_80211(PSDevice pDevice, struct sk_buff *skb, unsigned char *pbMPDU, unsigned int cbMPDULen) {
  2395. PSTxDesc pFrstTD;
  2396. unsigned char byPktType;
  2397. unsigned char *pbyTxBufferAddr;
  2398. void * pvRTS;
  2399. void * pvCTS;
  2400. void * pvTxDataHd;
  2401. unsigned int uDuration;
  2402. unsigned int cbReqCount;
  2403. PS802_11Header pMACHeader;
  2404. unsigned int cbHeaderSize;
  2405. unsigned int cbFrameBodySize;
  2406. bool bNeedACK;
  2407. bool bIsPSPOLL = false;
  2408. PSTxBufHead pTxBufHead;
  2409. unsigned int cbFrameSize;
  2410. unsigned int cbIVlen = 0;
  2411. unsigned int cbICVlen = 0;
  2412. unsigned int cbMIClen = 0;
  2413. unsigned int cbFCSlen = 4;
  2414. unsigned int uPadding = 0;
  2415. unsigned int cbMICHDR = 0;
  2416. unsigned int uLength = 0;
  2417. unsigned long dwMICKey0, dwMICKey1;
  2418. unsigned long dwMIC_Priority;
  2419. unsigned long *pdwMIC_L;
  2420. unsigned long *pdwMIC_R;
  2421. unsigned short wTxBufSize;
  2422. unsigned int cbMacHdLen;
  2423. SEthernetHeader sEthHeader;
  2424. void * pvRrvTime;
  2425. void * pMICHDR;
  2426. PSMgmtObject pMgmt = pDevice->pMgmt;
  2427. unsigned short wCurrentRate = RATE_1M;
  2428. PUWLAN_80211HDR p80211Header;
  2429. unsigned int uNodeIndex = 0;
  2430. bool bNodeExist = false;
  2431. SKeyItem STempKey;
  2432. PSKeyItem pTransmitKey = NULL;
  2433. unsigned char *pbyIVHead;
  2434. unsigned char *pbyPayloadHead;
  2435. unsigned char *pbyMacHdr;
  2436. unsigned int cbExtSuppRate = 0;
  2437. // PWLAN_IE pItem;
  2438. pvRrvTime = pMICHDR = pvRTS = pvCTS = pvTxDataHd = NULL;
  2439. if(cbMPDULen <= WLAN_HDR_ADDR3_LEN) {
  2440. cbFrameBodySize = 0;
  2441. }
  2442. else {
  2443. cbFrameBodySize = cbMPDULen - WLAN_HDR_ADDR3_LEN;
  2444. }
  2445. p80211Header = (PUWLAN_80211HDR)pbMPDU;
  2446. pFrstTD = pDevice->apCurrTD[TYPE_TXDMA0];
  2447. pbyTxBufferAddr = (unsigned char *)pFrstTD->pTDInfo->buf;
  2448. pTxBufHead = (PSTxBufHead) pbyTxBufferAddr;
  2449. wTxBufSize = sizeof(STxBufHead);
  2450. memset(pTxBufHead, 0, wTxBufSize);
  2451. if (pDevice->eCurrentPHYType == PHY_TYPE_11A) {
  2452. wCurrentRate = RATE_6M;
  2453. byPktType = PK_TYPE_11A;
  2454. } else {
  2455. wCurrentRate = RATE_1M;
  2456. byPktType = PK_TYPE_11B;
  2457. }
  2458. // SetPower will cause error power TX state for OFDM Date packet in TX buffer.
  2459. // 2004.11.11 Kyle -- Using OFDM power to tx MngPkt will decrease the connection capability.
  2460. // And cmd timer will wait data pkt TX finish before scanning so it's OK
  2461. // to set power here.
  2462. if (pDevice->pMgmt->eScanState != WMAC_NO_SCANNING) {
  2463. RFbSetPower(pDevice, wCurrentRate, pDevice->byCurrentCh);
  2464. } else {
  2465. RFbSetPower(pDevice, wCurrentRate, pMgmt->uCurrChannel);
  2466. }
  2467. pTxBufHead->byTxPower = pDevice->byCurPwr;
  2468. //+++++++++++++++++++++ Patch VT3253 A1 performance +++++++++++++++++++++++++++
  2469. if (pDevice->byFOETuning) {
  2470. if ((p80211Header->sA3.wFrameCtl & TYPE_DATE_NULL) == TYPE_DATE_NULL) {
  2471. wCurrentRate = RATE_24M;
  2472. byPktType = PK_TYPE_11GA;
  2473. }
  2474. }
  2475. DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"vDMA0_tx_80211: p80211Header->sA3.wFrameCtl = %x \n", p80211Header->sA3.wFrameCtl);
  2476. //Set packet type
  2477. if (byPktType == PK_TYPE_11A) {//0000 0000 0000 0000
  2478. pTxBufHead->wFIFOCtl = 0;
  2479. }
  2480. else if (byPktType == PK_TYPE_11B) {//0000 0001 0000 0000
  2481. pTxBufHead->wFIFOCtl |= FIFOCTL_11B;
  2482. }
  2483. else if (byPktType == PK_TYPE_11GB) {//0000 0010 0000 0000
  2484. pTxBufHead->wFIFOCtl |= FIFOCTL_11GB;
  2485. }
  2486. else if (byPktType == PK_TYPE_11GA) {//0000 0011 0000 0000
  2487. pTxBufHead->wFIFOCtl |= FIFOCTL_11GA;
  2488. }
  2489. pTxBufHead->wFIFOCtl |= FIFOCTL_TMOEN;
  2490. pTxBufHead->wTimeStamp = cpu_to_le16(DEFAULT_MGN_LIFETIME_RES_64us);
  2491. if (is_multicast_ether_addr(&(p80211Header->sA3.abyAddr1[0]))) {
  2492. bNeedACK = false;
  2493. if (pDevice->bEnableHostWEP) {
  2494. uNodeIndex = 0;
  2495. bNodeExist = true;
  2496. }
  2497. }
  2498. else {
  2499. if (pDevice->bEnableHostWEP) {
  2500. if (BSSDBbIsSTAInNodeDB(pDevice->pMgmt, (unsigned char *)(p80211Header->sA3.abyAddr1), &uNodeIndex))
  2501. bNodeExist = true;
  2502. }
  2503. bNeedACK = true;
  2504. pTxBufHead->wFIFOCtl |= FIFOCTL_NEEDACK;
  2505. };
  2506. if ((pMgmt->eCurrMode == WMAC_MODE_ESS_AP) ||
  2507. (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) ) {
  2508. pTxBufHead->wFIFOCtl |= FIFOCTL_LRETRY;
  2509. //Set Preamble type always long
  2510. //pDevice->byPreambleType = PREAMBLE_LONG;
  2511. // probe-response don't retry
  2512. //if ((p80211Header->sA4.wFrameCtl & TYPE_SUBTYPE_MASK) == TYPE_MGMT_PROBE_RSP) {
  2513. // bNeedACK = false;
  2514. // pTxBufHead->wFIFOCtl &= (~FIFOCTL_NEEDACK);
  2515. //}
  2516. }
  2517. pTxBufHead->wFIFOCtl |= (FIFOCTL_GENINT | FIFOCTL_ISDMA0);
  2518. if ((p80211Header->sA4.wFrameCtl & TYPE_SUBTYPE_MASK) == TYPE_CTL_PSPOLL) {
  2519. bIsPSPOLL = true;
  2520. cbMacHdLen = WLAN_HDR_ADDR2_LEN;
  2521. } else {
  2522. cbMacHdLen = WLAN_HDR_ADDR3_LEN;
  2523. }
  2524. // hostapd deamon ext support rate patch
  2525. if (WLAN_GET_FC_FSTYPE(p80211Header->sA4.wFrameCtl) == WLAN_FSTYPE_ASSOCRESP) {
  2526. if (((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates)->len != 0) {
  2527. cbExtSuppRate += ((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates)->len + WLAN_IEHDR_LEN;
  2528. }
  2529. if (((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates)->len != 0) {
  2530. cbExtSuppRate += ((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates)->len + WLAN_IEHDR_LEN;
  2531. }
  2532. if (cbExtSuppRate >0) {
  2533. cbFrameBodySize = WLAN_ASSOCRESP_OFF_SUPP_RATES;
  2534. }
  2535. }
  2536. //Set FRAGCTL_MACHDCNT
  2537. pTxBufHead->wFragCtl |= cpu_to_le16((unsigned short)cbMacHdLen << 10);
  2538. // Notes:
  2539. // Although spec says MMPDU can be fragmented; In most case,
  2540. // no one will send a MMPDU under fragmentation. With RTS may occur.
  2541. pDevice->bAES = false; //Set FRAGCTL_WEPTYP
  2542. if (WLAN_GET_FC_ISWEP(p80211Header->sA4.wFrameCtl) != 0) {
  2543. if (pDevice->eEncryptionStatus == Ndis802_11Encryption1Enabled) {
  2544. cbIVlen = 4;
  2545. cbICVlen = 4;
  2546. pTxBufHead->wFragCtl |= FRAGCTL_LEGACY;
  2547. }
  2548. else if (pDevice->eEncryptionStatus == Ndis802_11Encryption2Enabled) {
  2549. cbIVlen = 8;//IV+ExtIV
  2550. cbMIClen = 8;
  2551. cbICVlen = 4;
  2552. pTxBufHead->wFragCtl |= FRAGCTL_TKIP;
  2553. //We need to get seed here for filling TxKey entry.
  2554. //TKIPvMixKey(pTransmitKey->abyKey, pDevice->abyCurrentNetAddr,
  2555. // pTransmitKey->wTSC15_0, pTransmitKey->dwTSC47_16, pDevice->abyPRNG);
  2556. }
  2557. else if (pDevice->eEncryptionStatus == Ndis802_11Encryption3Enabled) {
  2558. cbIVlen = 8;//RSN Header
  2559. cbICVlen = 8;//MIC
  2560. cbMICHDR = sizeof(SMICHDRHead);
  2561. pTxBufHead->wFragCtl |= FRAGCTL_AES;
  2562. pDevice->bAES = true;
  2563. }
  2564. //MAC Header should be padding 0 to DW alignment.
  2565. uPadding = 4 - (cbMacHdLen%4);
  2566. uPadding %= 4;
  2567. }
  2568. cbFrameSize = cbMacHdLen + cbFrameBodySize + cbIVlen + cbMIClen + cbICVlen + cbFCSlen + cbExtSuppRate;
  2569. //Set FIFOCTL_GrpAckPolicy
  2570. if (pDevice->bGrpAckPolicy == true) {//0000 0100 0000 0000
  2571. pTxBufHead->wFIFOCtl |= FIFOCTL_GRPACK;
  2572. }
  2573. //the rest of pTxBufHead->wFragCtl:FragTyp will be set later in s_vFillFragParameter()
  2574. if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {//802.11g packet
  2575. pvRrvTime = (PSRrvTime_gCTS) (pbyTxBufferAddr + wTxBufSize);
  2576. pMICHDR = (PSMICHDRHead) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_gCTS));
  2577. pvRTS = NULL;
  2578. pvCTS = (PSCTS) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_gCTS) + cbMICHDR);
  2579. pvTxDataHd = (PSTxDataHead_g) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_gCTS) + cbMICHDR + sizeof(SCTS));
  2580. cbHeaderSize = wTxBufSize + sizeof(SRrvTime_gCTS) + cbMICHDR + sizeof(SCTS) + sizeof(STxDataHead_g);
  2581. }
  2582. else {//802.11a/b packet
  2583. pvRrvTime = (PSRrvTime_ab) (pbyTxBufferAddr + wTxBufSize);
  2584. pMICHDR = (PSMICHDRHead) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_ab));
  2585. pvRTS = NULL;
  2586. pvCTS = NULL;
  2587. pvTxDataHd = (PSTxDataHead_ab) (pbyTxBufferAddr + wTxBufSize + sizeof(SRrvTime_ab) + cbMICHDR);
  2588. cbHeaderSize = wTxBufSize + sizeof(SRrvTime_ab) + cbMICHDR + sizeof(STxDataHead_ab);
  2589. }
  2590. memset((void *)(pbyTxBufferAddr + wTxBufSize), 0, (cbHeaderSize - wTxBufSize));
  2591. memcpy(&(sEthHeader.abyDstAddr[0]), &(p80211Header->sA3.abyAddr1[0]), ETH_ALEN);
  2592. memcpy(&(sEthHeader.abySrcAddr[0]), &(p80211Header->sA3.abyAddr2[0]), ETH_ALEN);
  2593. //=========================
  2594. // No Fragmentation
  2595. //=========================
  2596. pTxBufHead->wFragCtl |= (unsigned short)FRAGCTL_NONFRAG;
  2597. //Fill FIFO,RrvTime,RTS,and CTS
  2598. s_vGenerateTxParameter(pDevice, byPktType, pbyTxBufferAddr, pvRrvTime, pvRTS, pvCTS,
  2599. cbFrameSize, bNeedACK, TYPE_TXDMA0, &sEthHeader, wCurrentRate);
  2600. //Fill DataHead
  2601. uDuration = s_uFillDataHead(pDevice, byPktType, pvTxDataHd, cbFrameSize, TYPE_TXDMA0, bNeedACK,
  2602. 0, 0, 1, AUTO_FB_NONE, wCurrentRate);
  2603. pMACHeader = (PS802_11Header) (pbyTxBufferAddr + cbHeaderSize);
  2604. cbReqCount = cbHeaderSize + cbMacHdLen + uPadding + cbIVlen + (cbFrameBodySize + cbMIClen) + cbExtSuppRate;
  2605. pbyMacHdr = (unsigned char *)(pbyTxBufferAddr + cbHeaderSize);
  2606. pbyPayloadHead = (unsigned char *)(pbyMacHdr + cbMacHdLen + uPadding + cbIVlen);
  2607. pbyIVHead = (unsigned char *)(pbyMacHdr + cbMacHdLen + uPadding);
  2608. // Copy the Packet into a tx Buffer
  2609. memcpy(pbyMacHdr, pbMPDU, cbMacHdLen);
  2610. // version set to 0, patch for hostapd deamon
  2611. pMACHeader->wFrameCtl &= cpu_to_le16(0xfffc);
  2612. memcpy(pbyPayloadHead, (pbMPDU + cbMacHdLen), cbFrameBodySize);
  2613. // replace support rate, patch for hostapd deamon( only support 11M)
  2614. if (WLAN_GET_FC_FSTYPE(p80211Header->sA4.wFrameCtl) == WLAN_FSTYPE_ASSOCRESP) {
  2615. if (cbExtSuppRate != 0) {
  2616. if (((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates)->len != 0)
  2617. memcpy((pbyPayloadHead + cbFrameBodySize),
  2618. pMgmt->abyCurrSuppRates,
  2619. ((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates)->len + WLAN_IEHDR_LEN
  2620. );
  2621. if (((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates)->len != 0)
  2622. memcpy((pbyPayloadHead + cbFrameBodySize) + ((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates)->len + WLAN_IEHDR_LEN,
  2623. pMgmt->abyCurrExtSuppRates,
  2624. ((PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates)->len + WLAN_IEHDR_LEN
  2625. );
  2626. }
  2627. }
  2628. // Set wep
  2629. if (WLAN_GET_FC_ISWEP(p80211Header->sA4.wFrameCtl) != 0) {
  2630. if (pDevice->bEnableHostWEP) {
  2631. pTransmitKey = &STempKey;
  2632. pTransmitKey->byCipherSuite = pMgmt->sNodeDBTable[uNodeIndex].byCipherSuite;
  2633. pTransmitKey->dwKeyIndex = pMgmt->sNodeDBTable[uNodeIndex].dwKeyIndex;
  2634. pTransmitKey->uKeyLength = pMgmt->sNodeDBTable[uNodeIndex].uWepKeyLength;
  2635. pTransmitKey->dwTSC47_16 = pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16;
  2636. pTransmitKey->wTSC15_0 = pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0;
  2637. memcpy(pTransmitKey->abyKey,
  2638. &pMgmt->sNodeDBTable[uNodeIndex].abyWepKey[0],
  2639. pTransmitKey->uKeyLength
  2640. );
  2641. }
  2642. if ((pTransmitKey != NULL) && (pTransmitKey->byCipherSuite == KEY_CTL_TKIP)) {
  2643. dwMICKey0 = *(unsigned long *)(&pTransmitKey->abyKey[16]);
  2644. dwMICKey1 = *(unsigned long *)(&pTransmitKey->abyKey[20]);
  2645. // DO Software Michael
  2646. MIC_vInit(dwMICKey0, dwMICKey1);
  2647. MIC_vAppend((unsigned char *)&(sEthHeader.abyDstAddr[0]), 12);
  2648. dwMIC_Priority = 0;
  2649. MIC_vAppend((unsigned char *)&dwMIC_Priority, 4);
  2650. DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"DMA0_tx_8021:MIC KEY: %lX, %lX\n", dwMICKey0, dwMICKey1);
  2651. uLength = cbHeaderSize + cbMacHdLen + uPadding + cbIVlen;
  2652. MIC_vAppend((pbyTxBufferAddr + uLength), cbFrameBodySize);
  2653. pdwMIC_L = (unsigned long *)(pbyTxBufferAddr + uLength + cbFrameBodySize);
  2654. pdwMIC_R = (unsigned long *)(pbyTxBufferAddr + uLength + cbFrameBodySize + 4);
  2655. MIC_vGetMIC(pdwMIC_L, pdwMIC_R);
  2656. MIC_vUnInit();
  2657. if (pDevice->bTxMICFail == true) {
  2658. *pdwMIC_L = 0;
  2659. *pdwMIC_R = 0;
  2660. pDevice->bTxMICFail = false;
  2661. }
  2662. DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"uLength: %d, %d\n", uLength, cbFrameBodySize);
  2663. DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"cbReqCount:%d, %d, %d, %d\n", cbReqCount, cbHeaderSize, uPadding, cbIVlen);
  2664. DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"MIC:%lx, %lx\n", *pdwMIC_L, *pdwMIC_R);
  2665. }
  2666. s_vFillTxKey(pDevice, (unsigned char *)(pTxBufHead->adwTxKey), pbyIVHead, pTransmitKey,
  2667. pbyMacHdr, (unsigned short)cbFrameBodySize, (unsigned char *)pMICHDR);
  2668. if (pDevice->bEnableHostWEP) {
  2669. pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16 = pTransmitKey->dwTSC47_16;
  2670. pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0 = pTransmitKey->wTSC15_0;
  2671. }
  2672. if ((pDevice->byLocalID <= REV_ID_VT3253_A1)) {
  2673. s_vSWencryption(pDevice, pTransmitKey, pbyPayloadHead, (unsigned short)(cbFrameBodySize + cbMIClen));
  2674. }
  2675. }
  2676. pMACHeader->wSeqCtl = cpu_to_le16(pDevice->wSeqCounter << 4);
  2677. pDevice->wSeqCounter++ ;
  2678. if (pDevice->wSeqCounter > 0x0fff)
  2679. pDevice->wSeqCounter = 0;
  2680. if (bIsPSPOLL) {
  2681. // The MAC will automatically replace the Duration-field of MAC header by Duration-field
  2682. // of FIFO control header.
  2683. // This will cause AID-field of PS-POLL packet be incorrect (Because PS-POLL's AID field is
  2684. // in the same place of other packet's Duration-field).
  2685. // And it will cause Cisco-AP to issue Disassociation-packet
  2686. if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {
  2687. ((PSTxDataHead_g)pvTxDataHd)->wDuration_a = cpu_to_le16(p80211Header->sA2.wDurationID);
  2688. ((PSTxDataHead_g)pvTxDataHd)->wDuration_b = cpu_to_le16(p80211Header->sA2.wDurationID);
  2689. } else {
  2690. ((PSTxDataHead_ab)pvTxDataHd)->wDuration = cpu_to_le16(p80211Header->sA2.wDurationID);
  2691. }
  2692. }
  2693. // first TD is the only TD
  2694. //Set TSR1 & ReqCount in TxDescHead
  2695. pFrstTD->pTDInfo->skb = skb;
  2696. pFrstTD->m_td1TD1.byTCR = (TCR_STP | TCR_EDP | EDMSDU);
  2697. pFrstTD->pTDInfo->skb_dma = pFrstTD->pTDInfo->buf_dma;
  2698. pFrstTD->m_td1TD1.wReqCount = cpu_to_le16(cbReqCount);
  2699. pFrstTD->buff_addr = cpu_to_le32(pFrstTD->pTDInfo->skb_dma);
  2700. pFrstTD->pTDInfo->byFlags = 0;
  2701. pFrstTD->pTDInfo->byFlags |= TD_FLAGS_PRIV_SKB;
  2702. if (MACbIsRegBitsOn(pDevice->PortOffset, MAC_REG_PSCTL, PSCTL_PS)) {
  2703. // Disable PS
  2704. MACbPSWakeup(pDevice->PortOffset);
  2705. }
  2706. pDevice->bPWBitOn = false;
  2707. wmb();
  2708. pFrstTD->m_td0TD0.f1Owner = OWNED_BY_NIC;
  2709. wmb();
  2710. pDevice->iTDUsed[TYPE_TXDMA0]++;
  2711. if (AVAIL_TD(pDevice, TYPE_TXDMA0) <= 1) {
  2712. DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " available td0 <= 1\n");
  2713. }
  2714. pDevice->apCurrTD[TYPE_TXDMA0] = pFrstTD->next;
  2715. // Poll Transmit the adapter
  2716. MACvTransmit0(pDevice->PortOffset);
  2717. return;
  2718. }