iwl-sta.c 32 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174
  1. /******************************************************************************
  2. *
  3. * Copyright(c) 2003 - 2009 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 <linux/etherdevice.h>
  31. #include "iwl-dev.h"
  32. #include "iwl-core.h"
  33. #include "iwl-sta.h"
  34. #define IWL_STA_DRIVER_ACTIVE BIT(0) /* driver entry is active */
  35. #define IWL_STA_UCODE_ACTIVE BIT(1) /* ucode entry is active */
  36. u8 iwl_find_station(struct iwl_priv *priv, const u8 *addr)
  37. {
  38. int i;
  39. int start = 0;
  40. int ret = IWL_INVALID_STATION;
  41. unsigned long flags;
  42. if ((priv->iw_mode == NL80211_IFTYPE_ADHOC) ||
  43. (priv->iw_mode == NL80211_IFTYPE_AP))
  44. start = IWL_STA_ID;
  45. if (is_broadcast_ether_addr(addr))
  46. return priv->hw_params.bcast_sta_id;
  47. spin_lock_irqsave(&priv->sta_lock, flags);
  48. for (i = start; i < priv->hw_params.max_stations; i++)
  49. if (priv->stations[i].used &&
  50. (!compare_ether_addr(priv->stations[i].sta.sta.addr,
  51. addr))) {
  52. ret = i;
  53. goto out;
  54. }
  55. IWL_DEBUG_ASSOC_LIMIT("can not find STA %pM total %d\n",
  56. addr, priv->num_stations);
  57. out:
  58. spin_unlock_irqrestore(&priv->sta_lock, flags);
  59. return ret;
  60. }
  61. EXPORT_SYMBOL(iwl_find_station);
  62. int iwl_get_ra_sta_id(struct iwl_priv *priv, struct ieee80211_hdr *hdr)
  63. {
  64. if (priv->iw_mode == NL80211_IFTYPE_STATION) {
  65. return IWL_AP_ID;
  66. } else {
  67. u8 *da = ieee80211_get_DA(hdr);
  68. return iwl_find_station(priv, da);
  69. }
  70. }
  71. EXPORT_SYMBOL(iwl_get_ra_sta_id);
  72. static void iwl_sta_ucode_activate(struct iwl_priv *priv, u8 sta_id)
  73. {
  74. unsigned long flags;
  75. spin_lock_irqsave(&priv->sta_lock, flags);
  76. if (!(priv->stations[sta_id].used & IWL_STA_DRIVER_ACTIVE))
  77. IWL_ERR(priv, "ACTIVATE a non DRIVER active station %d\n",
  78. 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_ERR(priv, "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_ERR(priv, "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_ERR(priv, "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_WARN(priv, "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_WARN(priv, "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_ERR(priv, "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_ERR(priv, "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_ERR(priv, "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_ERR(priv, "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_ERR(priv, "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_ERR(priv, "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_ERR(priv, "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_ERR(priv, "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_ERR(priv, "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 WEP_INVALID_OFFSET;
  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_ERR(priv, "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_ERR(priv, "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. WARN(priv->stations[sta_id].sta.key.key_offset == WEP_INVALID_OFFSET,
  517. "no space for a new key");
  518. priv->stations[sta_id].sta.key.key_flags = key_flags;
  519. priv->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_KEY_MASK;
  520. priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK;
  521. ret = iwl_send_add_sta(priv, &priv->stations[sta_id].sta, CMD_ASYNC);
  522. spin_unlock_irqrestore(&priv->sta_lock, flags);
  523. return ret;
  524. }
  525. static int iwl_set_ccmp_dynamic_key_info(struct iwl_priv *priv,
  526. struct ieee80211_key_conf *keyconf,
  527. u8 sta_id)
  528. {
  529. unsigned long flags;
  530. __le16 key_flags = 0;
  531. int ret;
  532. key_flags |= (STA_KEY_FLG_CCMP | STA_KEY_FLG_MAP_KEY_MSK);
  533. key_flags |= cpu_to_le16(keyconf->keyidx << STA_KEY_FLG_KEYID_POS);
  534. key_flags &= ~STA_KEY_FLG_INVALID;
  535. if (sta_id == priv->hw_params.bcast_sta_id)
  536. key_flags |= STA_KEY_MULTICAST_MSK;
  537. keyconf->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
  538. spin_lock_irqsave(&priv->sta_lock, flags);
  539. priv->stations[sta_id].keyinfo.alg = keyconf->alg;
  540. priv->stations[sta_id].keyinfo.keylen = keyconf->keylen;
  541. memcpy(priv->stations[sta_id].keyinfo.key, keyconf->key,
  542. keyconf->keylen);
  543. memcpy(priv->stations[sta_id].sta.key.key, keyconf->key,
  544. keyconf->keylen);
  545. if ((priv->stations[sta_id].sta.key.key_flags & STA_KEY_FLG_ENCRYPT_MSK)
  546. == STA_KEY_FLG_NO_ENC)
  547. priv->stations[sta_id].sta.key.key_offset =
  548. iwl_get_free_ucode_key_index(priv);
  549. /* else, we are overriding an existing key => no need to allocated room
  550. * in uCode. */
  551. WARN(priv->stations[sta_id].sta.key.key_offset == WEP_INVALID_OFFSET,
  552. "no space for a new key");
  553. priv->stations[sta_id].sta.key.key_flags = key_flags;
  554. priv->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_KEY_MASK;
  555. priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK;
  556. ret = iwl_send_add_sta(priv, &priv->stations[sta_id].sta, CMD_ASYNC);
  557. spin_unlock_irqrestore(&priv->sta_lock, flags);
  558. return ret;
  559. }
  560. static int iwl_set_tkip_dynamic_key_info(struct iwl_priv *priv,
  561. struct ieee80211_key_conf *keyconf,
  562. u8 sta_id)
  563. {
  564. unsigned long flags;
  565. int ret = 0;
  566. keyconf->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
  567. keyconf->flags |= IEEE80211_KEY_FLAG_GENERATE_MMIC;
  568. spin_lock_irqsave(&priv->sta_lock, flags);
  569. priv->stations[sta_id].keyinfo.alg = keyconf->alg;
  570. priv->stations[sta_id].keyinfo.keylen = 16;
  571. if ((priv->stations[sta_id].sta.key.key_flags & STA_KEY_FLG_ENCRYPT_MSK)
  572. == STA_KEY_FLG_NO_ENC)
  573. priv->stations[sta_id].sta.key.key_offset =
  574. iwl_get_free_ucode_key_index(priv);
  575. /* else, we are overriding an existing key => no need to allocated room
  576. * in uCode. */
  577. WARN(priv->stations[sta_id].sta.key.key_offset == WEP_INVALID_OFFSET,
  578. "no space for a new key");
  579. /* This copy is acutally not needed: we get the key with each TX */
  580. memcpy(priv->stations[sta_id].keyinfo.key, keyconf->key, 16);
  581. memcpy(priv->stations[sta_id].sta.key.key, keyconf->key, 16);
  582. spin_unlock_irqrestore(&priv->sta_lock, flags);
  583. return ret;
  584. }
  585. void iwl_update_tkip_key(struct iwl_priv *priv,
  586. struct ieee80211_key_conf *keyconf,
  587. const u8 *addr, u32 iv32, u16 *phase1key)
  588. {
  589. u8 sta_id = IWL_INVALID_STATION;
  590. unsigned long flags;
  591. __le16 key_flags = 0;
  592. int i;
  593. DECLARE_MAC_BUF(mac);
  594. sta_id = iwl_find_station(priv, addr);
  595. if (sta_id == IWL_INVALID_STATION) {
  596. IWL_DEBUG_MAC80211("leave - %pM not in station map.\n",
  597. addr);
  598. return;
  599. }
  600. if (iwl_scan_cancel(priv)) {
  601. /* cancel scan failed, just live w/ bad key and rely
  602. briefly on SW decryption */
  603. return;
  604. }
  605. key_flags |= (STA_KEY_FLG_TKIP | STA_KEY_FLG_MAP_KEY_MSK);
  606. key_flags |= cpu_to_le16(keyconf->keyidx << STA_KEY_FLG_KEYID_POS);
  607. key_flags &= ~STA_KEY_FLG_INVALID;
  608. if (sta_id == priv->hw_params.bcast_sta_id)
  609. key_flags |= STA_KEY_MULTICAST_MSK;
  610. spin_lock_irqsave(&priv->sta_lock, flags);
  611. priv->stations[sta_id].sta.key.key_flags = key_flags;
  612. priv->stations[sta_id].sta.key.tkip_rx_tsc_byte2 = (u8) iv32;
  613. for (i = 0; i < 5; i++)
  614. priv->stations[sta_id].sta.key.tkip_rx_ttak[i] =
  615. cpu_to_le16(phase1key[i]);
  616. priv->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_KEY_MASK;
  617. priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK;
  618. iwl_send_add_sta(priv, &priv->stations[sta_id].sta, CMD_ASYNC);
  619. spin_unlock_irqrestore(&priv->sta_lock, flags);
  620. }
  621. EXPORT_SYMBOL(iwl_update_tkip_key);
  622. int iwl_remove_dynamic_key(struct iwl_priv *priv,
  623. struct ieee80211_key_conf *keyconf,
  624. u8 sta_id)
  625. {
  626. unsigned long flags;
  627. int ret = 0;
  628. u16 key_flags;
  629. u8 keyidx;
  630. priv->key_mapping_key--;
  631. spin_lock_irqsave(&priv->sta_lock, flags);
  632. key_flags = le16_to_cpu(priv->stations[sta_id].sta.key.key_flags);
  633. keyidx = (key_flags >> STA_KEY_FLG_KEYID_POS) & 0x3;
  634. IWL_DEBUG_WEP("Remove dynamic key: idx=%d sta=%d\n",
  635. keyconf->keyidx, sta_id);
  636. if (keyconf->keyidx != keyidx) {
  637. /* We need to remove a key with index different that the one
  638. * in the uCode. This means that the key we need to remove has
  639. * been replaced by another one with different index.
  640. * Don't do anything and return ok
  641. */
  642. spin_unlock_irqrestore(&priv->sta_lock, flags);
  643. return 0;
  644. }
  645. if (priv->stations[sta_id].sta.key.key_offset == WEP_INVALID_OFFSET) {
  646. IWL_WARN(priv, "Removing wrong key %d 0x%x\n",
  647. keyconf->keyidx, key_flags);
  648. spin_unlock_irqrestore(&priv->sta_lock, flags);
  649. return 0;
  650. }
  651. if (!test_and_clear_bit(priv->stations[sta_id].sta.key.key_offset,
  652. &priv->ucode_key_table))
  653. IWL_ERR(priv, "index %d not used in uCode key table.\n",
  654. priv->stations[sta_id].sta.key.key_offset);
  655. memset(&priv->stations[sta_id].keyinfo, 0,
  656. sizeof(struct iwl_hw_key));
  657. memset(&priv->stations[sta_id].sta.key, 0,
  658. sizeof(struct iwl4965_keyinfo));
  659. priv->stations[sta_id].sta.key.key_flags =
  660. STA_KEY_FLG_NO_ENC | STA_KEY_FLG_INVALID;
  661. priv->stations[sta_id].sta.key.key_offset = WEP_INVALID_OFFSET;
  662. priv->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_KEY_MASK;
  663. priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK;
  664. ret = iwl_send_add_sta(priv, &priv->stations[sta_id].sta, CMD_ASYNC);
  665. spin_unlock_irqrestore(&priv->sta_lock, flags);
  666. return ret;
  667. }
  668. EXPORT_SYMBOL(iwl_remove_dynamic_key);
  669. int iwl_set_dynamic_key(struct iwl_priv *priv,
  670. struct ieee80211_key_conf *keyconf, u8 sta_id)
  671. {
  672. int ret;
  673. priv->key_mapping_key++;
  674. keyconf->hw_key_idx = HW_KEY_DYNAMIC;
  675. switch (keyconf->alg) {
  676. case ALG_CCMP:
  677. ret = iwl_set_ccmp_dynamic_key_info(priv, keyconf, sta_id);
  678. break;
  679. case ALG_TKIP:
  680. ret = iwl_set_tkip_dynamic_key_info(priv, keyconf, sta_id);
  681. break;
  682. case ALG_WEP:
  683. ret = iwl_set_wep_dynamic_key_info(priv, keyconf, sta_id);
  684. break;
  685. default:
  686. IWL_ERR(priv,
  687. "Unknown alg: %s alg = %d\n", __func__, keyconf->alg);
  688. ret = -EINVAL;
  689. }
  690. IWL_DEBUG_WEP("Set dynamic key: alg= %d len=%d idx=%d sta=%d ret=%d\n",
  691. keyconf->alg, keyconf->keylen, keyconf->keyidx,
  692. sta_id, ret);
  693. return ret;
  694. }
  695. EXPORT_SYMBOL(iwl_set_dynamic_key);
  696. #ifdef CONFIG_IWLWIFI_DEBUG
  697. static void iwl_dump_lq_cmd(struct iwl_priv *priv,
  698. struct iwl_link_quality_cmd *lq)
  699. {
  700. int i;
  701. IWL_DEBUG_RATE("lq station id 0x%x\n", lq->sta_id);
  702. IWL_DEBUG_RATE("lq ant 0x%X 0x%X\n",
  703. lq->general_params.single_stream_ant_msk,
  704. lq->general_params.dual_stream_ant_msk);
  705. for (i = 0; i < LINK_QUAL_MAX_RETRY_NUM; i++)
  706. IWL_DEBUG_RATE("lq index %d 0x%X\n",
  707. i, lq->rs_table[i].rate_n_flags);
  708. }
  709. #else
  710. static inline void iwl_dump_lq_cmd(struct iwl_priv *priv,
  711. struct iwl_link_quality_cmd *lq)
  712. {
  713. }
  714. #endif
  715. int iwl_send_lq_cmd(struct iwl_priv *priv,
  716. struct iwl_link_quality_cmd *lq, u8 flags)
  717. {
  718. struct iwl_host_cmd cmd = {
  719. .id = REPLY_TX_LINK_QUALITY_CMD,
  720. .len = sizeof(struct iwl_link_quality_cmd),
  721. .meta.flags = flags,
  722. .data = lq,
  723. };
  724. if ((lq->sta_id == 0xFF) &&
  725. (priv->iw_mode == NL80211_IFTYPE_ADHOC))
  726. return -EINVAL;
  727. if (lq->sta_id == 0xFF)
  728. lq->sta_id = IWL_AP_ID;
  729. iwl_dump_lq_cmd(priv, lq);
  730. if (iwl_is_associated(priv) && priv->assoc_station_added)
  731. return iwl_send_cmd(priv, &cmd);
  732. return 0;
  733. }
  734. EXPORT_SYMBOL(iwl_send_lq_cmd);
  735. /**
  736. * iwl_sta_init_lq - Initialize a station's hardware rate table
  737. *
  738. * The uCode's station table contains a table of fallback rates
  739. * for automatic fallback during transmission.
  740. *
  741. * NOTE: This sets up a default set of values. These will be replaced later
  742. * if the driver's iwl-agn-rs rate scaling algorithm is used, instead of
  743. * rc80211_simple.
  744. *
  745. * NOTE: Run REPLY_ADD_STA command to set up station table entry, before
  746. * calling this function (which runs REPLY_TX_LINK_QUALITY_CMD,
  747. * which requires station table entry to exist).
  748. */
  749. static void iwl_sta_init_lq(struct iwl_priv *priv, const u8 *addr, int is_ap)
  750. {
  751. int i, r;
  752. struct iwl_link_quality_cmd link_cmd = {
  753. .reserved1 = 0,
  754. };
  755. u32 rate_flags;
  756. /* Set up the rate scaling to start at selected rate, fall back
  757. * all the way down to 1M in IEEE order, and then spin on 1M */
  758. if (is_ap)
  759. r = IWL_RATE_54M_INDEX;
  760. else if (priv->band == IEEE80211_BAND_5GHZ)
  761. r = IWL_RATE_6M_INDEX;
  762. else
  763. r = IWL_RATE_1M_INDEX;
  764. for (i = 0; i < LINK_QUAL_MAX_RETRY_NUM; i++) {
  765. rate_flags = 0;
  766. if (r >= IWL_FIRST_CCK_RATE && r <= IWL_LAST_CCK_RATE)
  767. rate_flags |= RATE_MCS_CCK_MSK;
  768. rate_flags |= first_antenna(priv->hw_params.valid_tx_ant) <<
  769. RATE_MCS_ANT_POS;
  770. link_cmd.rs_table[i].rate_n_flags =
  771. iwl_hw_set_rate_n_flags(iwl_rates[r].plcp, rate_flags);
  772. r = iwl_get_prev_ieee_rate(r);
  773. }
  774. link_cmd.general_params.single_stream_ant_msk =
  775. first_antenna(priv->hw_params.valid_tx_ant);
  776. link_cmd.general_params.dual_stream_ant_msk = 3;
  777. link_cmd.agg_params.agg_dis_start_th = 3;
  778. link_cmd.agg_params.agg_time_limit = cpu_to_le16(4000);
  779. /* Update the rate scaling for control frame Tx to AP */
  780. link_cmd.sta_id = is_ap ? IWL_AP_ID : priv->hw_params.bcast_sta_id;
  781. iwl_send_cmd_pdu_async(priv, REPLY_TX_LINK_QUALITY_CMD,
  782. sizeof(link_cmd), &link_cmd, NULL);
  783. }
  784. /**
  785. * iwl_rxon_add_station - add station into station table.
  786. *
  787. * there is only one AP station with id= IWL_AP_ID
  788. * NOTE: mutex must be held before calling this function
  789. */
  790. int iwl_rxon_add_station(struct iwl_priv *priv, const u8 *addr, int is_ap)
  791. {
  792. struct ieee80211_sta *sta;
  793. struct ieee80211_sta_ht_cap ht_config;
  794. struct ieee80211_sta_ht_cap *cur_ht_config = NULL;
  795. u8 sta_id;
  796. /* Add station to device's station table */
  797. /*
  798. * XXX: This check is definitely not correct, if we're an AP
  799. * it'll always be false which is not what we want, but
  800. * it doesn't look like iwlagn is prepared to be an HT
  801. * AP anyway.
  802. */
  803. if (priv->current_ht_config.is_ht) {
  804. rcu_read_lock();
  805. sta = ieee80211_find_sta(priv->hw, addr);
  806. if (sta) {
  807. memcpy(&ht_config, &sta->ht_cap, sizeof(ht_config));
  808. cur_ht_config = &ht_config;
  809. }
  810. rcu_read_unlock();
  811. }
  812. sta_id = iwl_add_station_flags(priv, addr, is_ap,
  813. 0, cur_ht_config);
  814. /* Set up default rate scaling table in device's station table */
  815. iwl_sta_init_lq(priv, addr, is_ap);
  816. return sta_id;
  817. }
  818. EXPORT_SYMBOL(iwl_rxon_add_station);
  819. /**
  820. * iwl_get_sta_id - Find station's index within station table
  821. *
  822. * If new IBSS station, create new entry in station table
  823. */
  824. int iwl_get_sta_id(struct iwl_priv *priv, struct ieee80211_hdr *hdr)
  825. {
  826. int sta_id;
  827. u16 fc = le16_to_cpu(hdr->frame_control);
  828. /* If this frame is broadcast or management, use broadcast station id */
  829. if (((fc & IEEE80211_FCTL_FTYPE) != IEEE80211_FTYPE_DATA) ||
  830. is_multicast_ether_addr(hdr->addr1))
  831. return priv->hw_params.bcast_sta_id;
  832. switch (priv->iw_mode) {
  833. /* If we are a client station in a BSS network, use the special
  834. * AP station entry (that's the only station we communicate with) */
  835. case NL80211_IFTYPE_STATION:
  836. return IWL_AP_ID;
  837. /* If we are an AP, then find the station, or use BCAST */
  838. case NL80211_IFTYPE_AP:
  839. sta_id = iwl_find_station(priv, hdr->addr1);
  840. if (sta_id != IWL_INVALID_STATION)
  841. return sta_id;
  842. return priv->hw_params.bcast_sta_id;
  843. /* If this frame is going out to an IBSS network, find the station,
  844. * or create a new station table entry */
  845. case NL80211_IFTYPE_ADHOC:
  846. sta_id = iwl_find_station(priv, hdr->addr1);
  847. if (sta_id != IWL_INVALID_STATION)
  848. return sta_id;
  849. /* Create new station table entry */
  850. sta_id = iwl_add_station_flags(priv, hdr->addr1,
  851. 0, CMD_ASYNC, NULL);
  852. if (sta_id != IWL_INVALID_STATION)
  853. return sta_id;
  854. IWL_DEBUG_DROP("Station %pM not in station map. "
  855. "Defaulting to broadcast...\n",
  856. hdr->addr1);
  857. iwl_print_hex_dump(priv, IWL_DL_DROP, (u8 *) hdr, sizeof(*hdr));
  858. return priv->hw_params.bcast_sta_id;
  859. /* If we are in monitor mode, use BCAST. This is required for
  860. * packet injection. */
  861. case NL80211_IFTYPE_MONITOR:
  862. return priv->hw_params.bcast_sta_id;
  863. default:
  864. IWL_WARN(priv, "Unknown mode of operation: %d\n",
  865. priv->iw_mode);
  866. return priv->hw_params.bcast_sta_id;
  867. }
  868. }
  869. EXPORT_SYMBOL(iwl_get_sta_id);
  870. /**
  871. * iwl_sta_tx_modify_enable_tid - Enable Tx for this TID in station table
  872. */
  873. void iwl_sta_tx_modify_enable_tid(struct iwl_priv *priv, int sta_id, int tid)
  874. {
  875. unsigned long flags;
  876. /* Remove "disable" flag, to enable Tx for this TID */
  877. spin_lock_irqsave(&priv->sta_lock, flags);
  878. priv->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_TID_DISABLE_TX;
  879. priv->stations[sta_id].sta.tid_disable_tx &= cpu_to_le16(~(1 << tid));
  880. priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK;
  881. spin_unlock_irqrestore(&priv->sta_lock, flags);
  882. iwl_send_add_sta(priv, &priv->stations[sta_id].sta, CMD_ASYNC);
  883. }
  884. EXPORT_SYMBOL(iwl_sta_tx_modify_enable_tid);
  885. int iwl_sta_rx_agg_start(struct iwl_priv *priv,
  886. const u8 *addr, int tid, u16 ssn)
  887. {
  888. unsigned long flags;
  889. int sta_id;
  890. sta_id = iwl_find_station(priv, addr);
  891. if (sta_id == IWL_INVALID_STATION)
  892. return -ENXIO;
  893. spin_lock_irqsave(&priv->sta_lock, flags);
  894. priv->stations[sta_id].sta.station_flags_msk = 0;
  895. priv->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_ADDBA_TID_MSK;
  896. priv->stations[sta_id].sta.add_immediate_ba_tid = (u8)tid;
  897. priv->stations[sta_id].sta.add_immediate_ba_ssn = cpu_to_le16(ssn);
  898. priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK;
  899. spin_unlock_irqrestore(&priv->sta_lock, flags);
  900. return iwl_send_add_sta(priv, &priv->stations[sta_id].sta,
  901. CMD_ASYNC);
  902. }
  903. EXPORT_SYMBOL(iwl_sta_rx_agg_start);
  904. int iwl_sta_rx_agg_stop(struct iwl_priv *priv, const u8 *addr, int tid)
  905. {
  906. unsigned long flags;
  907. int sta_id;
  908. sta_id = iwl_find_station(priv, addr);
  909. if (sta_id == IWL_INVALID_STATION)
  910. return -ENXIO;
  911. spin_lock_irqsave(&priv->sta_lock, flags);
  912. priv->stations[sta_id].sta.station_flags_msk = 0;
  913. priv->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_DELBA_TID_MSK;
  914. priv->stations[sta_id].sta.remove_immediate_ba_tid = (u8)tid;
  915. priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK;
  916. spin_unlock_irqrestore(&priv->sta_lock, flags);
  917. return iwl_send_add_sta(priv, &priv->stations[sta_id].sta,
  918. CMD_ASYNC);
  919. }
  920. EXPORT_SYMBOL(iwl_sta_rx_agg_stop);
  921. static void iwl_sta_modify_ps_wake(struct iwl_priv *priv, int sta_id)
  922. {
  923. unsigned long flags;
  924. spin_lock_irqsave(&priv->sta_lock, flags);
  925. priv->stations[sta_id].sta.station_flags &= ~STA_FLG_PWR_SAVE_MSK;
  926. priv->stations[sta_id].sta.station_flags_msk = STA_FLG_PWR_SAVE_MSK;
  927. priv->stations[sta_id].sta.sta.modify_mask = 0;
  928. priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK;
  929. spin_unlock_irqrestore(&priv->sta_lock, flags);
  930. iwl_send_add_sta(priv, &priv->stations[sta_id].sta, CMD_ASYNC);
  931. }
  932. void iwl_update_ps_mode(struct iwl_priv *priv, u16 ps_bit, u8 *addr)
  933. {
  934. /* FIXME: need locking over ps_status ??? */
  935. u8 sta_id = iwl_find_station(priv, addr);
  936. if (sta_id != IWL_INVALID_STATION) {
  937. u8 sta_awake = priv->stations[sta_id].
  938. ps_status == STA_PS_STATUS_WAKE;
  939. if (sta_awake && ps_bit)
  940. priv->stations[sta_id].ps_status = STA_PS_STATUS_SLEEP;
  941. else if (!sta_awake && !ps_bit) {
  942. iwl_sta_modify_ps_wake(priv, sta_id);
  943. priv->stations[sta_id].ps_status = STA_PS_STATUS_WAKE;
  944. }
  945. }
  946. }