iwl-4965-sta.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721
  1. /******************************************************************************
  2. *
  3. * Copyright(c) 2003 - 2011 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. * Intel Linux Wireless <ilw@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-dev.h"
  31. #include "iwl-core.h"
  32. #include "iwl-sta.h"
  33. #include "iwl-4965.h"
  34. static struct iwl_link_quality_cmd *
  35. iwl4965_sta_alloc_lq(struct iwl_priv *priv, u8 sta_id)
  36. {
  37. int i, r;
  38. struct iwl_link_quality_cmd *link_cmd;
  39. u32 rate_flags = 0;
  40. __le32 rate_n_flags;
  41. link_cmd = kzalloc(sizeof(struct iwl_link_quality_cmd), GFP_KERNEL);
  42. if (!link_cmd) {
  43. IWL_ERR(priv, "Unable to allocate memory for LQ cmd.\n");
  44. return NULL;
  45. }
  46. /* Set up the rate scaling to start at selected rate, fall back
  47. * all the way down to 1M in IEEE order, and then spin on 1M */
  48. if (priv->band == IEEE80211_BAND_5GHZ)
  49. r = IWL_RATE_6M_INDEX;
  50. else
  51. r = IWL_RATE_1M_INDEX;
  52. if (r >= IWL_FIRST_CCK_RATE && r <= IWL_LAST_CCK_RATE)
  53. rate_flags |= RATE_MCS_CCK_MSK;
  54. rate_flags |= iwl4965_first_antenna(priv->hw_params.valid_tx_ant) <<
  55. RATE_MCS_ANT_POS;
  56. rate_n_flags = iwl4965_hw_set_rate_n_flags(iwlegacy_rates[r].plcp,
  57. rate_flags);
  58. for (i = 0; i < LINK_QUAL_MAX_RETRY_NUM; i++)
  59. link_cmd->rs_table[i].rate_n_flags = rate_n_flags;
  60. link_cmd->general_params.single_stream_ant_msk =
  61. iwl4965_first_antenna(priv->hw_params.valid_tx_ant);
  62. link_cmd->general_params.dual_stream_ant_msk =
  63. priv->hw_params.valid_tx_ant &
  64. ~iwl4965_first_antenna(priv->hw_params.valid_tx_ant);
  65. if (!link_cmd->general_params.dual_stream_ant_msk) {
  66. link_cmd->general_params.dual_stream_ant_msk = ANT_AB;
  67. } else if (iwl4965_num_of_ant(priv->hw_params.valid_tx_ant) == 2) {
  68. link_cmd->general_params.dual_stream_ant_msk =
  69. priv->hw_params.valid_tx_ant;
  70. }
  71. link_cmd->agg_params.agg_dis_start_th = LINK_QUAL_AGG_DISABLE_START_DEF;
  72. link_cmd->agg_params.agg_time_limit =
  73. cpu_to_le16(LINK_QUAL_AGG_TIME_LIMIT_DEF);
  74. link_cmd->sta_id = sta_id;
  75. return link_cmd;
  76. }
  77. /*
  78. * iwl4965_add_bssid_station - Add the special IBSS BSSID station
  79. *
  80. * Function sleeps.
  81. */
  82. int
  83. iwl4965_add_bssid_station(struct iwl_priv *priv, struct iwl_rxon_context *ctx,
  84. const u8 *addr, u8 *sta_id_r)
  85. {
  86. int ret;
  87. u8 sta_id;
  88. struct iwl_link_quality_cmd *link_cmd;
  89. unsigned long flags;
  90. if (sta_id_r)
  91. *sta_id_r = IWL_INVALID_STATION;
  92. ret = iwl_legacy_add_station_common(priv, ctx, addr, 0, NULL, &sta_id);
  93. if (ret) {
  94. IWL_ERR(priv, "Unable to add station %pM\n", addr);
  95. return ret;
  96. }
  97. if (sta_id_r)
  98. *sta_id_r = sta_id;
  99. spin_lock_irqsave(&priv->sta_lock, flags);
  100. priv->stations[sta_id].used |= IWL_STA_LOCAL;
  101. spin_unlock_irqrestore(&priv->sta_lock, flags);
  102. /* Set up default rate scaling table in device's station table */
  103. link_cmd = iwl4965_sta_alloc_lq(priv, sta_id);
  104. if (!link_cmd) {
  105. IWL_ERR(priv,
  106. "Unable to initialize rate scaling for station %pM.\n",
  107. addr);
  108. return -ENOMEM;
  109. }
  110. ret = iwl_legacy_send_lq_cmd(priv, ctx, link_cmd, CMD_SYNC, true);
  111. if (ret)
  112. IWL_ERR(priv, "Link quality command failed (%d)\n", ret);
  113. spin_lock_irqsave(&priv->sta_lock, flags);
  114. priv->stations[sta_id].lq = link_cmd;
  115. spin_unlock_irqrestore(&priv->sta_lock, flags);
  116. return 0;
  117. }
  118. static int iwl4965_static_wepkey_cmd(struct iwl_priv *priv,
  119. struct iwl_rxon_context *ctx,
  120. bool send_if_empty)
  121. {
  122. int i, not_empty = 0;
  123. u8 buff[sizeof(struct iwl_wep_cmd) +
  124. sizeof(struct iwl_wep_key) * WEP_KEYS_MAX];
  125. struct iwl_wep_cmd *wep_cmd = (struct iwl_wep_cmd *)buff;
  126. size_t cmd_size = sizeof(struct iwl_wep_cmd);
  127. struct iwl_host_cmd cmd = {
  128. .id = ctx->wep_key_cmd,
  129. .data = wep_cmd,
  130. .flags = CMD_SYNC,
  131. };
  132. might_sleep();
  133. memset(wep_cmd, 0, cmd_size +
  134. (sizeof(struct iwl_wep_key) * WEP_KEYS_MAX));
  135. for (i = 0; i < WEP_KEYS_MAX ; i++) {
  136. wep_cmd->key[i].key_index = i;
  137. if (ctx->wep_keys[i].key_size) {
  138. wep_cmd->key[i].key_offset = i;
  139. not_empty = 1;
  140. } else {
  141. wep_cmd->key[i].key_offset = WEP_INVALID_OFFSET;
  142. }
  143. wep_cmd->key[i].key_size = ctx->wep_keys[i].key_size;
  144. memcpy(&wep_cmd->key[i].key[3], ctx->wep_keys[i].key,
  145. ctx->wep_keys[i].key_size);
  146. }
  147. wep_cmd->global_key_type = WEP_KEY_WEP_TYPE;
  148. wep_cmd->num_keys = WEP_KEYS_MAX;
  149. cmd_size += sizeof(struct iwl_wep_key) * WEP_KEYS_MAX;
  150. cmd.len = cmd_size;
  151. if (not_empty || send_if_empty)
  152. return iwl_legacy_send_cmd(priv, &cmd);
  153. else
  154. return 0;
  155. }
  156. int iwl4965_restore_default_wep_keys(struct iwl_priv *priv,
  157. struct iwl_rxon_context *ctx)
  158. {
  159. lockdep_assert_held(&priv->mutex);
  160. return iwl4965_static_wepkey_cmd(priv, ctx, false);
  161. }
  162. int iwl4965_remove_default_wep_key(struct iwl_priv *priv,
  163. struct iwl_rxon_context *ctx,
  164. struct ieee80211_key_conf *keyconf)
  165. {
  166. int ret;
  167. lockdep_assert_held(&priv->mutex);
  168. IWL_DEBUG_WEP(priv, "Removing default WEP key: idx=%d\n",
  169. keyconf->keyidx);
  170. memset(&ctx->wep_keys[keyconf->keyidx], 0, sizeof(ctx->wep_keys[0]));
  171. if (iwl_legacy_is_rfkill(priv)) {
  172. IWL_DEBUG_WEP(priv,
  173. "Not sending REPLY_WEPKEY command due to RFKILL.\n");
  174. /* but keys in device are clear anyway so return success */
  175. return 0;
  176. }
  177. ret = iwl4965_static_wepkey_cmd(priv, ctx, 1);
  178. IWL_DEBUG_WEP(priv, "Remove default WEP key: idx=%d ret=%d\n",
  179. keyconf->keyidx, ret);
  180. return ret;
  181. }
  182. int iwl4965_set_default_wep_key(struct iwl_priv *priv,
  183. struct iwl_rxon_context *ctx,
  184. struct ieee80211_key_conf *keyconf)
  185. {
  186. int ret;
  187. lockdep_assert_held(&priv->mutex);
  188. if (keyconf->keylen != WEP_KEY_LEN_128 &&
  189. keyconf->keylen != WEP_KEY_LEN_64) {
  190. IWL_DEBUG_WEP(priv, "Bad WEP key length %d\n", keyconf->keylen);
  191. return -EINVAL;
  192. }
  193. keyconf->flags &= ~IEEE80211_KEY_FLAG_GENERATE_IV;
  194. keyconf->hw_key_idx = HW_KEY_DEFAULT;
  195. priv->stations[ctx->ap_sta_id].keyinfo.cipher = keyconf->cipher;
  196. ctx->wep_keys[keyconf->keyidx].key_size = keyconf->keylen;
  197. memcpy(&ctx->wep_keys[keyconf->keyidx].key, &keyconf->key,
  198. keyconf->keylen);
  199. ret = iwl4965_static_wepkey_cmd(priv, ctx, false);
  200. IWL_DEBUG_WEP(priv, "Set default WEP key: len=%d idx=%d ret=%d\n",
  201. keyconf->keylen, keyconf->keyidx, ret);
  202. return ret;
  203. }
  204. static int iwl4965_set_wep_dynamic_key_info(struct iwl_priv *priv,
  205. struct iwl_rxon_context *ctx,
  206. struct ieee80211_key_conf *keyconf,
  207. u8 sta_id)
  208. {
  209. unsigned long flags;
  210. __le16 key_flags = 0;
  211. struct iwl_legacy_addsta_cmd sta_cmd;
  212. lockdep_assert_held(&priv->mutex);
  213. keyconf->flags &= ~IEEE80211_KEY_FLAG_GENERATE_IV;
  214. key_flags |= (STA_KEY_FLG_WEP | STA_KEY_FLG_MAP_KEY_MSK);
  215. key_flags |= cpu_to_le16(keyconf->keyidx << STA_KEY_FLG_KEYID_POS);
  216. key_flags &= ~STA_KEY_FLG_INVALID;
  217. if (keyconf->keylen == WEP_KEY_LEN_128)
  218. key_flags |= STA_KEY_FLG_KEY_SIZE_MSK;
  219. if (sta_id == ctx->bcast_sta_id)
  220. key_flags |= STA_KEY_MULTICAST_MSK;
  221. spin_lock_irqsave(&priv->sta_lock, flags);
  222. priv->stations[sta_id].keyinfo.cipher = keyconf->cipher;
  223. priv->stations[sta_id].keyinfo.keylen = keyconf->keylen;
  224. priv->stations[sta_id].keyinfo.keyidx = keyconf->keyidx;
  225. memcpy(priv->stations[sta_id].keyinfo.key,
  226. keyconf->key, keyconf->keylen);
  227. memcpy(&priv->stations[sta_id].sta.key.key[3],
  228. keyconf->key, keyconf->keylen);
  229. if ((priv->stations[sta_id].sta.key.key_flags & STA_KEY_FLG_ENCRYPT_MSK)
  230. == STA_KEY_FLG_NO_ENC)
  231. priv->stations[sta_id].sta.key.key_offset =
  232. iwl_legacy_get_free_ucode_key_index(priv);
  233. /* else, we are overriding an existing key => no need to allocated room
  234. * in uCode. */
  235. WARN(priv->stations[sta_id].sta.key.key_offset == WEP_INVALID_OFFSET,
  236. "no space for a new key");
  237. priv->stations[sta_id].sta.key.key_flags = key_flags;
  238. priv->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_KEY_MASK;
  239. priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK;
  240. memcpy(&sta_cmd, &priv->stations[sta_id].sta,
  241. sizeof(struct iwl_legacy_addsta_cmd));
  242. spin_unlock_irqrestore(&priv->sta_lock, flags);
  243. return iwl_legacy_send_add_sta(priv, &sta_cmd, CMD_SYNC);
  244. }
  245. static int iwl4965_set_ccmp_dynamic_key_info(struct iwl_priv *priv,
  246. struct iwl_rxon_context *ctx,
  247. struct ieee80211_key_conf *keyconf,
  248. u8 sta_id)
  249. {
  250. unsigned long flags;
  251. __le16 key_flags = 0;
  252. struct iwl_legacy_addsta_cmd sta_cmd;
  253. lockdep_assert_held(&priv->mutex);
  254. key_flags |= (STA_KEY_FLG_CCMP | STA_KEY_FLG_MAP_KEY_MSK);
  255. key_flags |= cpu_to_le16(keyconf->keyidx << STA_KEY_FLG_KEYID_POS);
  256. key_flags &= ~STA_KEY_FLG_INVALID;
  257. if (sta_id == ctx->bcast_sta_id)
  258. key_flags |= STA_KEY_MULTICAST_MSK;
  259. keyconf->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
  260. spin_lock_irqsave(&priv->sta_lock, flags);
  261. priv->stations[sta_id].keyinfo.cipher = keyconf->cipher;
  262. priv->stations[sta_id].keyinfo.keylen = keyconf->keylen;
  263. memcpy(priv->stations[sta_id].keyinfo.key, keyconf->key,
  264. keyconf->keylen);
  265. memcpy(priv->stations[sta_id].sta.key.key, keyconf->key,
  266. keyconf->keylen);
  267. if ((priv->stations[sta_id].sta.key.key_flags & STA_KEY_FLG_ENCRYPT_MSK)
  268. == STA_KEY_FLG_NO_ENC)
  269. priv->stations[sta_id].sta.key.key_offset =
  270. iwl_legacy_get_free_ucode_key_index(priv);
  271. /* else, we are overriding an existing key => no need to allocated room
  272. * in uCode. */
  273. WARN(priv->stations[sta_id].sta.key.key_offset == WEP_INVALID_OFFSET,
  274. "no space for a new key");
  275. priv->stations[sta_id].sta.key.key_flags = key_flags;
  276. priv->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_KEY_MASK;
  277. priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK;
  278. memcpy(&sta_cmd, &priv->stations[sta_id].sta,
  279. sizeof(struct iwl_legacy_addsta_cmd));
  280. spin_unlock_irqrestore(&priv->sta_lock, flags);
  281. return iwl_legacy_send_add_sta(priv, &sta_cmd, CMD_SYNC);
  282. }
  283. static int iwl4965_set_tkip_dynamic_key_info(struct iwl_priv *priv,
  284. struct iwl_rxon_context *ctx,
  285. struct ieee80211_key_conf *keyconf,
  286. u8 sta_id)
  287. {
  288. unsigned long flags;
  289. int ret = 0;
  290. __le16 key_flags = 0;
  291. key_flags |= (STA_KEY_FLG_TKIP | STA_KEY_FLG_MAP_KEY_MSK);
  292. key_flags |= cpu_to_le16(keyconf->keyidx << STA_KEY_FLG_KEYID_POS);
  293. key_flags &= ~STA_KEY_FLG_INVALID;
  294. if (sta_id == ctx->bcast_sta_id)
  295. key_flags |= STA_KEY_MULTICAST_MSK;
  296. keyconf->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
  297. keyconf->flags |= IEEE80211_KEY_FLAG_GENERATE_MMIC;
  298. spin_lock_irqsave(&priv->sta_lock, flags);
  299. priv->stations[sta_id].keyinfo.cipher = keyconf->cipher;
  300. priv->stations[sta_id].keyinfo.keylen = 16;
  301. if ((priv->stations[sta_id].sta.key.key_flags & STA_KEY_FLG_ENCRYPT_MSK)
  302. == STA_KEY_FLG_NO_ENC)
  303. priv->stations[sta_id].sta.key.key_offset =
  304. iwl_legacy_get_free_ucode_key_index(priv);
  305. /* else, we are overriding an existing key => no need to allocated room
  306. * in uCode. */
  307. WARN(priv->stations[sta_id].sta.key.key_offset == WEP_INVALID_OFFSET,
  308. "no space for a new key");
  309. priv->stations[sta_id].sta.key.key_flags = key_flags;
  310. /* This copy is acutally not needed: we get the key with each TX */
  311. memcpy(priv->stations[sta_id].keyinfo.key, keyconf->key, 16);
  312. memcpy(priv->stations[sta_id].sta.key.key, keyconf->key, 16);
  313. spin_unlock_irqrestore(&priv->sta_lock, flags);
  314. return ret;
  315. }
  316. void iwl4965_update_tkip_key(struct iwl_priv *priv,
  317. struct iwl_rxon_context *ctx,
  318. struct ieee80211_key_conf *keyconf,
  319. struct ieee80211_sta *sta, u32 iv32, u16 *phase1key)
  320. {
  321. u8 sta_id;
  322. unsigned long flags;
  323. int i;
  324. if (iwl_legacy_scan_cancel(priv)) {
  325. /* cancel scan failed, just live w/ bad key and rely
  326. briefly on SW decryption */
  327. return;
  328. }
  329. sta_id = iwl_legacy_sta_id_or_broadcast(priv, ctx, sta);
  330. if (sta_id == IWL_INVALID_STATION)
  331. return;
  332. spin_lock_irqsave(&priv->sta_lock, flags);
  333. priv->stations[sta_id].sta.key.tkip_rx_tsc_byte2 = (u8) iv32;
  334. for (i = 0; i < 5; i++)
  335. priv->stations[sta_id].sta.key.tkip_rx_ttak[i] =
  336. cpu_to_le16(phase1key[i]);
  337. priv->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_KEY_MASK;
  338. priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK;
  339. iwl_legacy_send_add_sta(priv, &priv->stations[sta_id].sta, CMD_ASYNC);
  340. spin_unlock_irqrestore(&priv->sta_lock, flags);
  341. }
  342. int iwl4965_remove_dynamic_key(struct iwl_priv *priv,
  343. struct iwl_rxon_context *ctx,
  344. struct ieee80211_key_conf *keyconf,
  345. u8 sta_id)
  346. {
  347. unsigned long flags;
  348. u16 key_flags;
  349. u8 keyidx;
  350. struct iwl_legacy_addsta_cmd sta_cmd;
  351. lockdep_assert_held(&priv->mutex);
  352. ctx->key_mapping_keys--;
  353. spin_lock_irqsave(&priv->sta_lock, flags);
  354. key_flags = le16_to_cpu(priv->stations[sta_id].sta.key.key_flags);
  355. keyidx = (key_flags >> STA_KEY_FLG_KEYID_POS) & 0x3;
  356. IWL_DEBUG_WEP(priv, "Remove dynamic key: idx=%d sta=%d\n",
  357. keyconf->keyidx, sta_id);
  358. if (keyconf->keyidx != keyidx) {
  359. /* We need to remove a key with index different that the one
  360. * in the uCode. This means that the key we need to remove has
  361. * been replaced by another one with different index.
  362. * Don't do anything and return ok
  363. */
  364. spin_unlock_irqrestore(&priv->sta_lock, flags);
  365. return 0;
  366. }
  367. if (priv->stations[sta_id].sta.key.key_offset == WEP_INVALID_OFFSET) {
  368. IWL_WARN(priv, "Removing wrong key %d 0x%x\n",
  369. keyconf->keyidx, key_flags);
  370. spin_unlock_irqrestore(&priv->sta_lock, flags);
  371. return 0;
  372. }
  373. if (!test_and_clear_bit(priv->stations[sta_id].sta.key.key_offset,
  374. &priv->ucode_key_table))
  375. IWL_ERR(priv, "index %d not used in uCode key table.\n",
  376. priv->stations[sta_id].sta.key.key_offset);
  377. memset(&priv->stations[sta_id].keyinfo, 0,
  378. sizeof(struct iwl_hw_key));
  379. memset(&priv->stations[sta_id].sta.key, 0,
  380. sizeof(struct iwl4965_keyinfo));
  381. priv->stations[sta_id].sta.key.key_flags =
  382. STA_KEY_FLG_NO_ENC | STA_KEY_FLG_INVALID;
  383. priv->stations[sta_id].sta.key.key_offset = WEP_INVALID_OFFSET;
  384. priv->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_KEY_MASK;
  385. priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK;
  386. if (iwl_legacy_is_rfkill(priv)) {
  387. IWL_DEBUG_WEP(priv,
  388. "Not sending REPLY_ADD_STA command because RFKILL enabled.\n");
  389. spin_unlock_irqrestore(&priv->sta_lock, flags);
  390. return 0;
  391. }
  392. memcpy(&sta_cmd, &priv->stations[sta_id].sta,
  393. sizeof(struct iwl_legacy_addsta_cmd));
  394. spin_unlock_irqrestore(&priv->sta_lock, flags);
  395. return iwl_legacy_send_add_sta(priv, &sta_cmd, CMD_SYNC);
  396. }
  397. int iwl4965_set_dynamic_key(struct iwl_priv *priv, struct iwl_rxon_context *ctx,
  398. struct ieee80211_key_conf *keyconf, u8 sta_id)
  399. {
  400. int ret;
  401. lockdep_assert_held(&priv->mutex);
  402. ctx->key_mapping_keys++;
  403. keyconf->hw_key_idx = HW_KEY_DYNAMIC;
  404. switch (keyconf->cipher) {
  405. case WLAN_CIPHER_SUITE_CCMP:
  406. ret = iwl4965_set_ccmp_dynamic_key_info(priv, ctx,
  407. keyconf, sta_id);
  408. break;
  409. case WLAN_CIPHER_SUITE_TKIP:
  410. ret = iwl4965_set_tkip_dynamic_key_info(priv, ctx,
  411. keyconf, sta_id);
  412. break;
  413. case WLAN_CIPHER_SUITE_WEP40:
  414. case WLAN_CIPHER_SUITE_WEP104:
  415. ret = iwl4965_set_wep_dynamic_key_info(priv, ctx,
  416. keyconf, sta_id);
  417. break;
  418. default:
  419. IWL_ERR(priv,
  420. "Unknown alg: %s cipher = %x\n", __func__,
  421. keyconf->cipher);
  422. ret = -EINVAL;
  423. }
  424. IWL_DEBUG_WEP(priv,
  425. "Set dynamic key: cipher=%x len=%d idx=%d sta=%d ret=%d\n",
  426. keyconf->cipher, keyconf->keylen, keyconf->keyidx,
  427. sta_id, ret);
  428. return ret;
  429. }
  430. /**
  431. * iwl4965_alloc_bcast_station - add broadcast station into driver's station table.
  432. *
  433. * This adds the broadcast station into the driver's station table
  434. * and marks it driver active, so that it will be restored to the
  435. * device at the next best time.
  436. */
  437. int iwl4965_alloc_bcast_station(struct iwl_priv *priv,
  438. struct iwl_rxon_context *ctx)
  439. {
  440. struct iwl_link_quality_cmd *link_cmd;
  441. unsigned long flags;
  442. u8 sta_id;
  443. spin_lock_irqsave(&priv->sta_lock, flags);
  444. sta_id = iwl_legacy_prep_station(priv, ctx, iwlegacy_bcast_addr,
  445. false, NULL);
  446. if (sta_id == IWL_INVALID_STATION) {
  447. IWL_ERR(priv, "Unable to prepare broadcast station\n");
  448. spin_unlock_irqrestore(&priv->sta_lock, flags);
  449. return -EINVAL;
  450. }
  451. priv->stations[sta_id].used |= IWL_STA_DRIVER_ACTIVE;
  452. priv->stations[sta_id].used |= IWL_STA_BCAST;
  453. spin_unlock_irqrestore(&priv->sta_lock, flags);
  454. link_cmd = iwl4965_sta_alloc_lq(priv, sta_id);
  455. if (!link_cmd) {
  456. IWL_ERR(priv,
  457. "Unable to initialize rate scaling for bcast station.\n");
  458. return -ENOMEM;
  459. }
  460. spin_lock_irqsave(&priv->sta_lock, flags);
  461. priv->stations[sta_id].lq = link_cmd;
  462. spin_unlock_irqrestore(&priv->sta_lock, flags);
  463. return 0;
  464. }
  465. /**
  466. * iwl4965_update_bcast_station - update broadcast station's LQ command
  467. *
  468. * Only used by iwl4965. Placed here to have all bcast station management
  469. * code together.
  470. */
  471. static int iwl4965_update_bcast_station(struct iwl_priv *priv,
  472. struct iwl_rxon_context *ctx)
  473. {
  474. unsigned long flags;
  475. struct iwl_link_quality_cmd *link_cmd;
  476. u8 sta_id = ctx->bcast_sta_id;
  477. link_cmd = iwl4965_sta_alloc_lq(priv, sta_id);
  478. if (!link_cmd) {
  479. IWL_ERR(priv,
  480. "Unable to initialize rate scaling for bcast station.\n");
  481. return -ENOMEM;
  482. }
  483. spin_lock_irqsave(&priv->sta_lock, flags);
  484. if (priv->stations[sta_id].lq)
  485. kfree(priv->stations[sta_id].lq);
  486. else
  487. IWL_DEBUG_INFO(priv,
  488. "Bcast station rate scaling has not been initialized yet.\n");
  489. priv->stations[sta_id].lq = link_cmd;
  490. spin_unlock_irqrestore(&priv->sta_lock, flags);
  491. return 0;
  492. }
  493. int iwl4965_update_bcast_stations(struct iwl_priv *priv)
  494. {
  495. struct iwl_rxon_context *ctx;
  496. int ret = 0;
  497. for_each_context(priv, ctx) {
  498. ret = iwl4965_update_bcast_station(priv, ctx);
  499. if (ret)
  500. break;
  501. }
  502. return ret;
  503. }
  504. /**
  505. * iwl4965_sta_tx_modify_enable_tid - Enable Tx for this TID in station table
  506. */
  507. int iwl4965_sta_tx_modify_enable_tid(struct iwl_priv *priv, int sta_id, int tid)
  508. {
  509. unsigned long flags;
  510. struct iwl_legacy_addsta_cmd sta_cmd;
  511. lockdep_assert_held(&priv->mutex);
  512. /* Remove "disable" flag, to enable Tx for this TID */
  513. spin_lock_irqsave(&priv->sta_lock, flags);
  514. priv->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_TID_DISABLE_TX;
  515. priv->stations[sta_id].sta.tid_disable_tx &= cpu_to_le16(~(1 << tid));
  516. priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK;
  517. memcpy(&sta_cmd, &priv->stations[sta_id].sta,
  518. sizeof(struct iwl_legacy_addsta_cmd));
  519. spin_unlock_irqrestore(&priv->sta_lock, flags);
  520. return iwl_legacy_send_add_sta(priv, &sta_cmd, CMD_SYNC);
  521. }
  522. int iwl4965_sta_rx_agg_start(struct iwl_priv *priv, struct ieee80211_sta *sta,
  523. int tid, u16 ssn)
  524. {
  525. unsigned long flags;
  526. int sta_id;
  527. struct iwl_legacy_addsta_cmd sta_cmd;
  528. lockdep_assert_held(&priv->mutex);
  529. sta_id = iwl_legacy_sta_id(sta);
  530. if (sta_id == IWL_INVALID_STATION)
  531. return -ENXIO;
  532. spin_lock_irqsave(&priv->sta_lock, flags);
  533. priv->stations[sta_id].sta.station_flags_msk = 0;
  534. priv->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_ADDBA_TID_MSK;
  535. priv->stations[sta_id].sta.add_immediate_ba_tid = (u8)tid;
  536. priv->stations[sta_id].sta.add_immediate_ba_ssn = cpu_to_le16(ssn);
  537. priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK;
  538. memcpy(&sta_cmd, &priv->stations[sta_id].sta,
  539. sizeof(struct iwl_legacy_addsta_cmd));
  540. spin_unlock_irqrestore(&priv->sta_lock, flags);
  541. return iwl_legacy_send_add_sta(priv, &sta_cmd, CMD_SYNC);
  542. }
  543. int iwl4965_sta_rx_agg_stop(struct iwl_priv *priv, struct ieee80211_sta *sta,
  544. int tid)
  545. {
  546. unsigned long flags;
  547. int sta_id;
  548. struct iwl_legacy_addsta_cmd sta_cmd;
  549. lockdep_assert_held(&priv->mutex);
  550. sta_id = iwl_legacy_sta_id(sta);
  551. if (sta_id == IWL_INVALID_STATION) {
  552. IWL_ERR(priv, "Invalid station for AGG tid %d\n", tid);
  553. return -ENXIO;
  554. }
  555. spin_lock_irqsave(&priv->sta_lock, flags);
  556. priv->stations[sta_id].sta.station_flags_msk = 0;
  557. priv->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_DELBA_TID_MSK;
  558. priv->stations[sta_id].sta.remove_immediate_ba_tid = (u8)tid;
  559. priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK;
  560. memcpy(&sta_cmd, &priv->stations[sta_id].sta,
  561. sizeof(struct iwl_legacy_addsta_cmd));
  562. spin_unlock_irqrestore(&priv->sta_lock, flags);
  563. return iwl_legacy_send_add_sta(priv, &sta_cmd, CMD_SYNC);
  564. }
  565. void
  566. iwl4965_sta_modify_sleep_tx_count(struct iwl_priv *priv, int sta_id, int cnt)
  567. {
  568. unsigned long flags;
  569. spin_lock_irqsave(&priv->sta_lock, flags);
  570. priv->stations[sta_id].sta.station_flags |= STA_FLG_PWR_SAVE_MSK;
  571. priv->stations[sta_id].sta.station_flags_msk = STA_FLG_PWR_SAVE_MSK;
  572. priv->stations[sta_id].sta.sta.modify_mask =
  573. STA_MODIFY_SLEEP_TX_COUNT_MSK;
  574. priv->stations[sta_id].sta.sleep_tx_count = cpu_to_le16(cnt);
  575. priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK;
  576. iwl_legacy_send_add_sta(priv,
  577. &priv->stations[sta_id].sta, CMD_ASYNC);
  578. spin_unlock_irqrestore(&priv->sta_lock, flags);
  579. }