iwl-sta.c 33 KB

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