iwl-sta.c 33 KB

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