rt2x00config.c 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. /*
  2. Copyright (C) 2004 - 2007 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. /*
  22. * Set enviroment defines for rt2x00.h
  23. */
  24. #define DRV_NAME "rt2x00lib"
  25. #include <linux/kernel.h>
  26. #include <linux/module.h>
  27. #include "rt2x00.h"
  28. #include "rt2x00lib.h"
  29. /*
  30. * The MAC and BSSID addressess are simple array of bytes,
  31. * these arrays are little endian, so when sending the addressess
  32. * to the drivers, copy the it into a endian-signed variable.
  33. *
  34. * Note that all devices (except rt2500usb) have 32 bits
  35. * register word sizes. This means that whatever variable we
  36. * pass _must_ be a multiple of 32 bits. Otherwise the device
  37. * might not accept what we are sending to it.
  38. * This will also make it easier for the driver to write
  39. * the data to the device.
  40. *
  41. * Also note that when NULL is passed as address the
  42. * we will send 00:00:00:00:00 to the device to clear the address.
  43. * This will prevent the device being confused when it wants
  44. * to ACK frames or consideres itself associated.
  45. */
  46. void rt2x00lib_config_mac_addr(struct rt2x00_dev *rt2x00dev, u8 *mac)
  47. {
  48. __le32 reg[2];
  49. memset(&reg, 0, sizeof(reg));
  50. if (mac)
  51. memcpy(&reg, mac, ETH_ALEN);
  52. rt2x00dev->ops->lib->config_mac_addr(rt2x00dev, &reg[0]);
  53. }
  54. void rt2x00lib_config_bssid(struct rt2x00_dev *rt2x00dev, u8 *bssid)
  55. {
  56. __le32 reg[2];
  57. memset(&reg, 0, sizeof(reg));
  58. if (bssid)
  59. memcpy(&reg, bssid, ETH_ALEN);
  60. rt2x00dev->ops->lib->config_bssid(rt2x00dev, &reg[0]);
  61. }
  62. void rt2x00lib_config_type(struct rt2x00_dev *rt2x00dev, const int type)
  63. {
  64. int tsf_sync;
  65. switch (type) {
  66. case IEEE80211_IF_TYPE_IBSS:
  67. case IEEE80211_IF_TYPE_AP:
  68. tsf_sync = TSF_SYNC_BEACON;
  69. break;
  70. case IEEE80211_IF_TYPE_STA:
  71. tsf_sync = TSF_SYNC_INFRA;
  72. break;
  73. default:
  74. tsf_sync = TSF_SYNC_NONE;
  75. break;
  76. }
  77. rt2x00dev->ops->lib->config_type(rt2x00dev, type, tsf_sync);
  78. }
  79. void rt2x00lib_config(struct rt2x00_dev *rt2x00dev,
  80. struct ieee80211_conf *conf, const int force_config)
  81. {
  82. struct rt2x00lib_conf libconf;
  83. struct ieee80211_hw_mode *mode;
  84. struct ieee80211_rate *rate;
  85. int flags = 0;
  86. int short_slot_time;
  87. /*
  88. * In some situations we want to force all configurations
  89. * to be reloaded (When resuming for instance).
  90. */
  91. if (force_config) {
  92. flags = CONFIG_UPDATE_ALL;
  93. goto config;
  94. }
  95. /*
  96. * Check which configuration options have been
  97. * updated and should be send to the device.
  98. */
  99. if (rt2x00dev->rx_status.phymode != conf->phymode)
  100. flags |= CONFIG_UPDATE_PHYMODE;
  101. if (rt2x00dev->rx_status.channel != conf->channel)
  102. flags |= CONFIG_UPDATE_CHANNEL;
  103. if (rt2x00dev->tx_power != conf->power_level)
  104. flags |= CONFIG_UPDATE_TXPOWER;
  105. if (rt2x00dev->rx_status.antenna == conf->antenna_sel_rx)
  106. flags |= CONFIG_UPDATE_ANTENNA;
  107. /*
  108. * The following configuration options are never
  109. * stored anywhere and will always be updated.
  110. */
  111. flags |= CONFIG_UPDATE_SLOT_TIME;
  112. flags |= CONFIG_UPDATE_BEACON_INT;
  113. /*
  114. * We have determined what options should be updated,
  115. * now precalculate device configuration values depending
  116. * on what configuration options need to be updated.
  117. */
  118. config:
  119. memset(&libconf, 0, sizeof(libconf));
  120. if (flags & CONFIG_UPDATE_PHYMODE) {
  121. switch (conf->phymode) {
  122. case MODE_IEEE80211A:
  123. libconf.phymode = HWMODE_A;
  124. break;
  125. case MODE_IEEE80211B:
  126. libconf.phymode = HWMODE_B;
  127. break;
  128. case MODE_IEEE80211G:
  129. libconf.phymode = HWMODE_G;
  130. break;
  131. default:
  132. ERROR(rt2x00dev,
  133. "Attempt to configure unsupported mode (%d)"
  134. "Defaulting to 802.11b", conf->phymode);
  135. libconf.phymode = HWMODE_B;
  136. }
  137. mode = &rt2x00dev->hwmodes[libconf.phymode];
  138. rate = &mode->rates[mode->num_rates - 1];
  139. libconf.basic_rates =
  140. DEVICE_GET_RATE_FIELD(rate->val, RATEMASK) & DEV_BASIC_RATEMASK;
  141. }
  142. if (flags & CONFIG_UPDATE_CHANNEL) {
  143. memcpy(&libconf.rf,
  144. &rt2x00dev->spec.channels[conf->channel_val],
  145. sizeof(libconf.rf));
  146. }
  147. if (flags & CONFIG_UPDATE_SLOT_TIME) {
  148. short_slot_time = conf->flags & IEEE80211_CONF_SHORT_SLOT_TIME;
  149. libconf.slot_time =
  150. short_slot_time ? SHORT_SLOT_TIME : SLOT_TIME;
  151. libconf.sifs = SIFS;
  152. libconf.pifs = short_slot_time ? SHORT_PIFS : PIFS;
  153. libconf.difs = short_slot_time ? SHORT_DIFS : DIFS;
  154. libconf.eifs = EIFS;
  155. }
  156. libconf.conf = conf;
  157. /*
  158. * Start configuration.
  159. */
  160. rt2x00dev->ops->lib->config(rt2x00dev, flags, &libconf);
  161. /*
  162. * Some configuration changes affect the link quality
  163. * which means we need to reset the link tuner.
  164. */
  165. if (flags & (CONFIG_UPDATE_CHANNEL | CONFIG_UPDATE_ANTENNA))
  166. rt2x00lib_reset_link_tuner(rt2x00dev);
  167. rt2x00dev->curr_hwmode = libconf.phymode;
  168. rt2x00dev->rx_status.phymode = conf->phymode;
  169. rt2x00dev->rx_status.freq = conf->freq;
  170. rt2x00dev->rx_status.channel = conf->channel;
  171. rt2x00dev->tx_power = conf->power_level;
  172. rt2x00dev->rx_status.antenna = conf->antenna_sel_rx;
  173. }