iwl-sta.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. /******************************************************************************
  2. *
  3. * Copyright(c) 2003 - 2008 Intel Corporation. All rights reserved.
  4. *
  5. * Portions of this file are derived from the ipw3945 project, as well
  6. * as portions of the ieee80211 subsystem header files.
  7. *
  8. * This program is free software; you can redistribute it and/or modify it
  9. * under the terms of version 2 of the GNU General Public License as
  10. * published by the Free Software Foundation.
  11. *
  12. * This program is distributed in the hope that it will be useful, but WITHOUT
  13. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  14. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  15. * more details.
  16. *
  17. * You should have received a copy of the GNU General Public License along with
  18. * this program; if not, write to the Free Software Foundation, Inc.,
  19. * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
  20. *
  21. * The full GNU General Public License is included in this distribution in the
  22. * file called LICENSE.
  23. *
  24. * Contact Information:
  25. * James P. Ketrenos <ipw2100-admin@linux.intel.com>
  26. * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
  27. *
  28. *****************************************************************************/
  29. #include <net/mac80211.h>
  30. #include "iwl-eeprom.h"
  31. #include "iwl-4965.h"
  32. #include "iwl-core.h"
  33. #include "iwl-sta.h"
  34. #include "iwl-io.h"
  35. #include "iwl-helpers.h"
  36. int iwl_send_static_wepkey_cmd(struct iwl_priv *priv, u8 send_if_empty)
  37. {
  38. int i, not_empty = 0;
  39. u8 buff[sizeof(struct iwl_wep_cmd) +
  40. sizeof(struct iwl_wep_key) * WEP_KEYS_MAX];
  41. struct iwl_wep_cmd *wep_cmd = (struct iwl_wep_cmd *)buff;
  42. size_t cmd_size = sizeof(struct iwl_wep_cmd);
  43. struct iwl_host_cmd cmd = {
  44. .id = REPLY_WEPKEY,
  45. .data = wep_cmd,
  46. .meta.flags = CMD_ASYNC,
  47. };
  48. memset(wep_cmd, 0, cmd_size +
  49. (sizeof(struct iwl_wep_key) * WEP_KEYS_MAX));
  50. for (i = 0; i < WEP_KEYS_MAX ; i++) {
  51. wep_cmd->key[i].key_index = i;
  52. if (priv->wep_keys[i].key_size) {
  53. wep_cmd->key[i].key_offset = i;
  54. not_empty = 1;
  55. } else {
  56. wep_cmd->key[i].key_offset = WEP_INVALID_OFFSET;
  57. }
  58. wep_cmd->key[i].key_size = priv->wep_keys[i].key_size;
  59. memcpy(&wep_cmd->key[i].key[3], priv->wep_keys[i].key,
  60. priv->wep_keys[i].key_size);
  61. }
  62. wep_cmd->global_key_type = WEP_KEY_WEP_TYPE;
  63. wep_cmd->num_keys = WEP_KEYS_MAX;
  64. cmd_size += sizeof(struct iwl_wep_key) * WEP_KEYS_MAX;
  65. cmd.len = cmd_size;
  66. if (not_empty || send_if_empty)
  67. return iwl_send_cmd(priv, &cmd);
  68. else
  69. return 0;
  70. }
  71. int iwl_remove_default_wep_key(struct iwl_priv *priv,
  72. struct ieee80211_key_conf *key)
  73. {
  74. int ret;
  75. unsigned long flags;
  76. spin_lock_irqsave(&priv->sta_lock, flags);
  77. priv->default_wep_key--;
  78. memset(&priv->wep_keys[key->keyidx], 0, sizeof(priv->wep_keys[0]));
  79. ret = iwl_send_static_wepkey_cmd(priv, 1);
  80. spin_unlock_irqrestore(&priv->sta_lock, flags);
  81. return ret;
  82. }
  83. int iwl_set_default_wep_key(struct iwl_priv *priv,
  84. struct ieee80211_key_conf *keyconf)
  85. {
  86. int ret;
  87. unsigned long flags;
  88. keyconf->flags &= ~IEEE80211_KEY_FLAG_GENERATE_IV;
  89. keyconf->hw_key_idx = keyconf->keyidx;
  90. priv->stations[IWL_AP_ID].keyinfo.alg = ALG_WEP;
  91. spin_lock_irqsave(&priv->sta_lock, flags);
  92. priv->default_wep_key++;
  93. priv->wep_keys[keyconf->keyidx].key_size = keyconf->keylen;
  94. memcpy(&priv->wep_keys[keyconf->keyidx].key, &keyconf->key,
  95. keyconf->keylen);
  96. ret = iwl_send_static_wepkey_cmd(priv, 0);
  97. spin_unlock_irqrestore(&priv->sta_lock, flags);
  98. return ret;
  99. }