iwl-sta.c 33 KB

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