iwl-4965-sta.c 21 KB

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