PageRenderTime 48ms CodeModel.GetById 24ms RepoModel.GetById 0ms app.codeStats 0ms

/drivers/net/wireless/tiwlan1251/common/src/core/data_ctrl/Ctrl/4X/Concatenator.c

https://bitbucket.org/cyanogenmod/cm-kernel
C | 350 lines | 151 code | 62 blank | 137 comment | 19 complexity | de622afdecbb3a3c2e75c7cb9bce9c76 MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.0, AGPL-1.0
  1. /****************************************************************************
  2. **+-----------------------------------------------------------------------+**
  3. **| |**
  4. **| Copyright(c) 1998 - 2008 Texas Instruments. All rights reserved. |**
  5. **| All rights reserved. |**
  6. **| |**
  7. **| Redistribution and use in source and binary forms, with or without |**
  8. **| modification, are permitted provided that the following conditions |**
  9. **| are met: |**
  10. **| |**
  11. **| * Redistributions of source code must retain the above copyright |**
  12. **| notice, this list of conditions and the following disclaimer. |**
  13. **| * Redistributions in binary form must reproduce the above copyright |**
  14. **| notice, this list of conditions and the following disclaimer in |**
  15. **| the documentation and/or other materials provided with the |**
  16. **| distribution. |**
  17. **| * Neither the name Texas Instruments nor the names of its |**
  18. **| contributors may be used to endorse or promote products derived |**
  19. **| from this software without specific prior written permission. |**
  20. **| |**
  21. **| THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |**
  22. **| "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |**
  23. **| LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |**
  24. **| A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |**
  25. **| OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |**
  26. **| SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |**
  27. **| LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |**
  28. **| DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |**
  29. **| THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |**
  30. **| (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |**
  31. **| OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |**
  32. **| |**
  33. **+-----------------------------------------------------------------------+**
  34. ****************************************************************************/
  35. /***************************************************************************/
  36. /* */
  37. /* MODULE: */
  38. /* PURPOSE: */
  39. /* */
  40. /***************************************************************************/
  41. #include "Concatenator.h"
  42. #include "report.h"
  43. #include "osApi.h"
  44. #include "utils.h"
  45. #include "802_11Defs.h"
  46. #include "whalBus_Defs.h"
  47. #include "TNETW_Driver_api.h"
  48. static TI_STATUS concat_replaceWlanHeader(concatenator_t* pConcatenator,
  49. mem_MSDU_T *msduPtr);
  50. /*************************************************************************
  51. * concat_create *
  52. **************************************************************************
  53. * DESCRIPTION: This function initializes the Ctrl data module.
  54. *
  55. * INPUT: hOs - handle to Os Abstraction Layer
  56. *
  57. * OUTPUT: TxCmplt_CB - call back function that return to configMngr
  58. * in order to register in the Hal
  59. *
  60. * RETURN: Handle to the allocated Ctrl data control block
  61. ************************************************************************/
  62. concatenator_t* concat_create(TI_HANDLE hOs)
  63. {
  64. concatenator_t* pConcatenator;
  65. if( hOs == NULL )
  66. {
  67. WLAN_OS_REPORT(("FATAL ERROR: concat_create(): OS handle Error - Aborting\n"));
  68. return NULL;
  69. }
  70. /* alocate concatenator block */
  71. pConcatenator = os_memoryAlloc(hOs, (sizeof(concatenator_t)));
  72. if (!pConcatenator)
  73. {
  74. utils_nullMemoryFree(hOs, pConcatenator, sizeof(concatenator_t));
  75. WLAN_OS_REPORT(("FATAL ERROR: concat_create(): Error Creating Concatenator module- Aborting\n"));
  76. return(NULL);
  77. }
  78. /* reset control module control block */
  79. os_memoryZero(hOs, pConcatenator, (sizeof(concatenator_t)));
  80. pConcatenator->hOs = hOs;
  81. return(pConcatenator);
  82. }
  83. /***************************************************************************
  84. * concat_config *
  85. ****************************************************************************
  86. * DESCRIPTION: This function configures the Ctrl Data module
  87. *
  88. * INPUTS: hCtrlData - The object
  89. * hOs - Handle to the Os Abstraction Layer
  90. * hReport - Handle to the Report object
  91. * ctrlDataInitParams - pointer to Ctrl module init parameters
  92. * OUTPUT:
  93. *
  94. * RETURNS: OK - Configuration succesfull
  95. * NOK - Configuration unsuccesfull
  96. ***************************************************************************/
  97. TI_STATUS concat_config(concatenator_t* pConcatenator,
  98. TI_HANDLE hOs,
  99. TI_HANDLE hReport,
  100. TI_HANDLE hMemMngr
  101. /*concatInitParams_t* concatInitParams*/)
  102. {
  103. /* check parameters validity */
  104. if( pConcatenator == NULL || hOs == NULL ||
  105. hReport == NULL || hMemMngr == NULL /*|| concatInitParams == NULL*/)
  106. {
  107. WLAN_OS_REPORT(("FATAL ERROR: concat_config(): Parameters Error - Aborting\n"));
  108. return NOK;
  109. }
  110. /* set objects handles */
  111. pConcatenator->hOs = hOs;
  112. pConcatenator->hReport = hReport;
  113. pConcatenator->hMemMngr = hMemMngr;
  114. WLAN_REPORT_INIT(pConcatenator->hReport, CONCATENATOR_MODULE_LOG,
  115. (".....Concatenator configured successfully\n"));
  116. return OK;
  117. }
  118. /***************************************************************************
  119. * ctrlData_unLoad *
  120. ****************************************************************************
  121. * DESCRIPTION: This function unload the Ctrl data module.
  122. *
  123. * INPUTS: hCtrlData - the object
  124. *
  125. * OUTPUT:
  126. *
  127. * RETURNS: OK - Unload succesfull
  128. * NOK - Unload unsuccesfull
  129. ***************************************************************************/
  130. TI_STATUS concat_destroy(concatenator_t* pConcatenator)
  131. {
  132. /* free control module controll block */
  133. os_memoryFree(pConcatenator->hOs, pConcatenator, sizeof(concatenator_t));
  134. return OK;
  135. }
  136. /*************************************************************************
  137. * wdrv_txConcatMsduList *
  138. *************************************************************************
  139. DESCRIPTION: This function get a list of MSDUs (The first MSDU points
  140. on the others) and concatenate them into one MPDU by linking the
  141. buffers BDs. In return only the first MSDU struct is in use,
  142. and it contains the entire concatenated MPDU.
  143. INPUT: msduPtr - Pointer to the first MSDU.
  144. concatFlags - Concatenation flags.
  145. OUTPUT: By reference to the msduPtr.
  146. RETURN: OK : Initiation successful.
  147. NOK: Initiation unsuccessful.
  148. ************************************************************************/
  149. TI_STATUS concat_concatMsduList(concatenator_t* pConcatenator,
  150. mem_MSDU_T* pFirstMsduPtr,
  151. mem_MSDU_T** pReturnMsduPtr,
  152. UINT16 concatFlags)
  153. {
  154. mem_MSDU_T *currMsduPtr;
  155. mem_MSDU_T *prevMsduPtr;
  156. /*mem_MSDU_T *buildMsduPtr; */
  157. UINT8 *srcDataPtr;
  158. UINT8 *buildDataPtr;
  159. Wdrv4xHeader_t *w4xHeaderPtr;
  160. UINT8 tiSnapDataArray[8] = {0xAA,0xAA,0x03,0x08,0x00,0x28,0x60,0xD0};
  161. /* Allocate MSDU and a BD for the concatenatetion header. */
  162. if(wlan_memMngrAllocMSDU(pConcatenator->hMemMngr, pReturnMsduPtr,
  163. WLAN_HDR_LEN + WLAN_SNAP_HDR_LEN +WLAN_4X_CONCAT_HDR_LEN + sizeof(DbTescriptor),
  164. CONCAT_MODULE) == NOK)
  165. {
  166. WLAN_REPORT_ERROR(pConcatenator->hReport, CONCATENATOR_MODULE_LOG,
  167. ("concat_concatMsduList: no MemMngre resources, free the MsduList to concat\n"));
  168. wlan_memMngrFreeListOfMSDU(pConcatenator->hMemMngr, memMgr_MsduHandle(pFirstMsduPtr));
  169. return NOK;
  170. }
  171. (*pReturnMsduPtr)->txFlags = pFirstMsduPtr->txFlags;
  172. /* Create the first BD.(contains 802.11 header, TI wlan SNAP & Concat headr) */
  173. srcDataPtr = (UINT8 *)memMgr_MsduHdrAddr(pFirstMsduPtr);
  174. buildDataPtr = (UINT8 *)memMgr_MsduHdrAddr(*pReturnMsduPtr);
  175. /* Copy the 802.11 header. */
  176. os_memoryCopy(pConcatenator->hOs, buildDataPtr, srcDataPtr, WLAN_HDR_LEN );
  177. /* We send the frame from the STA so the AP */
  178. os_memoryCopy(pConcatenator->hOs, buildDataPtr+WLAN_DA_FIELD_OFFSET, srcDataPtr+WLAN_BSSID_FIELD_OFFSET, 6 );
  179. buildDataPtr += WLAN_HDR_LEN;
  180. /* create a TI WLAN SNAP */
  181. os_memoryCopy(pConcatenator->hOs, buildDataPtr ,tiSnapDataArray, WLAN_SNAP_HDR_LEN );
  182. buildDataPtr += WLAN_SNAP_HDR_LEN;
  183. /* create 4X header. */
  184. w4xHeaderPtr = (Wdrv4xHeader_t*)buildDataPtr;
  185. w4xHeaderPtr->type = WLAN_HEADER_TYPE_CONCATENATION;
  186. w4xHeaderPtr->headerLen = WLAN_CONCAT_HEADER_LEN;
  187. w4xHeaderPtr->txFlags = wlan_htons(concatFlags);
  188. (*pReturnMsduPtr)->firstBDPtr->length = WLAN_HDR_LEN + WLAN_SNAP_HDR_LEN +
  189. WLAN_4X_CONCAT_HDR_LEN;
  190. (*pReturnMsduPtr)->dataLen = WLAN_HDR_LEN + WLAN_SNAP_HDR_LEN +
  191. WLAN_4X_CONCAT_HDR_LEN;
  192. (*pReturnMsduPtr)->headerLen = WLAN_HDR_LEN;
  193. /*buildMsduPtr->nextMSDUinList = (*pMsduPtr);*/
  194. /* Link the new MSDU to the first MSDU to imitate the MSDU list format. */
  195. (*pReturnMsduPtr)->firstBDPtr->nextBDPtr = pFirstMsduPtr->firstBDPtr;
  196. /* Start Concatenating the MSDUs, payload is copied from the SNAP to */
  197. /* payload end. */
  198. currMsduPtr = pFirstMsduPtr;
  199. while( currMsduPtr != NULL )
  200. {
  201. concat_replaceWlanHeader(pConcatenator, currMsduPtr );
  202. /* Update the size of the concatenated MSDU. */
  203. (*pReturnMsduPtr)->dataLen += currMsduPtr->dataLen;
  204. if( currMsduPtr->nextMSDUinList != NULL )
  205. {
  206. /* Link last BD of the current MSDU to the first BD of the next MSDU.*/
  207. currMsduPtr->lastBDPtr->nextBDPtr = currMsduPtr->nextMSDUinList->firstBDPtr;
  208. /* Jump for the next MSDU */
  209. prevMsduPtr = currMsduPtr;
  210. currMsduPtr = currMsduPtr->nextMSDUinList;
  211. prevMsduPtr->firstBDPtr = NULL;
  212. prevMsduPtr->nextMSDUinList = NULL;
  213. wlan_memMngrFreeMSDU(pConcatenator->hMemMngr, memMgr_MsduHandle(prevMsduPtr));
  214. }
  215. else
  216. {
  217. /* Last MSDU */
  218. prevMsduPtr = currMsduPtr;
  219. prevMsduPtr->firstBDPtr = NULL;
  220. prevMsduPtr->nextMSDUinList = NULL;
  221. wlan_memMngrFreeMSDU(pConcatenator->hMemMngr, memMgr_MsduHandle(prevMsduPtr));
  222. currMsduPtr = NULL;
  223. }
  224. } /* While( currMsduPtr != NULL ) */
  225. return OK;
  226. }
  227. /*************************************************************************
  228. * wdrv_txReplaceWlanHeader *
  229. *************************************************************************
  230. DESCRIPTION: This function replaces the 802.11 header with length + SA as
  231. prefix to the concatenated MSDU.
  232. INPUT: msduPtr - Pointer to the first MSDU.
  233. RETURN: OK : Initiation succesfull.
  234. NOK: Initiation unsuccesfull.
  235. ************************************************************************/
  236. static TI_STATUS concat_replaceWlanHeader(concatenator_t* pConcatenator,
  237. mem_MSDU_T *msduPtr)
  238. {
  239. UINT8 *firstDataBuf;
  240. UINT8 numOfPadBytes;
  241. UINT8 *tmpPtr;
  242. UINT8 tmpMacAddr[WLAN_DA_FIELD_LEN];
  243. int i;
  244. /* Replace the 802.11 header with 2 length bytes and 6 DA . */
  245. firstDataBuf = (UINT8 *)(msduPtr->firstBDPtr->data +
  246. msduPtr->firstBDPtr->dataOffset);
  247. /*
  248. * Use temporary buffer to prevent overwrite on the same data
  249. */
  250. os_memoryCopy(pConcatenator->hOs,
  251. tmpMacAddr,
  252. firstDataBuf+WLAN_DA_FIELD_OFFSET, WLAN_DA_FIELD_LEN);
  253. os_memoryCopy(pConcatenator->hOs,
  254. firstDataBuf+ WLAN_HDR_LEN - WLAN_DA_FIELD_LEN,
  255. tmpMacAddr, WLAN_DA_FIELD_LEN);
  256. msduPtr->firstBDPtr->dataOffset += WLAN_CONCAT_HDR_OFFSET;
  257. msduPtr->firstBDPtr->length -= WLAN_CONCAT_HDR_OFFSET;
  258. msduPtr->dataLen -= WLAN_CONCAT_HDR_OFFSET;
  259. /* Fill the length bytes. */
  260. (*(UINT16*)(firstDataBuf+ WLAN_CONCAT_HDR_OFFSET)) =
  261. wlan_htons((UINT16)(msduPtr->dataLen - WLAN_4X_LEN_FIELD_LEN));
  262. /* Padding the last buffer with zeros.*/
  263. numOfPadBytes = msduPtr->dataLen % 4;
  264. if( numOfPadBytes > 0 )
  265. {
  266. #if 1
  267. /*
  268. * fixing the alignment bug.
  269. */
  270. numOfPadBytes = 4 - numOfPadBytes;
  271. #endif
  272. tmpPtr = (UINT8 *) ((UINT32)msduPtr->lastBDPtr->data + msduPtr->lastBDPtr->length +
  273. msduPtr->lastBDPtr->dataOffset);
  274. for( i=0; i<numOfPadBytes; i++)
  275. tmpPtr[i] = 0x00;
  276. msduPtr->lastBDPtr->length += numOfPadBytes;
  277. msduPtr->dataLen += numOfPadBytes;
  278. }
  279. return OK;
  280. }