Linux Audio

Check our new training course

Loading...
v4.10.11
 
  1/*
  2
  3  Broadcom B43 wireless driver
  4
  5  SYSFS support routines
  6
  7  Copyright (c) 2006 Michael Buesch <m@bues.ch>
  8
  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.
 13
 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.
 18
 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.
 23
 24*/
 25
 26#include <linux/capability.h>
 27#include <linux/io.h>
 28
 29#include "b43.h"
 30#include "sysfs.h"
 31#include "main.h"
 32#include "phy_common.h"
 33
 34#define GENERIC_FILESIZE	64
 35
 36static int get_integer(const char *buf, size_t count)
 37{
 38	char tmp[10 + 1] = { 0 };
 39	int ret = -EINVAL;
 40
 41	if (count == 0)
 42		goto out;
 43	count = min_t(size_t, count, 10);
 44	memcpy(tmp, buf, count);
 45	ret = simple_strtol(tmp, NULL, 10);
 46      out:
 47	return ret;
 48}
 49
 50static ssize_t b43_attr_interfmode_show(struct device *dev,
 51					struct device_attribute *attr,
 52					char *buf)
 53{
 54	struct b43_wldev *wldev = dev_to_b43_wldev(dev);
 55	ssize_t count = 0;
 56
 57	if (!capable(CAP_NET_ADMIN))
 58		return -EPERM;
 59
 60	mutex_lock(&wldev->wl->mutex);
 61
 62	if (wldev->phy.type != B43_PHYTYPE_G) {
 63		mutex_unlock(&wldev->wl->mutex);
 64		return -ENOSYS;
 65	}
 66
 67	switch (wldev->phy.g->interfmode) {
 68	case B43_INTERFMODE_NONE:
 69		count =
 70		    snprintf(buf, PAGE_SIZE,
 71			     "0 (No Interference Mitigation)\n");
 72		break;
 73	case B43_INTERFMODE_NONWLAN:
 74		count =
 75		    snprintf(buf, PAGE_SIZE,
 76			     "1 (Non-WLAN Interference Mitigation)\n");
 77		break;
 78	case B43_INTERFMODE_MANUALWLAN:
 79		count =
 80		    snprintf(buf, PAGE_SIZE,
 81			     "2 (WLAN Interference Mitigation)\n");
 82		break;
 83	default:
 84		B43_WARN_ON(1);
 85	}
 86
 87	mutex_unlock(&wldev->wl->mutex);
 88
 89	return count;
 90}
 91
 92static ssize_t b43_attr_interfmode_store(struct device *dev,
 93					 struct device_attribute *attr,
 94					 const char *buf, size_t count)
 95{
 96	struct b43_wldev *wldev = dev_to_b43_wldev(dev);
 97	int err;
 98	int mode;
 99
100	if (!capable(CAP_NET_ADMIN))
101		return -EPERM;
102
103	mode = get_integer(buf, count);
104	switch (mode) {
105	case 0:
106		mode = B43_INTERFMODE_NONE;
107		break;
108	case 1:
109		mode = B43_INTERFMODE_NONWLAN;
110		break;
111	case 2:
112		mode = B43_INTERFMODE_MANUALWLAN;
113		break;
114	case 3:
115		mode = B43_INTERFMODE_AUTOWLAN;
116		break;
117	default:
118		return -EINVAL;
119	}
120
121	mutex_lock(&wldev->wl->mutex);
122
123	if (wldev->phy.ops->interf_mitigation) {
124		err = wldev->phy.ops->interf_mitigation(wldev, mode);
125		if (err) {
126			b43err(wldev->wl, "Interference Mitigation not "
127			       "supported by device\n");
128		}
129	} else
130		err = -ENOSYS;
131
132	mmiowb();
133	mutex_unlock(&wldev->wl->mutex);
134
135	return err ? err : count;
136}
137
138static DEVICE_ATTR(interference, 0644,
139		   b43_attr_interfmode_show, b43_attr_interfmode_store);
140
141int b43_sysfs_register(struct b43_wldev *wldev)
142{
143	struct device *dev = wldev->dev->dev;
144
145	B43_WARN_ON(b43_status(wldev) != B43_STAT_INITIALIZED);
146
147	return device_create_file(dev, &dev_attr_interference);
148}
149
150void b43_sysfs_unregister(struct b43_wldev *wldev)
151{
152	struct device *dev = wldev->dev->dev;
153
154	device_remove_file(dev, &dev_attr_interference);
155}
v6.13.7
  1// SPDX-License-Identifier: GPL-2.0-or-later
  2/*
  3
  4  Broadcom B43 wireless driver
  5
  6  SYSFS support routines
  7
  8  Copyright (c) 2006 Michael Buesch <m@bues.ch>
  9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 10
 11*/
 12
 13#include <linux/capability.h>
 14#include <linux/io.h>
 15
 16#include "b43.h"
 17#include "sysfs.h"
 18#include "main.h"
 19#include "phy_common.h"
 20
 21#define GENERIC_FILESIZE	64
 22
 23static int get_integer(const char *buf, size_t count)
 24{
 25	char tmp[10 + 1] = { 0 };
 26	int ret = -EINVAL;
 27
 28	if (count == 0)
 29		goto out;
 30	count = min_t(size_t, count, 10);
 31	memcpy(tmp, buf, count);
 32	ret = simple_strtol(tmp, NULL, 10);
 33      out:
 34	return ret;
 35}
 36
 37static ssize_t b43_attr_interfmode_show(struct device *dev,
 38					struct device_attribute *attr,
 39					char *buf)
 40{
 41	struct b43_wldev *wldev = dev_to_b43_wldev(dev);
 42	ssize_t count = 0;
 43
 44	if (!capable(CAP_NET_ADMIN))
 45		return -EPERM;
 46
 47	mutex_lock(&wldev->wl->mutex);
 48
 49	if (wldev->phy.type != B43_PHYTYPE_G) {
 50		mutex_unlock(&wldev->wl->mutex);
 51		return -ENOSYS;
 52	}
 53
 54	switch (wldev->phy.g->interfmode) {
 55	case B43_INTERFMODE_NONE:
 56		count = sysfs_emit(buf, "0 (No Interference Mitigation)\n");
 
 
 57		break;
 58	case B43_INTERFMODE_NONWLAN:
 59		count = sysfs_emit(buf,
 60				   "1 (Non-WLAN Interference Mitigation)\n");
 
 61		break;
 62	case B43_INTERFMODE_MANUALWLAN:
 63		count = sysfs_emit(buf, "2 (WLAN Interference Mitigation)\n");
 
 
 64		break;
 65	default:
 66		B43_WARN_ON(1);
 67	}
 68
 69	mutex_unlock(&wldev->wl->mutex);
 70
 71	return count;
 72}
 73
 74static ssize_t b43_attr_interfmode_store(struct device *dev,
 75					 struct device_attribute *attr,
 76					 const char *buf, size_t count)
 77{
 78	struct b43_wldev *wldev = dev_to_b43_wldev(dev);
 79	int err;
 80	int mode;
 81
 82	if (!capable(CAP_NET_ADMIN))
 83		return -EPERM;
 84
 85	mode = get_integer(buf, count);
 86	switch (mode) {
 87	case 0:
 88		mode = B43_INTERFMODE_NONE;
 89		break;
 90	case 1:
 91		mode = B43_INTERFMODE_NONWLAN;
 92		break;
 93	case 2:
 94		mode = B43_INTERFMODE_MANUALWLAN;
 95		break;
 96	case 3:
 97		mode = B43_INTERFMODE_AUTOWLAN;
 98		break;
 99	default:
100		return -EINVAL;
101	}
102
103	mutex_lock(&wldev->wl->mutex);
104
105	if (wldev->phy.ops->interf_mitigation) {
106		err = wldev->phy.ops->interf_mitigation(wldev, mode);
107		if (err) {
108			b43err(wldev->wl, "Interference Mitigation not "
109			       "supported by device\n");
110		}
111	} else
112		err = -ENOSYS;
113
 
114	mutex_unlock(&wldev->wl->mutex);
115
116	return err ? err : count;
117}
118
119static DEVICE_ATTR(interference, 0644,
120		   b43_attr_interfmode_show, b43_attr_interfmode_store);
121
122int b43_sysfs_register(struct b43_wldev *wldev)
123{
124	struct device *dev = wldev->dev->dev;
125
126	B43_WARN_ON(b43_status(wldev) != B43_STAT_INITIALIZED);
127
128	return device_create_file(dev, &dev_attr_interference);
129}
130
131void b43_sysfs_unregister(struct b43_wldev *wldev)
132{
133	struct device *dev = wldev->dev->dev;
134
135	device_remove_file(dev, &dev_attr_interference);
136}