cam.c 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291
  1. /******************************************************************************
  2. *
  3. * Copyright(c) 2009-2010 Realtek Corporation.
  4. *
  5. * This program is free software; you can redistribute it and/or modify it
  6. * under the terms of version 2 of the GNU General Public License as
  7. * published by the Free Software Foundation.
  8. *
  9. * This program is distributed in the hope that it will be useful, but WITHOUT
  10. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  12. * more details.
  13. *
  14. * You should have received a copy of the GNU General Public License along with
  15. * this program; if not, write to the Free Software Foundation, Inc.,
  16. * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
  17. *
  18. * The full GNU General Public License is included in this distribution in the
  19. * file called LICENSE.
  20. *
  21. * Contact Information:
  22. * wlanfae <wlanfae@realtek.com>
  23. * Realtek Corporation, No. 2, Innovation Road II, Hsinchu Science Park,
  24. * Hsinchu 300, Taiwan.
  25. *
  26. *****************************************************************************/
  27. #include "wifi.h"
  28. #include "cam.h"
  29. void rtl_cam_reset_sec_info(struct ieee80211_hw *hw)
  30. {
  31. struct rtl_priv *rtlpriv = rtl_priv(hw);
  32. rtlpriv->sec.use_defaultkey = false;
  33. rtlpriv->sec.pairwise_enc_algorithm = NO_ENCRYPTION;
  34. rtlpriv->sec.group_enc_algorithm = NO_ENCRYPTION;
  35. memset(rtlpriv->sec.key_buf, 0, KEY_BUF_SIZE * MAX_KEY_LEN);
  36. memset(rtlpriv->sec.key_len, 0, KEY_BUF_SIZE);
  37. rtlpriv->sec.pairwise_key = NULL;
  38. }
  39. static void rtl_cam_program_entry(struct ieee80211_hw *hw, u32 entry_no,
  40. u8 *mac_addr, u8 *key_cont_128, u16 us_config)
  41. {
  42. struct rtl_priv *rtlpriv = rtl_priv(hw);
  43. u32 target_command;
  44. u32 target_content = 0;
  45. u8 entry_i;
  46. RT_TRACE(rtlpriv, COMP_SEC, DBG_DMESG,
  47. ("key_cont_128:\n %x:%x:%x:%x:%x:%x\n",
  48. key_cont_128[0], key_cont_128[1],
  49. key_cont_128[2], key_cont_128[3],
  50. key_cont_128[4], key_cont_128[5]));
  51. for (entry_i = 0; entry_i < CAM_CONTENT_COUNT; entry_i++) {
  52. target_command = entry_i + CAM_CONTENT_COUNT * entry_no;
  53. target_command = target_command | BIT(31) | BIT(16);
  54. if (entry_i == 0) {
  55. target_content = (u32) (*(mac_addr + 0)) << 16 |
  56. (u32) (*(mac_addr + 1)) << 24 | (u32) us_config;
  57. rtl_write_dword(rtlpriv, rtlpriv->cfg->maps[WCAMI],
  58. target_content);
  59. rtl_write_dword(rtlpriv, rtlpriv->cfg->maps[RWCAM],
  60. target_command);
  61. RT_TRACE(rtlpriv, COMP_SEC, DBG_DMESG,
  62. ("rtl_cam_program_entry(): "
  63. "WRITE %x: %x\n",
  64. rtlpriv->cfg->maps[WCAMI], target_content));
  65. RT_TRACE(rtlpriv, COMP_SEC, DBG_DMESG,
  66. ("The Key ID is %d\n", entry_no));
  67. RT_TRACE(rtlpriv, COMP_SEC, DBG_DMESG,
  68. ("rtl_cam_program_entry(): "
  69. "WRITE %x: %x\n",
  70. rtlpriv->cfg->maps[RWCAM], target_command));
  71. } else if (entry_i == 1) {
  72. target_content = (u32) (*(mac_addr + 5)) << 24 |
  73. (u32) (*(mac_addr + 4)) << 16 |
  74. (u32) (*(mac_addr + 3)) << 8 |
  75. (u32) (*(mac_addr + 2));
  76. rtl_write_dword(rtlpriv, rtlpriv->cfg->maps[WCAMI],
  77. target_content);
  78. rtl_write_dword(rtlpriv, rtlpriv->cfg->maps[RWCAM],
  79. target_command);
  80. RT_TRACE(rtlpriv, COMP_SEC, DBG_DMESG,
  81. ("rtl_cam_program_entry(): WRITE A4: %x\n",
  82. target_content));
  83. RT_TRACE(rtlpriv, COMP_SEC, DBG_DMESG,
  84. ("rtl_cam_program_entry(): WRITE A0: %x\n",
  85. target_command));
  86. } else {
  87. target_content =
  88. (u32) (*(key_cont_128 + (entry_i * 4 - 8) + 3)) <<
  89. 24 | (u32) (*(key_cont_128 + (entry_i * 4 - 8) + 2))
  90. << 16 |
  91. (u32) (*(key_cont_128 + (entry_i * 4 - 8) + 1)) << 8
  92. | (u32) (*(key_cont_128 + (entry_i * 4 - 8) + 0));
  93. rtl_write_dword(rtlpriv, rtlpriv->cfg->maps[WCAMI],
  94. target_content);
  95. rtl_write_dword(rtlpriv, rtlpriv->cfg->maps[RWCAM],
  96. target_command);
  97. udelay(100);
  98. RT_TRACE(rtlpriv, COMP_SEC, DBG_DMESG,
  99. ("rtl_cam_program_entry(): WRITE A4: %x\n",
  100. target_content));
  101. RT_TRACE(rtlpriv, COMP_SEC, DBG_DMESG,
  102. ("rtl_cam_program_entry(): WRITE A0: %x\n",
  103. target_command));
  104. }
  105. }
  106. RT_TRACE(rtlpriv, COMP_SEC, DBG_DMESG,
  107. ("after set key, usconfig:%x\n", us_config));
  108. }
  109. u8 rtl_cam_add_one_entry(struct ieee80211_hw *hw, u8 *mac_addr,
  110. u32 ul_key_id, u32 ul_entry_idx, u32 ul_enc_alg,
  111. u32 ul_default_key, u8 *key_content)
  112. {
  113. u32 us_config;
  114. struct rtl_priv *rtlpriv = rtl_priv(hw);
  115. RT_TRACE(rtlpriv, COMP_SEC, DBG_DMESG,
  116. ("EntryNo:%x, ulKeyId=%x, ulEncAlg=%x, "
  117. "ulUseDK=%x MacAddr" MAC_FMT "\n",
  118. ul_entry_idx, ul_key_id, ul_enc_alg,
  119. ul_default_key, MAC_ARG(mac_addr)));
  120. if (ul_key_id == TOTAL_CAM_ENTRY) {
  121. RT_TRACE(rtlpriv, COMP_ERR, DBG_WARNING,
  122. ("<=== ulKeyId exceed!\n"));
  123. return 0;
  124. }
  125. if (ul_default_key == 1) {
  126. us_config = CFG_VALID | ((u16) (ul_enc_alg) << 2);
  127. } else {
  128. us_config = CFG_VALID | ((ul_enc_alg) << 2) | ul_key_id;
  129. }
  130. rtl_cam_program_entry(hw, ul_entry_idx, mac_addr,
  131. (u8 *) key_content, us_config);
  132. RT_TRACE(rtlpriv, COMP_SEC, DBG_DMESG, ("<===\n"));
  133. return 1;
  134. }
  135. EXPORT_SYMBOL(rtl_cam_add_one_entry);
  136. int rtl_cam_delete_one_entry(struct ieee80211_hw *hw,
  137. u8 *mac_addr, u32 ul_key_id)
  138. {
  139. u32 ul_command;
  140. struct rtl_priv *rtlpriv = rtl_priv(hw);
  141. RT_TRACE(rtlpriv, COMP_SEC, DBG_DMESG, ("key_idx:%d\n", ul_key_id));
  142. ul_command = ul_key_id * CAM_CONTENT_COUNT;
  143. ul_command = ul_command | BIT(31) | BIT(16);
  144. rtl_write_dword(rtlpriv, rtlpriv->cfg->maps[WCAMI], 0);
  145. rtl_write_dword(rtlpriv, rtlpriv->cfg->maps[RWCAM], ul_command);
  146. RT_TRACE(rtlpriv, COMP_SEC, DBG_DMESG,
  147. ("rtl_cam_delete_one_entry(): WRITE A4: %x\n", 0));
  148. RT_TRACE(rtlpriv, COMP_SEC, DBG_DMESG,
  149. ("rtl_cam_delete_one_entry(): WRITE A0: %x\n", ul_command));
  150. return 0;
  151. }
  152. EXPORT_SYMBOL(rtl_cam_delete_one_entry);
  153. void rtl_cam_reset_all_entry(struct ieee80211_hw *hw)
  154. {
  155. u32 ul_command;
  156. struct rtl_priv *rtlpriv = rtl_priv(hw);
  157. ul_command = BIT(31) | BIT(30);
  158. rtl_write_dword(rtlpriv, rtlpriv->cfg->maps[RWCAM], ul_command);
  159. }
  160. EXPORT_SYMBOL(rtl_cam_reset_all_entry);
  161. void rtl_cam_mark_invalid(struct ieee80211_hw *hw, u8 uc_index)
  162. {
  163. struct rtl_priv *rtlpriv = rtl_priv(hw);
  164. u32 ul_command;
  165. u32 ul_content;
  166. u32 ul_enc_algo = rtlpriv->cfg->maps[SEC_CAM_AES];
  167. switch (rtlpriv->sec.pairwise_enc_algorithm) {
  168. case WEP40_ENCRYPTION:
  169. ul_enc_algo = rtlpriv->cfg->maps[SEC_CAM_WEP40];
  170. break;
  171. case WEP104_ENCRYPTION:
  172. ul_enc_algo = rtlpriv->cfg->maps[SEC_CAM_WEP104];
  173. break;
  174. case TKIP_ENCRYPTION:
  175. ul_enc_algo = rtlpriv->cfg->maps[SEC_CAM_TKIP];
  176. break;
  177. case AESCCMP_ENCRYPTION:
  178. ul_enc_algo = rtlpriv->cfg->maps[SEC_CAM_AES];
  179. break;
  180. default:
  181. ul_enc_algo = rtlpriv->cfg->maps[SEC_CAM_AES];
  182. }
  183. ul_content = (uc_index & 3) | ((u16) (ul_enc_algo) << 2);
  184. ul_content |= BIT(15);
  185. ul_command = CAM_CONTENT_COUNT * uc_index;
  186. ul_command = ul_command | BIT(31) | BIT(16);
  187. rtl_write_dword(rtlpriv, rtlpriv->cfg->maps[WCAMI], ul_content);
  188. rtl_write_dword(rtlpriv, rtlpriv->cfg->maps[RWCAM], ul_command);
  189. RT_TRACE(rtlpriv, COMP_SEC, DBG_DMESG,
  190. ("rtl_cam_mark_invalid(): WRITE A4: %x\n", ul_content));
  191. RT_TRACE(rtlpriv, COMP_SEC, DBG_DMESG,
  192. ("rtl_cam_mark_invalid(): WRITE A0: %x\n", ul_command));
  193. }
  194. EXPORT_SYMBOL(rtl_cam_mark_invalid);
  195. void rtl_cam_empty_entry(struct ieee80211_hw *hw, u8 uc_index)
  196. {
  197. struct rtl_priv *rtlpriv = rtl_priv(hw);
  198. u32 ul_command;
  199. u32 ul_content;
  200. u32 ul_encalgo = rtlpriv->cfg->maps[SEC_CAM_AES];
  201. u8 entry_i;
  202. switch (rtlpriv->sec.pairwise_enc_algorithm) {
  203. case WEP40_ENCRYPTION:
  204. ul_encalgo = rtlpriv->cfg->maps[SEC_CAM_WEP40];
  205. break;
  206. case WEP104_ENCRYPTION:
  207. ul_encalgo = rtlpriv->cfg->maps[SEC_CAM_WEP104];
  208. break;
  209. case TKIP_ENCRYPTION:
  210. ul_encalgo = rtlpriv->cfg->maps[SEC_CAM_TKIP];
  211. break;
  212. case AESCCMP_ENCRYPTION:
  213. ul_encalgo = rtlpriv->cfg->maps[SEC_CAM_AES];
  214. break;
  215. default:
  216. ul_encalgo = rtlpriv->cfg->maps[SEC_CAM_AES];
  217. }
  218. for (entry_i = 0; entry_i < CAM_CONTENT_COUNT; entry_i++) {
  219. if (entry_i == 0) {
  220. ul_content =
  221. (uc_index & 0x03) | ((u16) (ul_encalgo) << 2);
  222. ul_content |= BIT(15);
  223. } else {
  224. ul_content = 0;
  225. }
  226. ul_command = CAM_CONTENT_COUNT * uc_index + entry_i;
  227. ul_command = ul_command | BIT(31) | BIT(16);
  228. rtl_write_dword(rtlpriv, rtlpriv->cfg->maps[WCAMI], ul_content);
  229. rtl_write_dword(rtlpriv, rtlpriv->cfg->maps[RWCAM], ul_command);
  230. RT_TRACE(rtlpriv, COMP_SEC, DBG_LOUD,
  231. ("rtl_cam_empty_entry(): WRITE A4: %x\n",
  232. ul_content));
  233. RT_TRACE(rtlpriv, COMP_SEC, DBG_LOUD,
  234. ("rtl_cam_empty_entry(): WRITE A0: %x\n",
  235. ul_command));
  236. }
  237. }
  238. EXPORT_SYMBOL(rtl_cam_empty_entry);