iwl-agn-sta.c 20 KB

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