iwl-sta.c 32 KB

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