iwl-sta.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738
  1. /******************************************************************************
  2. *
  3. * Copyright(c) 2003 - 2008 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. * James P. Ketrenos <ipw2100-admin@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-eeprom.h"
  32. #include "iwl-dev.h"
  33. #include "iwl-core.h"
  34. #include "iwl-sta.h"
  35. #include "iwl-io.h"
  36. #include "iwl-helpers.h"
  37. u8 iwl_find_station(struct iwl_priv *priv, const u8 *addr)
  38. {
  39. int i;
  40. int start = 0;
  41. int ret = IWL_INVALID_STATION;
  42. unsigned long flags;
  43. DECLARE_MAC_BUF(mac);
  44. if ((priv->iw_mode == IEEE80211_IF_TYPE_IBSS) ||
  45. (priv->iw_mode == IEEE80211_IF_TYPE_AP))
  46. start = IWL_STA_ID;
  47. if (is_broadcast_ether_addr(addr))
  48. return priv->hw_params.bcast_sta_id;
  49. spin_lock_irqsave(&priv->sta_lock, flags);
  50. for (i = start; i < priv->hw_params.max_stations; i++)
  51. if (priv->stations[i].used &&
  52. (!compare_ether_addr(priv->stations[i].sta.sta.addr,
  53. addr))) {
  54. ret = i;
  55. goto out;
  56. }
  57. IWL_DEBUG_ASSOC_LIMIT("can not find STA %s total %d\n",
  58. print_mac(mac, addr), priv->num_stations);
  59. out:
  60. spin_unlock_irqrestore(&priv->sta_lock, flags);
  61. return ret;
  62. }
  63. EXPORT_SYMBOL(iwl_find_station);
  64. int iwl_send_add_sta(struct iwl_priv *priv,
  65. struct iwl_addsta_cmd *sta, u8 flags)
  66. {
  67. struct iwl_rx_packet *res = NULL;
  68. int ret = 0;
  69. u8 data[sizeof(*sta)];
  70. struct iwl_host_cmd cmd = {
  71. .id = REPLY_ADD_STA,
  72. .meta.flags = flags,
  73. .data = data,
  74. };
  75. if (!(flags & CMD_ASYNC))
  76. cmd.meta.flags |= CMD_WANT_SKB;
  77. cmd.len = priv->cfg->ops->utils->build_addsta_hcmd(sta, data);
  78. ret = iwl_send_cmd(priv, &cmd);
  79. if (ret || (flags & CMD_ASYNC))
  80. return ret;
  81. res = (struct iwl_rx_packet *)cmd.meta.u.skb->data;
  82. if (res->hdr.flags & IWL_CMD_FAILED_MSK) {
  83. IWL_ERROR("Bad return from REPLY_ADD_STA (0x%08X)\n",
  84. res->hdr.flags);
  85. ret = -EIO;
  86. }
  87. if (ret == 0) {
  88. switch (res->u.add_sta.status) {
  89. case ADD_STA_SUCCESS_MSK:
  90. IWL_DEBUG_INFO("REPLY_ADD_STA PASSED\n");
  91. break;
  92. default:
  93. ret = -EIO;
  94. IWL_WARNING("REPLY_ADD_STA failed\n");
  95. break;
  96. }
  97. }
  98. priv->alloc_rxb_skb--;
  99. dev_kfree_skb_any(cmd.meta.u.skb);
  100. return ret;
  101. }
  102. EXPORT_SYMBOL(iwl_send_add_sta);
  103. #ifdef CONFIG_IWL4965_HT
  104. static void iwl_set_ht_add_station(struct iwl_priv *priv, u8 index,
  105. struct ieee80211_ht_info *sta_ht_inf)
  106. {
  107. __le32 sta_flags;
  108. u8 mimo_ps_mode;
  109. if (!sta_ht_inf || !sta_ht_inf->ht_supported)
  110. goto done;
  111. mimo_ps_mode = (sta_ht_inf->cap & IEEE80211_HT_CAP_MIMO_PS) >> 2;
  112. sta_flags = priv->stations[index].sta.station_flags;
  113. sta_flags &= ~(STA_FLG_RTS_MIMO_PROT_MSK | STA_FLG_MIMO_DIS_MSK);
  114. switch (mimo_ps_mode) {
  115. case WLAN_HT_CAP_MIMO_PS_STATIC:
  116. sta_flags |= STA_FLG_MIMO_DIS_MSK;
  117. break;
  118. case WLAN_HT_CAP_MIMO_PS_DYNAMIC:
  119. sta_flags |= STA_FLG_RTS_MIMO_PROT_MSK;
  120. break;
  121. case WLAN_HT_CAP_MIMO_PS_DISABLED:
  122. break;
  123. default:
  124. IWL_WARNING("Invalid MIMO PS mode %d", mimo_ps_mode);
  125. break;
  126. }
  127. sta_flags |= cpu_to_le32(
  128. (u32)sta_ht_inf->ampdu_factor << STA_FLG_MAX_AGG_SIZE_POS);
  129. sta_flags |= cpu_to_le32(
  130. (u32)sta_ht_inf->ampdu_density << STA_FLG_AGG_MPDU_DENSITY_POS);
  131. if (iwl_is_fat_tx_allowed(priv, sta_ht_inf))
  132. sta_flags |= STA_FLG_FAT_EN_MSK;
  133. else
  134. sta_flags &= ~STA_FLG_FAT_EN_MSK;
  135. priv->stations[index].sta.station_flags = sta_flags;
  136. done:
  137. return;
  138. }
  139. #else
  140. static inline void iwl_set_ht_add_station(struct iwl_priv *priv, u8 index,
  141. struct ieee80211_ht_info *sta_ht_info)
  142. {
  143. }
  144. #endif
  145. /**
  146. * iwl_add_station_flags - Add station to tables in driver and device
  147. */
  148. u8 iwl_add_station_flags(struct iwl_priv *priv, const u8 *addr, int is_ap,
  149. u8 flags, struct ieee80211_ht_info *ht_info)
  150. {
  151. int i;
  152. int index = IWL_INVALID_STATION;
  153. struct iwl_station_entry *station;
  154. unsigned long flags_spin;
  155. DECLARE_MAC_BUF(mac);
  156. spin_lock_irqsave(&priv->sta_lock, flags_spin);
  157. if (is_ap)
  158. index = IWL_AP_ID;
  159. else if (is_broadcast_ether_addr(addr))
  160. index = priv->hw_params.bcast_sta_id;
  161. else
  162. for (i = IWL_STA_ID; i < priv->hw_params.max_stations; i++) {
  163. if (!compare_ether_addr(priv->stations[i].sta.sta.addr,
  164. addr)) {
  165. index = i;
  166. break;
  167. }
  168. if (!priv->stations[i].used &&
  169. index == IWL_INVALID_STATION)
  170. index = i;
  171. }
  172. /* These two conditions have the same outcome, but keep them separate
  173. since they have different meanings */
  174. if (unlikely(index == IWL_INVALID_STATION)) {
  175. spin_unlock_irqrestore(&priv->sta_lock, flags_spin);
  176. return index;
  177. }
  178. if (priv->stations[index].used &&
  179. !compare_ether_addr(priv->stations[index].sta.sta.addr, addr)) {
  180. spin_unlock_irqrestore(&priv->sta_lock, flags_spin);
  181. return index;
  182. }
  183. IWL_DEBUG_ASSOC("Add STA ID %d: %s\n", index, print_mac(mac, addr));
  184. station = &priv->stations[index];
  185. station->used = 1;
  186. priv->num_stations++;
  187. /* Set up the REPLY_ADD_STA command to send to device */
  188. memset(&station->sta, 0, sizeof(struct iwl_addsta_cmd));
  189. memcpy(station->sta.sta.addr, addr, ETH_ALEN);
  190. station->sta.mode = 0;
  191. station->sta.sta.sta_id = index;
  192. station->sta.station_flags = 0;
  193. /* BCAST station and IBSS stations do not work in HT mode */
  194. if (index != priv->hw_params.bcast_sta_id &&
  195. priv->iw_mode != IEEE80211_IF_TYPE_IBSS)
  196. iwl_set_ht_add_station(priv, index, ht_info);
  197. spin_unlock_irqrestore(&priv->sta_lock, flags_spin);
  198. /* Add station to device's station table */
  199. iwl_send_add_sta(priv, &station->sta, flags);
  200. return index;
  201. }
  202. EXPORT_SYMBOL(iwl_add_station_flags);
  203. int iwl_get_free_ucode_key_index(struct iwl_priv *priv)
  204. {
  205. int i;
  206. for (i = 0; i < STA_KEY_MAX_NUM; i++)
  207. if (!test_and_set_bit(i, &priv->ucode_key_table))
  208. return i;
  209. return -1;
  210. }
  211. int iwl_send_static_wepkey_cmd(struct iwl_priv *priv, u8 send_if_empty)
  212. {
  213. int i, not_empty = 0;
  214. u8 buff[sizeof(struct iwl_wep_cmd) +
  215. sizeof(struct iwl_wep_key) * WEP_KEYS_MAX];
  216. struct iwl_wep_cmd *wep_cmd = (struct iwl_wep_cmd *)buff;
  217. size_t cmd_size = sizeof(struct iwl_wep_cmd);
  218. struct iwl_host_cmd cmd = {
  219. .id = REPLY_WEPKEY,
  220. .data = wep_cmd,
  221. .meta.flags = CMD_ASYNC,
  222. };
  223. memset(wep_cmd, 0, cmd_size +
  224. (sizeof(struct iwl_wep_key) * WEP_KEYS_MAX));
  225. for (i = 0; i < WEP_KEYS_MAX ; i++) {
  226. wep_cmd->key[i].key_index = i;
  227. if (priv->wep_keys[i].key_size) {
  228. wep_cmd->key[i].key_offset = i;
  229. not_empty = 1;
  230. } else {
  231. wep_cmd->key[i].key_offset = WEP_INVALID_OFFSET;
  232. }
  233. wep_cmd->key[i].key_size = priv->wep_keys[i].key_size;
  234. memcpy(&wep_cmd->key[i].key[3], priv->wep_keys[i].key,
  235. priv->wep_keys[i].key_size);
  236. }
  237. wep_cmd->global_key_type = WEP_KEY_WEP_TYPE;
  238. wep_cmd->num_keys = WEP_KEYS_MAX;
  239. cmd_size += sizeof(struct iwl_wep_key) * WEP_KEYS_MAX;
  240. cmd.len = cmd_size;
  241. if (not_empty || send_if_empty)
  242. return iwl_send_cmd(priv, &cmd);
  243. else
  244. return 0;
  245. }
  246. EXPORT_SYMBOL(iwl_send_static_wepkey_cmd);
  247. int iwl_remove_default_wep_key(struct iwl_priv *priv,
  248. struct ieee80211_key_conf *keyconf)
  249. {
  250. int ret;
  251. unsigned long flags;
  252. spin_lock_irqsave(&priv->sta_lock, flags);
  253. if (!test_and_clear_bit(keyconf->keyidx, &priv->ucode_key_table))
  254. IWL_ERROR("index %d not used in uCode key table.\n",
  255. keyconf->keyidx);
  256. priv->default_wep_key--;
  257. memset(&priv->wep_keys[keyconf->keyidx], 0, sizeof(priv->wep_keys[0]));
  258. ret = iwl_send_static_wepkey_cmd(priv, 1);
  259. spin_unlock_irqrestore(&priv->sta_lock, flags);
  260. return ret;
  261. }
  262. EXPORT_SYMBOL(iwl_remove_default_wep_key);
  263. int iwl_set_default_wep_key(struct iwl_priv *priv,
  264. struct ieee80211_key_conf *keyconf)
  265. {
  266. int ret;
  267. unsigned long flags;
  268. keyconf->flags &= ~IEEE80211_KEY_FLAG_GENERATE_IV;
  269. keyconf->hw_key_idx = HW_KEY_DEFAULT;
  270. priv->stations[IWL_AP_ID].keyinfo.alg = ALG_WEP;
  271. spin_lock_irqsave(&priv->sta_lock, flags);
  272. priv->default_wep_key++;
  273. if (test_and_set_bit(keyconf->keyidx, &priv->ucode_key_table))
  274. IWL_ERROR("index %d already used in uCode key table.\n",
  275. keyconf->keyidx);
  276. priv->wep_keys[keyconf->keyidx].key_size = keyconf->keylen;
  277. memcpy(&priv->wep_keys[keyconf->keyidx].key, &keyconf->key,
  278. keyconf->keylen);
  279. ret = iwl_send_static_wepkey_cmd(priv, 0);
  280. spin_unlock_irqrestore(&priv->sta_lock, flags);
  281. return ret;
  282. }
  283. EXPORT_SYMBOL(iwl_set_default_wep_key);
  284. static int iwl_set_wep_dynamic_key_info(struct iwl_priv *priv,
  285. struct ieee80211_key_conf *keyconf,
  286. u8 sta_id)
  287. {
  288. unsigned long flags;
  289. __le16 key_flags = 0;
  290. int ret;
  291. keyconf->flags &= ~IEEE80211_KEY_FLAG_GENERATE_IV;
  292. key_flags |= (STA_KEY_FLG_WEP | STA_KEY_FLG_MAP_KEY_MSK);
  293. key_flags |= cpu_to_le16(keyconf->keyidx << STA_KEY_FLG_KEYID_POS);
  294. key_flags &= ~STA_KEY_FLG_INVALID;
  295. if (keyconf->keylen == WEP_KEY_LEN_128)
  296. key_flags |= STA_KEY_FLG_KEY_SIZE_MSK;
  297. if (sta_id == priv->hw_params.bcast_sta_id)
  298. key_flags |= STA_KEY_MULTICAST_MSK;
  299. spin_lock_irqsave(&priv->sta_lock, flags);
  300. priv->stations[sta_id].keyinfo.alg = keyconf->alg;
  301. priv->stations[sta_id].keyinfo.keylen = keyconf->keylen;
  302. priv->stations[sta_id].keyinfo.keyidx = keyconf->keyidx;
  303. memcpy(priv->stations[sta_id].keyinfo.key,
  304. keyconf->key, keyconf->keylen);
  305. memcpy(&priv->stations[sta_id].sta.key.key[3],
  306. keyconf->key, keyconf->keylen);
  307. if ((priv->stations[sta_id].sta.key.key_flags & STA_KEY_FLG_ENCRYPT_MSK)
  308. == STA_KEY_FLG_NO_ENC)
  309. priv->stations[sta_id].sta.key.key_offset =
  310. iwl_get_free_ucode_key_index(priv);
  311. /* else, we are overriding an existing key => no need to allocated room
  312. * in uCode. */
  313. priv->stations[sta_id].sta.key.key_flags = key_flags;
  314. priv->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_KEY_MASK;
  315. priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK;
  316. ret = iwl_send_add_sta(priv, &priv->stations[sta_id].sta, CMD_ASYNC);
  317. spin_unlock_irqrestore(&priv->sta_lock, flags);
  318. return ret;
  319. }
  320. static int iwl_set_ccmp_dynamic_key_info(struct iwl_priv *priv,
  321. struct ieee80211_key_conf *keyconf,
  322. u8 sta_id)
  323. {
  324. unsigned long flags;
  325. __le16 key_flags = 0;
  326. key_flags |= (STA_KEY_FLG_CCMP | STA_KEY_FLG_MAP_KEY_MSK);
  327. key_flags |= cpu_to_le16(keyconf->keyidx << STA_KEY_FLG_KEYID_POS);
  328. key_flags &= ~STA_KEY_FLG_INVALID;
  329. if (sta_id == priv->hw_params.bcast_sta_id)
  330. key_flags |= STA_KEY_MULTICAST_MSK;
  331. keyconf->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
  332. spin_lock_irqsave(&priv->sta_lock, flags);
  333. priv->stations[sta_id].keyinfo.alg = keyconf->alg;
  334. priv->stations[sta_id].keyinfo.keylen = keyconf->keylen;
  335. memcpy(priv->stations[sta_id].keyinfo.key, keyconf->key,
  336. keyconf->keylen);
  337. memcpy(priv->stations[sta_id].sta.key.key, keyconf->key,
  338. keyconf->keylen);
  339. if ((priv->stations[sta_id].sta.key.key_flags & STA_KEY_FLG_ENCRYPT_MSK)
  340. == STA_KEY_FLG_NO_ENC)
  341. priv->stations[sta_id].sta.key.key_offset =
  342. iwl_get_free_ucode_key_index(priv);
  343. /* else, we are overriding an existing key => no need to allocated room
  344. * in uCode. */
  345. priv->stations[sta_id].sta.key.key_flags = key_flags;
  346. priv->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_KEY_MASK;
  347. priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK;
  348. spin_unlock_irqrestore(&priv->sta_lock, flags);
  349. IWL_DEBUG_INFO("hwcrypto: modify ucode station key info\n");
  350. return iwl_send_add_sta(priv, &priv->stations[sta_id].sta, CMD_ASYNC);
  351. }
  352. static int iwl_set_tkip_dynamic_key_info(struct iwl_priv *priv,
  353. struct ieee80211_key_conf *keyconf,
  354. u8 sta_id)
  355. {
  356. unsigned long flags;
  357. int ret = 0;
  358. keyconf->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
  359. keyconf->flags |= IEEE80211_KEY_FLAG_GENERATE_MMIC;
  360. spin_lock_irqsave(&priv->sta_lock, flags);
  361. priv->stations[sta_id].keyinfo.alg = keyconf->alg;
  362. priv->stations[sta_id].keyinfo.keylen = 16;
  363. if ((priv->stations[sta_id].sta.key.key_flags & STA_KEY_FLG_ENCRYPT_MSK)
  364. == STA_KEY_FLG_NO_ENC)
  365. priv->stations[sta_id].sta.key.key_offset =
  366. iwl_get_free_ucode_key_index(priv);
  367. /* else, we are overriding an existing key => no need to allocated room
  368. * in uCode. */
  369. /* This copy is acutally not needed: we get the key with each TX */
  370. memcpy(priv->stations[sta_id].keyinfo.key, keyconf->key, 16);
  371. memcpy(priv->stations[sta_id].sta.key.key, keyconf->key, 16);
  372. spin_unlock_irqrestore(&priv->sta_lock, flags);
  373. return ret;
  374. }
  375. int iwl_remove_dynamic_key(struct iwl_priv *priv,
  376. struct ieee80211_key_conf *keyconf,
  377. u8 sta_id)
  378. {
  379. unsigned long flags;
  380. int ret = 0;
  381. u16 key_flags;
  382. u8 keyidx;
  383. priv->key_mapping_key--;
  384. spin_lock_irqsave(&priv->sta_lock, flags);
  385. key_flags = le16_to_cpu(priv->stations[sta_id].sta.key.key_flags);
  386. keyidx = (key_flags >> STA_KEY_FLG_KEYID_POS) & 0x3;
  387. if (keyconf->keyidx != keyidx) {
  388. /* We need to remove a key with index different that the one
  389. * in the uCode. This means that the key we need to remove has
  390. * been replaced by another one with different index.
  391. * Don't do anything and return ok
  392. */
  393. spin_unlock_irqrestore(&priv->sta_lock, flags);
  394. return 0;
  395. }
  396. if (!test_and_clear_bit(priv->stations[sta_id].sta.key.key_offset,
  397. &priv->ucode_key_table))
  398. IWL_ERROR("index %d not used in uCode key table.\n",
  399. priv->stations[sta_id].sta.key.key_offset);
  400. memset(&priv->stations[sta_id].keyinfo, 0,
  401. sizeof(struct iwl_hw_key));
  402. memset(&priv->stations[sta_id].sta.key, 0,
  403. sizeof(struct iwl4965_keyinfo));
  404. priv->stations[sta_id].sta.key.key_flags =
  405. STA_KEY_FLG_NO_ENC | STA_KEY_FLG_INVALID;
  406. priv->stations[sta_id].sta.key.key_offset = WEP_INVALID_OFFSET;
  407. priv->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_KEY_MASK;
  408. priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK;
  409. IWL_DEBUG_INFO("hwcrypto: clear ucode station key info\n");
  410. ret = iwl_send_add_sta(priv, &priv->stations[sta_id].sta, CMD_ASYNC);
  411. spin_unlock_irqrestore(&priv->sta_lock, flags);
  412. return ret;
  413. }
  414. EXPORT_SYMBOL(iwl_remove_dynamic_key);
  415. int iwl_set_dynamic_key(struct iwl_priv *priv,
  416. struct ieee80211_key_conf *keyconf, u8 sta_id)
  417. {
  418. int ret;
  419. priv->key_mapping_key++;
  420. keyconf->hw_key_idx = HW_KEY_DYNAMIC;
  421. switch (keyconf->alg) {
  422. case ALG_CCMP:
  423. ret = iwl_set_ccmp_dynamic_key_info(priv, keyconf, sta_id);
  424. break;
  425. case ALG_TKIP:
  426. ret = iwl_set_tkip_dynamic_key_info(priv, keyconf, sta_id);
  427. break;
  428. case ALG_WEP:
  429. ret = iwl_set_wep_dynamic_key_info(priv, keyconf, sta_id);
  430. break;
  431. default:
  432. IWL_ERROR("Unknown alg: %s alg = %d\n", __func__, keyconf->alg);
  433. ret = -EINVAL;
  434. }
  435. return ret;
  436. }
  437. EXPORT_SYMBOL(iwl_set_dynamic_key);
  438. #ifdef CONFIG_IWLWIFI_DEBUG
  439. static void iwl_dump_lq_cmd(struct iwl_priv *priv,
  440. struct iwl_link_quality_cmd *lq)
  441. {
  442. int i;
  443. IWL_DEBUG_RATE("lq station id 0x%x\n", lq->sta_id);
  444. IWL_DEBUG_RATE("lq dta 0x%X 0x%X\n",
  445. lq->general_params.single_stream_ant_msk,
  446. lq->general_params.dual_stream_ant_msk);
  447. for (i = 0; i < LINK_QUAL_MAX_RETRY_NUM; i++)
  448. IWL_DEBUG_RATE("lq index %d 0x%X\n",
  449. i, lq->rs_table[i].rate_n_flags);
  450. }
  451. #else
  452. static inline void iwl_dump_lq_cmd(struct iwl_priv *priv,
  453. struct iwl_link_quality_cmd *lq)
  454. {
  455. }
  456. #endif
  457. int iwl_send_lq_cmd(struct iwl_priv *priv,
  458. struct iwl_link_quality_cmd *lq, u8 flags)
  459. {
  460. struct iwl_host_cmd cmd = {
  461. .id = REPLY_TX_LINK_QUALITY_CMD,
  462. .len = sizeof(struct iwl_link_quality_cmd),
  463. .meta.flags = flags,
  464. .data = lq,
  465. };
  466. if ((lq->sta_id == 0xFF) &&
  467. (priv->iw_mode == IEEE80211_IF_TYPE_IBSS))
  468. return -EINVAL;
  469. if (lq->sta_id == 0xFF)
  470. lq->sta_id = IWL_AP_ID;
  471. iwl_dump_lq_cmd(priv,lq);
  472. if (iwl_is_associated(priv) && priv->assoc_station_added &&
  473. priv->lq_mngr.lq_ready)
  474. return iwl_send_cmd(priv, &cmd);
  475. return 0;
  476. }
  477. EXPORT_SYMBOL(iwl_send_lq_cmd);
  478. /**
  479. * iwl_sta_init_lq - Initialize a station's hardware rate table
  480. *
  481. * The uCode's station table contains a table of fallback rates
  482. * for automatic fallback during transmission.
  483. *
  484. * NOTE: This sets up a default set of values. These will be replaced later
  485. * if the driver's iwl-4965-rs rate scaling algorithm is used, instead of
  486. * rc80211_simple.
  487. *
  488. * NOTE: Run REPLY_ADD_STA command to set up station table entry, before
  489. * calling this function (which runs REPLY_TX_LINK_QUALITY_CMD,
  490. * which requires station table entry to exist).
  491. */
  492. static void iwl_sta_init_lq(struct iwl_priv *priv, const u8 *addr, int is_ap)
  493. {
  494. int i, r;
  495. struct iwl_link_quality_cmd link_cmd = {
  496. .reserved1 = 0,
  497. };
  498. u16 rate_flags;
  499. /* Set up the rate scaling to start at selected rate, fall back
  500. * all the way down to 1M in IEEE order, and then spin on 1M */
  501. if (is_ap)
  502. r = IWL_RATE_54M_INDEX;
  503. else if (priv->band == IEEE80211_BAND_5GHZ)
  504. r = IWL_RATE_6M_INDEX;
  505. else
  506. r = IWL_RATE_1M_INDEX;
  507. for (i = 0; i < LINK_QUAL_MAX_RETRY_NUM; i++) {
  508. rate_flags = 0;
  509. if (r >= IWL_FIRST_CCK_RATE && r <= IWL_LAST_CCK_RATE)
  510. rate_flags |= RATE_MCS_CCK_MSK;
  511. /* Use Tx antenna B only */
  512. rate_flags |= RATE_MCS_ANT_B_MSK; /*FIXME:RS*/
  513. link_cmd.rs_table[i].rate_n_flags =
  514. iwl4965_hw_set_rate_n_flags(iwl_rates[r].plcp, rate_flags);
  515. r = iwl4965_get_prev_ieee_rate(r);
  516. }
  517. link_cmd.general_params.single_stream_ant_msk = 2;
  518. link_cmd.general_params.dual_stream_ant_msk = 3;
  519. link_cmd.agg_params.agg_dis_start_th = 3;
  520. link_cmd.agg_params.agg_time_limit = cpu_to_le16(4000);
  521. /* Update the rate scaling for control frame Tx to AP */
  522. link_cmd.sta_id = is_ap ? IWL_AP_ID : priv->hw_params.bcast_sta_id;
  523. iwl_send_cmd_pdu_async(priv, REPLY_TX_LINK_QUALITY_CMD,
  524. sizeof(link_cmd), &link_cmd, NULL);
  525. }
  526. /**
  527. * iwl_rxon_add_station - add station into station table.
  528. *
  529. * there is only one AP station with id= IWL_AP_ID
  530. * NOTE: mutex must be held before calling this fnction
  531. */
  532. int iwl_rxon_add_station(struct iwl_priv *priv, const u8 *addr, int is_ap)
  533. {
  534. u8 sta_id;
  535. /* Add station to device's station table */
  536. #ifdef CONFIG_IWL4965_HT
  537. struct ieee80211_conf *conf = &priv->hw->conf;
  538. struct ieee80211_ht_info *cur_ht_config = &conf->ht_conf;
  539. if ((is_ap) &&
  540. (conf->flags & IEEE80211_CONF_SUPPORT_HT_MODE) &&
  541. (priv->iw_mode == IEEE80211_IF_TYPE_STA))
  542. sta_id = iwl_add_station_flags(priv, addr, is_ap,
  543. 0, cur_ht_config);
  544. else
  545. #endif /* CONFIG_IWL4965_HT */
  546. sta_id = iwl_add_station_flags(priv, addr, is_ap,
  547. 0, NULL);
  548. /* Set up default rate scaling table in device's station table */
  549. iwl_sta_init_lq(priv, addr, is_ap);
  550. return sta_id;
  551. }
  552. EXPORT_SYMBOL(iwl_rxon_add_station);
  553. /**
  554. * iwl_get_sta_id - Find station's index within station table
  555. *
  556. * If new IBSS station, create new entry in station table
  557. */
  558. int iwl_get_sta_id(struct iwl_priv *priv, struct ieee80211_hdr *hdr)
  559. {
  560. int sta_id;
  561. u16 fc = le16_to_cpu(hdr->frame_control);
  562. DECLARE_MAC_BUF(mac);
  563. /* If this frame is broadcast or management, use broadcast station id */
  564. if (((fc & IEEE80211_FCTL_FTYPE) != IEEE80211_FTYPE_DATA) ||
  565. is_multicast_ether_addr(hdr->addr1))
  566. return priv->hw_params.bcast_sta_id;
  567. switch (priv->iw_mode) {
  568. /* If we are a client station in a BSS network, use the special
  569. * AP station entry (that's the only station we communicate with) */
  570. case IEEE80211_IF_TYPE_STA:
  571. return IWL_AP_ID;
  572. /* If we are an AP, then find the station, or use BCAST */
  573. case IEEE80211_IF_TYPE_AP:
  574. sta_id = iwl_find_station(priv, hdr->addr1);
  575. if (sta_id != IWL_INVALID_STATION)
  576. return sta_id;
  577. return priv->hw_params.bcast_sta_id;
  578. /* If this frame is going out to an IBSS network, find the station,
  579. * or create a new station table entry */
  580. case IEEE80211_IF_TYPE_IBSS:
  581. sta_id = iwl_find_station(priv, hdr->addr1);
  582. if (sta_id != IWL_INVALID_STATION)
  583. return sta_id;
  584. /* Create new station table entry */
  585. sta_id = iwl_add_station_flags(priv, hdr->addr1,
  586. 0, CMD_ASYNC, NULL);
  587. if (sta_id != IWL_INVALID_STATION)
  588. return sta_id;
  589. IWL_DEBUG_DROP("Station %s not in station map. "
  590. "Defaulting to broadcast...\n",
  591. print_mac(mac, hdr->addr1));
  592. iwl_print_hex_dump(priv, IWL_DL_DROP, (u8 *) hdr, sizeof(*hdr));
  593. return priv->hw_params.bcast_sta_id;
  594. default:
  595. IWL_WARNING("Unknown mode of operation: %d", priv->iw_mode);
  596. return priv->hw_params.bcast_sta_id;
  597. }
  598. }
  599. EXPORT_SYMBOL(iwl_get_sta_id);