iwl-sta.c 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203
  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. IWL_DEBUG_WEP(priv, "Removing default WEP key: idx=%d\n",
  464. keyconf->keyidx);
  465. if (!test_and_clear_bit(keyconf->keyidx, &priv->ucode_key_table))
  466. IWL_ERR(priv, "index %d not used in uCode key table.\n",
  467. keyconf->keyidx);
  468. priv->default_wep_key--;
  469. memset(&priv->wep_keys[keyconf->keyidx], 0, sizeof(priv->wep_keys[0]));
  470. if (iwl_is_rfkill(priv)) {
  471. IWL_DEBUG_WEP(priv, "Not sending REPLY_WEPKEY command due to RFKILL.\n");
  472. spin_unlock_irqrestore(&priv->sta_lock, flags);
  473. return 0;
  474. }
  475. ret = iwl_send_static_wepkey_cmd(priv, 1);
  476. IWL_DEBUG_WEP(priv, "Remove default WEP key: idx=%d ret=%d\n",
  477. keyconf->keyidx, ret);
  478. spin_unlock_irqrestore(&priv->sta_lock, flags);
  479. return ret;
  480. }
  481. EXPORT_SYMBOL(iwl_remove_default_wep_key);
  482. int iwl_set_default_wep_key(struct iwl_priv *priv,
  483. struct ieee80211_key_conf *keyconf)
  484. {
  485. int ret;
  486. unsigned long flags;
  487. if (keyconf->keylen != WEP_KEY_LEN_128 &&
  488. keyconf->keylen != WEP_KEY_LEN_64) {
  489. IWL_DEBUG_WEP(priv, "Bad WEP key length %d\n", keyconf->keylen);
  490. return -EINVAL;
  491. }
  492. keyconf->flags &= ~IEEE80211_KEY_FLAG_GENERATE_IV;
  493. keyconf->hw_key_idx = HW_KEY_DEFAULT;
  494. priv->stations[IWL_AP_ID].keyinfo.alg = ALG_WEP;
  495. spin_lock_irqsave(&priv->sta_lock, flags);
  496. priv->default_wep_key++;
  497. if (test_and_set_bit(keyconf->keyidx, &priv->ucode_key_table))
  498. IWL_ERR(priv, "index %d already used in uCode key table.\n",
  499. keyconf->keyidx);
  500. priv->wep_keys[keyconf->keyidx].key_size = keyconf->keylen;
  501. memcpy(&priv->wep_keys[keyconf->keyidx].key, &keyconf->key,
  502. keyconf->keylen);
  503. ret = iwl_send_static_wepkey_cmd(priv, 0);
  504. IWL_DEBUG_WEP(priv, "Set default WEP key: len=%d idx=%d ret=%d\n",
  505. keyconf->keylen, keyconf->keyidx, ret);
  506. spin_unlock_irqrestore(&priv->sta_lock, flags);
  507. return ret;
  508. }
  509. EXPORT_SYMBOL(iwl_set_default_wep_key);
  510. static int iwl_set_wep_dynamic_key_info(struct iwl_priv *priv,
  511. struct ieee80211_key_conf *keyconf,
  512. u8 sta_id)
  513. {
  514. unsigned long flags;
  515. __le16 key_flags = 0;
  516. int ret;
  517. keyconf->flags &= ~IEEE80211_KEY_FLAG_GENERATE_IV;
  518. key_flags |= (STA_KEY_FLG_WEP | STA_KEY_FLG_MAP_KEY_MSK);
  519. key_flags |= cpu_to_le16(keyconf->keyidx << STA_KEY_FLG_KEYID_POS);
  520. key_flags &= ~STA_KEY_FLG_INVALID;
  521. if (keyconf->keylen == WEP_KEY_LEN_128)
  522. key_flags |= STA_KEY_FLG_KEY_SIZE_MSK;
  523. if (sta_id == priv->hw_params.bcast_sta_id)
  524. key_flags |= STA_KEY_MULTICAST_MSK;
  525. spin_lock_irqsave(&priv->sta_lock, flags);
  526. priv->stations[sta_id].keyinfo.alg = keyconf->alg;
  527. priv->stations[sta_id].keyinfo.keylen = keyconf->keylen;
  528. priv->stations[sta_id].keyinfo.keyidx = keyconf->keyidx;
  529. memcpy(priv->stations[sta_id].keyinfo.key,
  530. keyconf->key, keyconf->keylen);
  531. memcpy(&priv->stations[sta_id].sta.key.key[3],
  532. keyconf->key, keyconf->keylen);
  533. if ((priv->stations[sta_id].sta.key.key_flags & STA_KEY_FLG_ENCRYPT_MSK)
  534. == STA_KEY_FLG_NO_ENC)
  535. priv->stations[sta_id].sta.key.key_offset =
  536. iwl_get_free_ucode_key_index(priv);
  537. /* else, we are overriding an existing key => no need to allocated room
  538. * in uCode. */
  539. WARN(priv->stations[sta_id].sta.key.key_offset == WEP_INVALID_OFFSET,
  540. "no space for a new key");
  541. priv->stations[sta_id].sta.key.key_flags = key_flags;
  542. priv->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_KEY_MASK;
  543. priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK;
  544. ret = iwl_send_add_sta(priv, &priv->stations[sta_id].sta, CMD_ASYNC);
  545. spin_unlock_irqrestore(&priv->sta_lock, flags);
  546. return ret;
  547. }
  548. static int iwl_set_ccmp_dynamic_key_info(struct iwl_priv *priv,
  549. struct ieee80211_key_conf *keyconf,
  550. u8 sta_id)
  551. {
  552. unsigned long flags;
  553. __le16 key_flags = 0;
  554. int ret;
  555. key_flags |= (STA_KEY_FLG_CCMP | STA_KEY_FLG_MAP_KEY_MSK);
  556. key_flags |= cpu_to_le16(keyconf->keyidx << STA_KEY_FLG_KEYID_POS);
  557. key_flags &= ~STA_KEY_FLG_INVALID;
  558. if (sta_id == priv->hw_params.bcast_sta_id)
  559. key_flags |= STA_KEY_MULTICAST_MSK;
  560. keyconf->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
  561. spin_lock_irqsave(&priv->sta_lock, flags);
  562. priv->stations[sta_id].keyinfo.alg = keyconf->alg;
  563. priv->stations[sta_id].keyinfo.keylen = keyconf->keylen;
  564. memcpy(priv->stations[sta_id].keyinfo.key, keyconf->key,
  565. keyconf->keylen);
  566. memcpy(priv->stations[sta_id].sta.key.key, keyconf->key,
  567. keyconf->keylen);
  568. if ((priv->stations[sta_id].sta.key.key_flags & STA_KEY_FLG_ENCRYPT_MSK)
  569. == STA_KEY_FLG_NO_ENC)
  570. priv->stations[sta_id].sta.key.key_offset =
  571. iwl_get_free_ucode_key_index(priv);
  572. /* else, we are overriding an existing key => no need to allocated room
  573. * in uCode. */
  574. WARN(priv->stations[sta_id].sta.key.key_offset == WEP_INVALID_OFFSET,
  575. "no space for a new key");
  576. priv->stations[sta_id].sta.key.key_flags = key_flags;
  577. priv->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_KEY_MASK;
  578. priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK;
  579. ret = iwl_send_add_sta(priv, &priv->stations[sta_id].sta, CMD_ASYNC);
  580. spin_unlock_irqrestore(&priv->sta_lock, flags);
  581. return ret;
  582. }
  583. static int iwl_set_tkip_dynamic_key_info(struct iwl_priv *priv,
  584. struct ieee80211_key_conf *keyconf,
  585. u8 sta_id)
  586. {
  587. unsigned long flags;
  588. int ret = 0;
  589. __le16 key_flags = 0;
  590. key_flags |= (STA_KEY_FLG_TKIP | STA_KEY_FLG_MAP_KEY_MSK);
  591. key_flags |= cpu_to_le16(keyconf->keyidx << STA_KEY_FLG_KEYID_POS);
  592. key_flags &= ~STA_KEY_FLG_INVALID;
  593. if (sta_id == priv->hw_params.bcast_sta_id)
  594. key_flags |= STA_KEY_MULTICAST_MSK;
  595. keyconf->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
  596. keyconf->flags |= IEEE80211_KEY_FLAG_GENERATE_MMIC;
  597. spin_lock_irqsave(&priv->sta_lock, flags);
  598. priv->stations[sta_id].keyinfo.alg = keyconf->alg;
  599. priv->stations[sta_id].keyinfo.keylen = 16;
  600. if ((priv->stations[sta_id].sta.key.key_flags & STA_KEY_FLG_ENCRYPT_MSK)
  601. == STA_KEY_FLG_NO_ENC)
  602. priv->stations[sta_id].sta.key.key_offset =
  603. iwl_get_free_ucode_key_index(priv);
  604. /* else, we are overriding an existing key => no need to allocated room
  605. * in uCode. */
  606. WARN(priv->stations[sta_id].sta.key.key_offset == WEP_INVALID_OFFSET,
  607. "no space for a new key");
  608. priv->stations[sta_id].sta.key.key_flags = key_flags;
  609. /* This copy is acutally not needed: we get the key with each TX */
  610. memcpy(priv->stations[sta_id].keyinfo.key, keyconf->key, 16);
  611. memcpy(priv->stations[sta_id].sta.key.key, keyconf->key, 16);
  612. spin_unlock_irqrestore(&priv->sta_lock, flags);
  613. return ret;
  614. }
  615. void iwl_update_tkip_key(struct iwl_priv *priv,
  616. struct ieee80211_key_conf *keyconf,
  617. const u8 *addr, u32 iv32, u16 *phase1key)
  618. {
  619. u8 sta_id = IWL_INVALID_STATION;
  620. unsigned long flags;
  621. int i;
  622. sta_id = iwl_find_station(priv, addr);
  623. if (sta_id == IWL_INVALID_STATION) {
  624. IWL_DEBUG_MAC80211(priv, "leave - %pM not in station map.\n",
  625. addr);
  626. return;
  627. }
  628. if (iwl_scan_cancel(priv)) {
  629. /* cancel scan failed, just live w/ bad key and rely
  630. briefly on SW decryption */
  631. return;
  632. }
  633. spin_lock_irqsave(&priv->sta_lock, flags);
  634. priv->stations[sta_id].sta.key.tkip_rx_tsc_byte2 = (u8) iv32;
  635. for (i = 0; i < 5; i++)
  636. priv->stations[sta_id].sta.key.tkip_rx_ttak[i] =
  637. cpu_to_le16(phase1key[i]);
  638. priv->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_KEY_MASK;
  639. priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK;
  640. iwl_send_add_sta(priv, &priv->stations[sta_id].sta, CMD_ASYNC);
  641. spin_unlock_irqrestore(&priv->sta_lock, flags);
  642. }
  643. EXPORT_SYMBOL(iwl_update_tkip_key);
  644. int iwl_remove_dynamic_key(struct iwl_priv *priv,
  645. struct ieee80211_key_conf *keyconf,
  646. u8 sta_id)
  647. {
  648. unsigned long flags;
  649. int ret = 0;
  650. u16 key_flags;
  651. u8 keyidx;
  652. priv->key_mapping_key--;
  653. spin_lock_irqsave(&priv->sta_lock, flags);
  654. key_flags = le16_to_cpu(priv->stations[sta_id].sta.key.key_flags);
  655. keyidx = (key_flags >> STA_KEY_FLG_KEYID_POS) & 0x3;
  656. IWL_DEBUG_WEP(priv, "Remove dynamic key: idx=%d sta=%d\n",
  657. keyconf->keyidx, sta_id);
  658. if (keyconf->keyidx != keyidx) {
  659. /* We need to remove a key with index different that the one
  660. * in the uCode. This means that the key we need to remove has
  661. * been replaced by another one with different index.
  662. * Don't do anything and return ok
  663. */
  664. spin_unlock_irqrestore(&priv->sta_lock, flags);
  665. return 0;
  666. }
  667. if (priv->stations[sta_id].sta.key.key_offset == WEP_INVALID_OFFSET) {
  668. IWL_WARN(priv, "Removing wrong key %d 0x%x\n",
  669. keyconf->keyidx, key_flags);
  670. spin_unlock_irqrestore(&priv->sta_lock, flags);
  671. return 0;
  672. }
  673. if (!test_and_clear_bit(priv->stations[sta_id].sta.key.key_offset,
  674. &priv->ucode_key_table))
  675. IWL_ERR(priv, "index %d not used in uCode key table.\n",
  676. priv->stations[sta_id].sta.key.key_offset);
  677. memset(&priv->stations[sta_id].keyinfo, 0,
  678. sizeof(struct iwl_hw_key));
  679. memset(&priv->stations[sta_id].sta.key, 0,
  680. sizeof(struct iwl4965_keyinfo));
  681. priv->stations[sta_id].sta.key.key_flags =
  682. STA_KEY_FLG_NO_ENC | STA_KEY_FLG_INVALID;
  683. priv->stations[sta_id].sta.key.key_offset = WEP_INVALID_OFFSET;
  684. priv->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_KEY_MASK;
  685. priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK;
  686. if (iwl_is_rfkill(priv)) {
  687. IWL_DEBUG_WEP(priv, "Not sending REPLY_ADD_STA command because RFKILL enabled. \n");
  688. spin_unlock_irqrestore(&priv->sta_lock, flags);
  689. return 0;
  690. }
  691. ret = iwl_send_add_sta(priv, &priv->stations[sta_id].sta, CMD_ASYNC);
  692. spin_unlock_irqrestore(&priv->sta_lock, flags);
  693. return ret;
  694. }
  695. EXPORT_SYMBOL(iwl_remove_dynamic_key);
  696. int iwl_set_dynamic_key(struct iwl_priv *priv,
  697. struct ieee80211_key_conf *keyconf, u8 sta_id)
  698. {
  699. int ret;
  700. priv->key_mapping_key++;
  701. keyconf->hw_key_idx = HW_KEY_DYNAMIC;
  702. switch (keyconf->alg) {
  703. case ALG_CCMP:
  704. ret = iwl_set_ccmp_dynamic_key_info(priv, keyconf, sta_id);
  705. break;
  706. case ALG_TKIP:
  707. ret = iwl_set_tkip_dynamic_key_info(priv, keyconf, sta_id);
  708. break;
  709. case ALG_WEP:
  710. ret = iwl_set_wep_dynamic_key_info(priv, keyconf, sta_id);
  711. break;
  712. default:
  713. IWL_ERR(priv,
  714. "Unknown alg: %s alg = %d\n", __func__, keyconf->alg);
  715. ret = -EINVAL;
  716. }
  717. IWL_DEBUG_WEP(priv, "Set dynamic key: alg= %d len=%d idx=%d sta=%d ret=%d\n",
  718. keyconf->alg, keyconf->keylen, keyconf->keyidx,
  719. sta_id, ret);
  720. return ret;
  721. }
  722. EXPORT_SYMBOL(iwl_set_dynamic_key);
  723. #ifdef CONFIG_IWLWIFI_DEBUG
  724. static void iwl_dump_lq_cmd(struct iwl_priv *priv,
  725. struct iwl_link_quality_cmd *lq)
  726. {
  727. int i;
  728. IWL_DEBUG_RATE(priv, "lq station id 0x%x\n", lq->sta_id);
  729. IWL_DEBUG_RATE(priv, "lq ant 0x%X 0x%X\n",
  730. lq->general_params.single_stream_ant_msk,
  731. lq->general_params.dual_stream_ant_msk);
  732. for (i = 0; i < LINK_QUAL_MAX_RETRY_NUM; i++)
  733. IWL_DEBUG_RATE(priv, "lq index %d 0x%X\n",
  734. i, lq->rs_table[i].rate_n_flags);
  735. }
  736. #else
  737. static inline void iwl_dump_lq_cmd(struct iwl_priv *priv,
  738. struct iwl_link_quality_cmd *lq)
  739. {
  740. }
  741. #endif
  742. int iwl_send_lq_cmd(struct iwl_priv *priv,
  743. struct iwl_link_quality_cmd *lq, u8 flags)
  744. {
  745. struct iwl_host_cmd cmd = {
  746. .id = REPLY_TX_LINK_QUALITY_CMD,
  747. .len = sizeof(struct iwl_link_quality_cmd),
  748. .meta.flags = flags,
  749. .data = lq,
  750. };
  751. if ((lq->sta_id == 0xFF) &&
  752. (priv->iw_mode == NL80211_IFTYPE_ADHOC))
  753. return -EINVAL;
  754. if (lq->sta_id == 0xFF)
  755. lq->sta_id = IWL_AP_ID;
  756. iwl_dump_lq_cmd(priv, lq);
  757. if (iwl_is_associated(priv) && priv->assoc_station_added)
  758. return iwl_send_cmd(priv, &cmd);
  759. return 0;
  760. }
  761. EXPORT_SYMBOL(iwl_send_lq_cmd);
  762. /**
  763. * iwl_sta_init_lq - Initialize a station's hardware rate table
  764. *
  765. * The uCode's station table contains a table of fallback rates
  766. * for automatic fallback during transmission.
  767. *
  768. * NOTE: This sets up a default set of values. These will be replaced later
  769. * if the driver's iwl-agn-rs rate scaling algorithm is used, instead of
  770. * rc80211_simple.
  771. *
  772. * NOTE: Run REPLY_ADD_STA command to set up station table entry, before
  773. * calling this function (which runs REPLY_TX_LINK_QUALITY_CMD,
  774. * which requires station table entry to exist).
  775. */
  776. static void iwl_sta_init_lq(struct iwl_priv *priv, const u8 *addr, bool is_ap)
  777. {
  778. int i, r;
  779. struct iwl_link_quality_cmd link_cmd = {
  780. .reserved1 = 0,
  781. };
  782. u32 rate_flags;
  783. /* Set up the rate scaling to start at selected rate, fall back
  784. * all the way down to 1M in IEEE order, and then spin on 1M */
  785. if (is_ap)
  786. r = IWL_RATE_54M_INDEX;
  787. else if (priv->band == IEEE80211_BAND_5GHZ)
  788. r = IWL_RATE_6M_INDEX;
  789. else
  790. r = IWL_RATE_1M_INDEX;
  791. for (i = 0; i < LINK_QUAL_MAX_RETRY_NUM; i++) {
  792. rate_flags = 0;
  793. if (r >= IWL_FIRST_CCK_RATE && r <= IWL_LAST_CCK_RATE)
  794. rate_flags |= RATE_MCS_CCK_MSK;
  795. rate_flags |= first_antenna(priv->hw_params.valid_tx_ant) <<
  796. RATE_MCS_ANT_POS;
  797. link_cmd.rs_table[i].rate_n_flags =
  798. iwl_hw_set_rate_n_flags(iwl_rates[r].plcp, rate_flags);
  799. r = iwl_get_prev_ieee_rate(r);
  800. }
  801. link_cmd.general_params.single_stream_ant_msk =
  802. first_antenna(priv->hw_params.valid_tx_ant);
  803. link_cmd.general_params.dual_stream_ant_msk = 3;
  804. link_cmd.agg_params.agg_dis_start_th = LINK_QUAL_AGG_DISABLE_START_DEF;
  805. link_cmd.agg_params.agg_time_limit =
  806. cpu_to_le16(LINK_QUAL_AGG_TIME_LIMIT_DEF);
  807. /* Update the rate scaling for control frame Tx to AP */
  808. link_cmd.sta_id = is_ap ? IWL_AP_ID : priv->hw_params.bcast_sta_id;
  809. iwl_send_cmd_pdu_async(priv, REPLY_TX_LINK_QUALITY_CMD,
  810. sizeof(link_cmd), &link_cmd, NULL);
  811. }
  812. /**
  813. * iwl_rxon_add_station - add station into station table.
  814. *
  815. * there is only one AP station with id= IWL_AP_ID
  816. * NOTE: mutex must be held before calling this function
  817. */
  818. int iwl_rxon_add_station(struct iwl_priv *priv, const u8 *addr, bool is_ap)
  819. {
  820. struct ieee80211_sta *sta;
  821. struct ieee80211_sta_ht_cap ht_config;
  822. struct ieee80211_sta_ht_cap *cur_ht_config = NULL;
  823. u8 sta_id;
  824. /* Add station to device's station table */
  825. /*
  826. * XXX: This check is definitely not correct, if we're an AP
  827. * it'll always be false which is not what we want, but
  828. * it doesn't look like iwlagn is prepared to be an HT
  829. * AP anyway.
  830. */
  831. if (priv->current_ht_config.is_ht) {
  832. rcu_read_lock();
  833. sta = ieee80211_find_sta(priv->hw, addr);
  834. if (sta) {
  835. memcpy(&ht_config, &sta->ht_cap, sizeof(ht_config));
  836. cur_ht_config = &ht_config;
  837. }
  838. rcu_read_unlock();
  839. }
  840. sta_id = iwl_add_station(priv, addr, is_ap, CMD_SYNC, cur_ht_config);
  841. /* Set up default rate scaling table in device's station table */
  842. iwl_sta_init_lq(priv, addr, is_ap);
  843. return sta_id;
  844. }
  845. EXPORT_SYMBOL(iwl_rxon_add_station);
  846. /**
  847. * iwl_get_sta_id - Find station's index within station table
  848. *
  849. * If new IBSS station, create new entry in station table
  850. */
  851. int iwl_get_sta_id(struct iwl_priv *priv, struct ieee80211_hdr *hdr)
  852. {
  853. int sta_id;
  854. u16 fc = le16_to_cpu(hdr->frame_control);
  855. /* If this frame is broadcast or management, use broadcast station id */
  856. if (((fc & IEEE80211_FCTL_FTYPE) != IEEE80211_FTYPE_DATA) ||
  857. is_multicast_ether_addr(hdr->addr1))
  858. return priv->hw_params.bcast_sta_id;
  859. switch (priv->iw_mode) {
  860. /* If we are a client station in a BSS network, use the special
  861. * AP station entry (that's the only station we communicate with) */
  862. case NL80211_IFTYPE_STATION:
  863. return IWL_AP_ID;
  864. /* If we are an AP, then find the station, or use BCAST */
  865. case NL80211_IFTYPE_AP:
  866. sta_id = iwl_find_station(priv, hdr->addr1);
  867. if (sta_id != IWL_INVALID_STATION)
  868. return sta_id;
  869. return priv->hw_params.bcast_sta_id;
  870. /* If this frame is going out to an IBSS network, find the station,
  871. * or create a new station table entry */
  872. case NL80211_IFTYPE_ADHOC:
  873. sta_id = iwl_find_station(priv, hdr->addr1);
  874. if (sta_id != IWL_INVALID_STATION)
  875. return sta_id;
  876. /* Create new station table entry */
  877. sta_id = iwl_add_station(priv, hdr->addr1, false,
  878. CMD_ASYNC, NULL);
  879. if (sta_id != IWL_INVALID_STATION)
  880. return sta_id;
  881. IWL_DEBUG_DROP(priv, "Station %pM not in station map. "
  882. "Defaulting to broadcast...\n",
  883. hdr->addr1);
  884. iwl_print_hex_dump(priv, IWL_DL_DROP, (u8 *) hdr, sizeof(*hdr));
  885. return priv->hw_params.bcast_sta_id;
  886. default:
  887. IWL_WARN(priv, "Unknown mode of operation: %d\n",
  888. priv->iw_mode);
  889. return priv->hw_params.bcast_sta_id;
  890. }
  891. }
  892. EXPORT_SYMBOL(iwl_get_sta_id);
  893. /**
  894. * iwl_sta_tx_modify_enable_tid - Enable Tx for this TID in station table
  895. */
  896. void iwl_sta_tx_modify_enable_tid(struct iwl_priv *priv, int sta_id, int tid)
  897. {
  898. unsigned long flags;
  899. /* Remove "disable" flag, to enable Tx for this TID */
  900. spin_lock_irqsave(&priv->sta_lock, flags);
  901. priv->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_TID_DISABLE_TX;
  902. priv->stations[sta_id].sta.tid_disable_tx &= cpu_to_le16(~(1 << tid));
  903. priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK;
  904. spin_unlock_irqrestore(&priv->sta_lock, flags);
  905. iwl_send_add_sta(priv, &priv->stations[sta_id].sta, CMD_ASYNC);
  906. }
  907. EXPORT_SYMBOL(iwl_sta_tx_modify_enable_tid);
  908. int iwl_sta_rx_agg_start(struct iwl_priv *priv,
  909. const u8 *addr, int tid, u16 ssn)
  910. {
  911. unsigned long flags;
  912. int sta_id;
  913. sta_id = iwl_find_station(priv, addr);
  914. if (sta_id == IWL_INVALID_STATION)
  915. return -ENXIO;
  916. spin_lock_irqsave(&priv->sta_lock, flags);
  917. priv->stations[sta_id].sta.station_flags_msk = 0;
  918. priv->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_ADDBA_TID_MSK;
  919. priv->stations[sta_id].sta.add_immediate_ba_tid = (u8)tid;
  920. priv->stations[sta_id].sta.add_immediate_ba_ssn = cpu_to_le16(ssn);
  921. priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK;
  922. spin_unlock_irqrestore(&priv->sta_lock, flags);
  923. return iwl_send_add_sta(priv, &priv->stations[sta_id].sta,
  924. CMD_ASYNC);
  925. }
  926. EXPORT_SYMBOL(iwl_sta_rx_agg_start);
  927. int iwl_sta_rx_agg_stop(struct iwl_priv *priv, const u8 *addr, int tid)
  928. {
  929. unsigned long flags;
  930. int sta_id;
  931. sta_id = iwl_find_station(priv, addr);
  932. if (sta_id == IWL_INVALID_STATION) {
  933. IWL_ERR(priv, "Invalid station for AGG tid %d\n", tid);
  934. return -ENXIO;
  935. }
  936. spin_lock_irqsave(&priv->sta_lock, flags);
  937. priv->stations[sta_id].sta.station_flags_msk = 0;
  938. priv->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_DELBA_TID_MSK;
  939. priv->stations[sta_id].sta.remove_immediate_ba_tid = (u8)tid;
  940. priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK;
  941. spin_unlock_irqrestore(&priv->sta_lock, flags);
  942. return iwl_send_add_sta(priv, &priv->stations[sta_id].sta,
  943. CMD_ASYNC);
  944. }
  945. EXPORT_SYMBOL(iwl_sta_rx_agg_stop);
  946. static void iwl_sta_modify_ps_wake(struct iwl_priv *priv, int sta_id)
  947. {
  948. unsigned long flags;
  949. spin_lock_irqsave(&priv->sta_lock, flags);
  950. priv->stations[sta_id].sta.station_flags &= ~STA_FLG_PWR_SAVE_MSK;
  951. priv->stations[sta_id].sta.station_flags_msk = STA_FLG_PWR_SAVE_MSK;
  952. priv->stations[sta_id].sta.sta.modify_mask = 0;
  953. priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK;
  954. spin_unlock_irqrestore(&priv->sta_lock, flags);
  955. iwl_send_add_sta(priv, &priv->stations[sta_id].sta, CMD_ASYNC);
  956. }
  957. void iwl_update_ps_mode(struct iwl_priv *priv, u16 ps_bit, u8 *addr)
  958. {
  959. /* FIXME: need locking over ps_status ??? */
  960. u8 sta_id = iwl_find_station(priv, addr);
  961. if (sta_id != IWL_INVALID_STATION) {
  962. u8 sta_awake = priv->stations[sta_id].
  963. ps_status == STA_PS_STATUS_WAKE;
  964. if (sta_awake && ps_bit)
  965. priv->stations[sta_id].ps_status = STA_PS_STATUS_SLEEP;
  966. else if (!sta_awake && !ps_bit) {
  967. iwl_sta_modify_ps_wake(priv, sta_id);
  968. priv->stations[sta_id].ps_status = STA_PS_STATUS_WAKE;
  969. }
  970. }
  971. }