3 Broadcom B43legacy wireless driver
7 Copyright (c) 2006 Michael Buesch <m@bues.ch>
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.
27 #include "b43legacy.h"
32 #include <linux/capability.h>
35 #define GENERIC_FILESIZE 64
38 static int get_integer(const char *buf, size_t count)
40 char tmp[10 + 1] = { 0 };
45 count = min_t(size_t, count, 10);
46 memcpy(tmp, buf, count);
47 ret = simple_strtol(tmp, NULL, 10);
52 static int get_boolean(const char *buf, size_t count)
59 if (count >= 4 && memcmp(buf, "true", 4) == 0)
61 if (count >= 5 && memcmp(buf, "false", 5) == 0)
63 if (count >= 3 && memcmp(buf, "yes", 3) == 0)
65 if (count >= 2 && memcmp(buf, "no", 2) == 0)
67 if (count >= 2 && memcmp(buf, "on", 2) == 0)
69 if (count >= 3 && memcmp(buf, "off", 3) == 0)
75 static ssize_t b43legacy_attr_interfmode_show(struct device *dev,
76 struct device_attribute *attr,
79 struct b43legacy_wldev *wldev = dev_to_b43legacy_wldev(dev);
82 if (!capable(CAP_NET_ADMIN))
85 mutex_lock(&wldev->wl->mutex);
87 switch (wldev->phy.interfmode) {
88 case B43legacy_INTERFMODE_NONE:
89 count = snprintf(buf, PAGE_SIZE, "0 (No Interference"
92 case B43legacy_INTERFMODE_NONWLAN:
93 count = snprintf(buf, PAGE_SIZE, "1 (Non-WLAN Interference"
96 case B43legacy_INTERFMODE_MANUALWLAN:
97 count = snprintf(buf, PAGE_SIZE, "2 (WLAN Interference"
101 B43legacy_WARN_ON(1);
104 mutex_unlock(&wldev->wl->mutex);
109 static ssize_t b43legacy_attr_interfmode_store(struct device *dev,
110 struct device_attribute *attr,
111 const char *buf, size_t count)
113 struct b43legacy_wldev *wldev = dev_to_b43legacy_wldev(dev);
118 if (!capable(CAP_NET_ADMIN))
121 mode = get_integer(buf, count);
124 mode = B43legacy_INTERFMODE_NONE;
127 mode = B43legacy_INTERFMODE_NONWLAN;
130 mode = B43legacy_INTERFMODE_MANUALWLAN;
133 mode = B43legacy_INTERFMODE_AUTOWLAN;
139 mutex_lock(&wldev->wl->mutex);
140 spin_lock_irqsave(&wldev->wl->irq_lock, flags);
142 err = b43legacy_radio_set_interference_mitigation(wldev, mode);
144 b43legacyerr(wldev->wl, "Interference Mitigation not "
145 "supported by device\n");
146 spin_unlock_irqrestore(&wldev->wl->irq_lock, flags);
147 mutex_unlock(&wldev->wl->mutex);
149 return err ? err : count;
152 static DEVICE_ATTR(interference, 0644,
153 b43legacy_attr_interfmode_show,
154 b43legacy_attr_interfmode_store);
156 static ssize_t b43legacy_attr_preamble_show(struct device *dev,
157 struct device_attribute *attr,
160 struct b43legacy_wldev *wldev = dev_to_b43legacy_wldev(dev);
163 if (!capable(CAP_NET_ADMIN))
166 mutex_lock(&wldev->wl->mutex);
168 if (wldev->short_preamble)
169 count = snprintf(buf, PAGE_SIZE, "1 (Short Preamble"
172 count = snprintf(buf, PAGE_SIZE, "0 (Short Preamble"
175 mutex_unlock(&wldev->wl->mutex);
180 static ssize_t b43legacy_attr_preamble_store(struct device *dev,
181 struct device_attribute *attr,
182 const char *buf, size_t count)
184 struct b43legacy_wldev *wldev = dev_to_b43legacy_wldev(dev);
188 if (!capable(CAP_NET_ADMIN))
191 value = get_boolean(buf, count);
194 mutex_lock(&wldev->wl->mutex);
195 spin_lock_irqsave(&wldev->wl->irq_lock, flags);
197 wldev->short_preamble = !!value;
199 spin_unlock_irqrestore(&wldev->wl->irq_lock, flags);
200 mutex_unlock(&wldev->wl->mutex);
205 static DEVICE_ATTR(shortpreamble, 0644,
206 b43legacy_attr_preamble_show,
207 b43legacy_attr_preamble_store);
209 int b43legacy_sysfs_register(struct b43legacy_wldev *wldev)
211 struct device *dev = wldev->dev->dev;
214 B43legacy_WARN_ON(b43legacy_status(wldev) !=
215 B43legacy_STAT_INITIALIZED);
217 err = device_create_file(dev, &dev_attr_interference);
220 err = device_create_file(dev, &dev_attr_shortpreamble);
222 goto err_remove_interfmode;
226 err_remove_interfmode:
227 device_remove_file(dev, &dev_attr_interference);
231 void b43legacy_sysfs_unregister(struct b43legacy_wldev *wldev)
233 struct device *dev = wldev->dev->dev;
235 device_remove_file(dev, &dev_attr_shortpreamble);
236 device_remove_file(dev, &dev_attr_interference);