3 Broadcom BCM43xx wireless driver
7 Copyright (c) 2006 Michael Buesch <mbuesch@freenet.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 "bcm43xx_sysfs.h"
28 #include "bcm43xx_main.h"
29 #include "bcm43xx_radio.h"
31 #include <linux/capability.h>
34 #define GENERIC_FILESIZE 64
37 static int get_integer(const char *buf
, size_t count
)
39 char tmp
[10 + 1] = { 0 };
44 count
= min(count
, (size_t)10);
45 memcpy(tmp
, buf
, count
);
46 ret
= simple_strtol(tmp
, NULL
, 10);
51 static int get_boolean(const char *buf
, size_t count
)
58 if (count
>= 4 && memcmp(buf
, "true", 4) == 0)
60 if (count
>= 5 && memcmp(buf
, "false", 5) == 0)
62 if (count
>= 3 && memcmp(buf
, "yes", 3) == 0)
64 if (count
>= 2 && memcmp(buf
, "no", 2) == 0)
66 if (count
>= 2 && memcmp(buf
, "on", 2) == 0)
68 if (count
>= 3 && memcmp(buf
, "off", 3) == 0)
74 static ssize_t
bcm43xx_attr_sprom_show(struct device
*dev
,
75 struct device_attribute
*attr
,
78 struct bcm43xx_private
*bcm
= devattr_to_bcm(attr
, attr_sprom
);
83 if (!capable(CAP_NET_ADMIN
))
86 assert(BCM43xx_SPROM_SIZE
* sizeof(u16
) <= PAGE_SIZE
);
87 sprom
= kmalloc(BCM43xx_SPROM_SIZE
* sizeof(*sprom
),
91 bcm43xx_lock_mmio(bcm
, flags
);
92 assert(bcm
->initialized
);
93 err
= bcm43xx_sprom_read(bcm
, sprom
);
95 for (i
= 0; i
< BCM43xx_SPROM_SIZE
; i
++) {
96 buf
[i
* 2] = sprom
[i
] & 0x00FF;
97 buf
[i
* 2 + 1] = (sprom
[i
] & 0xFF00) >> 8;
100 bcm43xx_unlock_mmio(bcm
, flags
);
103 return err
? err
: BCM43xx_SPROM_SIZE
* sizeof(u16
);
106 static ssize_t
bcm43xx_attr_sprom_store(struct device
*dev
,
107 struct device_attribute
*attr
,
108 const char *buf
, size_t count
)
110 struct bcm43xx_private
*bcm
= devattr_to_bcm(attr
, attr_sprom
);
115 if (!capable(CAP_NET_ADMIN
))
118 if (count
!= BCM43xx_SPROM_SIZE
* sizeof(u16
))
120 sprom
= kmalloc(BCM43xx_SPROM_SIZE
* sizeof(*sprom
),
124 for (i
= 0; i
< BCM43xx_SPROM_SIZE
; i
++) {
125 sprom
[i
] = buf
[i
* 2] & 0xFF;
126 sprom
[i
] |= ((u16
)(buf
[i
* 2 + 1] & 0xFF)) << 8;
128 bcm43xx_lock_mmio(bcm
, flags
);
129 assert(bcm
->initialized
);
130 err
= bcm43xx_sprom_write(bcm
, sprom
);
131 bcm43xx_unlock_mmio(bcm
, flags
);
134 return err
? err
: count
;
138 static ssize_t
bcm43xx_attr_interfmode_show(struct device
*dev
,
139 struct device_attribute
*attr
,
142 struct bcm43xx_private
*bcm
= devattr_to_bcm(attr
, attr_interfmode
);
147 if (!capable(CAP_NET_ADMIN
))
150 bcm43xx_lock(bcm
, flags
);
151 assert(bcm
->initialized
);
153 switch (bcm43xx_current_radio(bcm
)->interfmode
) {
154 case BCM43xx_RADIO_INTERFMODE_NONE
:
155 count
= snprintf(buf
, PAGE_SIZE
, "0 (No Interference Mitigation)\n");
157 case BCM43xx_RADIO_INTERFMODE_NONWLAN
:
158 count
= snprintf(buf
, PAGE_SIZE
, "1 (Non-WLAN Interference Mitigation)\n");
160 case BCM43xx_RADIO_INTERFMODE_MANUALWLAN
:
161 count
= snprintf(buf
, PAGE_SIZE
, "2 (WLAN Interference Mitigation)\n");
168 bcm43xx_unlock(bcm
, flags
);
170 return err
? err
: count
;
174 static ssize_t
bcm43xx_attr_interfmode_store(struct device
*dev
,
175 struct device_attribute
*attr
,
176 const char *buf
, size_t count
)
178 struct bcm43xx_private
*bcm
= devattr_to_bcm(attr
, attr_interfmode
);
183 if (!capable(CAP_NET_ADMIN
))
186 mode
= get_integer(buf
, count
);
189 mode
= BCM43xx_RADIO_INTERFMODE_NONE
;
192 mode
= BCM43xx_RADIO_INTERFMODE_NONWLAN
;
195 mode
= BCM43xx_RADIO_INTERFMODE_MANUALWLAN
;
198 mode
= BCM43xx_RADIO_INTERFMODE_AUTOWLAN
;
204 bcm43xx_lock_mmio(bcm
, flags
);
205 assert(bcm
->initialized
);
207 err
= bcm43xx_radio_set_interference_mitigation(bcm
, mode
);
209 printk(KERN_ERR PFX
"Interference Mitigation not "
210 "supported by device\n");
213 bcm43xx_unlock_mmio(bcm
, flags
);
215 return err
? err
: count
;
218 static ssize_t
bcm43xx_attr_preamble_show(struct device
*dev
,
219 struct device_attribute
*attr
,
222 struct bcm43xx_private
*bcm
= devattr_to_bcm(attr
, attr_preamble
);
227 if (!capable(CAP_NET_ADMIN
))
230 bcm43xx_lock(bcm
, flags
);
231 assert(bcm
->initialized
);
233 if (bcm
->short_preamble
)
234 count
= snprintf(buf
, PAGE_SIZE
, "1 (Short Preamble enabled)\n");
236 count
= snprintf(buf
, PAGE_SIZE
, "0 (Short Preamble disabled)\n");
239 bcm43xx_unlock(bcm
, flags
);
241 return err
? err
: count
;
244 static ssize_t
bcm43xx_attr_preamble_store(struct device
*dev
,
245 struct device_attribute
*attr
,
246 const char *buf
, size_t count
)
248 struct bcm43xx_private
*bcm
= devattr_to_bcm(attr
, attr_preamble
);
253 if (!capable(CAP_NET_ADMIN
))
256 value
= get_boolean(buf
, count
);
259 bcm43xx_lock(bcm
, flags
);
260 assert(bcm
->initialized
);
262 bcm
->short_preamble
= !!value
;
265 bcm43xx_unlock(bcm
, flags
);
267 return err
? err
: count
;
270 int bcm43xx_sysfs_register(struct bcm43xx_private
*bcm
)
272 struct device
*dev
= &bcm
->pci_dev
->dev
;
273 struct bcm43xx_sysfs
*sysfs
= &bcm
->sysfs
;
276 assert(bcm
->initialized
);
278 sysfs
->attr_sprom
.attr
.name
= "sprom";
279 sysfs
->attr_sprom
.attr
.owner
= THIS_MODULE
;
280 sysfs
->attr_sprom
.attr
.mode
= 0600;
281 sysfs
->attr_sprom
.show
= bcm43xx_attr_sprom_show
;
282 sysfs
->attr_sprom
.store
= bcm43xx_attr_sprom_store
;
283 err
= device_create_file(dev
, &sysfs
->attr_sprom
);
287 sysfs
->attr_interfmode
.attr
.name
= "interference";
288 sysfs
->attr_interfmode
.attr
.owner
= THIS_MODULE
;
289 sysfs
->attr_interfmode
.attr
.mode
= 0600;
290 sysfs
->attr_interfmode
.show
= bcm43xx_attr_interfmode_show
;
291 sysfs
->attr_interfmode
.store
= bcm43xx_attr_interfmode_store
;
292 err
= device_create_file(dev
, &sysfs
->attr_interfmode
);
294 goto err_remove_sprom
;
296 sysfs
->attr_preamble
.attr
.name
= "shortpreamble";
297 sysfs
->attr_preamble
.attr
.owner
= THIS_MODULE
;
298 sysfs
->attr_preamble
.attr
.mode
= 0600;
299 sysfs
->attr_preamble
.show
= bcm43xx_attr_preamble_show
;
300 sysfs
->attr_preamble
.store
= bcm43xx_attr_preamble_store
;
301 err
= device_create_file(dev
, &sysfs
->attr_preamble
);
303 goto err_remove_interfmode
;
307 err_remove_interfmode
:
308 device_remove_file(dev
, &sysfs
->attr_interfmode
);
310 device_remove_file(dev
, &sysfs
->attr_sprom
);
314 void bcm43xx_sysfs_unregister(struct bcm43xx_private
*bcm
)
316 struct device
*dev
= &bcm
->pci_dev
->dev
;
317 struct bcm43xx_sysfs
*sysfs
= &bcm
->sysfs
;
319 device_remove_file(dev
, &sysfs
->attr_preamble
);
320 device_remove_file(dev
, &sysfs
->attr_interfmode
);
321 device_remove_file(dev
, &sysfs
->attr_sprom
);
324 /* vim: set ts=8 sw=8 sts=8: */