PageRenderTime 52ms CodeModel.GetById 24ms RepoModel.GetById 1ms app.codeStats 0ms

/drivers/net/wireless/tiwlan1251/common/src/hal/security/whalWpa.c

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