developer | 6a1998b | 2022-12-08 18:09:45 +0800 | [diff] [blame] | 1 | From: Felix Fietkau <nbd@nbd.name> |
| 2 | Date: Thu, 11 Dec 2014 00:00:00 +0100 |
| 3 | Subject: [PATCH] cfg80211: add support for changing the device mac address via |
| 4 | sysfs |
| 5 | |
| 6 | --- |
| 7 | net/wireless/sysfs.c | 27 ++++++++++++++++++++++----- |
| 8 | 1 file changed, 22 insertions(+), 5 deletions(-) |
| 9 | |
| 10 | --- a/net/wireless/sysfs.c |
| 11 | +++ b/net/wireless/sysfs.c |
| 12 | @@ -24,18 +24,35 @@ static inline struct cfg80211_registered |
| 13 | return container_of(dev, struct cfg80211_registered_device, wiphy.dev); |
| 14 | } |
| 15 | |
| 16 | -#define SHOW_FMT(name, fmt, member) \ |
| 17 | +#define SHOW_FMT(name, fmt, member, mode) \ |
| 18 | static ssize_t name ## _show(struct device *dev, \ |
| 19 | struct device_attribute *attr, \ |
| 20 | char *buf) \ |
| 21 | { \ |
| 22 | return sprintf(buf, fmt "\n", dev_to_rdev(dev)->member); \ |
| 23 | } \ |
| 24 | -static DEVICE_ATTR_RO(name) |
| 25 | +static DEVICE_ATTR_##mode(name) |
| 26 | |
| 27 | -SHOW_FMT(index, "%d", wiphy_idx); |
| 28 | -SHOW_FMT(macaddress, "%pM", wiphy.perm_addr); |
| 29 | -SHOW_FMT(address_mask, "%pM", wiphy.addr_mask); |
| 30 | +static ssize_t macaddress_store(struct device *dev, |
| 31 | + struct device_attribute *attr, |
| 32 | + const char *buf, size_t len) |
| 33 | +{ |
| 34 | + u8 mac[ETH_ALEN]; |
| 35 | + |
| 36 | + if (!mac_pton(buf, mac)) |
| 37 | + return -EINVAL; |
| 38 | + |
| 39 | + if (buf[3 * ETH_ALEN - 1] && buf[3 * ETH_ALEN - 1] != '\n') |
| 40 | + return -EINVAL; |
| 41 | + |
| 42 | + memcpy(dev_to_rdev(dev)->wiphy.perm_addr, mac, ETH_ALEN); |
| 43 | + |
| 44 | + return strnlen(buf, len); |
| 45 | +} |
| 46 | + |
| 47 | +SHOW_FMT(index, "%d", wiphy_idx, RO); |
| 48 | +SHOW_FMT(macaddress, "%pM", wiphy.perm_addr, RW); |
| 49 | +SHOW_FMT(address_mask, "%pM", wiphy.addr_mask, RO); |
| 50 | |
| 51 | static ssize_t name_show(struct device *dev, |
| 52 | struct device_attribute *attr, |