Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 1 | /* |
| 2 | Copyright (C) 2004 - 2007 rt2x00 SourceForge Project |
| 3 | <http://rt2x00.serialmonkey.com> |
| 4 | |
| 5 | This program is free software; you can redistribute it and/or modify |
| 6 | it under the terms of the GNU General Public License as published by |
| 7 | the Free Software Foundation; either version 2 of the License, or |
| 8 | (at your option) any later version. |
| 9 | |
| 10 | This program is distributed in the hope that it will be useful, |
| 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | GNU General Public License for more details. |
| 14 | |
| 15 | You should have received a copy of the GNU General Public License |
| 16 | along with this program; if not, write to the |
| 17 | Free Software Foundation, Inc., |
| 18 | 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
| 19 | */ |
| 20 | |
| 21 | /* |
| 22 | Module: rt2x00lib |
| 23 | Abstract: rt2x00 generic configuration routines. |
| 24 | */ |
| 25 | |
| 26 | /* |
| 27 | * Set enviroment defines for rt2x00.h |
| 28 | */ |
| 29 | #define DRV_NAME "rt2x00lib" |
| 30 | |
| 31 | #include <linux/kernel.h> |
| 32 | #include <linux/module.h> |
| 33 | |
| 34 | #include "rt2x00.h" |
| 35 | #include "rt2x00lib.h" |
| 36 | |
Ivo van Doorn | 4abee4b | 2007-10-06 14:11:46 +0200 | [diff] [blame^] | 37 | |
| 38 | /* |
| 39 | * The MAC and BSSID addressess are simple array of bytes, |
| 40 | * these arrays are little endian, so when sending the addressess |
| 41 | * to the drivers, copy the it into a endian-signed variable. |
| 42 | * |
| 43 | * Note that all devices (except rt2500usb) have 32 bits |
| 44 | * register word sizes. This means that whatever variable we |
| 45 | * pass _must_ be a multiple of 32 bits. Otherwise the device |
| 46 | * might not accept what we are sending to it. |
| 47 | * This will also make it easier for the driver to write |
| 48 | * the data to the device. |
| 49 | * |
| 50 | * Also note that when NULL is passed as address the |
| 51 | * we will send 00:00:00:00:00 to the device to clear the address. |
| 52 | * This will prevent the device being confused when it wants |
| 53 | * to ACK frames or consideres itself associated. |
| 54 | */ |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 55 | void rt2x00lib_config_mac_addr(struct rt2x00_dev *rt2x00dev, u8 *mac) |
| 56 | { |
Ivo van Doorn | 4abee4b | 2007-10-06 14:11:46 +0200 | [diff] [blame^] | 57 | __le32 reg[2]; |
| 58 | |
| 59 | memset(®, 0, sizeof(reg)); |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 60 | if (mac) |
Ivo van Doorn | 4abee4b | 2007-10-06 14:11:46 +0200 | [diff] [blame^] | 61 | memcpy(®, mac, ETH_ALEN); |
| 62 | |
| 63 | rt2x00dev->ops->lib->config_mac_addr(rt2x00dev, ®[0]); |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 64 | } |
| 65 | |
| 66 | void rt2x00lib_config_bssid(struct rt2x00_dev *rt2x00dev, u8 *bssid) |
| 67 | { |
Ivo van Doorn | 4abee4b | 2007-10-06 14:11:46 +0200 | [diff] [blame^] | 68 | __le32 reg[2]; |
| 69 | |
| 70 | memset(®, 0, sizeof(reg)); |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 71 | if (bssid) |
Ivo van Doorn | 4abee4b | 2007-10-06 14:11:46 +0200 | [diff] [blame^] | 72 | memcpy(®, bssid, ETH_ALEN); |
| 73 | |
| 74 | rt2x00dev->ops->lib->config_bssid(rt2x00dev, ®[0]); |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 75 | } |
| 76 | |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 77 | void rt2x00lib_config_type(struct rt2x00_dev *rt2x00dev, int type) |
| 78 | { |
Ivo van Doorn | 066cb63 | 2007-09-25 20:55:39 +0200 | [diff] [blame] | 79 | if (type != INVALID_INTERFACE) |
| 80 | rt2x00dev->ops->lib->config_type(rt2x00dev, type); |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 81 | } |
| 82 | |
Ivo van Doorn | 066cb63 | 2007-09-25 20:55:39 +0200 | [diff] [blame] | 83 | void rt2x00lib_config(struct rt2x00_dev *rt2x00dev, |
| 84 | struct ieee80211_conf *conf, const int force_config) |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 85 | { |
| 86 | int flags = 0; |
| 87 | |
| 88 | /* |
Ivo van Doorn | 066cb63 | 2007-09-25 20:55:39 +0200 | [diff] [blame] | 89 | * In some situations we want to force all configurations |
| 90 | * to be reloaded (When resuming for instance). |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 91 | */ |
Ivo van Doorn | 066cb63 | 2007-09-25 20:55:39 +0200 | [diff] [blame] | 92 | if (force_config) { |
Ivo van Doorn | 95ea362 | 2007-09-25 17:57:13 -0700 | [diff] [blame] | 93 | flags = CONFIG_UPDATE_ALL; |
| 94 | goto config; |
| 95 | } |
| 96 | |
| 97 | /* |
| 98 | * Check which configuration options have been |
| 99 | * updated and should be send to the device. |
| 100 | */ |
| 101 | if (rt2x00dev->rx_status.phymode != conf->phymode) |
| 102 | flags |= CONFIG_UPDATE_PHYMODE; |
| 103 | if (rt2x00dev->rx_status.channel != conf->channel) |
| 104 | flags |= CONFIG_UPDATE_CHANNEL; |
| 105 | if (rt2x00dev->tx_power != conf->power_level) |
| 106 | flags |= CONFIG_UPDATE_TXPOWER; |
| 107 | if (rt2x00dev->rx_status.antenna == conf->antenna_sel_rx) |
| 108 | flags |= CONFIG_UPDATE_ANTENNA; |
| 109 | |
| 110 | /* |
| 111 | * The following configuration options are never |
| 112 | * stored anywhere and will always be updated. |
| 113 | */ |
| 114 | flags |= CONFIG_UPDATE_SLOT_TIME; |
| 115 | flags |= CONFIG_UPDATE_BEACON_INT; |
| 116 | |
| 117 | config: |
| 118 | rt2x00dev->ops->lib->config(rt2x00dev, flags, conf); |
| 119 | |
| 120 | /* |
| 121 | * Some configuration changes affect the link quality |
| 122 | * which means we need to reset the link tuner. |
| 123 | */ |
| 124 | if (flags & (CONFIG_UPDATE_CHANNEL | CONFIG_UPDATE_ANTENNA)) |
| 125 | rt2x00lib_reset_link_tuner(rt2x00dev); |
| 126 | |
| 127 | rt2x00dev->rx_status.phymode = conf->phymode; |
| 128 | rt2x00dev->rx_status.freq = conf->freq; |
| 129 | rt2x00dev->rx_status.channel = conf->channel; |
| 130 | rt2x00dev->tx_power = conf->power_level; |
| 131 | rt2x00dev->rx_status.antenna = conf->antenna_sel_rx; |
| 132 | } |