rt2x00config.c 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. /*
  2. Copyright (C) 2004 - 2008 rt2x00 SourceForge Project
  3. <http://rt2x00.serialmonkey.com>
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; if not, write to the
  14. Free Software Foundation, Inc.,
  15. 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  16. */
  17. /*
  18. Module: rt2x00lib
  19. Abstract: rt2x00 generic configuration routines.
  20. */
  21. #include <linux/kernel.h>
  22. #include <linux/module.h>
  23. #include "rt2x00.h"
  24. #include "rt2x00lib.h"
  25. void rt2x00lib_config_intf(struct rt2x00_dev *rt2x00dev,
  26. struct rt2x00_intf *intf,
  27. enum nl80211_iftype type,
  28. u8 *mac, u8 *bssid)
  29. {
  30. struct rt2x00intf_conf conf;
  31. unsigned int flags = 0;
  32. conf.type = type;
  33. switch (type) {
  34. case NL80211_IFTYPE_ADHOC:
  35. case NL80211_IFTYPE_AP:
  36. conf.sync = TSF_SYNC_BEACON;
  37. break;
  38. case NL80211_IFTYPE_STATION:
  39. conf.sync = TSF_SYNC_INFRA;
  40. break;
  41. default:
  42. conf.sync = TSF_SYNC_NONE;
  43. break;
  44. }
  45. /*
  46. * Note that when NULL is passed as address we will send
  47. * 00:00:00:00:00 to the device to clear the address.
  48. * This will prevent the device being confused when it wants
  49. * to ACK frames or consideres itself associated.
  50. */
  51. memset(&conf.mac, 0, sizeof(conf.mac));
  52. if (mac)
  53. memcpy(&conf.mac, mac, ETH_ALEN);
  54. memset(&conf.bssid, 0, sizeof(conf.bssid));
  55. if (bssid)
  56. memcpy(&conf.bssid, bssid, ETH_ALEN);
  57. flags |= CONFIG_UPDATE_TYPE;
  58. if (mac || (!rt2x00dev->intf_ap_count && !rt2x00dev->intf_sta_count))
  59. flags |= CONFIG_UPDATE_MAC;
  60. if (bssid || (!rt2x00dev->intf_ap_count && !rt2x00dev->intf_sta_count))
  61. flags |= CONFIG_UPDATE_BSSID;
  62. rt2x00dev->ops->lib->config_intf(rt2x00dev, intf, &conf, flags);
  63. }
  64. void rt2x00lib_config_erp(struct rt2x00_dev *rt2x00dev,
  65. struct rt2x00_intf *intf,
  66. struct ieee80211_bss_conf *bss_conf)
  67. {
  68. struct rt2x00lib_erp erp;
  69. memset(&erp, 0, sizeof(erp));
  70. erp.short_preamble = bss_conf->use_short_preamble;
  71. erp.cts_protection = bss_conf->use_cts_prot;
  72. erp.slot_time = bss_conf->use_short_slot ? SHORT_SLOT_TIME : SLOT_TIME;
  73. erp.sifs = SIFS;
  74. erp.pifs = bss_conf->use_short_slot ? SHORT_PIFS : PIFS;
  75. erp.difs = bss_conf->use_short_slot ? SHORT_DIFS : DIFS;
  76. erp.eifs = bss_conf->use_short_slot ? SHORT_EIFS : EIFS;
  77. erp.ack_timeout = PLCP + erp.difs + get_duration(ACK_SIZE, 10);
  78. erp.ack_consume_time = SIFS + PLCP + get_duration(ACK_SIZE, 10);
  79. if (bss_conf->use_short_preamble) {
  80. erp.ack_timeout += SHORT_PREAMBLE;
  81. erp.ack_consume_time += SHORT_PREAMBLE;
  82. } else {
  83. erp.ack_timeout += PREAMBLE;
  84. erp.ack_consume_time += PREAMBLE;
  85. }
  86. erp.basic_rates = bss_conf->basic_rates;
  87. rt2x00dev->ops->lib->config_erp(rt2x00dev, &erp);
  88. }
  89. void rt2x00lib_config_antenna(struct rt2x00_dev *rt2x00dev,
  90. enum antenna rx, enum antenna tx)
  91. {
  92. struct antenna_setup ant;
  93. ant.rx = rx;
  94. ant.tx = tx;
  95. if (rx == rt2x00dev->link.ant.active.rx &&
  96. tx == rt2x00dev->link.ant.active.tx)
  97. return;
  98. /*
  99. * Antenna setup changes require the RX to be disabled,
  100. * else the changes will be ignored by the device.
  101. */
  102. if (test_bit(DEVICE_STATE_ENABLED_RADIO, &rt2x00dev->flags))
  103. rt2x00lib_toggle_rx(rt2x00dev, STATE_RADIO_RX_OFF_LINK);
  104. /*
  105. * Write new antenna setup to device and reset the link tuner.
  106. * The latter is required since we need to recalibrate the
  107. * noise-sensitivity ratio for the new setup.
  108. */
  109. rt2x00dev->ops->lib->config_ant(rt2x00dev, &ant);
  110. rt2x00lib_reset_link_tuner(rt2x00dev);
  111. rt2x00_reset_link_ant_rssi(&rt2x00dev->link);
  112. memcpy(&rt2x00dev->link.ant.active, &ant, sizeof(ant));
  113. if (test_bit(DEVICE_STATE_ENABLED_RADIO, &rt2x00dev->flags))
  114. rt2x00lib_toggle_rx(rt2x00dev, STATE_RADIO_RX_ON_LINK);
  115. }
  116. void rt2x00lib_config(struct rt2x00_dev *rt2x00dev,
  117. struct ieee80211_conf *conf,
  118. unsigned int ieee80211_flags)
  119. {
  120. struct rt2x00lib_conf libconf;
  121. memset(&libconf, 0, sizeof(libconf));
  122. libconf.conf = conf;
  123. if (ieee80211_flags & IEEE80211_CONF_CHANGE_CHANNEL) {
  124. memcpy(&libconf.rf,
  125. &rt2x00dev->spec.channels[conf->channel->hw_value],
  126. sizeof(libconf.rf));
  127. memcpy(&libconf.channel,
  128. &rt2x00dev->spec.channels_info[conf->channel->hw_value],
  129. sizeof(libconf.channel));
  130. }
  131. /*
  132. * Start configuration.
  133. */
  134. rt2x00dev->ops->lib->config(rt2x00dev, &libconf, ieee80211_flags);
  135. /*
  136. * Some configuration changes affect the link quality
  137. * which means we need to reset the link tuner.
  138. */
  139. if (ieee80211_flags & IEEE80211_CONF_CHANGE_CHANNEL)
  140. rt2x00lib_reset_link_tuner(rt2x00dev);
  141. rt2x00dev->curr_band = conf->channel->band;
  142. rt2x00dev->tx_power = conf->power_level;
  143. rt2x00dev->rx_status.band = conf->channel->band;
  144. rt2x00dev->rx_status.freq = conf->channel->center_freq;
  145. }