iwl-agn-sta.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698
  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-agn.h"
  34. #include "iwl-trans.h"
  35. static struct iwl_link_quality_cmd *
  36. iwl_sta_alloc_lq(struct iwl_priv *priv, struct iwl_rxon_context *ctx, u8 sta_id)
  37. {
  38. int i, r;
  39. struct iwl_link_quality_cmd *link_cmd;
  40. u32 rate_flags = 0;
  41. __le32 rate_n_flags;
  42. link_cmd = kzalloc(sizeof(struct iwl_link_quality_cmd), GFP_KERNEL);
  43. if (!link_cmd) {
  44. IWL_ERR(priv, "Unable to allocate memory for LQ cmd.\n");
  45. return NULL;
  46. }
  47. lockdep_assert_held(&priv->mutex);
  48. /* Set up the rate scaling to start at selected rate, fall back
  49. * all the way down to 1M in IEEE order, and then spin on 1M */
  50. if (priv->band == IEEE80211_BAND_5GHZ)
  51. r = IWL_RATE_6M_INDEX;
  52. else if (ctx && ctx->vif && ctx->vif->p2p)
  53. r = IWL_RATE_6M_INDEX;
  54. else
  55. r = IWL_RATE_1M_INDEX;
  56. if (r >= IWL_FIRST_CCK_RATE && r <= IWL_LAST_CCK_RATE)
  57. rate_flags |= RATE_MCS_CCK_MSK;
  58. rate_flags |= first_antenna(priv->hw_params.valid_tx_ant) <<
  59. RATE_MCS_ANT_POS;
  60. rate_n_flags = iwl_hw_set_rate_n_flags(iwl_rates[r].plcp, rate_flags);
  61. for (i = 0; i < LINK_QUAL_MAX_RETRY_NUM; i++)
  62. link_cmd->rs_table[i].rate_n_flags = rate_n_flags;
  63. link_cmd->general_params.single_stream_ant_msk =
  64. first_antenna(priv->hw_params.valid_tx_ant);
  65. link_cmd->general_params.dual_stream_ant_msk =
  66. priv->hw_params.valid_tx_ant &
  67. ~first_antenna(priv->hw_params.valid_tx_ant);
  68. if (!link_cmd->general_params.dual_stream_ant_msk) {
  69. link_cmd->general_params.dual_stream_ant_msk = ANT_AB;
  70. } else if (num_of_ant(priv->hw_params.valid_tx_ant) == 2) {
  71. link_cmd->general_params.dual_stream_ant_msk =
  72. priv->hw_params.valid_tx_ant;
  73. }
  74. link_cmd->agg_params.agg_dis_start_th = LINK_QUAL_AGG_DISABLE_START_DEF;
  75. link_cmd->agg_params.agg_time_limit =
  76. cpu_to_le16(LINK_QUAL_AGG_TIME_LIMIT_DEF);
  77. link_cmd->sta_id = sta_id;
  78. return link_cmd;
  79. }
  80. /*
  81. * iwlagn_add_bssid_station - Add the special IBSS BSSID station
  82. *
  83. * Function sleeps.
  84. */
  85. int iwlagn_add_bssid_station(struct iwl_priv *priv, struct iwl_rxon_context *ctx,
  86. const u8 *addr, u8 *sta_id_r)
  87. {
  88. int ret;
  89. u8 sta_id;
  90. struct iwl_link_quality_cmd *link_cmd;
  91. unsigned long flags;
  92. if (sta_id_r)
  93. *sta_id_r = IWL_INVALID_STATION;
  94. ret = iwl_add_station_common(priv, ctx, addr, 0, NULL, &sta_id);
  95. if (ret) {
  96. IWL_ERR(priv, "Unable to add station %pM\n", addr);
  97. return ret;
  98. }
  99. if (sta_id_r)
  100. *sta_id_r = sta_id;
  101. spin_lock_irqsave(&priv->sta_lock, flags);
  102. priv->stations[sta_id].used |= IWL_STA_LOCAL;
  103. spin_unlock_irqrestore(&priv->sta_lock, flags);
  104. /* Set up default rate scaling table in device's station table */
  105. link_cmd = iwl_sta_alloc_lq(priv, ctx, sta_id);
  106. if (!link_cmd) {
  107. IWL_ERR(priv, "Unable to initialize rate scaling for station %pM.\n",
  108. addr);
  109. return -ENOMEM;
  110. }
  111. ret = iwl_send_lq_cmd(priv, ctx, link_cmd, CMD_SYNC, true);
  112. if (ret)
  113. IWL_ERR(priv, "Link quality command failed (%d)\n", ret);
  114. spin_lock_irqsave(&priv->sta_lock, flags);
  115. priv->stations[sta_id].lq = link_cmd;
  116. spin_unlock_irqrestore(&priv->sta_lock, flags);
  117. return 0;
  118. }
  119. /*
  120. * static WEP keys
  121. *
  122. * For each context, the device has a table of 4 static WEP keys
  123. * (one for each key index) that is updated with the following
  124. * commands.
  125. */
  126. static int iwl_send_static_wepkey_cmd(struct iwl_priv *priv,
  127. struct iwl_rxon_context *ctx,
  128. bool send_if_empty)
  129. {
  130. int i, not_empty = 0;
  131. u8 buff[sizeof(struct iwl_wep_cmd) +
  132. sizeof(struct iwl_wep_key) * WEP_KEYS_MAX];
  133. struct iwl_wep_cmd *wep_cmd = (struct iwl_wep_cmd *)buff;
  134. size_t cmd_size = sizeof(struct iwl_wep_cmd);
  135. struct iwl_host_cmd cmd = {
  136. .id = ctx->wep_key_cmd,
  137. .data = { wep_cmd, },
  138. .flags = CMD_SYNC,
  139. };
  140. might_sleep();
  141. memset(wep_cmd, 0, cmd_size +
  142. (sizeof(struct iwl_wep_key) * WEP_KEYS_MAX));
  143. for (i = 0; i < WEP_KEYS_MAX ; i++) {
  144. wep_cmd->key[i].key_index = i;
  145. if (ctx->wep_keys[i].key_size) {
  146. wep_cmd->key[i].key_offset = i;
  147. not_empty = 1;
  148. } else {
  149. wep_cmd->key[i].key_offset = WEP_INVALID_OFFSET;
  150. }
  151. wep_cmd->key[i].key_size = ctx->wep_keys[i].key_size;
  152. memcpy(&wep_cmd->key[i].key[3], ctx->wep_keys[i].key,
  153. ctx->wep_keys[i].key_size);
  154. }
  155. wep_cmd->global_key_type = WEP_KEY_WEP_TYPE;
  156. wep_cmd->num_keys = WEP_KEYS_MAX;
  157. cmd_size += sizeof(struct iwl_wep_key) * WEP_KEYS_MAX;
  158. cmd.len[0] = cmd_size;
  159. if (not_empty || send_if_empty)
  160. return trans_send_cmd(&priv->trans, &cmd);
  161. else
  162. return 0;
  163. }
  164. int iwl_restore_default_wep_keys(struct iwl_priv *priv,
  165. struct iwl_rxon_context *ctx)
  166. {
  167. lockdep_assert_held(&priv->mutex);
  168. return iwl_send_static_wepkey_cmd(priv, ctx, false);
  169. }
  170. int iwl_remove_default_wep_key(struct iwl_priv *priv,
  171. struct iwl_rxon_context *ctx,
  172. struct ieee80211_key_conf *keyconf)
  173. {
  174. int ret;
  175. lockdep_assert_held(&priv->mutex);
  176. IWL_DEBUG_WEP(priv, "Removing default WEP key: idx=%d\n",
  177. keyconf->keyidx);
  178. memset(&ctx->wep_keys[keyconf->keyidx], 0, sizeof(ctx->wep_keys[0]));
  179. if (iwl_is_rfkill(priv)) {
  180. IWL_DEBUG_WEP(priv, "Not sending REPLY_WEPKEY command due to RFKILL.\n");
  181. /* but keys in device are clear anyway so return success */
  182. return 0;
  183. }
  184. ret = iwl_send_static_wepkey_cmd(priv, ctx, 1);
  185. IWL_DEBUG_WEP(priv, "Remove default WEP key: idx=%d ret=%d\n",
  186. keyconf->keyidx, ret);
  187. return ret;
  188. }
  189. int iwl_set_default_wep_key(struct iwl_priv *priv,
  190. struct iwl_rxon_context *ctx,
  191. struct ieee80211_key_conf *keyconf)
  192. {
  193. int ret;
  194. lockdep_assert_held(&priv->mutex);
  195. if (keyconf->keylen != WEP_KEY_LEN_128 &&
  196. keyconf->keylen != WEP_KEY_LEN_64) {
  197. IWL_DEBUG_WEP(priv, "Bad WEP key length %d\n", keyconf->keylen);
  198. return -EINVAL;
  199. }
  200. keyconf->hw_key_idx = IWLAGN_HW_KEY_DEFAULT;
  201. ctx->wep_keys[keyconf->keyidx].key_size = keyconf->keylen;
  202. memcpy(&ctx->wep_keys[keyconf->keyidx].key, &keyconf->key,
  203. keyconf->keylen);
  204. ret = iwl_send_static_wepkey_cmd(priv, ctx, false);
  205. IWL_DEBUG_WEP(priv, "Set default WEP key: len=%d idx=%d ret=%d\n",
  206. keyconf->keylen, keyconf->keyidx, ret);
  207. return ret;
  208. }
  209. /*
  210. * dynamic (per-station) keys
  211. *
  212. * The dynamic keys are a little more complicated. The device has
  213. * a key cache of up to STA_KEY_MAX_NUM/STA_KEY_MAX_NUM_PAN keys.
  214. * These are linked to stations by a table that contains an index
  215. * into the key table for each station/key index/{mcast,unicast},
  216. * i.e. it's basically an array of pointers like this:
  217. * key_offset_t key_mapping[NUM_STATIONS][4][2];
  218. * (it really works differently, but you can think of it as such)
  219. *
  220. * The key uploading and linking happens in the same command, the
  221. * add station command with STA_MODIFY_KEY_MASK.
  222. */
  223. static u8 iwlagn_key_sta_id(struct iwl_priv *priv,
  224. struct ieee80211_vif *vif,
  225. struct ieee80211_sta *sta)
  226. {
  227. struct iwl_vif_priv *vif_priv = (void *)vif->drv_priv;
  228. u8 sta_id = IWL_INVALID_STATION;
  229. if (sta)
  230. sta_id = iwl_sta_id(sta);
  231. /*
  232. * The device expects GTKs for station interfaces to be
  233. * installed as GTKs for the AP station. If we have no
  234. * station ID, then use the ap_sta_id in that case.
  235. */
  236. if (!sta && vif && vif_priv->ctx) {
  237. switch (vif->type) {
  238. case NL80211_IFTYPE_STATION:
  239. sta_id = vif_priv->ctx->ap_sta_id;
  240. break;
  241. default:
  242. /*
  243. * In all other cases, the key will be
  244. * used either for TX only or is bound
  245. * to a station already.
  246. */
  247. break;
  248. }
  249. }
  250. return sta_id;
  251. }
  252. static int iwlagn_send_sta_key(struct iwl_priv *priv,
  253. struct ieee80211_key_conf *keyconf,
  254. u8 sta_id, u32 tkip_iv32, u16 *tkip_p1k,
  255. u32 cmd_flags)
  256. {
  257. unsigned long flags;
  258. __le16 key_flags;
  259. struct iwl_addsta_cmd sta_cmd;
  260. int i;
  261. spin_lock_irqsave(&priv->sta_lock, flags);
  262. memcpy(&sta_cmd, &priv->stations[sta_id].sta, sizeof(sta_cmd));
  263. spin_unlock_irqrestore(&priv->sta_lock, flags);
  264. key_flags = cpu_to_le16(keyconf->keyidx << STA_KEY_FLG_KEYID_POS);
  265. key_flags |= STA_KEY_FLG_MAP_KEY_MSK;
  266. switch (keyconf->cipher) {
  267. case WLAN_CIPHER_SUITE_CCMP:
  268. key_flags |= STA_KEY_FLG_CCMP;
  269. memcpy(sta_cmd.key.key, keyconf->key, keyconf->keylen);
  270. break;
  271. case WLAN_CIPHER_SUITE_TKIP:
  272. key_flags |= STA_KEY_FLG_TKIP;
  273. sta_cmd.key.tkip_rx_tsc_byte2 = tkip_iv32;
  274. for (i = 0; i < 5; i++)
  275. sta_cmd.key.tkip_rx_ttak[i] = cpu_to_le16(tkip_p1k[i]);
  276. memcpy(sta_cmd.key.key, keyconf->key, keyconf->keylen);
  277. break;
  278. case WLAN_CIPHER_SUITE_WEP104:
  279. key_flags |= STA_KEY_FLG_KEY_SIZE_MSK;
  280. /* fall through */
  281. case WLAN_CIPHER_SUITE_WEP40:
  282. key_flags |= STA_KEY_FLG_WEP;
  283. memcpy(&sta_cmd.key.key[3], keyconf->key, keyconf->keylen);
  284. break;
  285. default:
  286. WARN_ON(1);
  287. return -EINVAL;
  288. }
  289. if (!(keyconf->flags & IEEE80211_KEY_FLAG_PAIRWISE))
  290. key_flags |= STA_KEY_MULTICAST_MSK;
  291. /* key pointer (offset) */
  292. sta_cmd.key.key_offset = keyconf->hw_key_idx;
  293. sta_cmd.key.key_flags = key_flags;
  294. sta_cmd.mode = STA_CONTROL_MODIFY_MSK;
  295. sta_cmd.sta.modify_mask = STA_MODIFY_KEY_MASK;
  296. return iwl_send_add_sta(priv, &sta_cmd, cmd_flags);
  297. }
  298. void iwl_update_tkip_key(struct iwl_priv *priv,
  299. struct ieee80211_vif *vif,
  300. struct ieee80211_key_conf *keyconf,
  301. struct ieee80211_sta *sta, u32 iv32, u16 *phase1key)
  302. {
  303. u8 sta_id = iwlagn_key_sta_id(priv, vif, sta);
  304. if (sta_id == IWL_INVALID_STATION)
  305. return;
  306. if (iwl_scan_cancel(priv)) {
  307. /* cancel scan failed, just live w/ bad key and rely
  308. briefly on SW decryption */
  309. return;
  310. }
  311. iwlagn_send_sta_key(priv, keyconf, sta_id,
  312. iv32, phase1key, CMD_ASYNC);
  313. }
  314. int iwl_remove_dynamic_key(struct iwl_priv *priv,
  315. struct iwl_rxon_context *ctx,
  316. struct ieee80211_key_conf *keyconf,
  317. struct ieee80211_sta *sta)
  318. {
  319. unsigned long flags;
  320. struct iwl_addsta_cmd sta_cmd;
  321. u8 sta_id = iwlagn_key_sta_id(priv, ctx->vif, sta);
  322. /* if station isn't there, neither is the key */
  323. if (sta_id == IWL_INVALID_STATION)
  324. return -ENOENT;
  325. spin_lock_irqsave(&priv->sta_lock, flags);
  326. memcpy(&sta_cmd, &priv->stations[sta_id].sta, sizeof(sta_cmd));
  327. if (!(priv->stations[sta_id].used & IWL_STA_UCODE_ACTIVE))
  328. sta_id = IWL_INVALID_STATION;
  329. spin_unlock_irqrestore(&priv->sta_lock, flags);
  330. if (sta_id == IWL_INVALID_STATION)
  331. return 0;
  332. lockdep_assert_held(&priv->mutex);
  333. ctx->key_mapping_keys--;
  334. IWL_DEBUG_WEP(priv, "Remove dynamic key: idx=%d sta=%d\n",
  335. keyconf->keyidx, sta_id);
  336. if (!test_and_clear_bit(keyconf->hw_key_idx, &priv->ucode_key_table))
  337. IWL_ERR(priv, "offset %d not used in uCode key table.\n",
  338. keyconf->hw_key_idx);
  339. sta_cmd.key.key_flags = STA_KEY_FLG_NO_ENC | STA_KEY_FLG_INVALID;
  340. sta_cmd.key.key_offset = WEP_INVALID_OFFSET;
  341. sta_cmd.sta.modify_mask = STA_MODIFY_KEY_MASK;
  342. sta_cmd.mode = STA_CONTROL_MODIFY_MSK;
  343. return iwl_send_add_sta(priv, &sta_cmd, CMD_SYNC);
  344. }
  345. int iwl_set_dynamic_key(struct iwl_priv *priv,
  346. struct iwl_rxon_context *ctx,
  347. struct ieee80211_key_conf *keyconf,
  348. struct ieee80211_sta *sta)
  349. {
  350. struct ieee80211_key_seq seq;
  351. u16 p1k[5];
  352. int ret;
  353. u8 sta_id = iwlagn_key_sta_id(priv, ctx->vif, sta);
  354. const u8 *addr;
  355. if (sta_id == IWL_INVALID_STATION)
  356. return -EINVAL;
  357. lockdep_assert_held(&priv->mutex);
  358. keyconf->hw_key_idx = iwl_get_free_ucode_key_offset(priv);
  359. if (keyconf->hw_key_idx == WEP_INVALID_OFFSET)
  360. return -ENOSPC;
  361. ctx->key_mapping_keys++;
  362. switch (keyconf->cipher) {
  363. case WLAN_CIPHER_SUITE_TKIP:
  364. keyconf->flags |= IEEE80211_KEY_FLAG_GENERATE_MMIC;
  365. keyconf->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
  366. if (sta)
  367. addr = sta->addr;
  368. else /* station mode case only */
  369. addr = ctx->active.bssid_addr;
  370. /* pre-fill phase 1 key into device cache */
  371. ieee80211_get_key_rx_seq(keyconf, 0, &seq);
  372. ieee80211_get_tkip_rx_p1k(keyconf, addr, seq.tkip.iv32, p1k);
  373. ret = iwlagn_send_sta_key(priv, keyconf, sta_id,
  374. seq.tkip.iv32, p1k, CMD_SYNC);
  375. break;
  376. case WLAN_CIPHER_SUITE_CCMP:
  377. keyconf->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
  378. /* fall through */
  379. case WLAN_CIPHER_SUITE_WEP40:
  380. case WLAN_CIPHER_SUITE_WEP104:
  381. ret = iwlagn_send_sta_key(priv, keyconf, sta_id,
  382. 0, NULL, CMD_SYNC);
  383. break;
  384. default:
  385. IWL_ERR(priv, "Unknown cipher %x\n", keyconf->cipher);
  386. ret = -EINVAL;
  387. }
  388. if (ret) {
  389. ctx->key_mapping_keys--;
  390. clear_bit(keyconf->hw_key_idx, &priv->ucode_key_table);
  391. }
  392. IWL_DEBUG_WEP(priv, "Set dynamic key: cipher=%x len=%d idx=%d sta=%pM ret=%d\n",
  393. keyconf->cipher, keyconf->keylen, keyconf->keyidx,
  394. sta ? sta->addr : NULL, ret);
  395. return ret;
  396. }
  397. /**
  398. * iwlagn_alloc_bcast_station - add broadcast station into driver's station table.
  399. *
  400. * This adds the broadcast station into the driver's station table
  401. * and marks it driver active, so that it will be restored to the
  402. * device at the next best time.
  403. */
  404. int iwlagn_alloc_bcast_station(struct iwl_priv *priv,
  405. struct iwl_rxon_context *ctx)
  406. {
  407. struct iwl_link_quality_cmd *link_cmd;
  408. unsigned long flags;
  409. u8 sta_id;
  410. spin_lock_irqsave(&priv->sta_lock, flags);
  411. sta_id = iwl_prep_station(priv, ctx, iwl_bcast_addr, false, NULL);
  412. if (sta_id == IWL_INVALID_STATION) {
  413. IWL_ERR(priv, "Unable to prepare broadcast station\n");
  414. spin_unlock_irqrestore(&priv->sta_lock, flags);
  415. return -EINVAL;
  416. }
  417. priv->stations[sta_id].used |= IWL_STA_DRIVER_ACTIVE;
  418. priv->stations[sta_id].used |= IWL_STA_BCAST;
  419. spin_unlock_irqrestore(&priv->sta_lock, flags);
  420. link_cmd = iwl_sta_alloc_lq(priv, ctx, sta_id);
  421. if (!link_cmd) {
  422. IWL_ERR(priv,
  423. "Unable to initialize rate scaling for bcast station.\n");
  424. return -ENOMEM;
  425. }
  426. spin_lock_irqsave(&priv->sta_lock, flags);
  427. priv->stations[sta_id].lq = link_cmd;
  428. spin_unlock_irqrestore(&priv->sta_lock, flags);
  429. return 0;
  430. }
  431. /**
  432. * iwl_update_bcast_station - update broadcast station's LQ command
  433. *
  434. * Only used by iwlagn. Placed here to have all bcast station management
  435. * code together.
  436. */
  437. int iwl_update_bcast_station(struct iwl_priv *priv,
  438. struct iwl_rxon_context *ctx)
  439. {
  440. unsigned long flags;
  441. struct iwl_link_quality_cmd *link_cmd;
  442. u8 sta_id = ctx->bcast_sta_id;
  443. link_cmd = iwl_sta_alloc_lq(priv, ctx, sta_id);
  444. if (!link_cmd) {
  445. IWL_ERR(priv, "Unable to initialize rate scaling for bcast station.\n");
  446. return -ENOMEM;
  447. }
  448. spin_lock_irqsave(&priv->sta_lock, flags);
  449. if (priv->stations[sta_id].lq)
  450. kfree(priv->stations[sta_id].lq);
  451. else
  452. IWL_DEBUG_INFO(priv, "Bcast station rate scaling has not been initialized yet.\n");
  453. priv->stations[sta_id].lq = link_cmd;
  454. spin_unlock_irqrestore(&priv->sta_lock, flags);
  455. return 0;
  456. }
  457. int iwl_update_bcast_stations(struct iwl_priv *priv)
  458. {
  459. struct iwl_rxon_context *ctx;
  460. int ret = 0;
  461. for_each_context(priv, ctx) {
  462. ret = iwl_update_bcast_station(priv, ctx);
  463. if (ret)
  464. break;
  465. }
  466. return ret;
  467. }
  468. /**
  469. * iwl_sta_tx_modify_enable_tid - Enable Tx for this TID in station table
  470. */
  471. int iwl_sta_tx_modify_enable_tid(struct iwl_priv *priv, int sta_id, int tid)
  472. {
  473. unsigned long flags;
  474. struct iwl_addsta_cmd sta_cmd;
  475. lockdep_assert_held(&priv->mutex);
  476. /* Remove "disable" flag, to enable Tx for this TID */
  477. spin_lock_irqsave(&priv->sta_lock, flags);
  478. priv->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_TID_DISABLE_TX;
  479. priv->stations[sta_id].sta.tid_disable_tx &= cpu_to_le16(~(1 << tid));
  480. priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK;
  481. memcpy(&sta_cmd, &priv->stations[sta_id].sta, sizeof(struct iwl_addsta_cmd));
  482. spin_unlock_irqrestore(&priv->sta_lock, flags);
  483. return iwl_send_add_sta(priv, &sta_cmd, CMD_SYNC);
  484. }
  485. int iwl_sta_rx_agg_start(struct iwl_priv *priv, struct ieee80211_sta *sta,
  486. int tid, u16 ssn)
  487. {
  488. unsigned long flags;
  489. int sta_id;
  490. struct iwl_addsta_cmd sta_cmd;
  491. lockdep_assert_held(&priv->mutex);
  492. sta_id = iwl_sta_id(sta);
  493. if (sta_id == IWL_INVALID_STATION)
  494. return -ENXIO;
  495. spin_lock_irqsave(&priv->sta_lock, flags);
  496. priv->stations[sta_id].sta.station_flags_msk = 0;
  497. priv->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_ADDBA_TID_MSK;
  498. priv->stations[sta_id].sta.add_immediate_ba_tid = (u8)tid;
  499. priv->stations[sta_id].sta.add_immediate_ba_ssn = cpu_to_le16(ssn);
  500. priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK;
  501. memcpy(&sta_cmd, &priv->stations[sta_id].sta, sizeof(struct iwl_addsta_cmd));
  502. spin_unlock_irqrestore(&priv->sta_lock, flags);
  503. return iwl_send_add_sta(priv, &sta_cmd, CMD_SYNC);
  504. }
  505. int iwl_sta_rx_agg_stop(struct iwl_priv *priv, struct ieee80211_sta *sta,
  506. int tid)
  507. {
  508. unsigned long flags;
  509. int sta_id;
  510. struct iwl_addsta_cmd sta_cmd;
  511. lockdep_assert_held(&priv->mutex);
  512. sta_id = iwl_sta_id(sta);
  513. if (sta_id == IWL_INVALID_STATION) {
  514. IWL_ERR(priv, "Invalid station for AGG tid %d\n", tid);
  515. return -ENXIO;
  516. }
  517. spin_lock_irqsave(&priv->sta_lock, flags);
  518. priv->stations[sta_id].sta.station_flags_msk = 0;
  519. priv->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_DELBA_TID_MSK;
  520. priv->stations[sta_id].sta.remove_immediate_ba_tid = (u8)tid;
  521. priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK;
  522. memcpy(&sta_cmd, &priv->stations[sta_id].sta, sizeof(struct iwl_addsta_cmd));
  523. spin_unlock_irqrestore(&priv->sta_lock, flags);
  524. return iwl_send_add_sta(priv, &sta_cmd, CMD_SYNC);
  525. }
  526. static void iwl_sta_modify_ps_wake(struct iwl_priv *priv, int sta_id)
  527. {
  528. unsigned long flags;
  529. spin_lock_irqsave(&priv->sta_lock, flags);
  530. priv->stations[sta_id].sta.station_flags &= ~STA_FLG_PWR_SAVE_MSK;
  531. priv->stations[sta_id].sta.station_flags_msk = STA_FLG_PWR_SAVE_MSK;
  532. priv->stations[sta_id].sta.sta.modify_mask = 0;
  533. priv->stations[sta_id].sta.sleep_tx_count = 0;
  534. priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK;
  535. iwl_send_add_sta(priv, &priv->stations[sta_id].sta, CMD_ASYNC);
  536. spin_unlock_irqrestore(&priv->sta_lock, flags);
  537. }
  538. void iwl_sta_modify_sleep_tx_count(struct iwl_priv *priv, int sta_id, int cnt)
  539. {
  540. unsigned long flags;
  541. spin_lock_irqsave(&priv->sta_lock, flags);
  542. priv->stations[sta_id].sta.station_flags |= STA_FLG_PWR_SAVE_MSK;
  543. priv->stations[sta_id].sta.station_flags_msk = STA_FLG_PWR_SAVE_MSK;
  544. priv->stations[sta_id].sta.sta.modify_mask =
  545. STA_MODIFY_SLEEP_TX_COUNT_MSK;
  546. priv->stations[sta_id].sta.sleep_tx_count = cpu_to_le16(cnt);
  547. priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK;
  548. iwl_send_add_sta(priv, &priv->stations[sta_id].sta, CMD_ASYNC);
  549. spin_unlock_irqrestore(&priv->sta_lock, flags);
  550. }
  551. void iwlagn_mac_sta_notify(struct ieee80211_hw *hw,
  552. struct ieee80211_vif *vif,
  553. enum sta_notify_cmd cmd,
  554. struct ieee80211_sta *sta)
  555. {
  556. struct iwl_priv *priv = hw->priv;
  557. struct iwl_station_priv *sta_priv = (void *)sta->drv_priv;
  558. int sta_id;
  559. switch (cmd) {
  560. case STA_NOTIFY_SLEEP:
  561. WARN_ON(!sta_priv->client);
  562. sta_priv->asleep = true;
  563. if (atomic_read(&sta_priv->pending_frames) > 0)
  564. ieee80211_sta_block_awake(hw, sta, true);
  565. break;
  566. case STA_NOTIFY_AWAKE:
  567. WARN_ON(!sta_priv->client);
  568. if (!sta_priv->asleep)
  569. break;
  570. sta_priv->asleep = false;
  571. sta_id = iwl_sta_id(sta);
  572. if (sta_id != IWL_INVALID_STATION)
  573. iwl_sta_modify_ps_wake(priv, sta_id);
  574. break;
  575. default:
  576. break;
  577. }
  578. }