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 "802_11Defs.h" 37 #include "Ethernet.h" 38 #include "whalCommon.h" 39 #include "whalCtrl_api.h" 40 #include "whalCtrl.h" 41 #include "whalSecurity.h" 42 #include "whalWpa.h" 43 44 45 46 #undef WHAL_WPA_MODULE_LOG_PRINT_ENABLE 47 48 static void whal_MsduContentDump (TI_HANDLE hWhalWpa, mem_MSDU_T* pMsdu, char* str); 49 50 /* 51 * ---------------------------------------------------------------------------- 52 * Function : whal_MsduContentDump 53 * 54 * Input : 55 * Output : 56 * Process : 57 * Note(s) : 58 * ----------------------------------------------------------------------------- 59 */ 60 static void whal_MsduContentDump (TI_HANDLE hWhalWpa, mem_MSDU_T* pMsdu, char *str) 61 { 62 #ifdef WHAL_WPA_MODULE_LOG_PRINT_ENABLE 63 UINT32 msduLen; 64 mem_BD_T* pCurrBd; 65 WHAL_WPA* pWhalWpa = (WHAL_WPA *)hWhalWpa; 66 67 WLAN_REPORT_INFORMATION(pWhalWpa->hReport, HAL_SECURITY_MODULE_LOG, 68 ("%s totalLen=%d^^^^^ \n", str, pMsdu->dataLen)); 69 70 msduLen = pMsdu->dataLen; 71 pCurrBd = pMsdu->firstBDPtr; 72 73 while ((msduLen >= 0)&&(pCurrBd!=NULL)) 74 { 75 WLAN_REPORT_INFORMATION(pWhalWpa->hReport, HAL_SECURITY_MODULE_LOG, 76 ("\nBdLen = %d\n", pCurrBd->length)); 77 78 HexDumpData((UINT8*)(pCurrBd->data+pCurrBd->dataOffset), pCurrBd->length); 79 80 msduLen -= pCurrBd->length; 81 pCurrBd = pCurrBd->nextBDPtr; 82 } 83 84 #endif /*WHAL_WPA_MODULE_LOG_PRINT_ENABLE*/ 85 } 86 /* 87 * ---------------------------------------------------------------------------- 88 * Function : whalWpa_Create 89 * 90 * Input : 91 * Output : 92 * Process : Create the WPA - security sub-module. 93 * Note(s) : 94 * ----------------------------------------------------------------------------- 95 */ 96 TI_HANDLE whalWpa_Create (TI_HANDLE hOs, TI_HANDLE hWhalCtrl) 97 { 98 WHAL_WPA* pWhalWpa; 99 100 pWhalWpa = (WHAL_WPA *)os_memoryAlloc (hOs, sizeof(WHAL_WPA)); 101 if (pWhalWpa == NULL) 102 return NULL; 103 104 os_memoryZero (hOs, (void *)pWhalWpa, sizeof(WHAL_WPA)); 105 106 pWhalWpa->pWhalCtrl = (WHAL_CTRL *)hWhalCtrl; 107 pWhalWpa->hOs = hOs; 108 109 return((TI_HANDLE)pWhalWpa); 110 } 111 112 /* 113 * ---------------------------------------------------------------------------- 114 * Function : whalWpa_Config 115 * 116 * Input : 117 * Output : 118 * Process : Configure the WPA - security sub-module. 119 * Note(s) : 120 * ----------------------------------------------------------------------------- 121 */ 122 int whalWpa_Config (TI_HANDLE hWhalWpa, whalWpa_config_t* pWhalWpaCfg) 123 { 124 WHAL_WPA* pWhalWpa = (WHAL_WPA *)hWhalWpa; 125 126 pWhalWpa->hReport = pWhalWpaCfg->hReport; 127 pWhalWpa->hMemMgr = pWhalWpaCfg->hMemMgr; 128 129 return (OK); 130 } 131 132 /* 133 * ---------------------------------------------------------------------------- 134 * Function : whalWpa_MpduListFieldsAdd 135 * 136 * Input : Transmitted MSDU 137 * Output : MSDU after padding for TKIP EIV or AES RSN fields. 138 * Process : Shift LLC+SNAP apart from WLAN header to add padding for EIV/RSN field. 139 * 140 * Note(s) : An LLC+SNAP is located just after the 802.11 header 141 * on the first MPDU header only. 142 * ----------------------------------------------------------------------------- 143 */ 144 int whalWpa_MpduListFieldsAdd (TI_HANDLE hWhalWpa, mem_MSDU_T* pMpduList) 145 { 146 WHAL_WPA* pWhalWpa = (WHAL_WPA *)hWhalWpa; 147 UINT32 AddFieldSize; 148 UINT8 tempbuff[WLAN_SNAP_HDR_LEN + WLAN_4X_CONCAT_HDR_LEN]; 149 150 /* 151 * Check TX key type 152 * In case of TKIP we need to add bytes for IV 153 * For AES we need to add 8 bytes 154 * For unified AES - always add 8 bytes 155 */ 156 if(pWhalWpa->currTxKeyType == TKIP_KEY) 157 { 158 AddFieldSize = IV_FIELD_SIZE; 159 } 160 else 161 if(pWhalWpa->currTxKeyType == AES_KEY) 162 { 163 AddFieldSize = AES_AFTER_HEADER_FIELD_SIZE; 164 } 165 else 166 return OK; 167 168 /* Check if LLC+SNAP exist in the buffer of the header. */ 169 if ( (memMgr_MsduFirstLen(pMpduList) == pMpduList->headerLen+WLAN_SNAP_HDR_LEN) || 170 (memMgr_MsduFirstLen(pMpduList) == pMpduList->headerLen+WLAN_SNAP_HDR_LEN + WLAN_4X_CONCAT_HDR_LEN ) ) 171 { 172 UINT8 *pHeaderEnd = (UINT8*)( (UINT32)memMgr_BufData(pMpduList->firstBDPtr) + 173 memMgr_BufOffset(pMpduList->firstBDPtr) + pMpduList->headerLen ); 174 175 /* Copy LLC+SNAP to temp buffer. */ 176 os_memoryCopy (pWhalWpa->hOs, (void *)tempbuff, (void *)pHeaderEnd, WLAN_SNAP_HDR_LEN + WLAN_4X_CONCAT_HDR_LEN); 177 178 /* Copy LLC+SNAP from temp buffer back to BD with required padding. */ 179 os_memoryCopy (pWhalWpa->hOs, (void *)(pHeaderEnd + AddFieldSize), (void *)tempbuff, WLAN_SNAP_HDR_LEN + WLAN_4X_CONCAT_HDR_LEN); 180 181 /* Clear padding field. */ 182 os_memoryZero (pWhalWpa->hOs, (void *)pHeaderEnd, AddFieldSize); 183 } 184 else 185 { 186 WLAN_REPORT_WARNING(pWhalWpa->hReport, HAL_SECURITY_MODULE_LOG, 187 ("whalWpa_MpduListFieldsAdd: ERROR: First Buffer Length Is Illegal !!!!!! \n")); 188 } 189 190 /* Update BD and MSDU sizes to include the padding. */ 191 memMgr_MsduFirstLen(pMpduList) += AddFieldSize; 192 memMgr_MsduDataSize(pMpduList) += AddFieldSize; 193 194 whal_MsduContentDump (pWhalWpa, pMpduList, "whalWpa_MpduListFieldsAdd: Exit (Tx Path) "); 195 return (OK); 196 } 197 198 /* 199 * ---------------------------------------------------------------------------- 200 * Function : whalWpa_KeyAdd 201 * 202 * Input : 203 * Output : 204 * Process : Add key to the HW. 205 * Note(s) : 206 * ----------------------------------------------------------------------------- 207 */ 208 int whalWpa_KeyAdd (TI_HANDLE hWhalWpa, securityKeys_t* pKey, void *CB_Func, TI_HANDLE CB_handle) 209 { 210 WHAL_WPA* pWhalWpa = (WHAL_WPA *)hWhalWpa; 211 212 /* Only WEP, TKIP, AES keys are handled*/ 213 switch (pKey->keyType) 214 { 215 case WEP_KEY: 216 /* Configure the encKeys to the HW - default keys cache*/ 217 return (whal_hwCtrl_WepDefaultKeyAdd (pWhalWpa->pWhalCtrl->pHwCtrl, pKey, CB_Func, CB_handle)); 218 219 case TKIP_KEY: 220 /* Set the REAL TKIP key into the TKIP key cache*/ 221 if (whal_hwCtrl_TkipMicMappingKeyAdd (pWhalWpa->pWhalCtrl->pHwCtrl, pKey, CB_Func, CB_handle) != OK) 222 return (NOK); 223 224 break; 225 226 case AES_KEY: 227 if (whal_hwCtrl_AesMappingKeyAdd (pWhalWpa->pWhalCtrl->pHwCtrl, pKey, CB_Func, CB_handle) != OK) 228 return (NOK); 229 break; 230 231 default: 232 return (NOK); 233 } 234 235 /* AES or TKIP key has been successfully added. Store the current */ 236 /* key type of the unicast (i.e. transmit !) key */ 237 if(!MAC_BROADCAST((&pKey->macAddress))) 238 { 239 pWhalWpa->currTxKeyType = pKey->keyType; 240 } 241 242 return (OK); 243 } 244 245 /* 246 * ---------------------------------------------------------------------------- 247 * Function : whalWpa_KeyRemove 248 * 249 * Input : 250 * Output : 251 * Process : Add key to the HW. 252 * Note(s) : 253 * ----------------------------------------------------------------------------- 254 */ 255 int whalWpa_KeyRemove (TI_HANDLE hWhalWpa, securityKeys_t* pKey, void *CB_Func, TI_HANDLE CB_handle) 256 { 257 WHAL_WPA* pWhalWpa = (WHAL_WPA *)hWhalWpa; 258 259 /* Only WEP, TKIP, AES keys are handled*/ 260 switch (pKey->keyType) 261 { 262 case WEP_KEY: 263 /* Configure the encKeys to the HW - default keys cache*/ 264 return (whal_hwCtrl_WepDefaultKeyRemove (pWhalWpa->pWhalCtrl->pHwCtrl, pKey, CB_Func, CB_handle)); 265 266 case TKIP_KEY: 267 /* Configure the encKeys to the HW - mapping keys cache*/ 268 /* configure through SET_KEYS command */ 269 270 /* remove the TKIP key from the TKIP key cache*/ 271 if (whal_hwCtrl_TkipMicMappingKeyRemove (pWhalWpa->pWhalCtrl->pHwCtrl, pKey, CB_Func, CB_handle) != OK) 272 return (NOK); 273 274 break; 275 276 case AES_KEY: 277 if (whal_hwCtrl_AesMappingKeyRemove (pWhalWpa->pWhalCtrl->pHwCtrl, pKey, CB_Func, CB_handle) != OK) 278 return (NOK); 279 break; 280 281 282 default: 283 return (NOK); 284 } 285 286 return (OK); 287 } 288 289 /* 290 * ---------------------------------------------------------------------------- 291 * Function : whalWpa_DefaultKeyIdSet 292 * 293 * Input : 294 * Output : 295 * Process : Configure the default key Id to the HW. 296 * Note(s) : 297 * ----------------------------------------------------------------------------- 298 */ 299 int whalWpa_DefaultKeyIdSet (TI_HANDLE hWhalWpa, UINT8 aKeyId, void *CB_Func, TI_HANDLE CB_handle) 300 { 301 /* Do not configure the default key id to the HW, return OK to the caller*/ 302 return (OK); 303 } 304 305 /* 306 * ---------------------------------------------------------------------------- 307 * Function : whalWpa_Destroy 308 * 309 * Input : 310 * Output : 311 * Process : Destroy the WPA - security sub-module. 312 * Note(s) : 313 * ----------------------------------------------------------------------------- 314 */ 315 int whalWpa_Destroy (TI_HANDLE hWhalWpa) 316 { 317 WHAL_WPA *pWhalWpa = (WHAL_WPA *)hWhalWpa; 318 319 if (pWhalWpa) 320 os_memoryFree (pWhalWpa->hOs, pWhalWpa, sizeof(WHAL_WPA)); 321 322 return (OK); 323 } 324 325