iwl-sta.c 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245
  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 void iwl_add_sta_callback(struct iwl_priv *priv,
  85. struct iwl_device_cmd *cmd,
  86. struct iwl_rx_packet *pkt)
  87. {
  88. struct iwl_addsta_cmd *addsta =
  89. (struct iwl_addsta_cmd *)cmd->cmd.payload;
  90. u8 sta_id = addsta->sta.sta_id;
  91. if (pkt->hdr.flags & IWL_CMD_FAILED_MSK) {
  92. IWL_ERR(priv, "Bad return from REPLY_ADD_STA (0x%08X)\n",
  93. pkt->hdr.flags);
  94. return;
  95. }
  96. switch (pkt->u.add_sta.status) {
  97. case ADD_STA_SUCCESS_MSK:
  98. iwl_sta_ucode_activate(priv, sta_id);
  99. /* fall through */
  100. default:
  101. IWL_DEBUG_HC(priv, "Received REPLY_ADD_STA:(0x%08X)\n",
  102. pkt->u.add_sta.status);
  103. break;
  104. }
  105. }
  106. int iwl_send_add_sta(struct iwl_priv *priv,
  107. struct iwl_addsta_cmd *sta, u8 flags)
  108. {
  109. struct iwl_rx_packet *pkt = NULL;
  110. int ret = 0;
  111. u8 data[sizeof(*sta)];
  112. struct iwl_host_cmd cmd = {
  113. .id = REPLY_ADD_STA,
  114. .flags = flags,
  115. .data = data,
  116. };
  117. if (flags & CMD_ASYNC)
  118. cmd.callback = iwl_add_sta_callback;
  119. else
  120. cmd.flags |= CMD_WANT_SKB;
  121. cmd.len = priv->cfg->ops->utils->build_addsta_hcmd(sta, data);
  122. ret = iwl_send_cmd(priv, &cmd);
  123. if (ret || (flags & CMD_ASYNC))
  124. return ret;
  125. pkt = (struct iwl_rx_packet *)cmd.reply_page;
  126. if (pkt->hdr.flags & IWL_CMD_FAILED_MSK) {
  127. IWL_ERR(priv, "Bad return from REPLY_ADD_STA (0x%08X)\n",
  128. pkt->hdr.flags);
  129. ret = -EIO;
  130. }
  131. if (ret == 0) {
  132. switch (pkt->u.add_sta.status) {
  133. case ADD_STA_SUCCESS_MSK:
  134. iwl_sta_ucode_activate(priv, sta->sta.sta_id);
  135. IWL_DEBUG_INFO(priv, "REPLY_ADD_STA PASSED\n");
  136. break;
  137. default:
  138. ret = -EIO;
  139. IWL_WARN(priv, "REPLY_ADD_STA failed\n");
  140. break;
  141. }
  142. }
  143. iwl_free_pages(priv, cmd.reply_page);
  144. return ret;
  145. }
  146. EXPORT_SYMBOL(iwl_send_add_sta);
  147. static void iwl_set_ht_add_station(struct iwl_priv *priv, u8 index,
  148. struct ieee80211_sta_ht_cap *sta_ht_inf)
  149. {
  150. __le32 sta_flags;
  151. u8 mimo_ps_mode;
  152. if (!sta_ht_inf || !sta_ht_inf->ht_supported)
  153. goto done;
  154. mimo_ps_mode = (sta_ht_inf->cap & IEEE80211_HT_CAP_SM_PS) >> 2;
  155. IWL_DEBUG_ASSOC(priv, "spatial multiplexing power save mode: %s\n",
  156. (mimo_ps_mode == WLAN_HT_CAP_SM_PS_STATIC) ?
  157. "static" :
  158. (mimo_ps_mode == WLAN_HT_CAP_SM_PS_DYNAMIC) ?
  159. "dynamic" : "disabled");
  160. sta_flags = priv->stations[index].sta.station_flags;
  161. sta_flags &= ~(STA_FLG_RTS_MIMO_PROT_MSK | STA_FLG_MIMO_DIS_MSK);
  162. switch (mimo_ps_mode) {
  163. case WLAN_HT_CAP_SM_PS_STATIC:
  164. sta_flags |= STA_FLG_MIMO_DIS_MSK;
  165. break;
  166. case WLAN_HT_CAP_SM_PS_DYNAMIC:
  167. sta_flags |= STA_FLG_RTS_MIMO_PROT_MSK;
  168. break;
  169. case WLAN_HT_CAP_SM_PS_DISABLED:
  170. break;
  171. default:
  172. IWL_WARN(priv, "Invalid MIMO PS mode %d\n", mimo_ps_mode);
  173. break;
  174. }
  175. sta_flags |= cpu_to_le32(
  176. (u32)sta_ht_inf->ampdu_factor << STA_FLG_MAX_AGG_SIZE_POS);
  177. sta_flags |= cpu_to_le32(
  178. (u32)sta_ht_inf->ampdu_density << STA_FLG_AGG_MPDU_DENSITY_POS);
  179. if (iwl_is_ht40_tx_allowed(priv, sta_ht_inf))
  180. sta_flags |= STA_FLG_HT40_EN_MSK;
  181. else
  182. sta_flags &= ~STA_FLG_HT40_EN_MSK;
  183. priv->stations[index].sta.station_flags = sta_flags;
  184. done:
  185. return;
  186. }
  187. /**
  188. * iwl_add_station - Add station to tables in driver and device
  189. */
  190. u8 iwl_add_station(struct iwl_priv *priv, const u8 *addr, bool is_ap, u8 flags,
  191. struct ieee80211_sta_ht_cap *ht_info)
  192. {
  193. struct iwl_station_entry *station;
  194. unsigned long flags_spin;
  195. int i;
  196. int sta_id = IWL_INVALID_STATION;
  197. u16 rate;
  198. spin_lock_irqsave(&priv->sta_lock, flags_spin);
  199. if (is_ap)
  200. sta_id = IWL_AP_ID;
  201. else if (is_broadcast_ether_addr(addr))
  202. sta_id = priv->hw_params.bcast_sta_id;
  203. else
  204. for (i = IWL_STA_ID; i < priv->hw_params.max_stations; i++) {
  205. if (!compare_ether_addr(priv->stations[i].sta.sta.addr,
  206. addr)) {
  207. sta_id = i;
  208. break;
  209. }
  210. if (!priv->stations[i].used &&
  211. sta_id == IWL_INVALID_STATION)
  212. sta_id = i;
  213. }
  214. /* These two conditions have the same outcome, but keep them separate
  215. since they have different meanings */
  216. if (unlikely(sta_id == IWL_INVALID_STATION)) {
  217. spin_unlock_irqrestore(&priv->sta_lock, flags_spin);
  218. return sta_id;
  219. }
  220. if (priv->stations[sta_id].used &&
  221. !compare_ether_addr(priv->stations[sta_id].sta.sta.addr, addr)) {
  222. spin_unlock_irqrestore(&priv->sta_lock, flags_spin);
  223. return sta_id;
  224. }
  225. station = &priv->stations[sta_id];
  226. station->used = IWL_STA_DRIVER_ACTIVE;
  227. IWL_DEBUG_ASSOC(priv, "Add STA to driver ID %d: %pM\n",
  228. sta_id, addr);
  229. priv->num_stations++;
  230. /* Set up the REPLY_ADD_STA command to send to device */
  231. memset(&station->sta, 0, sizeof(struct iwl_addsta_cmd));
  232. memcpy(station->sta.sta.addr, addr, ETH_ALEN);
  233. station->sta.mode = 0;
  234. station->sta.sta.sta_id = sta_id;
  235. station->sta.station_flags = 0;
  236. /* BCAST station and IBSS stations do not work in HT mode */
  237. if (sta_id != priv->hw_params.bcast_sta_id &&
  238. priv->iw_mode != NL80211_IFTYPE_ADHOC)
  239. iwl_set_ht_add_station(priv, sta_id, ht_info);
  240. /* 3945 only */
  241. rate = (priv->band == IEEE80211_BAND_5GHZ) ?
  242. IWL_RATE_6M_PLCP : IWL_RATE_1M_PLCP;
  243. /* Turn on both antennas for the station... */
  244. station->sta.rate_n_flags = cpu_to_le16(rate | RATE_MCS_ANT_AB_MSK);
  245. spin_unlock_irqrestore(&priv->sta_lock, flags_spin);
  246. /* Add station to device's station table */
  247. iwl_send_add_sta(priv, &station->sta, flags);
  248. return sta_id;
  249. }
  250. EXPORT_SYMBOL(iwl_add_station);
  251. static void iwl_sta_ucode_deactivate(struct iwl_priv *priv, const char *addr)
  252. {
  253. unsigned long flags;
  254. u8 sta_id = iwl_find_station(priv, addr);
  255. BUG_ON(sta_id == IWL_INVALID_STATION);
  256. IWL_DEBUG_ASSOC(priv, "Removed STA from Ucode: %pM\n", addr);
  257. spin_lock_irqsave(&priv->sta_lock, flags);
  258. /* Ucode must be active and driver must be non active */
  259. if (priv->stations[sta_id].used != IWL_STA_UCODE_ACTIVE)
  260. IWL_ERR(priv, "removed non active STA %d\n", sta_id);
  261. priv->stations[sta_id].used &= ~IWL_STA_UCODE_ACTIVE;
  262. memset(&priv->stations[sta_id], 0, sizeof(struct iwl_station_entry));
  263. spin_unlock_irqrestore(&priv->sta_lock, flags);
  264. }
  265. static void iwl_remove_sta_callback(struct iwl_priv *priv,
  266. struct iwl_device_cmd *cmd,
  267. struct iwl_rx_packet *pkt)
  268. {
  269. struct iwl_rem_sta_cmd *rm_sta =
  270. (struct iwl_rem_sta_cmd *)cmd->cmd.payload;
  271. const char *addr = rm_sta->addr;
  272. if (pkt->hdr.flags & IWL_CMD_FAILED_MSK) {
  273. IWL_ERR(priv, "Bad return from REPLY_REMOVE_STA (0x%08X)\n",
  274. pkt->hdr.flags);
  275. return;
  276. }
  277. switch (pkt->u.rem_sta.status) {
  278. case REM_STA_SUCCESS_MSK:
  279. iwl_sta_ucode_deactivate(priv, addr);
  280. break;
  281. default:
  282. IWL_ERR(priv, "REPLY_REMOVE_STA failed\n");
  283. break;
  284. }
  285. }
  286. static int iwl_send_remove_station(struct iwl_priv *priv, const u8 *addr,
  287. u8 flags)
  288. {
  289. struct iwl_rx_packet *pkt;
  290. int ret;
  291. struct iwl_rem_sta_cmd rm_sta_cmd;
  292. struct iwl_host_cmd cmd = {
  293. .id = REPLY_REMOVE_STA,
  294. .len = sizeof(struct iwl_rem_sta_cmd),
  295. .flags = flags,
  296. .data = &rm_sta_cmd,
  297. };
  298. memset(&rm_sta_cmd, 0, sizeof(rm_sta_cmd));
  299. rm_sta_cmd.num_sta = 1;
  300. memcpy(&rm_sta_cmd.addr, addr , ETH_ALEN);
  301. if (flags & CMD_ASYNC)
  302. cmd.callback = iwl_remove_sta_callback;
  303. else
  304. cmd.flags |= CMD_WANT_SKB;
  305. ret = iwl_send_cmd(priv, &cmd);
  306. if (ret || (flags & CMD_ASYNC))
  307. return ret;
  308. pkt = (struct iwl_rx_packet *)cmd.reply_page;
  309. if (pkt->hdr.flags & IWL_CMD_FAILED_MSK) {
  310. IWL_ERR(priv, "Bad return from REPLY_REMOVE_STA (0x%08X)\n",
  311. pkt->hdr.flags);
  312. ret = -EIO;
  313. }
  314. if (!ret) {
  315. switch (pkt->u.rem_sta.status) {
  316. case REM_STA_SUCCESS_MSK:
  317. iwl_sta_ucode_deactivate(priv, addr);
  318. IWL_DEBUG_ASSOC(priv, "REPLY_REMOVE_STA PASSED\n");
  319. break;
  320. default:
  321. ret = -EIO;
  322. IWL_ERR(priv, "REPLY_REMOVE_STA failed\n");
  323. break;
  324. }
  325. }
  326. iwl_free_pages(priv, cmd.reply_page);
  327. return ret;
  328. }
  329. /**
  330. * iwl_remove_station - Remove driver's knowledge of station.
  331. */
  332. int iwl_remove_station(struct iwl_priv *priv, const u8 *addr, bool is_ap)
  333. {
  334. int sta_id = IWL_INVALID_STATION;
  335. int i, ret = -EINVAL;
  336. unsigned long flags;
  337. spin_lock_irqsave(&priv->sta_lock, flags);
  338. if (is_ap)
  339. sta_id = IWL_AP_ID;
  340. else if (is_broadcast_ether_addr(addr))
  341. sta_id = priv->hw_params.bcast_sta_id;
  342. else
  343. for (i = IWL_STA_ID; i < priv->hw_params.max_stations; i++)
  344. if (priv->stations[i].used &&
  345. !compare_ether_addr(priv->stations[i].sta.sta.addr,
  346. addr)) {
  347. sta_id = i;
  348. break;
  349. }
  350. if (unlikely(sta_id == IWL_INVALID_STATION))
  351. goto out;
  352. IWL_DEBUG_ASSOC(priv, "Removing STA from driver:%d %pM\n",
  353. sta_id, addr);
  354. if (!(priv->stations[sta_id].used & IWL_STA_DRIVER_ACTIVE)) {
  355. IWL_ERR(priv, "Removing %pM but non DRIVER active\n",
  356. addr);
  357. goto out;
  358. }
  359. if (!(priv->stations[sta_id].used & IWL_STA_UCODE_ACTIVE)) {
  360. IWL_ERR(priv, "Removing %pM but non UCODE active\n",
  361. addr);
  362. goto out;
  363. }
  364. priv->stations[sta_id].used &= ~IWL_STA_DRIVER_ACTIVE;
  365. priv->num_stations--;
  366. BUG_ON(priv->num_stations < 0);
  367. spin_unlock_irqrestore(&priv->sta_lock, flags);
  368. ret = iwl_send_remove_station(priv, addr, CMD_ASYNC);
  369. return ret;
  370. out:
  371. spin_unlock_irqrestore(&priv->sta_lock, flags);
  372. return ret;
  373. }
  374. /**
  375. * iwl_clear_stations_table - Clear the driver's station table
  376. *
  377. * NOTE: This does not clear or otherwise alter the device's station table.
  378. */
  379. void iwl_clear_stations_table(struct iwl_priv *priv)
  380. {
  381. unsigned long flags;
  382. int i;
  383. spin_lock_irqsave(&priv->sta_lock, flags);
  384. if (iwl_is_alive(priv) &&
  385. !test_bit(STATUS_EXIT_PENDING, &priv->status) &&
  386. iwl_send_cmd_pdu_async(priv, REPLY_REMOVE_ALL_STA, 0, NULL, NULL))
  387. IWL_ERR(priv, "Couldn't clear the station table\n");
  388. priv->num_stations = 0;
  389. memset(priv->stations, 0, sizeof(priv->stations));
  390. /* clean ucode key table bit map */
  391. priv->ucode_key_table = 0;
  392. /* keep track of static keys */
  393. for (i = 0; i < WEP_KEYS_MAX ; i++) {
  394. if (priv->wep_keys[i].key_size)
  395. set_bit(i, &priv->ucode_key_table);
  396. }
  397. spin_unlock_irqrestore(&priv->sta_lock, flags);
  398. }
  399. EXPORT_SYMBOL(iwl_clear_stations_table);
  400. int iwl_get_free_ucode_key_index(struct iwl_priv *priv)
  401. {
  402. int i;
  403. for (i = 0; i < STA_KEY_MAX_NUM; i++)
  404. if (!test_and_set_bit(i, &priv->ucode_key_table))
  405. return i;
  406. return WEP_INVALID_OFFSET;
  407. }
  408. EXPORT_SYMBOL(iwl_get_free_ucode_key_index);
  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. .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. IWL_DEBUG_WEP(priv, "Removing default WEP key: idx=%d\n",
  452. keyconf->keyidx);
  453. if (!test_and_clear_bit(keyconf->keyidx, &priv->ucode_key_table))
  454. IWL_ERR(priv, "index %d not used in uCode key table.\n",
  455. keyconf->keyidx);
  456. priv->default_wep_key--;
  457. memset(&priv->wep_keys[keyconf->keyidx], 0, sizeof(priv->wep_keys[0]));
  458. if (iwl_is_rfkill(priv)) {
  459. IWL_DEBUG_WEP(priv, "Not sending REPLY_WEPKEY command due to RFKILL.\n");
  460. spin_unlock_irqrestore(&priv->sta_lock, flags);
  461. return 0;
  462. }
  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. if (iwl_is_rfkill(priv)) {
  675. IWL_DEBUG_WEP(priv, "Not sending REPLY_ADD_STA command because RFKILL enabled. \n");
  676. spin_unlock_irqrestore(&priv->sta_lock, flags);
  677. return 0;
  678. }
  679. ret = iwl_send_add_sta(priv, &priv->stations[sta_id].sta, CMD_ASYNC);
  680. spin_unlock_irqrestore(&priv->sta_lock, flags);
  681. return ret;
  682. }
  683. EXPORT_SYMBOL(iwl_remove_dynamic_key);
  684. int iwl_set_dynamic_key(struct iwl_priv *priv,
  685. struct ieee80211_key_conf *keyconf, u8 sta_id)
  686. {
  687. int ret;
  688. priv->key_mapping_key++;
  689. keyconf->hw_key_idx = HW_KEY_DYNAMIC;
  690. switch (keyconf->alg) {
  691. case ALG_CCMP:
  692. ret = iwl_set_ccmp_dynamic_key_info(priv, keyconf, sta_id);
  693. break;
  694. case ALG_TKIP:
  695. ret = iwl_set_tkip_dynamic_key_info(priv, keyconf, sta_id);
  696. break;
  697. case ALG_WEP:
  698. ret = iwl_set_wep_dynamic_key_info(priv, keyconf, sta_id);
  699. break;
  700. default:
  701. IWL_ERR(priv,
  702. "Unknown alg: %s alg = %d\n", __func__, keyconf->alg);
  703. ret = -EINVAL;
  704. }
  705. IWL_DEBUG_WEP(priv, "Set dynamic key: alg= %d len=%d idx=%d sta=%d ret=%d\n",
  706. keyconf->alg, keyconf->keylen, keyconf->keyidx,
  707. sta_id, ret);
  708. return ret;
  709. }
  710. EXPORT_SYMBOL(iwl_set_dynamic_key);
  711. #ifdef CONFIG_IWLWIFI_DEBUG
  712. static void iwl_dump_lq_cmd(struct iwl_priv *priv,
  713. struct iwl_link_quality_cmd *lq)
  714. {
  715. int i;
  716. IWL_DEBUG_RATE(priv, "lq station id 0x%x\n", lq->sta_id);
  717. IWL_DEBUG_RATE(priv, "lq ant 0x%X 0x%X\n",
  718. lq->general_params.single_stream_ant_msk,
  719. lq->general_params.dual_stream_ant_msk);
  720. for (i = 0; i < LINK_QUAL_MAX_RETRY_NUM; i++)
  721. IWL_DEBUG_RATE(priv, "lq index %d 0x%X\n",
  722. i, lq->rs_table[i].rate_n_flags);
  723. }
  724. #else
  725. static inline void iwl_dump_lq_cmd(struct iwl_priv *priv,
  726. struct iwl_link_quality_cmd *lq)
  727. {
  728. }
  729. #endif
  730. int iwl_send_lq_cmd(struct iwl_priv *priv,
  731. struct iwl_link_quality_cmd *lq, u8 flags)
  732. {
  733. struct iwl_host_cmd cmd = {
  734. .id = REPLY_TX_LINK_QUALITY_CMD,
  735. .len = sizeof(struct iwl_link_quality_cmd),
  736. .flags = flags,
  737. .data = lq,
  738. };
  739. if ((lq->sta_id == 0xFF) &&
  740. (priv->iw_mode == NL80211_IFTYPE_ADHOC))
  741. return -EINVAL;
  742. if (lq->sta_id == 0xFF)
  743. lq->sta_id = IWL_AP_ID;
  744. iwl_dump_lq_cmd(priv, lq);
  745. if (iwl_is_associated(priv) && priv->assoc_station_added)
  746. return iwl_send_cmd(priv, &cmd);
  747. return 0;
  748. }
  749. EXPORT_SYMBOL(iwl_send_lq_cmd);
  750. /**
  751. * iwl_sta_init_lq - Initialize a station's hardware rate table
  752. *
  753. * The uCode's station table contains a table of fallback rates
  754. * for automatic fallback during transmission.
  755. *
  756. * NOTE: This sets up a default set of values. These will be replaced later
  757. * if the driver's iwl-agn-rs rate scaling algorithm is used, instead of
  758. * rc80211_simple.
  759. *
  760. * NOTE: Run REPLY_ADD_STA command to set up station table entry, before
  761. * calling this function (which runs REPLY_TX_LINK_QUALITY_CMD,
  762. * which requires station table entry to exist).
  763. */
  764. static void iwl_sta_init_lq(struct iwl_priv *priv, const u8 *addr, bool is_ap)
  765. {
  766. int i, r;
  767. struct iwl_link_quality_cmd link_cmd = {
  768. .reserved1 = 0,
  769. };
  770. u32 rate_flags;
  771. /* Set up the rate scaling to start at selected rate, fall back
  772. * all the way down to 1M in IEEE order, and then spin on 1M */
  773. if (is_ap)
  774. r = IWL_RATE_54M_INDEX;
  775. else if (priv->band == IEEE80211_BAND_5GHZ)
  776. r = IWL_RATE_6M_INDEX;
  777. else
  778. r = IWL_RATE_1M_INDEX;
  779. for (i = 0; i < LINK_QUAL_MAX_RETRY_NUM; i++) {
  780. rate_flags = 0;
  781. if (r >= IWL_FIRST_CCK_RATE && r <= IWL_LAST_CCK_RATE)
  782. rate_flags |= RATE_MCS_CCK_MSK;
  783. rate_flags |= first_antenna(priv->hw_params.valid_tx_ant) <<
  784. RATE_MCS_ANT_POS;
  785. link_cmd.rs_table[i].rate_n_flags =
  786. iwl_hw_set_rate_n_flags(iwl_rates[r].plcp, rate_flags);
  787. r = iwl_get_prev_ieee_rate(r);
  788. }
  789. link_cmd.general_params.single_stream_ant_msk =
  790. first_antenna(priv->hw_params.valid_tx_ant);
  791. link_cmd.general_params.dual_stream_ant_msk = 3;
  792. link_cmd.agg_params.agg_dis_start_th = LINK_QUAL_AGG_DISABLE_START_DEF;
  793. link_cmd.agg_params.agg_time_limit =
  794. cpu_to_le16(LINK_QUAL_AGG_TIME_LIMIT_DEF);
  795. /* Update the rate scaling for control frame Tx to AP */
  796. link_cmd.sta_id = is_ap ? IWL_AP_ID : priv->hw_params.bcast_sta_id;
  797. iwl_send_cmd_pdu_async(priv, REPLY_TX_LINK_QUALITY_CMD,
  798. sizeof(link_cmd), &link_cmd, NULL);
  799. }
  800. /**
  801. * iwl_rxon_add_station - add station into station table.
  802. *
  803. * there is only one AP station with id= IWL_AP_ID
  804. * NOTE: mutex must be held before calling this function
  805. */
  806. int iwl_rxon_add_station(struct iwl_priv *priv, const u8 *addr, bool is_ap)
  807. {
  808. struct ieee80211_sta *sta;
  809. struct ieee80211_sta_ht_cap ht_config;
  810. struct ieee80211_sta_ht_cap *cur_ht_config = NULL;
  811. u8 sta_id;
  812. /* Add station to device's station table */
  813. /*
  814. * XXX: This check is definitely not correct, if we're an AP
  815. * it'll always be false which is not what we want, but
  816. * it doesn't look like iwlagn is prepared to be an HT
  817. * AP anyway.
  818. */
  819. if (priv->current_ht_config.is_ht) {
  820. rcu_read_lock();
  821. sta = ieee80211_find_sta(priv->vif, addr);
  822. if (sta) {
  823. memcpy(&ht_config, &sta->ht_cap, sizeof(ht_config));
  824. cur_ht_config = &ht_config;
  825. }
  826. rcu_read_unlock();
  827. }
  828. sta_id = iwl_add_station(priv, addr, is_ap, CMD_SYNC, cur_ht_config);
  829. /* Set up default rate scaling table in device's station table */
  830. iwl_sta_init_lq(priv, addr, is_ap);
  831. return sta_id;
  832. }
  833. EXPORT_SYMBOL(iwl_rxon_add_station);
  834. /**
  835. * iwl_sta_init_bcast_lq - Initialize a bcast station's hardware rate table
  836. *
  837. * NOTE: Run REPLY_ADD_STA command to set up station table entry, before
  838. * calling this function (which runs REPLY_TX_LINK_QUALITY_CMD,
  839. * which requires station table entry to exist).
  840. */
  841. static void iwl_sta_init_bcast_lq(struct iwl_priv *priv)
  842. {
  843. int i, r;
  844. struct iwl_link_quality_cmd link_cmd = {
  845. .reserved1 = 0,
  846. };
  847. u32 rate_flags;
  848. /* Set up the rate scaling to start at selected rate, fall back
  849. * all the way down to 1M in IEEE order, and then spin on 1M */
  850. if (priv->band == IEEE80211_BAND_5GHZ)
  851. r = IWL_RATE_6M_INDEX;
  852. else
  853. r = IWL_RATE_1M_INDEX;
  854. for (i = 0; i < LINK_QUAL_MAX_RETRY_NUM; i++) {
  855. rate_flags = 0;
  856. if (r >= IWL_FIRST_CCK_RATE && r <= IWL_LAST_CCK_RATE)
  857. rate_flags |= RATE_MCS_CCK_MSK;
  858. rate_flags |= first_antenna(priv->hw_params.valid_tx_ant) <<
  859. RATE_MCS_ANT_POS;
  860. link_cmd.rs_table[i].rate_n_flags =
  861. iwl_hw_set_rate_n_flags(iwl_rates[r].plcp, rate_flags);
  862. r = iwl_get_prev_ieee_rate(r);
  863. }
  864. link_cmd.general_params.single_stream_ant_msk =
  865. first_antenna(priv->hw_params.valid_tx_ant);
  866. link_cmd.general_params.dual_stream_ant_msk = 3;
  867. link_cmd.agg_params.agg_dis_start_th = LINK_QUAL_AGG_DISABLE_START_DEF;
  868. link_cmd.agg_params.agg_time_limit =
  869. cpu_to_le16(LINK_QUAL_AGG_TIME_LIMIT_DEF);
  870. /* Update the rate scaling for control frame Tx to AP */
  871. link_cmd.sta_id = priv->hw_params.bcast_sta_id;
  872. iwl_send_cmd_pdu_async(priv, REPLY_TX_LINK_QUALITY_CMD,
  873. sizeof(link_cmd), &link_cmd, NULL);
  874. }
  875. /**
  876. * iwl_add_bcast_station - add broadcast station into station table.
  877. */
  878. void iwl_add_bcast_station(struct iwl_priv *priv)
  879. {
  880. iwl_add_station(priv, iwl_bcast_addr, false, CMD_SYNC, NULL);
  881. /* Set up default rate scaling table in device's station table */
  882. iwl_sta_init_bcast_lq(priv);
  883. }
  884. EXPORT_SYMBOL(iwl_add_bcast_station);
  885. /**
  886. * iwl_get_sta_id - Find station's index within station table
  887. *
  888. * If new IBSS station, create new entry in station table
  889. */
  890. int iwl_get_sta_id(struct iwl_priv *priv, struct ieee80211_hdr *hdr)
  891. {
  892. int sta_id;
  893. __le16 fc = hdr->frame_control;
  894. /* If this frame is broadcast or management, use broadcast station id */
  895. if (!ieee80211_is_data(fc) || is_multicast_ether_addr(hdr->addr1))
  896. return priv->hw_params.bcast_sta_id;
  897. switch (priv->iw_mode) {
  898. /* If we are a client station in a BSS network, use the special
  899. * AP station entry (that's the only station we communicate with) */
  900. case NL80211_IFTYPE_STATION:
  901. return IWL_AP_ID;
  902. /* If we are an AP, then find the station, or use BCAST */
  903. case NL80211_IFTYPE_AP:
  904. sta_id = iwl_find_station(priv, hdr->addr1);
  905. if (sta_id != IWL_INVALID_STATION)
  906. return sta_id;
  907. return priv->hw_params.bcast_sta_id;
  908. /* If this frame is going out to an IBSS network, find the station,
  909. * or create a new station table entry */
  910. case NL80211_IFTYPE_ADHOC:
  911. sta_id = iwl_find_station(priv, hdr->addr1);
  912. if (sta_id != IWL_INVALID_STATION)
  913. return sta_id;
  914. /* Create new station table entry */
  915. sta_id = iwl_add_station(priv, hdr->addr1, false,
  916. CMD_ASYNC, NULL);
  917. if (sta_id != IWL_INVALID_STATION)
  918. return sta_id;
  919. IWL_DEBUG_DROP(priv, "Station %pM not in station map. "
  920. "Defaulting to broadcast...\n",
  921. hdr->addr1);
  922. iwl_print_hex_dump(priv, IWL_DL_DROP, (u8 *) hdr, sizeof(*hdr));
  923. return priv->hw_params.bcast_sta_id;
  924. default:
  925. IWL_WARN(priv, "Unknown mode of operation: %d\n",
  926. priv->iw_mode);
  927. return priv->hw_params.bcast_sta_id;
  928. }
  929. }
  930. EXPORT_SYMBOL(iwl_get_sta_id);
  931. /**
  932. * iwl_sta_tx_modify_enable_tid - Enable Tx for this TID in station table
  933. */
  934. void iwl_sta_tx_modify_enable_tid(struct iwl_priv *priv, int sta_id, int tid)
  935. {
  936. unsigned long flags;
  937. /* Remove "disable" flag, to enable Tx for this TID */
  938. spin_lock_irqsave(&priv->sta_lock, flags);
  939. priv->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_TID_DISABLE_TX;
  940. priv->stations[sta_id].sta.tid_disable_tx &= cpu_to_le16(~(1 << tid));
  941. priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK;
  942. spin_unlock_irqrestore(&priv->sta_lock, flags);
  943. iwl_send_add_sta(priv, &priv->stations[sta_id].sta, CMD_ASYNC);
  944. }
  945. EXPORT_SYMBOL(iwl_sta_tx_modify_enable_tid);
  946. int iwl_sta_rx_agg_start(struct iwl_priv *priv,
  947. const u8 *addr, int tid, u16 ssn)
  948. {
  949. unsigned long flags;
  950. int sta_id;
  951. sta_id = iwl_find_station(priv, addr);
  952. if (sta_id == IWL_INVALID_STATION)
  953. return -ENXIO;
  954. spin_lock_irqsave(&priv->sta_lock, flags);
  955. priv->stations[sta_id].sta.station_flags_msk = 0;
  956. priv->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_ADDBA_TID_MSK;
  957. priv->stations[sta_id].sta.add_immediate_ba_tid = (u8)tid;
  958. priv->stations[sta_id].sta.add_immediate_ba_ssn = cpu_to_le16(ssn);
  959. priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK;
  960. spin_unlock_irqrestore(&priv->sta_lock, flags);
  961. return iwl_send_add_sta(priv, &priv->stations[sta_id].sta,
  962. CMD_ASYNC);
  963. }
  964. EXPORT_SYMBOL(iwl_sta_rx_agg_start);
  965. int iwl_sta_rx_agg_stop(struct iwl_priv *priv, const u8 *addr, int tid)
  966. {
  967. unsigned long flags;
  968. int sta_id;
  969. sta_id = iwl_find_station(priv, addr);
  970. if (sta_id == IWL_INVALID_STATION) {
  971. IWL_ERR(priv, "Invalid station for AGG tid %d\n", tid);
  972. return -ENXIO;
  973. }
  974. spin_lock_irqsave(&priv->sta_lock, flags);
  975. priv->stations[sta_id].sta.station_flags_msk = 0;
  976. priv->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_DELBA_TID_MSK;
  977. priv->stations[sta_id].sta.remove_immediate_ba_tid = (u8)tid;
  978. priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK;
  979. spin_unlock_irqrestore(&priv->sta_lock, flags);
  980. return iwl_send_add_sta(priv, &priv->stations[sta_id].sta,
  981. CMD_ASYNC);
  982. }
  983. EXPORT_SYMBOL(iwl_sta_rx_agg_stop);
  984. void iwl_sta_modify_ps_wake(struct iwl_priv *priv, int sta_id)
  985. {
  986. unsigned long flags;
  987. spin_lock_irqsave(&priv->sta_lock, flags);
  988. priv->stations[sta_id].sta.station_flags &= ~STA_FLG_PWR_SAVE_MSK;
  989. priv->stations[sta_id].sta.station_flags_msk = STA_FLG_PWR_SAVE_MSK;
  990. priv->stations[sta_id].sta.sta.modify_mask = 0;
  991. priv->stations[sta_id].sta.sleep_tx_count = 0;
  992. priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK;
  993. spin_unlock_irqrestore(&priv->sta_lock, flags);
  994. iwl_send_add_sta(priv, &priv->stations[sta_id].sta, CMD_ASYNC);
  995. }
  996. EXPORT_SYMBOL(iwl_sta_modify_ps_wake);
  997. void iwl_sta_modify_sleep_tx_count(struct iwl_priv *priv, int sta_id, int cnt)
  998. {
  999. unsigned long flags;
  1000. spin_lock_irqsave(&priv->sta_lock, flags);
  1001. priv->stations[sta_id].sta.station_flags |= STA_FLG_PWR_SAVE_MSK;
  1002. priv->stations[sta_id].sta.station_flags_msk = STA_FLG_PWR_SAVE_MSK;
  1003. priv->stations[sta_id].sta.sta.modify_mask =
  1004. STA_MODIFY_SLEEP_TX_COUNT_MSK;
  1005. priv->stations[sta_id].sta.sleep_tx_count = cpu_to_le16(cnt);
  1006. priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK;
  1007. spin_unlock_irqrestore(&priv->sta_lock, flags);
  1008. iwl_send_add_sta(priv, &priv->stations[sta_id].sta, CMD_ASYNC);
  1009. }