blob: eb9ca6f991221ddd2dd8140b184c367c421f1289 [file] [log] [blame]
Alexander Aringe23e9ec2014-10-28 18:21:32 +01001/* This program is free software; you can redistribute it and/or modify
2 * it under the terms of the GNU General Public License version 2
3 * as published by the Free Software Foundation.
4 *
5 * This program is distributed in the hope that it will be useful,
6 * but WITHOUT ANY WARRANTY; without even the implied warranty of
7 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
8 * GNU General Public License for more details.
9 *
10 * Authors:
11 * Alexander Aring <aar@pengutronix.de>
12 *
13 * Based on: net/wireless/sysfs.c
14 */
15
16#include <linux/device.h>
17
18#include <net/cfg802154.h>
19
20#define MASTER_SHOW_COMPLEX(name, format_string, args...) \
21static ssize_t name ## _show(struct device *dev, \
22 struct device_attribute *attr, char *buf) \
23{ \
24 struct wpan_phy *phy = container_of(dev, struct wpan_phy, dev); \
25 int ret; \
26 \
27 mutex_lock(&phy->pib_lock); \
28 ret = snprintf(buf, PAGE_SIZE, format_string "\n", args); \
29 mutex_unlock(&phy->pib_lock); \
30 return ret; \
31} \
32static DEVICE_ATTR_RO(name)
33
34#define MASTER_SHOW(field, format_string) \
35 MASTER_SHOW_COMPLEX(field, format_string, phy->field)
36
37MASTER_SHOW(current_channel, "%d");
38MASTER_SHOW(current_page, "%d");
39MASTER_SHOW(transmit_power, "%d +- 1 dB");
40MASTER_SHOW(cca_mode, "%d");
41
42static ssize_t channels_supported_show(struct device *dev,
43 struct device_attribute *attr,
44 char *buf)
45{
46 struct wpan_phy *phy = container_of(dev, struct wpan_phy, dev);
47 int ret;
48 int i, len = 0;
49
50 mutex_lock(&phy->pib_lock);
51 for (i = 0; i < 32; i++) {
52 ret = snprintf(buf + len, PAGE_SIZE - len,
53 "%#09x\n", phy->channels_supported[i]);
54 if (ret < 0)
55 break;
56 len += ret;
57 }
58 mutex_unlock(&phy->pib_lock);
59 return len;
60}
61static DEVICE_ATTR_RO(channels_supported);
62
63static void wpan_phy_release(struct device *d)
64{
65 struct wpan_phy *phy = container_of(d, struct wpan_phy, dev);
66
67 kfree(phy);
68}
69
70static struct attribute *pmib_attrs[] = {
71 &dev_attr_current_channel.attr,
72 &dev_attr_current_page.attr,
73 &dev_attr_channels_supported.attr,
74 &dev_attr_transmit_power.attr,
75 &dev_attr_cca_mode.attr,
76 NULL,
77};
78ATTRIBUTE_GROUPS(pmib);
79
80struct class wpan_phy_class = {
81 .name = "ieee802154",
82 .dev_release = wpan_phy_release,
83 .dev_groups = pmib_groups,
84};
85
86int wpan_phy_sysfs_init(void)
87{
88 return class_register(&wpan_phy_class);
89}
90
91void wpan_phy_sysfs_exit(void)
92{
93 class_unregister(&wpan_phy_class);
94}