diff options
author | Alexander Aring <alex.aring@gmail.com> | 2014-10-28 13:21:32 -0400 |
---|---|---|
committer | Marcel Holtmann <marcel@holtmann.org> | 2014-10-28 18:19:09 -0400 |
commit | e23e9ec16bf4bbaf12fc030079b277cb00f618f4 (patch) | |
tree | 5d582e1aa668854f421c03df0c7c20b59de32584 | |
parent | 74457641558baded3c9f05bc3fb81293a2c02b2e (diff) |
ieee802154: introduce sysfs file
This patch moves the sysfs handling in a own file. This is like wireless
sysfs file handling.
Signed-off-by: Alexander Aring <alex.aring@gmail.com>
Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
-rw-r--r-- | net/ieee802154/Makefile | 2 | ||||
-rw-r--r-- | net/ieee802154/core.c | 73 | ||||
-rw-r--r-- | net/ieee802154/sysfs.c | 94 | ||||
-rw-r--r-- | net/ieee802154/sysfs.h | 9 |
4 files changed, 108 insertions, 70 deletions
diff --git a/net/ieee802154/Makefile b/net/ieee802154/Makefile index e58c4cbb3639..38354d4a70cb 100644 --- a/net/ieee802154/Makefile +++ b/net/ieee802154/Makefile | |||
@@ -3,7 +3,7 @@ obj-$(CONFIG_IEEE802154_6LOWPAN) += ieee802154_6lowpan.o | |||
3 | 3 | ||
4 | ieee802154_6lowpan-y := 6lowpan_rtnl.o reassembly.o | 4 | ieee802154_6lowpan-y := 6lowpan_rtnl.o reassembly.o |
5 | ieee802154-y := netlink.o nl-mac.o nl-phy.o nl_policy.o core.o \ | 5 | ieee802154-y := netlink.o nl-mac.o nl-phy.o nl_policy.o core.o \ |
6 | header_ops.o | 6 | header_ops.o sysfs.o |
7 | af_802154-y := af_ieee802154.o raw.o dgram.o | 7 | af_802154-y := af_ieee802154.o raw.o dgram.o |
8 | 8 | ||
9 | ccflags-y += -D__CHECK_ENDIAN__ | 9 | ccflags-y += -D__CHECK_ENDIAN__ |
diff --git a/net/ieee802154/core.c b/net/ieee802154/core.c index 760b7d752190..620abc2ba5fc 100644 --- a/net/ieee802154/core.c +++ b/net/ieee802154/core.c | |||
@@ -20,72 +20,7 @@ | |||
20 | #include <net/cfg802154.h> | 20 | #include <net/cfg802154.h> |
21 | 21 | ||
22 | #include "ieee802154.h" | 22 | #include "ieee802154.h" |
23 | 23 | #include "sysfs.h" | |
24 | #define MASTER_SHOW_COMPLEX(name, format_string, args...) \ | ||
25 | static ssize_t name ## _show(struct device *dev, \ | ||
26 | struct device_attribute *attr, char *buf) \ | ||
27 | { \ | ||
28 | struct wpan_phy *phy = container_of(dev, struct wpan_phy, dev); \ | ||
29 | int ret; \ | ||
30 | \ | ||
31 | mutex_lock(&phy->pib_lock); \ | ||
32 | ret = snprintf(buf, PAGE_SIZE, format_string "\n", args); \ | ||
33 | mutex_unlock(&phy->pib_lock); \ | ||
34 | return ret; \ | ||
35 | } \ | ||
36 | static DEVICE_ATTR_RO(name) | ||
37 | |||
38 | #define MASTER_SHOW(field, format_string) \ | ||
39 | MASTER_SHOW_COMPLEX(field, format_string, phy->field) | ||
40 | |||
41 | MASTER_SHOW(current_channel, "%d"); | ||
42 | MASTER_SHOW(current_page, "%d"); | ||
43 | MASTER_SHOW(transmit_power, "%d +- 1 dB"); | ||
44 | MASTER_SHOW(cca_mode, "%d"); | ||
45 | |||
46 | static ssize_t channels_supported_show(struct device *dev, | ||
47 | struct device_attribute *attr, | ||
48 | char *buf) | ||
49 | { | ||
50 | struct wpan_phy *phy = container_of(dev, struct wpan_phy, dev); | ||
51 | int ret; | ||
52 | int i, len = 0; | ||
53 | |||
54 | mutex_lock(&phy->pib_lock); | ||
55 | for (i = 0; i < 32; i++) { | ||
56 | ret = snprintf(buf + len, PAGE_SIZE - len, | ||
57 | "%#09x\n", phy->channels_supported[i]); | ||
58 | if (ret < 0) | ||
59 | break; | ||
60 | len += ret; | ||
61 | } | ||
62 | mutex_unlock(&phy->pib_lock); | ||
63 | return len; | ||
64 | } | ||
65 | static DEVICE_ATTR_RO(channels_supported); | ||
66 | |||
67 | static struct attribute *pmib_attrs[] = { | ||
68 | &dev_attr_current_channel.attr, | ||
69 | &dev_attr_current_page.attr, | ||
70 | &dev_attr_channels_supported.attr, | ||
71 | &dev_attr_transmit_power.attr, | ||
72 | &dev_attr_cca_mode.attr, | ||
73 | NULL, | ||
74 | }; | ||
75 | ATTRIBUTE_GROUPS(pmib); | ||
76 | |||
77 | static void wpan_phy_release(struct device *d) | ||
78 | { | ||
79 | struct wpan_phy *phy = container_of(d, struct wpan_phy, dev); | ||
80 | |||
81 | kfree(phy); | ||
82 | } | ||
83 | |||
84 | static struct class wpan_phy_class = { | ||
85 | .name = "ieee802154", | ||
86 | .dev_release = wpan_phy_release, | ||
87 | .dev_groups = pmib_groups, | ||
88 | }; | ||
89 | 24 | ||
90 | static DEFINE_MUTEX(wpan_phy_mutex); | 25 | static DEFINE_MUTEX(wpan_phy_mutex); |
91 | static int wpan_phy_idx; | 26 | static int wpan_phy_idx; |
@@ -197,7 +132,7 @@ static int __init wpan_phy_class_init(void) | |||
197 | { | 132 | { |
198 | int rc; | 133 | int rc; |
199 | 134 | ||
200 | rc = class_register(&wpan_phy_class); | 135 | rc = wpan_phy_sysfs_init(); |
201 | if (rc) | 136 | if (rc) |
202 | goto err; | 137 | goto err; |
203 | 138 | ||
@@ -207,7 +142,7 @@ static int __init wpan_phy_class_init(void) | |||
207 | 142 | ||
208 | return 0; | 143 | return 0; |
209 | err_nl: | 144 | err_nl: |
210 | class_unregister(&wpan_phy_class); | 145 | wpan_phy_sysfs_exit(); |
211 | err: | 146 | err: |
212 | return rc; | 147 | return rc; |
213 | } | 148 | } |
@@ -216,7 +151,7 @@ subsys_initcall(wpan_phy_class_init); | |||
216 | static void __exit wpan_phy_class_exit(void) | 151 | static void __exit wpan_phy_class_exit(void) |
217 | { | 152 | { |
218 | ieee802154_nl_exit(); | 153 | ieee802154_nl_exit(); |
219 | class_unregister(&wpan_phy_class); | 154 | wpan_phy_sysfs_exit(); |
220 | } | 155 | } |
221 | module_exit(wpan_phy_class_exit); | 156 | module_exit(wpan_phy_class_exit); |
222 | 157 | ||
diff --git a/net/ieee802154/sysfs.c b/net/ieee802154/sysfs.c new file mode 100644 index 000000000000..eb9ca6f99122 --- /dev/null +++ b/net/ieee802154/sysfs.c | |||
@@ -0,0 +1,94 @@ | |||
1 | /* 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...) \ | ||
21 | static 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 | } \ | ||
32 | static DEVICE_ATTR_RO(name) | ||
33 | |||
34 | #define MASTER_SHOW(field, format_string) \ | ||
35 | MASTER_SHOW_COMPLEX(field, format_string, phy->field) | ||
36 | |||
37 | MASTER_SHOW(current_channel, "%d"); | ||
38 | MASTER_SHOW(current_page, "%d"); | ||
39 | MASTER_SHOW(transmit_power, "%d +- 1 dB"); | ||
40 | MASTER_SHOW(cca_mode, "%d"); | ||
41 | |||
42 | static 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 | } | ||
61 | static DEVICE_ATTR_RO(channels_supported); | ||
62 | |||
63 | static 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 | |||
70 | static 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 | }; | ||
78 | ATTRIBUTE_GROUPS(pmib); | ||
79 | |||
80 | struct class wpan_phy_class = { | ||
81 | .name = "ieee802154", | ||
82 | .dev_release = wpan_phy_release, | ||
83 | .dev_groups = pmib_groups, | ||
84 | }; | ||
85 | |||
86 | int wpan_phy_sysfs_init(void) | ||
87 | { | ||
88 | return class_register(&wpan_phy_class); | ||
89 | } | ||
90 | |||
91 | void wpan_phy_sysfs_exit(void) | ||
92 | { | ||
93 | class_unregister(&wpan_phy_class); | ||
94 | } | ||
diff --git a/net/ieee802154/sysfs.h b/net/ieee802154/sysfs.h new file mode 100644 index 000000000000..aa42e39ecbec --- /dev/null +++ b/net/ieee802154/sysfs.h | |||
@@ -0,0 +1,9 @@ | |||
1 | #ifndef __IEEE802154_SYSFS_H | ||
2 | #define __IEEE802154_SYSFS_H | ||
3 | |||
4 | int wpan_phy_sysfs_init(void); | ||
5 | void wpan_phy_sysfs_exit(void); | ||
6 | |||
7 | extern struct class wpan_phy_class; | ||
8 | |||
9 | #endif /* __IEEE802154_SYSFS_H */ | ||