iwl-sta.c 32 KB

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