aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/net/wireless/rt2x00/rt2x00config.c
blob: de890a17d8fd4beee713ea26da92aed15b3b7a10 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
/*
	Copyright (C) 2004 - 2007 rt2x00 SourceForge Project
	<http://rt2x00.serialmonkey.com>

	This program is free software; you can redistribute it and/or modify
	it under the terms of the GNU General Public License as published by
	the Free Software Foundation; either version 2 of the License, or
	(at your option) any later version.

	This program is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
	GNU General Public License for more details.

	You should have received a copy of the GNU General Public License
	along with this program; if not, write to the
	Free Software Foundation, Inc.,
	59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 */

/*
	Module: rt2x00lib
	Abstract: rt2x00 generic configuration routines.
 */

/*
 * Set enviroment defines for rt2x00.h
 */
#define DRV_NAME "rt2x00lib"

#include <linux/kernel.h>
#include <linux/module.h>

#include "rt2x00.h"
#include "rt2x00lib.h"

void rt2x00lib_config_mac_addr(struct rt2x00_dev *rt2x00dev, u8 *mac)
{
	if (mac)
		rt2x00dev->ops->lib->config_mac_addr(rt2x00dev, mac);
}

void rt2x00lib_config_bssid(struct rt2x00_dev *rt2x00dev, u8 *bssid)
{
	if (bssid)
		rt2x00dev->ops->lib->config_bssid(rt2x00dev, bssid);
}

void rt2x00lib_config_packet_filter(struct rt2x00_dev *rt2x00dev, int filter)
{
	/*
	 * Only configure the device when something has changed,
	 * or if we are in RESUME state in which case all configuration
	 * will be forced upon the device.
	 */
	if (!test_bit(INTERFACE_RESUME, &rt2x00dev->flags) &&
	    !test_bit(PACKET_FILTER_PENDING, &rt2x00dev->flags))
		return;

	/*
	 * Write configuration to device and clear the update flag.
	 */
	rt2x00dev->ops->lib->config_packet_filter(rt2x00dev, filter);
	__clear_bit(PACKET_FILTER_PENDING, &rt2x00dev->flags);
}

void rt2x00lib_config_type(struct rt2x00_dev *rt2x00dev, int type)
{
	struct interface *intf = &rt2x00dev->interface;

	/*
	 * Fallback when a invalid interface is attempted to
	 * be configured. If a monitor interface is present,
	 * we are going configure that, otherwise exit.
	 */
	if (type == INVALID_INTERFACE) {
		if (is_monitor_present(intf))
			type = IEEE80211_IF_TYPE_MNTR;
		else
			return;
	}

	/*
	 * Only configure the device when something has changed,
	 * or if we are in RESUME state in which case all configuration
	 * will be forced upon the device.
	 */
	if (!test_bit(INTERFACE_RESUME, &rt2x00dev->flags) &&
	    (!(is_interface_present(intf) ^
	       test_bit(INTERFACE_ENABLED, &rt2x00dev->flags)) &&
	     !(is_monitor_present(intf) ^
	       test_bit(INTERFACE_ENABLED_MONITOR, &rt2x00dev->flags))))
		return;

	/*
	 * Configure device.
	 */
	rt2x00dev->ops->lib->config_type(rt2x00dev, type);

	/*
	 * Update the configuration flags.
	 */
	if (type != IEEE80211_IF_TYPE_MNTR) {
		if (is_interface_present(intf))
			__set_bit(INTERFACE_ENABLED, &rt2x00dev->flags);
		else
			__clear_bit(INTERFACE_ENABLED, &rt2x00dev->flags);
	} else {
		if (is_monitor_present(intf))
			__set_bit(INTERFACE_ENABLED_MONITOR, &rt2x00dev->flags);
		else
			__clear_bit(INTERFACE_ENABLED_MONITOR,
				    &rt2x00dev->flags);
	}
}

void rt2x00lib_config(struct rt2x00_dev *rt2x00dev, struct ieee80211_conf *conf)
{
	int flags = 0;

	/*
	 * If we are in RESUME state we should
	 * force all configuration options.
	 */
	if (test_bit(INTERFACE_RESUME, &rt2x00dev->flags)) {
		flags = CONFIG_UPDATE_ALL;
		goto config;
	}

	/*
	 * Check which configuration options have been
	 * updated and should be send to the device.
	 */
	if (rt2x00dev->rx_status.phymode != conf->phymode)
		flags |= CONFIG_UPDATE_PHYMODE;
	if (rt2x00dev->rx_status.channel != conf->channel)
		flags |= CONFIG_UPDATE_CHANNEL;
	if (rt2x00dev->tx_power != conf->power_level)
		flags |= CONFIG_UPDATE_TXPOWER;
	if (rt2x00dev->rx_status.antenna == conf->antenna_sel_rx)
		flags |= CONFIG_UPDATE_ANTENNA;

	/*
	 * The following configuration options are never
	 * stored anywhere and will always be updated.
	 */
	flags |= CONFIG_UPDATE_SLOT_TIME;
	flags |= CONFIG_UPDATE_BEACON_INT;

config:
	rt2x00dev->ops->lib->config(rt2x00dev, flags, conf);

	/*
	 * Some configuration changes affect the link quality
	 * which means we need to reset the link tuner.
	 */
	if (flags & (CONFIG_UPDATE_CHANNEL | CONFIG_UPDATE_ANTENNA))
		rt2x00lib_reset_link_tuner(rt2x00dev);

	rt2x00dev->rx_status.phymode = conf->phymode;
	rt2x00dev->rx_status.freq = conf->freq;
	rt2x00dev->rx_status.channel = conf->channel;
	rt2x00dev->tx_power = conf->power_level;
	rt2x00dev->rx_status.antenna = conf->antenna_sel_rx;
}