PageRenderTime 46ms CodeModel.GetById 14ms RepoModel.GetById 1ms app.codeStats 0ms

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

http://github.com/CyanogenMod/cm-kernel
C | 511 lines | 262 code | 75 blank | 174 comment | 59 complexity | 9e43b349a923e4a5a912bab33918235d 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 "whalCommon.h"
  36. #include "whalCtrl_api.h"
  37. #include "whalCtrl.h"
  38. #include "whalSecurity.h"
  39. /*
  40. * ----------------------------------------------------------------------------
  41. * Function : whalSecur_Create
  42. *
  43. * Input :
  44. * Output :
  45. * Process :
  46. * Note(s) :
  47. * -----------------------------------------------------------------------------
  48. */
  49. TI_HANDLE whalSecur_Create (TI_HANDLE hOs, TI_HANDLE hWhalCtrl, UINT16 numOfStations)
  50. {
  51. WHAL_SECURITY* pWhalSecur;
  52. pWhalSecur = (WHAL_SECURITY *)os_memoryAlloc (hOs, sizeof(WHAL_SECURITY));
  53. if (pWhalSecur == NULL)
  54. return NULL;
  55. os_memoryZero (hOs, (void *)pWhalSecur, sizeof(WHAL_SECURITY));
  56. pWhalSecur->pWhalCtrl = (WHAL_CTRL*)hWhalCtrl;
  57. pWhalSecur->hOs = hOs;
  58. pWhalSecur->securityMode = RSN_CIPHER_NONE;
  59. pWhalSecur->pWhalWep = (WHAL_WEP*)whalWep_Create (hOs, hWhalCtrl);
  60. if (pWhalSecur->pWhalWep == NULL)
  61. {
  62. whalSecur_Destroy(pWhalSecur, numOfStations);
  63. return NULL;
  64. }
  65. pWhalSecur->pWhalWpa = (WHAL_WPA*)whalWpa_Create (hOs, hWhalCtrl);
  66. if (pWhalSecur->pWhalWpa == NULL)
  67. {
  68. whalSecur_Destroy(pWhalSecur, numOfStations);
  69. return NULL;
  70. }
  71. #ifdef CKIP_ENABLED
  72. pWhalSecur->pWhalPrivacy = (privacy_t*)privacy_create (hOs);
  73. pWhalSecur->pWhalExc = (WHAL_EXC*)whalExc_Create(hOs, hWhalCtrl);
  74. if (pWhalSecur->pWhalExc == NULL)
  75. {
  76. whalSecur_Destroy(pWhalSecur, numOfStations);
  77. return NULL;
  78. }
  79. #endif /* CKIP_ENABLED */
  80. pWhalSecur->numOfStations = numOfStations;
  81. pWhalSecur->reconfData.reconfKeys = (securityKeys_t*)os_memoryAlloc (hOs,
  82. (sizeof(securityKeys_t))*(numOfStations*NO_OF_RECONF_SECUR_KEYS_PER_STATION+NO_OF_EXTRA_RECONF_SECUR_KEYS));
  83. os_memoryZero (hOs, (void *)pWhalSecur->reconfData.reconfKeys,
  84. (sizeof(securityKeys_t))*(numOfStations*NO_OF_RECONF_SECUR_KEYS_PER_STATION+NO_OF_EXTRA_RECONF_SECUR_KEYS));
  85. return ((TI_HANDLE)pWhalSecur);
  86. }
  87. /*
  88. * ----------------------------------------------------------------------------
  89. * Function : whalSecur_Config
  90. *
  91. * Input :
  92. * Output :
  93. * Process :
  94. * Note(s) :
  95. * -----------------------------------------------------------------------------
  96. */
  97. int whalSecur_Config (TI_HANDLE hWhalSecur, whalSecur_config_t* pWhalSecurCfg)
  98. {
  99. UINT32 index;
  100. whalWep_config_t wepCfg;
  101. whalWpa_config_t wpaCfg;
  102. #ifdef CKIP_ENABLED
  103. whalExc_config_t excCfg;
  104. #endif /* CKIP_ENABLED*/
  105. WHAL_SECURITY* pWhalSecur = (TI_HANDLE)hWhalSecur;
  106. /* Reset all reconfig valid fields*/
  107. pWhalSecur->reconfData.isHwEncDecrEnableValid = FALSE;
  108. pWhalSecur->reconfData.isDefaultKeyIdValid = FALSE;
  109. for (index=0; index < ((pWhalSecur->numOfStations)*NO_OF_RECONF_SECUR_KEYS_PER_STATION+NO_OF_EXTRA_RECONF_SECUR_KEYS); index++)
  110. (pWhalSecur->reconfData.reconfKeys+index)->keyType = NULL_KEY;
  111. /* Save configuration parameters */
  112. pWhalSecur->hMemMgr = pWhalSecurCfg->hMemMgr;
  113. pWhalSecur->hReport = pWhalSecurCfg->hReport;
  114. /* Config the wep sub-module*/
  115. wepCfg.hMemMgr = pWhalSecur->hMemMgr;
  116. wepCfg.hReport = pWhalSecur->hReport;
  117. if (whalWep_Config (pWhalSecur->pWhalWep, &wepCfg) != OK)
  118. return (NOK);
  119. /* Config the wpa sub-module*/
  120. wpaCfg.hMemMgr = pWhalSecur->hMemMgr;
  121. wpaCfg.hReport = pWhalSecur->hReport;
  122. if (whalWpa_Config (pWhalSecur->pWhalWpa, &wpaCfg) != OK)
  123. return (NOK);
  124. #ifdef CKIP_ENABLED
  125. wpaCfg.pWhalPrivacy = pWhalSecur->pWhalPrivacy;
  126. /* Config the privacy sub-module*/
  127. if (privacy_config (pWhalSecur->pWhalPrivacy,
  128. pWhalSecur->hReport, pWhalSecur->hOs) != OK)
  129. return (NOK);
  130. excCfg.hMemMgr = pWhalSecur->hMemMgr;
  131. excCfg.hReport = pWhalSecur->hReport;
  132. excCfg.pWhalPrivacy = pWhalSecur->pWhalPrivacy;
  133. if (whalExc_Config (pWhalSecur->pWhalExc, &excCfg) != OK)
  134. return (NOK);
  135. #endif /*CKIP_ENABLED */
  136. return (OK);
  137. }
  138. /*
  139. * ----------------------------------------------------------------------------
  140. * Function : whalSecur_KeyAdd
  141. *
  142. * Input :
  143. * Output :
  144. * Process :
  145. * Note(s) :
  146. * -----------------------------------------------------------------------------
  147. */
  148. int whalSecur_KeyAdd (TI_HANDLE hWhalSecur, securityKeys_t* pKey, BOOL reconfFlag, void *CB_Func, TI_HANDLE CB_handle)
  149. {
  150. WHAL_SECURITY* pWhalSecur = (TI_HANDLE)hWhalSecur;
  151. UINT8 keyIdx = (UINT8)pKey->keyIndex;
  152. /* store the security key for reconfigure time (FW reload)*/
  153. if (reconfFlag != TRUE)
  154. {
  155. if (keyIdx >= ((pWhalSecur->numOfStations)*NO_OF_RECONF_SECUR_KEYS_PER_STATION+NO_OF_EXTRA_RECONF_SECUR_KEYS))
  156. {
  157. WLAN_REPORT_ERROR(pWhalSecur->hReport, HAL_SECURITY_MODULE_LOG,
  158. ("whalSecur_KeyAdd: ERROR Key keyIndex field out of range =%d, range is (0 to %d)\n",
  159. pKey->keyIndex, (pWhalSecur->numOfStations)*NO_OF_RECONF_SECUR_KEYS_PER_STATION+NO_OF_EXTRA_RECONF_SECUR_KEYS-1));
  160. return (NOK);
  161. }
  162. if (pKey->keyType == NULL_KEY)
  163. {
  164. WLAN_REPORT_ERROR(pWhalSecur->hReport, HAL_SECURITY_MODULE_LOG,
  165. ("whalSecur_KeyAdd: ERROR KeyType is NULL_KEY\n"));
  166. return (NOK);
  167. }
  168. os_memoryCopy (pWhalSecur->hOs,
  169. (void *)(pWhalSecur->reconfData.reconfKeys + keyIdx),
  170. (void *)pKey, sizeof(securityKeys_t));
  171. }
  172. switch (pWhalSecur->securityMode)
  173. {
  174. case RSN_CIPHER_WEP:
  175. case RSN_CIPHER_WEP104:
  176. return (whalWep_KeyAdd (pWhalSecur->pWhalWep, pKey, CB_Func, CB_handle));
  177. case RSN_CIPHER_TKIP:
  178. case RSN_CIPHER_AES_CCMP:
  179. return (whalWpa_KeyAdd (pWhalSecur->pWhalWpa, pKey, CB_Func, CB_handle));
  180. default:
  181. return (NOK);
  182. }
  183. }
  184. /*
  185. * ----------------------------------------------------------------------------
  186. * Function : whalSecur_KeyRemove
  187. *
  188. * Input :
  189. * Output :
  190. * Process :
  191. * Note(s) :
  192. * -----------------------------------------------------------------------------
  193. */
  194. int whalSecur_KeyRemove (TI_HANDLE hWhalSecur, securityKeys_t* pKey, BOOL reconfFlag, void *CB_Func, TI_HANDLE CB_handle)
  195. {
  196. WHAL_SECURITY* pWhalSecur = (TI_HANDLE)hWhalSecur;
  197. switch (pWhalSecur->securityMode)
  198. {
  199. case RSN_CIPHER_WEP:
  200. case RSN_CIPHER_WEP104:
  201. return (whalWep_KeyRemove (pWhalSecur->pWhalWep, pKey, CB_Func, CB_handle));
  202. case RSN_CIPHER_TKIP:
  203. case RSN_CIPHER_AES_CCMP:
  204. return (whalWpa_KeyRemove (pWhalSecur->pWhalWpa, pKey, CB_Func, CB_handle));
  205. default:
  206. return (NOK);
  207. }
  208. }
  209. /*
  210. * ----------------------------------------------------------------------------
  211. * Function : whalSecur_DefaultKeyIdSet
  212. *
  213. * Input :
  214. * Output :
  215. * Process :
  216. * Note(s) :
  217. * -----------------------------------------------------------------------------
  218. */
  219. int whalSecur_DefaultKeyIdSet (TI_HANDLE hWhalSecur, UINT8 aKeyId, void *CB_Func, TI_HANDLE CB_handle)
  220. {
  221. WHAL_SECURITY* pWhalSecur = (TI_HANDLE)hWhalSecur;
  222. /* store the default key ID value for reconfigure time (FW reload)*/
  223. pWhalSecur->reconfData.reconfDefaultKeyId = aKeyId;
  224. switch (pWhalSecur->securityMode)
  225. {
  226. case RSN_CIPHER_WEP:
  227. case RSN_CIPHER_WEP104:
  228. pWhalSecur->reconfData.isDefaultKeyIdValid = TRUE;
  229. return (whalWep_DefaultKeyIdSet (pWhalSecur->pWhalWep, aKeyId, CB_Func, CB_handle));
  230. case RSN_CIPHER_TKIP:
  231. case RSN_CIPHER_AES_CCMP:
  232. pWhalSecur->reconfData.isDefaultKeyIdValid = TRUE;
  233. return (whalWpa_DefaultKeyIdSet (pWhalSecur->pWhalWpa, aKeyId, CB_Func, CB_handle));
  234. default:
  235. return (NOK);
  236. }
  237. }
  238. /*
  239. * ----------------------------------------------------------------------------
  240. * Function : whalSecur_HwEncDecrEnable
  241. *
  242. * Input :
  243. * Output :
  244. * Process :
  245. * Note(s) :
  246. * -----------------------------------------------------------------------------
  247. */
  248. int whalSecur_HwEncDecrEnable (TI_HANDLE hWhalSecur, BOOL aHwEncEnable)
  249. {
  250. WHAL_SECURITY* pWhalSecur = (TI_HANDLE)hWhalSecur;
  251. /* store the HW encryption Enable flag for reconfigure time (FW reload)*/
  252. pWhalSecur->reconfData.reconfHwEncEnable = aHwEncEnable;
  253. pWhalSecur->reconfData.isHwEncDecrEnableValid = TRUE;
  254. return (whal_hwCtrl_EncDecrSet (pWhalSecur->pWhalCtrl->pHwCtrl, aHwEncEnable, aHwEncEnable));
  255. }
  256. #ifdef CKIP_ENABLED
  257. /*
  258. * ----------------------------------------------------------------------------
  259. * Function : whalSecur_SwEncEnable
  260. *
  261. * Input :
  262. * Output :
  263. * Process :
  264. * Note(s) :
  265. * -----------------------------------------------------------------------------
  266. */
  267. int whalSecur_SwEncEnable (TI_HANDLE hWhalSecur, BOOL aSwEncEnable)
  268. {
  269. WHAL_SECURITY* pWhalSecur = (TI_HANDLE)hWhalSecur;
  270. return (whalExc_swEncEnable (pWhalSecur->pWhalExc, aSwEncEnable));
  271. }
  272. /*
  273. * ----------------------------------------------------------------------------
  274. * Function : whalSecur_MicFieldEnable
  275. *
  276. * Input :
  277. * Output :
  278. * Process :
  279. * Note(s) :
  280. * -----------------------------------------------------------------------------
  281. */
  282. int whalSecur_MicFieldEnable (TI_HANDLE hWhalSecur, BOOL aMicFieldEnable)
  283. {
  284. WHAL_SECURITY* pWhalSecur = (TI_HANDLE)hWhalSecur;
  285. return (whalExc_micFieldEnable (pWhalSecur->pWhalExc, aMicFieldEnable));
  286. }
  287. #endif /*CKIP_ENABLED*/
  288. /*
  289. * ----------------------------------------------------------------------------
  290. * Function : whalSecur_SecurModeSet
  291. *
  292. * Input :
  293. * Output :
  294. * Process :
  295. * Note(s) :
  296. * -----------------------------------------------------------------------------
  297. */
  298. int whalSecur_SecurModeSet (TI_HANDLE hWhalSecur, cipherSuite_e aSecurMode)
  299. {
  300. UINT32 index;
  301. WHAL_SECURITY* pWhalSecur = (TI_HANDLE)hWhalSecur;
  302. if (aSecurMode<=RSN_CIPHER_CKIP)
  303. {
  304. WLAN_REPORT_INFORMATION (pWhalSecur->hReport, HAL_SECURITY_MODULE_LOG,
  305. ("whalSecur_SecurModeSet: change security mode from %d --> %d\n",
  306. pWhalSecur->securityMode, aSecurMode));
  307. /* check if security mode is equal to previous one*/
  308. if (pWhalSecur->securityMode == aSecurMode)
  309. return (OK);
  310. /* Reset all reconfig valid fields*/
  311. pWhalSecur->reconfData.isHwEncDecrEnableValid = FALSE;
  312. pWhalSecur->reconfData.isDefaultKeyIdValid = FALSE;
  313. for (index=0; index < ((pWhalSecur->numOfStations)*NO_OF_RECONF_SECUR_KEYS_PER_STATION+NO_OF_EXTRA_RECONF_SECUR_KEYS); index++)
  314. (pWhalSecur->reconfData.reconfKeys+index)->keyType = NULL_KEY;
  315. /* set the new security mode*/
  316. pWhalSecur->securityMode = aSecurMode;
  317. #ifdef CKIP_ENABLED
  318. /* Upon entering to RSN_PRIVACY_EXC mode, disable the excSwEnc and excMicField flags,
  319. reset the privacy Enc sub-module */
  320. if (aSecurMode == RSN_CIPHER_CKIP)
  321. {
  322. if (whalExc_swEncEnable (pWhalSecur->pWhalExc, FALSE) != OK)
  323. return (NOK);
  324. if (whalExc_micFieldEnable (pWhalSecur->pWhalExc, FALSE) != OK)
  325. return (NOK);
  326. if (privacy_resetEnc (pWhalSecur->pWhalPrivacy) != OK)
  327. return (NOK);
  328. }
  329. privacy_setPrivacyMode(pWhalSecur->pWhalPrivacy, aSecurMode);
  330. #endif /* CKIP_ENABLED*/
  331. /* disable defrag, duplicate detection on TNETW+EXC on chip level*/
  332. if (pWhalSecur->securityMode==RSN_CIPHER_CKIP)
  333. /* YV- to add fragmentation control (if there is- artur ?)*/
  334. return (whal_hwCtrl_RxMsduFormatSet (pWhalSecur->pWhalCtrl->pHwCtrl, FALSE));
  335. else
  336. /* YV- to add fragmentation control (if there is- artur ?)*/
  337. return (whal_hwCtrl_RxMsduFormatSet (pWhalSecur->pWhalCtrl->pHwCtrl, TRUE));
  338. }
  339. else
  340. return (NOK);
  341. }
  342. /*
  343. * ----------------------------------------------------------------------------
  344. * Function : whalSecur_SecurModeGet
  345. *
  346. * Input :
  347. * Output : security mode
  348. * Process :
  349. * Note(s) :
  350. * -----------------------------------------------------------------------------
  351. */
  352. cipherSuite_e whalSecur_SecurModeGet (TI_HANDLE hWhalSecur)
  353. {
  354. WHAL_SECURITY* pWhalSecur = (TI_HANDLE)hWhalSecur;
  355. return pWhalSecur->securityMode;
  356. }
  357. /*
  358. * ----------------------------------------------------------------------------
  359. * Function : whalSecur_KeysReconfig
  360. *
  361. * Input :
  362. * Output :
  363. * Process : Reconfig security keys, default key Id and encryption/decryption
  364. * control to the FW
  365. * Note(s) :
  366. * -----------------------------------------------------------------------------
  367. */
  368. int whalSecur_KeysReconfig (TI_HANDLE hWhalSecur)
  369. {
  370. UINT32 index;
  371. WHAL_SECURITY* pWhalSecur = (WHAL_SECURITY *)hWhalSecur;
  372. if (pWhalSecur->securityMode != RSN_CIPHER_NONE)
  373. {
  374. /* set the keys to the HW*/
  375. for (index=0; index < ((pWhalSecur->numOfStations)*NO_OF_RECONF_SECUR_KEYS_PER_STATION+NO_OF_EXTRA_RECONF_SECUR_KEYS); index++)
  376. {
  377. if ((pWhalSecur->reconfData.reconfKeys+index)->keyType != NULL_KEY)
  378. {
  379. if (whalSecur_KeyAdd (pWhalSecur, pWhalSecur->reconfData.reconfKeys+index, TRUE, NULL, NULL) != OK)
  380. {
  381. WLAN_REPORT_ERROR(pWhalSecur->hReport, HAL_SECURITY_MODULE_LOG,
  382. ("whalSecur_KeysReconfig: ERROR whalSecur_KeyAdd failure index=%d\n", index));
  383. return (NOK);
  384. }
  385. }
  386. }
  387. if (pWhalSecur->reconfData.isDefaultKeyIdValid == TRUE)
  388. {
  389. /* set the deafult key ID to the HW*/
  390. if (whalSecur_DefaultKeyIdSet (pWhalSecur, pWhalSecur->reconfData.reconfDefaultKeyId, NULL, NULL) != OK)
  391. {
  392. WLAN_REPORT_ERROR(pWhalSecur->hReport, HAL_SECURITY_MODULE_LOG,
  393. ("whalSecur_KeysReconfig: ERROR whalSecur_DefaultKeyIdSet failure \n"));
  394. return (NOK);
  395. }
  396. }
  397. } /* pWhalSecur->securityMode != RSN_CIPHER_NONE */
  398. /* set the encryption/decryption control on the HW*/
  399. if (whalSecur_HwEncDecrEnable (pWhalSecur, pWhalSecur->reconfData.reconfHwEncEnable) != OK)
  400. {
  401. WLAN_REPORT_ERROR(pWhalSecur->hReport, HAL_SECURITY_MODULE_LOG,
  402. ("whalSecur_KeysReconfig: ERROR whalSecur_HwEncDecrEnable failure \n"));
  403. return (NOK);
  404. }
  405. return (OK);
  406. }
  407. /*
  408. * ----------------------------------------------------------------------------
  409. * Function : whalSecur_Destroy
  410. *
  411. * Input :
  412. * Output :
  413. * Process : Unload the HAL security module
  414. * Note(s) :
  415. * -----------------------------------------------------------------------------
  416. */
  417. int whalSecur_Destroy (TI_HANDLE hWhalSecur, UINT16 numOfStations)
  418. {
  419. WHAL_SECURITY* pWhalSecur = (WHAL_SECURITY *)hWhalSecur;
  420. if (!pWhalSecur)
  421. return OK;
  422. #ifdef CKIP_ENABLED
  423. whalExc_Destroy (pWhalSecur->pWhalExc);
  424. if (privacy_unload(pWhalSecur->pWhalPrivacy) != OK)
  425. WLAN_REPORT_ERROR(pWhalSecur->hReport, HAL_CTRL_MODULE_LOG, (" whalSecur_Destroy: privacy_unload failure \n"));
  426. #endif /* CKIP_ENABLED*/
  427. if (whalWpa_Destroy (pWhalSecur->pWhalWpa) != OK)
  428. WLAN_REPORT_ERROR(pWhalSecur->hReport, HAL_CTRL_MODULE_LOG, (" whalSecur_Destroy: whalWpa_Destroy failure \n"));
  429. if (whalWep_Destroy (pWhalSecur->pWhalWep) != OK)
  430. WLAN_REPORT_ERROR(pWhalSecur->hReport, HAL_CTRL_MODULE_LOG, (" whalSecur_Destroy: whalWep_Destroy failure \n"));
  431. if (pWhalSecur->reconfData.reconfKeys)
  432. os_memoryFree (pWhalSecur->hOs, pWhalSecur->reconfData.reconfKeys,
  433. (sizeof(securityKeys_t))*(numOfStations*NO_OF_RECONF_SECUR_KEYS_PER_STATION+NO_OF_EXTRA_RECONF_SECUR_KEYS));
  434. os_memoryFree (pWhalSecur->hOs, pWhalSecur, sizeof(WHAL_SECURITY));
  435. return (OK);
  436. }