PageRenderTime 49ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/drivers/net/wireless/tiwlan1251/common/src/hal/hl_data/whalDefrag.c

http://github.com/CyanogenMod/cm-kernel
C | 241 lines | 113 code | 32 blank | 96 comment | 31 complexity | 91103b59ced53f55e8379876f6533efc MD5 | raw file
Possible License(s): AGPL-1.0, GPL-2.0, LGPL-2.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. #include "whalDefrag_api.h"
  36. /*
  37. * ----------------------------------------------------------------------------
  38. * Function : findAndInsertEndpointIndex
  39. *
  40. * Input :
  41. * Output :
  42. * Process :
  43. * Note(s) :
  44. * -----------------------------------------------------------------------------
  45. */
  46. static int findAndInsertEndpointIndex (TI_HANDLE hWhalDefrag, UINT8* mac, UINT8* idx)
  47. {
  48. UINT8 i;
  49. WHAL_DEFRAG *pWhalDefrag = (WHAL_DEFRAG *)hWhalDefrag;
  50. /* first search for the endpoint*/
  51. for (i=0; i<pWhalDefrag->numCollectEntry; i++)
  52. {
  53. if ((pWhalDefrag->endpntMngr[i].inUse == TRUE) &&
  54. (os_memoryCompare (pWhalDefrag->hOs, pWhalDefrag->endpntMngr[i].srcMac, mac, MAC_ADDR_LEN) == 0))
  55. {
  56. *idx = i;
  57. return OK;
  58. }
  59. }
  60. /* endpoint not found, now try to locate unused entry and insert the endpoint*/
  61. for (i=0; i<pWhalDefrag->numCollectEntry; i++)
  62. {
  63. if (pWhalDefrag->endpntMngr[i].inUse == FALSE)
  64. {
  65. pWhalDefrag->endpntMngr[i].inUse = TRUE;
  66. os_memoryCopy (pWhalDefrag->hOs, pWhalDefrag->endpntMngr[i].srcMac, mac, MAC_ADDR_LEN);
  67. *idx = i;
  68. return OK;
  69. }
  70. }
  71. /* no free entry found*/
  72. return NOK;
  73. }
  74. /*
  75. * ----------------------------------------------------------------------------
  76. * Function : whalDefrag_Create
  77. *
  78. * Input :
  79. * Output :
  80. * Process :
  81. * Note(s) :
  82. * -----------------------------------------------------------------------------
  83. */
  84. TI_HANDLE whalDefrag_Create (TI_HANDLE hWhalCtrl, TI_HANDLE hOs, UINT8 numCollectEntries)
  85. {
  86. UINT8 i;
  87. WHAL_DEFRAG* pWhalDefrag;
  88. pWhalDefrag = (WHAL_DEFRAG *)os_memoryAlloc (hOs, sizeof(WHAL_DEFRAG));
  89. if (pWhalDefrag == NULL)
  90. return NULL;
  91. os_memoryZero (hOs, pWhalDefrag, sizeof(WHAL_DEFRAG));
  92. pWhalDefrag->hWhalCtrl = (WHAL_CTRL *)hWhalCtrl;
  93. pWhalDefrag->hOs = hOs;
  94. /* get the number of fragment collection entries from HAL DB*/
  95. pWhalDefrag->numCollectEntry = numCollectEntries;
  96. /* Create EndPoint objects*/
  97. for (i=0; i<pWhalDefrag->numCollectEntry; i++)
  98. {
  99. pWhalDefrag->pWhalEndpntEnt[i] = whalEndpnt_Create (hWhalCtrl, hOs);
  100. if (pWhalDefrag->pWhalEndpntEnt[i] == NULL)
  101. {
  102. whalDefrag_Destroy(pWhalDefrag);
  103. return NULL;
  104. }
  105. }
  106. return((TI_HANDLE)pWhalDefrag);
  107. }
  108. /*
  109. * ----------------------------------------------------------------------------
  110. * Function : whalDefrag_Config
  111. *
  112. * Input :
  113. * Output :
  114. * Process :
  115. * Note(s) :
  116. * -----------------------------------------------------------------------------
  117. */
  118. int whalDefrag_Config (TI_HANDLE hWhalDefrag, whalDefrag_config_t* pWhalDefragCfg)
  119. {
  120. UINT8 i;
  121. whalEndpnt_config_t whalEndpntCfg;
  122. whalEndpnt_config_t* pWhalEndpntCfg = &whalEndpntCfg;
  123. WHAL_DEFRAG *pWhalDefrag = (WHAL_DEFRAG *)hWhalDefrag;
  124. /* Save configuration parameters */
  125. pWhalDefrag->hReport = pWhalDefragCfg->hReport;
  126. pWhalDefrag->hMemMngr = pWhalDefragCfg->hMemMngr;
  127. /* Config EndPoint object */
  128. pWhalEndpntCfg->hReport = pWhalDefrag->hReport;
  129. pWhalEndpntCfg->hMemMngr = pWhalDefrag->hMemMngr;
  130. for (i=0; i<pWhalDefrag->numCollectEntry; i++)
  131. whalEndpnt_Config (pWhalDefrag->pWhalEndpntEnt[i], pWhalEndpntCfg);
  132. return (OK);
  133. }
  134. /*
  135. * ----------------------------------------------------------------------------
  136. * Function : whalDefrag_MpduCollect
  137. *
  138. * Input :
  139. * Output :
  140. * Process :
  141. * Note(s) :
  142. * -----------------------------------------------------------------------------
  143. */
  144. collectStatus_e whalDefrag_MpduCollect (TI_HANDLE hWhalDefrag, mem_MSDU_T* pMpdu, mem_MSDU_T** pMsdu)
  145. {
  146. UINT8 index;
  147. dot11_header_t* pHeader;
  148. UINT32 moreFrag;
  149. collectStatus_e rc;
  150. WHAL_DEFRAG *pWhalDefrag = (WHAL_DEFRAG *)hWhalDefrag;
  151. UINT8 *bssid = whal_ParamsGetBssId(pWhalDefrag->hWhalCtrl->pWhalParams);
  152. if (pMpdu == NULL)
  153. return (MPDU_DROP);
  154. /*
  155. * if the received bssid isn't match the current bssid we wan't to filter the those fragments,
  156. * we don't expect to get fragments without the current bssid.
  157. */
  158. pHeader = (dot11_header_t*)((pMpdu->firstBDPtr->data) + memMgr_BufOffset(pMpdu->firstBDPtr));
  159. moreFrag = (pHeader->fc & DOT11_FC_MORE_FRAG);
  160. if(moreFrag && (os_memoryCompare(pWhalDefrag->hOs,(void *)bssid,(void *)pHeader->address2.addr,MAC_ADDR_LEN)!=0))
  161. {
  162. if (wlan_memMngrFreeMSDU(pWhalDefrag->hMemMngr, pMpdu->handle) != OK)
  163. WLAN_REPORT_ERROR(pWhalDefrag->hReport, HAL_RX_MODULE_LOG,
  164. ("whalDefrag_MpduCollect: drop mpdu because moreFrag = %d && bssid = 0x%x \n",moreFrag,pHeader->address2.addr[0],pHeader->address2.addr[1],pHeader->address2.addr[2],pHeader->address2.addr[3],pHeader->address2.addr[4],pHeader->address2.addr[5]));
  165. return (MPDU_DROP);
  166. }
  167. if (findAndInsertEndpointIndex (hWhalDefrag, (UINT8 *)pHeader->address2.addr, &index) == OK)
  168. {
  169. rc = whalEndpnt_FragCollect (pWhalDefrag->pWhalEndpntEnt[index], pMpdu, pMsdu);
  170. if (whalEndpnt_IsCollect (pWhalDefrag->pWhalEndpntEnt[index]) == FALSE)
  171. pWhalDefrag->endpntMngr[index].inUse = FALSE;
  172. return (rc);
  173. }
  174. else
  175. {
  176. WLAN_REPORT_ERROR(pWhalDefrag->hReport, HAL_RX_MODULE_LOG,
  177. (" whalDefrag_MpduCollect: findAndInsertEndpointIndex failure, MPDU drop\n"));
  178. if (wlan_memMngrFreeMSDU(pWhalDefrag->hMemMngr, pMpdu->handle) != OK)
  179. WLAN_REPORT_ERROR(pWhalDefrag->hReport, HAL_RX_MODULE_LOG,
  180. ("whalDefrag_MpduCollect: ERROR wlan_memMngrFreeMSDU failure \n"));
  181. return (MPDU_DROP);
  182. }
  183. }
  184. /*
  185. * ----------------------------------------------------------------------------
  186. * Function : whalDefrag_Destroy
  187. *
  188. * Input :
  189. * Output :
  190. * Process :
  191. * Note(s) :
  192. * -----------------------------------------------------------------------------
  193. */
  194. int whalDefrag_Destroy (TI_HANDLE hWhalDefrag)
  195. {
  196. UINT8 i;
  197. WHAL_DEFRAG *pWhalDefrag = (WHAL_DEFRAG *)hWhalDefrag;
  198. if (pWhalDefrag == NULL)
  199. return OK;
  200. for (i=0; i<pWhalDefrag->numCollectEntry; i++)
  201. {
  202. /* Destroy EndPoint object */
  203. if (whalEndpnt_Destroy (pWhalDefrag->pWhalEndpntEnt[i]) != OK)
  204. WLAN_REPORT_ERROR(pWhalDefrag->hReport, HAL_RX_MODULE_LOG,
  205. (" whalDefrag_Destroy: whalEndpnt_Destroy failure \n"));
  206. }
  207. os_memoryFree (pWhalDefrag->hOs, pWhalDefrag, sizeof(WHAL_DEFRAG));
  208. return (OK);
  209. }