iwl-sta.c 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155
  1. /******************************************************************************
  2. *
  3. * Copyright(c) 2003 - 2008 Intel Corporation. All rights reserved.
  4. *
  5. * Portions of this file are derived from the ipw3945 project, as well
  6. * as portions of the ieee80211 subsystem header files.
  7. *
  8. * This program is free software; you can redistribute it and/or modify it
  9. * under the terms of version 2 of the GNU General Public License as
  10. * published by the Free Software Foundation.
  11. *
  12. * This program is distributed in the hope that it will be useful, but WITHOUT
  13. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  14. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  15. * more details.
  16. *
  17. * You should have received a copy of the GNU General Public License along with
  18. * this program; if not, write to the Free Software Foundation, Inc.,
  19. * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
  20. *
  21. * The full GNU General Public License is included in this distribution in the
  22. * file called LICENSE.
  23. *
  24. * Contact Information:
  25. * James P. Ketrenos <ipw2100-admin@linux.intel.com>
  26. * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
  27. *
  28. *****************************************************************************/
  29. #include <net/mac80211.h>
  30. #include <linux/etherdevice.h>
  31. #include "iwl-dev.h"
  32. #include "iwl-core.h"
  33. #include "iwl-sta.h"
  34. #include "iwl-helpers.h"
  35. #define IWL_STA_DRIVER_ACTIVE BIT(0) /* driver entry is active */
  36. #define IWL_STA_UCODE_ACTIVE BIT(1) /* ucode entry is active */
  37. u8 iwl_find_station(struct iwl_priv *priv, const u8 *addr)
  38. {
  39. int i;
  40. int start = 0;
  41. int ret = IWL_INVALID_STATION;
  42. unsigned long flags;
  43. if ((priv->iw_mode == NL80211_IFTYPE_ADHOC) ||
  44. (priv->iw_mode == NL80211_IFTYPE_AP))
  45. start = IWL_STA_ID;
  46. if (is_broadcast_ether_addr(addr))
  47. return priv->hw_params.bcast_sta_id;
  48. spin_lock_irqsave(&priv->sta_lock, flags);
  49. for (i = start; i < priv->hw_params.max_stations; i++)
  50. if (priv->stations[i].used &&
  51. (!compare_ether_addr(priv->stations[i].sta.sta.addr,
  52. addr))) {
  53. ret = i;
  54. goto out;
  55. }
  56. IWL_DEBUG_ASSOC_LIMIT("can not find STA %pM total %d\n",
  57. addr, priv->num_stations);
  58. out:
  59. spin_unlock_irqrestore(&priv->sta_lock, flags);
  60. return ret;
  61. }
  62. EXPORT_SYMBOL(iwl_find_station);
  63. int iwl_get_ra_sta_id(struct iwl_priv *priv, struct ieee80211_hdr *hdr)
  64. {
  65. if (priv->iw_mode == NL80211_IFTYPE_STATION) {
  66. return IWL_AP_ID;
  67. } else {
  68. u8 *da = ieee80211_get_DA(hdr);
  69. return iwl_find_station(priv, da);
  70. }
  71. }
  72. EXPORT_SYMBOL(iwl_get_ra_sta_id);
  73. static void iwl_sta_ucode_activate(struct iwl_priv *priv, u8 sta_id)
  74. {
  75. unsigned long flags;
  76. spin_lock_irqsave(&priv->sta_lock, flags);
  77. if (!(priv->stations[sta_id].used & IWL_STA_DRIVER_ACTIVE))
  78. IWL_ERROR("ACTIVATE a non DRIVER active station %d\n", sta_id);
  79. priv->stations[sta_id].used |= IWL_STA_UCODE_ACTIVE;
  80. IWL_DEBUG_ASSOC("Added STA to Ucode: %pM\n",
  81. priv->stations[sta_id].sta.sta.addr);
  82. spin_unlock_irqrestore(&priv->sta_lock, flags);
  83. }
  84. static int iwl_add_sta_callback(struct iwl_priv *priv,
  85. struct iwl_cmd *cmd, struct sk_buff *skb)
  86. {
  87. struct iwl_rx_packet *res = NULL;
  88. struct iwl_addsta_cmd *addsta =
  89. (struct iwl_addsta_cmd *)cmd->cmd.payload;
  90. u8 sta_id = addsta->sta.sta_id;
  91. if (!skb) {
  92. IWL_ERROR("Error: Response NULL in REPLY_ADD_STA.\n");
  93. return 1;
  94. }
  95. res = (struct iwl_rx_packet *)skb->data;
  96. if (res->hdr.flags & IWL_CMD_FAILED_MSK) {
  97. IWL_ERROR("Bad return from REPLY_ADD_STA (0x%08X)\n",
  98. res->hdr.flags);
  99. return 1;
  100. }
  101. switch (res->u.add_sta.status) {
  102. case ADD_STA_SUCCESS_MSK:
  103. iwl_sta_ucode_activate(priv, sta_id);
  104. /* fall through */
  105. default:
  106. IWL_DEBUG_HC("Received REPLY_ADD_STA:(0x%08X)\n",
  107. res->u.add_sta.status);
  108. break;
  109. }
  110. /* We didn't cache the SKB; let the caller free it */
  111. return 1;
  112. }
  113. static int iwl_send_add_sta(struct iwl_priv *priv,
  114. struct iwl_addsta_cmd *sta, u8 flags)
  115. {
  116. struct iwl_rx_packet *res = NULL;
  117. int ret = 0;
  118. u8 data[sizeof(*sta)];
  119. struct iwl_host_cmd cmd = {
  120. .id = REPLY_ADD_STA,
  121. .meta.flags = flags,
  122. .data = data,
  123. };
  124. if (flags & CMD_ASYNC)
  125. cmd.meta.u.callback = iwl_add_sta_callback;
  126. else
  127. cmd.meta.flags |= CMD_WANT_SKB;
  128. cmd.len = priv->cfg->ops->utils->build_addsta_hcmd(sta, data);
  129. ret = iwl_send_cmd(priv, &cmd);
  130. if (ret || (flags & CMD_ASYNC))
  131. return ret;
  132. res = (struct iwl_rx_packet *)cmd.meta.u.skb->data;
  133. if (res->hdr.flags & IWL_CMD_FAILED_MSK) {
  134. IWL_ERROR("Bad return from REPLY_ADD_STA (0x%08X)\n",
  135. res->hdr.flags);
  136. ret = -EIO;
  137. }
  138. if (ret == 0) {
  139. switch (res->u.add_sta.status) {
  140. case ADD_STA_SUCCESS_MSK:
  141. iwl_sta_ucode_activate(priv, sta->sta.sta_id);
  142. IWL_DEBUG_INFO("REPLY_ADD_STA PASSED\n");
  143. break;
  144. default:
  145. ret = -EIO;
  146. IWL_WARNING("REPLY_ADD_STA failed\n");
  147. break;
  148. }
  149. }
  150. priv->alloc_rxb_skb--;
  151. dev_kfree_skb_any(cmd.meta.u.skb);
  152. return ret;
  153. }
  154. static void iwl_set_ht_add_station(struct iwl_priv *priv, u8 index,
  155. struct ieee80211_sta_ht_cap *sta_ht_inf)
  156. {
  157. __le32 sta_flags;
  158. u8 mimo_ps_mode;
  159. if (!sta_ht_inf || !sta_ht_inf->ht_supported)
  160. goto done;
  161. mimo_ps_mode = (sta_ht_inf->cap & IEEE80211_HT_CAP_SM_PS) >> 2;
  162. sta_flags = priv->stations[index].sta.station_flags;
  163. sta_flags &= ~(STA_FLG_RTS_MIMO_PROT_MSK | STA_FLG_MIMO_DIS_MSK);
  164. switch (mimo_ps_mode) {
  165. case WLAN_HT_CAP_SM_PS_STATIC:
  166. sta_flags |= STA_FLG_MIMO_DIS_MSK;
  167. break;
  168. case WLAN_HT_CAP_SM_PS_DYNAMIC:
  169. sta_flags |= STA_FLG_RTS_MIMO_PROT_MSK;
  170. break;
  171. case WLAN_HT_CAP_SM_PS_DISABLED:
  172. break;
  173. default:
  174. IWL_WARNING("Invalid MIMO PS mode %d\n", mimo_ps_mode);
  175. break;
  176. }
  177. sta_flags |= cpu_to_le32(
  178. (u32)sta_ht_inf->ampdu_factor << STA_FLG_MAX_AGG_SIZE_POS);
  179. sta_flags |= cpu_to_le32(
  180. (u32)sta_ht_inf->ampdu_density << STA_FLG_AGG_MPDU_DENSITY_POS);
  181. if (iwl_is_fat_tx_allowed(priv, sta_ht_inf))
  182. sta_flags |= STA_FLG_FAT_EN_MSK;
  183. else
  184. sta_flags &= ~STA_FLG_FAT_EN_MSK;
  185. priv->stations[index].sta.station_flags = sta_flags;
  186. done:
  187. return;
  188. }
  189. /**
  190. * iwl_add_station_flags - Add station to tables in driver and device
  191. */
  192. u8 iwl_add_station_flags(struct iwl_priv *priv, const u8 *addr, int is_ap,
  193. u8 flags, struct ieee80211_sta_ht_cap *ht_info)
  194. {
  195. int i;
  196. int sta_id = IWL_INVALID_STATION;
  197. struct iwl_station_entry *station;
  198. unsigned long flags_spin;
  199. spin_lock_irqsave(&priv->sta_lock, flags_spin);
  200. if (is_ap)
  201. sta_id = IWL_AP_ID;
  202. else if (is_broadcast_ether_addr(addr))
  203. sta_id = priv->hw_params.bcast_sta_id;
  204. else
  205. for (i = IWL_STA_ID; i < priv->hw_params.max_stations; i++) {
  206. if (!compare_ether_addr(priv->stations[i].sta.sta.addr,
  207. addr)) {
  208. sta_id = i;
  209. break;
  210. }
  211. if (!priv->stations[i].used &&
  212. sta_id == IWL_INVALID_STATION)
  213. sta_id = i;
  214. }
  215. /* These two conditions have the same outcome, but keep them separate
  216. since they have different meanings */
  217. if (unlikely(sta_id == IWL_INVALID_STATION)) {
  218. spin_unlock_irqrestore(&priv->sta_lock, flags_spin);
  219. return sta_id;
  220. }
  221. if (priv->stations[sta_id].used &&
  222. !compare_ether_addr(priv->stations[sta_id].sta.sta.addr, addr)) {
  223. spin_unlock_irqrestore(&priv->sta_lock, flags_spin);
  224. return sta_id;
  225. }
  226. station = &priv->stations[sta_id];
  227. station->used = IWL_STA_DRIVER_ACTIVE;
  228. IWL_DEBUG_ASSOC("Add STA to driver ID %d: %pM\n",
  229. sta_id, addr);
  230. priv->num_stations++;
  231. /* Set up the REPLY_ADD_STA command to send to device */
  232. memset(&station->sta, 0, sizeof(struct iwl_addsta_cmd));
  233. memcpy(station->sta.sta.addr, addr, ETH_ALEN);
  234. station->sta.mode = 0;
  235. station->sta.sta.sta_id = sta_id;
  236. station->sta.station_flags = 0;
  237. /* BCAST station and IBSS stations do not work in HT mode */
  238. if (sta_id != priv->hw_params.bcast_sta_id &&
  239. priv->iw_mode != NL80211_IFTYPE_ADHOC)
  240. iwl_set_ht_add_station(priv, sta_id, ht_info);
  241. spin_unlock_irqrestore(&priv->sta_lock, flags_spin);
  242. /* Add station to device's station table */
  243. iwl_send_add_sta(priv, &station->sta, flags);
  244. return sta_id;
  245. }
  246. EXPORT_SYMBOL(iwl_add_station_flags);
  247. static void iwl_sta_ucode_deactivate(struct iwl_priv *priv, const char *addr)
  248. {
  249. unsigned long flags;
  250. u8 sta_id = iwl_find_station(priv, addr);
  251. BUG_ON(sta_id == IWL_INVALID_STATION);
  252. IWL_DEBUG_ASSOC("Removed STA from Ucode: %pM\n", addr);
  253. spin_lock_irqsave(&priv->sta_lock, flags);
  254. /* Ucode must be active and driver must be non active */
  255. if (priv->stations[sta_id].used != IWL_STA_UCODE_ACTIVE)
  256. IWL_ERROR("removed non active STA %d\n", sta_id);
  257. priv->stations[sta_id].used &= ~IWL_STA_UCODE_ACTIVE;
  258. memset(&priv->stations[sta_id], 0, sizeof(struct iwl_station_entry));
  259. spin_unlock_irqrestore(&priv->sta_lock, flags);
  260. }
  261. static int iwl_remove_sta_callback(struct iwl_priv *priv,
  262. struct iwl_cmd *cmd, struct sk_buff *skb)
  263. {
  264. struct iwl_rx_packet *res = NULL;
  265. struct iwl_rem_sta_cmd *rm_sta =
  266. (struct iwl_rem_sta_cmd *)cmd->cmd.payload;
  267. const char *addr = rm_sta->addr;
  268. if (!skb) {
  269. IWL_ERROR("Error: Response NULL in REPLY_REMOVE_STA.\n");
  270. return 1;
  271. }
  272. res = (struct iwl_rx_packet *)skb->data;
  273. if (res->hdr.flags & IWL_CMD_FAILED_MSK) {
  274. IWL_ERROR("Bad return from REPLY_REMOVE_STA (0x%08X)\n",
  275. res->hdr.flags);
  276. return 1;
  277. }
  278. switch (res->u.rem_sta.status) {
  279. case REM_STA_SUCCESS_MSK:
  280. iwl_sta_ucode_deactivate(priv, addr);
  281. break;
  282. default:
  283. IWL_ERROR("REPLY_REMOVE_STA failed\n");
  284. break;
  285. }
  286. /* We didn't cache the SKB; let the caller free it */
  287. return 1;
  288. }
  289. static int iwl_send_remove_station(struct iwl_priv *priv, const u8 *addr,
  290. u8 flags)
  291. {
  292. struct iwl_rx_packet *res = NULL;
  293. int ret;
  294. struct iwl_rem_sta_cmd rm_sta_cmd;
  295. struct iwl_host_cmd cmd = {
  296. .id = REPLY_REMOVE_STA,
  297. .len = sizeof(struct iwl_rem_sta_cmd),
  298. .meta.flags = flags,
  299. .data = &rm_sta_cmd,
  300. };
  301. memset(&rm_sta_cmd, 0, sizeof(rm_sta_cmd));
  302. rm_sta_cmd.num_sta = 1;
  303. memcpy(&rm_sta_cmd.addr, addr , ETH_ALEN);
  304. if (flags & CMD_ASYNC)
  305. cmd.meta.u.callback = iwl_remove_sta_callback;
  306. else
  307. cmd.meta.flags |= CMD_WANT_SKB;
  308. ret = iwl_send_cmd(priv, &cmd);
  309. if (ret || (flags & CMD_ASYNC))
  310. return ret;
  311. res = (struct iwl_rx_packet *)cmd.meta.u.skb->data;
  312. if (res->hdr.flags & IWL_CMD_FAILED_MSK) {
  313. IWL_ERROR("Bad return from REPLY_REMOVE_STA (0x%08X)\n",
  314. res->hdr.flags);
  315. ret = -EIO;
  316. }
  317. if (!ret) {
  318. switch (res->u.rem_sta.status) {
  319. case REM_STA_SUCCESS_MSK:
  320. iwl_sta_ucode_deactivate(priv, addr);
  321. IWL_DEBUG_ASSOC("REPLY_REMOVE_STA PASSED\n");
  322. break;
  323. default:
  324. ret = -EIO;
  325. IWL_ERROR("REPLY_REMOVE_STA failed\n");
  326. break;
  327. }
  328. }
  329. priv->alloc_rxb_skb--;
  330. dev_kfree_skb_any(cmd.meta.u.skb);
  331. return ret;
  332. }
  333. /**
  334. * iwl_remove_station - Remove driver's knowledge of station.
  335. */
  336. int iwl_remove_station(struct iwl_priv *priv, const u8 *addr, int is_ap)
  337. {
  338. int sta_id = IWL_INVALID_STATION;
  339. int i, ret = -EINVAL;
  340. unsigned long flags;
  341. spin_lock_irqsave(&priv->sta_lock, flags);
  342. if (is_ap)
  343. sta_id = IWL_AP_ID;
  344. else if (is_broadcast_ether_addr(addr))
  345. sta_id = priv->hw_params.bcast_sta_id;
  346. else
  347. for (i = IWL_STA_ID; i < priv->hw_params.max_stations; i++)
  348. if (priv->stations[i].used &&
  349. !compare_ether_addr(priv->stations[i].sta.sta.addr,
  350. addr)) {
  351. sta_id = i;
  352. break;
  353. }
  354. if (unlikely(sta_id == IWL_INVALID_STATION))
  355. goto out;
  356. IWL_DEBUG_ASSOC("Removing STA from driver:%d %pM\n",
  357. sta_id, addr);
  358. if (!(priv->stations[sta_id].used & IWL_STA_DRIVER_ACTIVE)) {
  359. IWL_ERROR("Removing %pM but non DRIVER active\n",
  360. addr);
  361. goto out;
  362. }
  363. if (!(priv->stations[sta_id].used & IWL_STA_UCODE_ACTIVE)) {
  364. IWL_ERROR("Removing %pM but non UCODE active\n",
  365. addr);
  366. goto out;
  367. }
  368. priv->stations[sta_id].used &= ~IWL_STA_DRIVER_ACTIVE;
  369. priv->num_stations--;
  370. BUG_ON(priv->num_stations < 0);
  371. spin_unlock_irqrestore(&priv->sta_lock, flags);
  372. ret = iwl_send_remove_station(priv, addr, CMD_ASYNC);
  373. return ret;
  374. out:
  375. spin_unlock_irqrestore(&priv->sta_lock, flags);
  376. return ret;
  377. }
  378. EXPORT_SYMBOL(iwl_remove_station);
  379. /**
  380. * iwl_clear_stations_table - Clear the driver's station table
  381. *
  382. * NOTE: This does not clear or otherwise alter the device's station table.
  383. */
  384. void iwl_clear_stations_table(struct iwl_priv *priv)
  385. {
  386. unsigned long flags;
  387. spin_lock_irqsave(&priv->sta_lock, flags);
  388. if (iwl_is_alive(priv) &&
  389. !test_bit(STATUS_EXIT_PENDING, &priv->status) &&
  390. iwl_send_cmd_pdu_async(priv, REPLY_REMOVE_ALL_STA, 0, NULL, NULL))
  391. IWL_ERROR("Couldn't clear the station table\n");
  392. priv->num_stations = 0;
  393. memset(priv->stations, 0, sizeof(priv->stations));
  394. spin_unlock_irqrestore(&priv->sta_lock, flags);
  395. }
  396. EXPORT_SYMBOL(iwl_clear_stations_table);
  397. static int iwl_get_free_ucode_key_index(struct iwl_priv *priv)
  398. {
  399. int i;
  400. for (i = 0; i < STA_KEY_MAX_NUM; i++)
  401. if (!test_and_set_bit(i, &priv->ucode_key_table))
  402. return i;
  403. return -1;
  404. }
  405. int iwl_send_static_wepkey_cmd(struct iwl_priv *priv, u8 send_if_empty)
  406. {
  407. int i, not_empty = 0;
  408. u8 buff[sizeof(struct iwl_wep_cmd) +
  409. sizeof(struct iwl_wep_key) * WEP_KEYS_MAX];
  410. struct iwl_wep_cmd *wep_cmd = (struct iwl_wep_cmd *)buff;
  411. size_t cmd_size = sizeof(struct iwl_wep_cmd);
  412. struct iwl_host_cmd cmd = {
  413. .id = REPLY_WEPKEY,
  414. .data = wep_cmd,
  415. .meta.flags = CMD_ASYNC,
  416. };
  417. memset(wep_cmd, 0, cmd_size +
  418. (sizeof(struct iwl_wep_key) * WEP_KEYS_MAX));
  419. for (i = 0; i < WEP_KEYS_MAX ; i++) {
  420. wep_cmd->key[i].key_index = i;
  421. if (priv->wep_keys[i].key_size) {
  422. wep_cmd->key[i].key_offset = i;
  423. not_empty = 1;
  424. } else {
  425. wep_cmd->key[i].key_offset = WEP_INVALID_OFFSET;
  426. }
  427. wep_cmd->key[i].key_size = priv->wep_keys[i].key_size;
  428. memcpy(&wep_cmd->key[i].key[3], priv->wep_keys[i].key,
  429. priv->wep_keys[i].key_size);
  430. }
  431. wep_cmd->global_key_type = WEP_KEY_WEP_TYPE;
  432. wep_cmd->num_keys = WEP_KEYS_MAX;
  433. cmd_size += sizeof(struct iwl_wep_key) * WEP_KEYS_MAX;
  434. cmd.len = cmd_size;
  435. if (not_empty || send_if_empty)
  436. return iwl_send_cmd(priv, &cmd);
  437. else
  438. return 0;
  439. }
  440. EXPORT_SYMBOL(iwl_send_static_wepkey_cmd);
  441. int iwl_remove_default_wep_key(struct iwl_priv *priv,
  442. struct ieee80211_key_conf *keyconf)
  443. {
  444. int ret;
  445. unsigned long flags;
  446. spin_lock_irqsave(&priv->sta_lock, flags);
  447. if (!test_and_clear_bit(keyconf->keyidx, &priv->ucode_key_table))
  448. IWL_ERROR("index %d not used in uCode key table.\n",
  449. keyconf->keyidx);
  450. priv->default_wep_key--;
  451. memset(&priv->wep_keys[keyconf->keyidx], 0, sizeof(priv->wep_keys[0]));
  452. ret = iwl_send_static_wepkey_cmd(priv, 1);
  453. IWL_DEBUG_WEP("Remove default WEP key: idx=%d ret=%d\n",
  454. keyconf->keyidx, ret);
  455. spin_unlock_irqrestore(&priv->sta_lock, flags);
  456. return ret;
  457. }
  458. EXPORT_SYMBOL(iwl_remove_default_wep_key);
  459. int iwl_set_default_wep_key(struct iwl_priv *priv,
  460. struct ieee80211_key_conf *keyconf)
  461. {
  462. int ret;
  463. unsigned long flags;
  464. if (keyconf->keylen != WEP_KEY_LEN_128 &&
  465. keyconf->keylen != WEP_KEY_LEN_64) {
  466. IWL_DEBUG_WEP("Bad WEP key length %d\n", keyconf->keylen);
  467. return -EINVAL;
  468. }
  469. keyconf->flags &= ~IEEE80211_KEY_FLAG_GENERATE_IV;
  470. keyconf->hw_key_idx = HW_KEY_DEFAULT;
  471. priv->stations[IWL_AP_ID].keyinfo.alg = ALG_WEP;
  472. spin_lock_irqsave(&priv->sta_lock, flags);
  473. priv->default_wep_key++;
  474. if (test_and_set_bit(keyconf->keyidx, &priv->ucode_key_table))
  475. IWL_ERROR("index %d already used in uCode key table.\n",
  476. keyconf->keyidx);
  477. priv->wep_keys[keyconf->keyidx].key_size = keyconf->keylen;
  478. memcpy(&priv->wep_keys[keyconf->keyidx].key, &keyconf->key,
  479. keyconf->keylen);
  480. ret = iwl_send_static_wepkey_cmd(priv, 0);
  481. IWL_DEBUG_WEP("Set default WEP key: len=%d idx=%d ret=%d\n",
  482. keyconf->keylen, keyconf->keyidx, ret);
  483. spin_unlock_irqrestore(&priv->sta_lock, flags);
  484. return ret;
  485. }
  486. EXPORT_SYMBOL(iwl_set_default_wep_key);
  487. static int iwl_set_wep_dynamic_key_info(struct iwl_priv *priv,
  488. struct ieee80211_key_conf *keyconf,
  489. u8 sta_id)
  490. {
  491. unsigned long flags;
  492. __le16 key_flags = 0;
  493. int ret;
  494. keyconf->flags &= ~IEEE80211_KEY_FLAG_GENERATE_IV;
  495. key_flags |= (STA_KEY_FLG_WEP | STA_KEY_FLG_MAP_KEY_MSK);
  496. key_flags |= cpu_to_le16(keyconf->keyidx << STA_KEY_FLG_KEYID_POS);
  497. key_flags &= ~STA_KEY_FLG_INVALID;
  498. if (keyconf->keylen == WEP_KEY_LEN_128)
  499. key_flags |= STA_KEY_FLG_KEY_SIZE_MSK;
  500. if (sta_id == priv->hw_params.bcast_sta_id)
  501. key_flags |= STA_KEY_MULTICAST_MSK;
  502. spin_lock_irqsave(&priv->sta_lock, flags);
  503. priv->stations[sta_id].keyinfo.alg = keyconf->alg;
  504. priv->stations[sta_id].keyinfo.keylen = keyconf->keylen;
  505. priv->stations[sta_id].keyinfo.keyidx = keyconf->keyidx;
  506. memcpy(priv->stations[sta_id].keyinfo.key,
  507. keyconf->key, keyconf->keylen);
  508. memcpy(&priv->stations[sta_id].sta.key.key[3],
  509. keyconf->key, keyconf->keylen);
  510. if ((priv->stations[sta_id].sta.key.key_flags & STA_KEY_FLG_ENCRYPT_MSK)
  511. == STA_KEY_FLG_NO_ENC)
  512. priv->stations[sta_id].sta.key.key_offset =
  513. iwl_get_free_ucode_key_index(priv);
  514. /* else, we are overriding an existing key => no need to allocated room
  515. * in uCode. */
  516. priv->stations[sta_id].sta.key.key_flags = key_flags;
  517. priv->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_KEY_MASK;
  518. priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK;
  519. ret = iwl_send_add_sta(priv, &priv->stations[sta_id].sta, CMD_ASYNC);
  520. spin_unlock_irqrestore(&priv->sta_lock, flags);
  521. return ret;
  522. }
  523. static int iwl_set_ccmp_dynamic_key_info(struct iwl_priv *priv,
  524. struct ieee80211_key_conf *keyconf,
  525. u8 sta_id)
  526. {
  527. unsigned long flags;
  528. __le16 key_flags = 0;
  529. key_flags |= (STA_KEY_FLG_CCMP | STA_KEY_FLG_MAP_KEY_MSK);
  530. key_flags |= cpu_to_le16(keyconf->keyidx << STA_KEY_FLG_KEYID_POS);
  531. key_flags &= ~STA_KEY_FLG_INVALID;
  532. if (sta_id == priv->hw_params.bcast_sta_id)
  533. key_flags |= STA_KEY_MULTICAST_MSK;
  534. keyconf->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
  535. spin_lock_irqsave(&priv->sta_lock, flags);
  536. priv->stations[sta_id].keyinfo.alg = keyconf->alg;
  537. priv->stations[sta_id].keyinfo.keylen = keyconf->keylen;
  538. memcpy(priv->stations[sta_id].keyinfo.key, keyconf->key,
  539. keyconf->keylen);
  540. memcpy(priv->stations[sta_id].sta.key.key, keyconf->key,
  541. keyconf->keylen);
  542. if ((priv->stations[sta_id].sta.key.key_flags & STA_KEY_FLG_ENCRYPT_MSK)
  543. == STA_KEY_FLG_NO_ENC)
  544. priv->stations[sta_id].sta.key.key_offset =
  545. iwl_get_free_ucode_key_index(priv);
  546. /* else, we are overriding an existing key => no need to allocated room
  547. * in uCode. */
  548. priv->stations[sta_id].sta.key.key_flags = key_flags;
  549. priv->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_KEY_MASK;
  550. priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK;
  551. spin_unlock_irqrestore(&priv->sta_lock, flags);
  552. IWL_DEBUG_INFO("hwcrypto: modify ucode station key info\n");
  553. return iwl_send_add_sta(priv, &priv->stations[sta_id].sta, CMD_ASYNC);
  554. }
  555. static int iwl_set_tkip_dynamic_key_info(struct iwl_priv *priv,
  556. struct ieee80211_key_conf *keyconf,
  557. u8 sta_id)
  558. {
  559. unsigned long flags;
  560. int ret = 0;
  561. keyconf->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
  562. keyconf->flags |= IEEE80211_KEY_FLAG_GENERATE_MMIC;
  563. spin_lock_irqsave(&priv->sta_lock, flags);
  564. priv->stations[sta_id].keyinfo.alg = keyconf->alg;
  565. priv->stations[sta_id].keyinfo.keylen = 16;
  566. if ((priv->stations[sta_id].sta.key.key_flags & STA_KEY_FLG_ENCRYPT_MSK)
  567. == STA_KEY_FLG_NO_ENC)
  568. priv->stations[sta_id].sta.key.key_offset =
  569. iwl_get_free_ucode_key_index(priv);
  570. /* else, we are overriding an existing key => no need to allocated room
  571. * in uCode. */
  572. /* This copy is actually not needed: we get the key with each TX */
  573. memcpy(priv->stations[sta_id].keyinfo.key, keyconf->key, 16);
  574. memcpy(priv->stations[sta_id].sta.key.key, keyconf->key, 16);
  575. spin_unlock_irqrestore(&priv->sta_lock, flags);
  576. return ret;
  577. }
  578. void iwl_update_tkip_key(struct iwl_priv *priv,
  579. struct ieee80211_key_conf *keyconf,
  580. const u8 *addr, u32 iv32, u16 *phase1key)
  581. {
  582. u8 sta_id = IWL_INVALID_STATION;
  583. unsigned long flags;
  584. __le16 key_flags = 0;
  585. int i;
  586. DECLARE_MAC_BUF(mac);
  587. sta_id = iwl_find_station(priv, addr);
  588. if (sta_id == IWL_INVALID_STATION) {
  589. IWL_DEBUG_MAC80211("leave - %pM not in station map.\n",
  590. addr);
  591. return;
  592. }
  593. if (iwl_scan_cancel(priv)) {
  594. /* cancel scan failed, just live w/ bad key and rely
  595. briefly on SW decryption */
  596. return;
  597. }
  598. key_flags |= (STA_KEY_FLG_TKIP | STA_KEY_FLG_MAP_KEY_MSK);
  599. key_flags |= cpu_to_le16(keyconf->keyidx << STA_KEY_FLG_KEYID_POS);
  600. key_flags &= ~STA_KEY_FLG_INVALID;
  601. if (sta_id == priv->hw_params.bcast_sta_id)
  602. key_flags |= STA_KEY_MULTICAST_MSK;
  603. spin_lock_irqsave(&priv->sta_lock, flags);
  604. priv->stations[sta_id].sta.key.key_flags = key_flags;
  605. priv->stations[sta_id].sta.key.tkip_rx_tsc_byte2 = (u8) iv32;
  606. for (i = 0; i < 5; i++)
  607. priv->stations[sta_id].sta.key.tkip_rx_ttak[i] =
  608. cpu_to_le16(phase1key[i]);
  609. priv->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_KEY_MASK;
  610. priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK;
  611. iwl_send_add_sta(priv, &priv->stations[sta_id].sta, CMD_ASYNC);
  612. spin_unlock_irqrestore(&priv->sta_lock, flags);
  613. }
  614. EXPORT_SYMBOL(iwl_update_tkip_key);
  615. int iwl_remove_dynamic_key(struct iwl_priv *priv,
  616. struct ieee80211_key_conf *keyconf,
  617. u8 sta_id)
  618. {
  619. unsigned long flags;
  620. int ret = 0;
  621. u16 key_flags;
  622. u8 keyidx;
  623. priv->key_mapping_key--;
  624. spin_lock_irqsave(&priv->sta_lock, flags);
  625. key_flags = le16_to_cpu(priv->stations[sta_id].sta.key.key_flags);
  626. keyidx = (key_flags >> STA_KEY_FLG_KEYID_POS) & 0x3;
  627. IWL_DEBUG_WEP("Remove dynamic key: idx=%d sta=%d\n",
  628. keyconf->keyidx, sta_id);
  629. if (keyconf->keyidx != keyidx) {
  630. /* We need to remove a key with index different that the one
  631. * in the uCode. This means that the key we need to remove has
  632. * been replaced by another one with different index.
  633. * Don't do anything and return ok
  634. */
  635. spin_unlock_irqrestore(&priv->sta_lock, flags);
  636. return 0;
  637. }
  638. if (!test_and_clear_bit(priv->stations[sta_id].sta.key.key_offset,
  639. &priv->ucode_key_table))
  640. IWL_ERROR("index %d not used in uCode key table.\n",
  641. priv->stations[sta_id].sta.key.key_offset);
  642. memset(&priv->stations[sta_id].keyinfo, 0,
  643. sizeof(struct iwl_hw_key));
  644. memset(&priv->stations[sta_id].sta.key, 0,
  645. sizeof(struct iwl4965_keyinfo));
  646. priv->stations[sta_id].sta.key.key_flags =
  647. STA_KEY_FLG_NO_ENC | STA_KEY_FLG_INVALID;
  648. priv->stations[sta_id].sta.key.key_offset = WEP_INVALID_OFFSET;
  649. priv->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_KEY_MASK;
  650. priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK;
  651. ret = iwl_send_add_sta(priv, &priv->stations[sta_id].sta, CMD_ASYNC);
  652. spin_unlock_irqrestore(&priv->sta_lock, flags);
  653. return ret;
  654. }
  655. EXPORT_SYMBOL(iwl_remove_dynamic_key);
  656. int iwl_set_dynamic_key(struct iwl_priv *priv,
  657. struct ieee80211_key_conf *keyconf, u8 sta_id)
  658. {
  659. int ret;
  660. priv->key_mapping_key++;
  661. keyconf->hw_key_idx = HW_KEY_DYNAMIC;
  662. switch (keyconf->alg) {
  663. case ALG_CCMP:
  664. ret = iwl_set_ccmp_dynamic_key_info(priv, keyconf, sta_id);
  665. break;
  666. case ALG_TKIP:
  667. ret = iwl_set_tkip_dynamic_key_info(priv, keyconf, sta_id);
  668. break;
  669. case ALG_WEP:
  670. ret = iwl_set_wep_dynamic_key_info(priv, keyconf, sta_id);
  671. break;
  672. default:
  673. IWL_ERROR("Unknown alg: %s alg = %d\n", __func__, keyconf->alg);
  674. ret = -EINVAL;
  675. }
  676. IWL_DEBUG_WEP("Set dynamic key: alg= %d len=%d idx=%d sta=%d ret=%d\n",
  677. keyconf->alg, keyconf->keylen, keyconf->keyidx,
  678. sta_id, ret);
  679. return ret;
  680. }
  681. EXPORT_SYMBOL(iwl_set_dynamic_key);
  682. #ifdef CONFIG_IWLWIFI_DEBUG
  683. static void iwl_dump_lq_cmd(struct iwl_priv *priv,
  684. struct iwl_link_quality_cmd *lq)
  685. {
  686. int i;
  687. IWL_DEBUG_RATE("lq station id 0x%x\n", lq->sta_id);
  688. IWL_DEBUG_RATE("lq ant 0x%X 0x%X\n",
  689. lq->general_params.single_stream_ant_msk,
  690. lq->general_params.dual_stream_ant_msk);
  691. for (i = 0; i < LINK_QUAL_MAX_RETRY_NUM; i++)
  692. IWL_DEBUG_RATE("lq index %d 0x%X\n",
  693. i, lq->rs_table[i].rate_n_flags);
  694. }
  695. #else
  696. static inline void iwl_dump_lq_cmd(struct iwl_priv *priv,
  697. struct iwl_link_quality_cmd *lq)
  698. {
  699. }
  700. #endif
  701. int iwl_send_lq_cmd(struct iwl_priv *priv,
  702. struct iwl_link_quality_cmd *lq, u8 flags)
  703. {
  704. struct iwl_host_cmd cmd = {
  705. .id = REPLY_TX_LINK_QUALITY_CMD,
  706. .len = sizeof(struct iwl_link_quality_cmd),
  707. .meta.flags = flags,
  708. .data = lq,
  709. };
  710. if ((lq->sta_id == 0xFF) &&
  711. (priv->iw_mode == NL80211_IFTYPE_ADHOC))
  712. return -EINVAL;
  713. if (lq->sta_id == 0xFF)
  714. lq->sta_id = IWL_AP_ID;
  715. iwl_dump_lq_cmd(priv, lq);
  716. if (iwl_is_associated(priv) && priv->assoc_station_added)
  717. return iwl_send_cmd(priv, &cmd);
  718. return 0;
  719. }
  720. EXPORT_SYMBOL(iwl_send_lq_cmd);
  721. /**
  722. * iwl_sta_init_lq - Initialize a station's hardware rate table
  723. *
  724. * The uCode's station table contains a table of fallback rates
  725. * for automatic fallback during transmission.
  726. *
  727. * NOTE: This sets up a default set of values. These will be replaced later
  728. * if the driver's iwl-agn-rs rate scaling algorithm is used, instead of
  729. * rc80211_simple.
  730. *
  731. * NOTE: Run REPLY_ADD_STA command to set up station table entry, before
  732. * calling this function (which runs REPLY_TX_LINK_QUALITY_CMD,
  733. * which requires station table entry to exist).
  734. */
  735. static void iwl_sta_init_lq(struct iwl_priv *priv, const u8 *addr, int is_ap)
  736. {
  737. int i, r;
  738. struct iwl_link_quality_cmd link_cmd = {
  739. .reserved1 = 0,
  740. };
  741. u32 rate_flags;
  742. /* Set up the rate scaling to start at selected rate, fall back
  743. * all the way down to 1M in IEEE order, and then spin on 1M */
  744. if (is_ap)
  745. r = IWL_RATE_54M_INDEX;
  746. else if (priv->band == IEEE80211_BAND_5GHZ)
  747. r = IWL_RATE_6M_INDEX;
  748. else
  749. r = IWL_RATE_1M_INDEX;
  750. for (i = 0; i < LINK_QUAL_MAX_RETRY_NUM; i++) {
  751. rate_flags = 0;
  752. if (r >= IWL_FIRST_CCK_RATE && r <= IWL_LAST_CCK_RATE)
  753. rate_flags |= RATE_MCS_CCK_MSK;
  754. rate_flags |= first_antenna(priv->hw_params.valid_tx_ant) <<
  755. RATE_MCS_ANT_POS;
  756. link_cmd.rs_table[i].rate_n_flags =
  757. iwl_hw_set_rate_n_flags(iwl_rates[r].plcp, rate_flags);
  758. r = iwl_get_prev_ieee_rate(r);
  759. }
  760. link_cmd.general_params.single_stream_ant_msk =
  761. first_antenna(priv->hw_params.valid_tx_ant);
  762. link_cmd.general_params.dual_stream_ant_msk = 3;
  763. link_cmd.agg_params.agg_dis_start_th = 3;
  764. link_cmd.agg_params.agg_time_limit = cpu_to_le16(4000);
  765. /* Update the rate scaling for control frame Tx to AP */
  766. link_cmd.sta_id = is_ap ? IWL_AP_ID : priv->hw_params.bcast_sta_id;
  767. iwl_send_cmd_pdu_async(priv, REPLY_TX_LINK_QUALITY_CMD,
  768. sizeof(link_cmd), &link_cmd, NULL);
  769. }
  770. /**
  771. * iwl_rxon_add_station - add station into station table.
  772. *
  773. * there is only one AP station with id= IWL_AP_ID
  774. * NOTE: mutex must be held before calling this function
  775. */
  776. int iwl_rxon_add_station(struct iwl_priv *priv, const u8 *addr, int is_ap)
  777. {
  778. struct ieee80211_sta *sta;
  779. struct ieee80211_sta_ht_cap ht_config;
  780. struct ieee80211_sta_ht_cap *cur_ht_config = NULL;
  781. u8 sta_id;
  782. /* Add station to device's station table */
  783. /*
  784. * XXX: This check is definitely not correct, if we're an AP
  785. * it'll always be false which is not what we want, but
  786. * it doesn't look like iwlagn is prepared to be an HT
  787. * AP anyway.
  788. */
  789. if (priv->current_ht_config.is_ht) {
  790. rcu_read_lock();
  791. sta = ieee80211_find_sta(priv->hw, addr);
  792. if (sta) {
  793. memcpy(&ht_config, &sta->ht_cap, sizeof(ht_config));
  794. cur_ht_config = &ht_config;
  795. }
  796. rcu_read_unlock();
  797. }
  798. sta_id = iwl_add_station_flags(priv, addr, is_ap,
  799. 0, cur_ht_config);
  800. /* Set up default rate scaling table in device's station table */
  801. iwl_sta_init_lq(priv, addr, is_ap);
  802. return sta_id;
  803. }
  804. EXPORT_SYMBOL(iwl_rxon_add_station);
  805. /**
  806. * iwl_get_sta_id - Find station's index within station table
  807. *
  808. * If new IBSS station, create new entry in station table
  809. */
  810. int iwl_get_sta_id(struct iwl_priv *priv, struct ieee80211_hdr *hdr)
  811. {
  812. int sta_id;
  813. u16 fc = le16_to_cpu(hdr->frame_control);
  814. /* If this frame is broadcast or management, use broadcast station id */
  815. if (((fc & IEEE80211_FCTL_FTYPE) != IEEE80211_FTYPE_DATA) ||
  816. is_multicast_ether_addr(hdr->addr1))
  817. return priv->hw_params.bcast_sta_id;
  818. switch (priv->iw_mode) {
  819. /* If we are a client station in a BSS network, use the special
  820. * AP station entry (that's the only station we communicate with) */
  821. case NL80211_IFTYPE_STATION:
  822. return IWL_AP_ID;
  823. /* If we are an AP, then find the station, or use BCAST */
  824. case NL80211_IFTYPE_AP:
  825. sta_id = iwl_find_station(priv, hdr->addr1);
  826. if (sta_id != IWL_INVALID_STATION)
  827. return sta_id;
  828. return priv->hw_params.bcast_sta_id;
  829. /* If this frame is going out to an IBSS network, find the station,
  830. * or create a new station table entry */
  831. case NL80211_IFTYPE_ADHOC:
  832. sta_id = iwl_find_station(priv, hdr->addr1);
  833. if (sta_id != IWL_INVALID_STATION)
  834. return sta_id;
  835. /* Create new station table entry */
  836. sta_id = iwl_add_station_flags(priv, hdr->addr1,
  837. 0, CMD_ASYNC, NULL);
  838. if (sta_id != IWL_INVALID_STATION)
  839. return sta_id;
  840. IWL_DEBUG_DROP("Station %pM not in station map. "
  841. "Defaulting to broadcast...\n",
  842. hdr->addr1);
  843. iwl_print_hex_dump(priv, IWL_DL_DROP, (u8 *) hdr, sizeof(*hdr));
  844. return priv->hw_params.bcast_sta_id;
  845. /* If we are in monitor mode, use BCAST. This is required for
  846. * packet injection. */
  847. case NL80211_IFTYPE_MONITOR:
  848. return priv->hw_params.bcast_sta_id;
  849. default:
  850. IWL_WARNING("Unknown mode of operation: %d\n", priv->iw_mode);
  851. return priv->hw_params.bcast_sta_id;
  852. }
  853. }
  854. EXPORT_SYMBOL(iwl_get_sta_id);
  855. /**
  856. * iwl_sta_tx_modify_enable_tid - Enable Tx for this TID in station table
  857. */
  858. void iwl_sta_tx_modify_enable_tid(struct iwl_priv *priv, int sta_id, int tid)
  859. {
  860. unsigned long flags;
  861. /* Remove "disable" flag, to enable Tx for this TID */
  862. spin_lock_irqsave(&priv->sta_lock, flags);
  863. priv->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_TID_DISABLE_TX;
  864. priv->stations[sta_id].sta.tid_disable_tx &= cpu_to_le16(~(1 << tid));
  865. priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK;
  866. spin_unlock_irqrestore(&priv->sta_lock, flags);
  867. iwl_send_add_sta(priv, &priv->stations[sta_id].sta, CMD_ASYNC);
  868. }
  869. EXPORT_SYMBOL(iwl_sta_tx_modify_enable_tid);
  870. int iwl_sta_rx_agg_start(struct iwl_priv *priv,
  871. const u8 *addr, int tid, u16 ssn)
  872. {
  873. unsigned long flags;
  874. int sta_id;
  875. sta_id = iwl_find_station(priv, addr);
  876. if (sta_id == IWL_INVALID_STATION)
  877. return -ENXIO;
  878. spin_lock_irqsave(&priv->sta_lock, flags);
  879. priv->stations[sta_id].sta.station_flags_msk = 0;
  880. priv->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_ADDBA_TID_MSK;
  881. priv->stations[sta_id].sta.add_immediate_ba_tid = (u8)tid;
  882. priv->stations[sta_id].sta.add_immediate_ba_ssn = cpu_to_le16(ssn);
  883. priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK;
  884. spin_unlock_irqrestore(&priv->sta_lock, flags);
  885. return iwl_send_add_sta(priv, &priv->stations[sta_id].sta,
  886. CMD_ASYNC);
  887. }
  888. EXPORT_SYMBOL(iwl_sta_rx_agg_start);
  889. int iwl_sta_rx_agg_stop(struct iwl_priv *priv, const u8 *addr, int tid)
  890. {
  891. unsigned long flags;
  892. int sta_id;
  893. sta_id = iwl_find_station(priv, addr);
  894. if (sta_id == IWL_INVALID_STATION)
  895. return -ENXIO;
  896. spin_lock_irqsave(&priv->sta_lock, flags);
  897. priv->stations[sta_id].sta.station_flags_msk = 0;
  898. priv->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_DELBA_TID_MSK;
  899. priv->stations[sta_id].sta.remove_immediate_ba_tid = (u8)tid;
  900. priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK;
  901. spin_unlock_irqrestore(&priv->sta_lock, flags);
  902. return iwl_send_add_sta(priv, &priv->stations[sta_id].sta,
  903. CMD_ASYNC);
  904. }
  905. EXPORT_SYMBOL(iwl_sta_rx_agg_stop);
  906. static void iwl_sta_modify_ps_wake(struct iwl_priv *priv, int sta_id)
  907. {
  908. unsigned long flags;
  909. spin_lock_irqsave(&priv->sta_lock, flags);
  910. priv->stations[sta_id].sta.station_flags &= ~STA_FLG_PWR_SAVE_MSK;
  911. priv->stations[sta_id].sta.station_flags_msk = STA_FLG_PWR_SAVE_MSK;
  912. priv->stations[sta_id].sta.sta.modify_mask = 0;
  913. priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK;
  914. spin_unlock_irqrestore(&priv->sta_lock, flags);
  915. iwl_send_add_sta(priv, &priv->stations[sta_id].sta, CMD_ASYNC);
  916. }
  917. void iwl_update_ps_mode(struct iwl_priv *priv, u16 ps_bit, u8 *addr)
  918. {
  919. /* FIXME: need locking over ps_status ??? */
  920. u8 sta_id = iwl_find_station(priv, addr);
  921. if (sta_id != IWL_INVALID_STATION) {
  922. u8 sta_awake = priv->stations[sta_id].
  923. ps_status == STA_PS_STATUS_WAKE;
  924. if (sta_awake && ps_bit)
  925. priv->stations[sta_id].ps_status = STA_PS_STATUS_SLEEP;
  926. else if (!sta_awake && !ps_bit) {
  927. iwl_sta_modify_ps_wake(priv, sta_id);
  928. priv->stations[sta_id].ps_status = STA_PS_STATUS_WAKE;
  929. }
  930. }
  931. }