iwl-sta.c 33 KB

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