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