3 Broadcom B43 wireless driver
7 Copyright (c) 2006 Michael Buesch <mb@bu3sch.de>
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program; see the file COPYING. If not, write to
21 the Free Software Foundation, Inc., 51 Franklin Steet, Fifth Floor,
22 Boston, MA 02110-1301, USA.
26 #include <linux/capability.h>
34 #define GENERIC_FILESIZE 64
36 static int get_integer(const char *buf, size_t count)
38 char tmp[10 + 1] = { 0 };
43 count = min(count, (size_t) 10);
44 memcpy(tmp, buf, count);
45 ret = simple_strtol(tmp, NULL, 10);
50 static int get_boolean(const char *buf, size_t count)
57 if (count >= 4 && memcmp(buf, "true", 4) == 0)
59 if (count >= 5 && memcmp(buf, "false", 5) == 0)
61 if (count >= 3 && memcmp(buf, "yes", 3) == 0)
63 if (count >= 2 && memcmp(buf, "no", 2) == 0)
65 if (count >= 2 && memcmp(buf, "on", 2) == 0)
67 if (count >= 3 && memcmp(buf, "off", 3) == 0)
73 static ssize_t b43_attr_interfmode_show(struct device *dev,
74 struct device_attribute *attr,
77 struct b43_wldev *wldev = dev_to_b43_wldev(dev);
80 if (!capable(CAP_NET_ADMIN))
83 mutex_lock(&wldev->wl->mutex);
85 switch (wldev->phy.interfmode) {
86 case B43_INTERFMODE_NONE:
88 snprintf(buf, PAGE_SIZE,
89 "0 (No Interference Mitigation)\n");
91 case B43_INTERFMODE_NONWLAN:
93 snprintf(buf, PAGE_SIZE,
94 "1 (Non-WLAN Interference Mitigation)\n");
96 case B43_INTERFMODE_MANUALWLAN:
98 snprintf(buf, PAGE_SIZE,
99 "2 (WLAN Interference Mitigation)\n");
105 mutex_unlock(&wldev->wl->mutex);
110 static ssize_t b43_attr_interfmode_store(struct device *dev,
111 struct device_attribute *attr,
112 const char *buf, size_t count)
114 struct b43_wldev *wldev = dev_to_b43_wldev(dev);
119 if (!capable(CAP_NET_ADMIN))
122 mode = get_integer(buf, count);
125 mode = B43_INTERFMODE_NONE;
128 mode = B43_INTERFMODE_NONWLAN;
131 mode = B43_INTERFMODE_MANUALWLAN;
134 mode = B43_INTERFMODE_AUTOWLAN;
140 mutex_lock(&wldev->wl->mutex);
141 spin_lock_irqsave(&wldev->wl->irq_lock, flags);
143 err = b43_radio_set_interference_mitigation(wldev, mode);
145 b43err(wldev->wl, "Interference Mitigation not "
146 "supported by device\n");
149 spin_unlock_irqrestore(&wldev->wl->irq_lock, flags);
150 mutex_unlock(&wldev->wl->mutex);
152 return err ? err : count;
155 static DEVICE_ATTR(interference, 0644,
156 b43_attr_interfmode_show, b43_attr_interfmode_store);
158 static ssize_t b43_attr_preamble_show(struct device *dev,
159 struct device_attribute *attr, char *buf)
161 struct b43_wldev *wldev = dev_to_b43_wldev(dev);
164 if (!capable(CAP_NET_ADMIN))
167 mutex_lock(&wldev->wl->mutex);
169 if (wldev->short_preamble)
171 snprintf(buf, PAGE_SIZE, "1 (Short Preamble enabled)\n");
174 snprintf(buf, PAGE_SIZE, "0 (Short Preamble disabled)\n");
176 mutex_unlock(&wldev->wl->mutex);
181 static ssize_t b43_attr_preamble_store(struct device *dev,
182 struct device_attribute *attr,
183 const char *buf, size_t count)
185 struct b43_wldev *wldev = dev_to_b43_wldev(dev);
189 if (!capable(CAP_NET_ADMIN))
192 value = get_boolean(buf, count);
195 mutex_lock(&wldev->wl->mutex);
196 spin_lock_irqsave(&wldev->wl->irq_lock, flags);
198 wldev->short_preamble = !!value;
200 spin_unlock_irqrestore(&wldev->wl->irq_lock, flags);
201 mutex_unlock(&wldev->wl->mutex);
206 static DEVICE_ATTR(shortpreamble, 0644,
207 b43_attr_preamble_show, b43_attr_preamble_store);
209 int b43_sysfs_register(struct b43_wldev *wldev)
211 struct device *dev = wldev->dev->dev;
214 B43_WARN_ON(b43_status(wldev) != B43_STAT_INITIALIZED);
216 err = device_create_file(dev, &dev_attr_interference);
219 err = device_create_file(dev, &dev_attr_shortpreamble);
221 goto err_remove_interfmode;
225 err_remove_interfmode:
226 device_remove_file(dev, &dev_attr_interference);
230 void b43_sysfs_unregister(struct b43_wldev *wldev)
232 struct device *dev = wldev->dev->dev;
234 device_remove_file(dev, &dev_attr_shortpreamble);
235 device_remove_file(dev, &dev_attr_interference);