iwl-sta.c 35 KB

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