Commit | Line | Data |
---|---|---|
e23e9ec1 AA |
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 | ||
a5dd1d72 | 20 | #include "core.h" |
c5fbbc46 | 21 | #include "sysfs.h" |
a5dd1d72 AA |
22 | |
23 | static inline struct cfg802154_registered_device * | |
24 | dev_to_rdev(struct device *dev) | |
25 | { | |
26 | return container_of(dev, struct cfg802154_registered_device, | |
27 | wpan_phy.dev); | |
28 | } | |
29 | ||
e23e9ec1 AA |
30 | #define MASTER_SHOW_COMPLEX(name, format_string, args...) \ |
31 | static ssize_t name ## _show(struct device *dev, \ | |
32 | struct device_attribute *attr, char *buf) \ | |
33 | { \ | |
34 | struct wpan_phy *phy = container_of(dev, struct wpan_phy, dev); \ | |
35 | int ret; \ | |
36 | \ | |
37 | mutex_lock(&phy->pib_lock); \ | |
38 | ret = snprintf(buf, PAGE_SIZE, format_string "\n", args); \ | |
39 | mutex_unlock(&phy->pib_lock); \ | |
40 | return ret; \ | |
41 | } \ | |
42 | static DEVICE_ATTR_RO(name) | |
43 | ||
44 | #define MASTER_SHOW(field, format_string) \ | |
45 | MASTER_SHOW_COMPLEX(field, format_string, phy->field) | |
46 | ||
47 | MASTER_SHOW(current_channel, "%d"); | |
48 | MASTER_SHOW(current_page, "%d"); | |
49 | MASTER_SHOW(transmit_power, "%d +- 1 dB"); | |
50 | MASTER_SHOW(cca_mode, "%d"); | |
51 | ||
52 | static ssize_t channels_supported_show(struct device *dev, | |
53 | struct device_attribute *attr, | |
54 | char *buf) | |
55 | { | |
56 | struct wpan_phy *phy = container_of(dev, struct wpan_phy, dev); | |
57 | int ret; | |
58 | int i, len = 0; | |
59 | ||
60 | mutex_lock(&phy->pib_lock); | |
61 | for (i = 0; i < 32; i++) { | |
62 | ret = snprintf(buf + len, PAGE_SIZE - len, | |
63 | "%#09x\n", phy->channels_supported[i]); | |
64 | if (ret < 0) | |
65 | break; | |
66 | len += ret; | |
67 | } | |
68 | mutex_unlock(&phy->pib_lock); | |
69 | return len; | |
70 | } | |
71 | static DEVICE_ATTR_RO(channels_supported); | |
72 | ||
a5dd1d72 | 73 | static void wpan_phy_release(struct device *dev) |
e23e9ec1 | 74 | { |
a5dd1d72 | 75 | struct cfg802154_registered_device *rdev = dev_to_rdev(dev); |
e23e9ec1 | 76 | |
a5dd1d72 | 77 | cfg802154_dev_free(rdev); |
e23e9ec1 AA |
78 | } |
79 | ||
80 | static struct attribute *pmib_attrs[] = { | |
81 | &dev_attr_current_channel.attr, | |
82 | &dev_attr_current_page.attr, | |
83 | &dev_attr_channels_supported.attr, | |
84 | &dev_attr_transmit_power.attr, | |
85 | &dev_attr_cca_mode.attr, | |
86 | NULL, | |
87 | }; | |
88 | ATTRIBUTE_GROUPS(pmib); | |
89 | ||
90 | struct class wpan_phy_class = { | |
91 | .name = "ieee802154", | |
92 | .dev_release = wpan_phy_release, | |
93 | .dev_groups = pmib_groups, | |
94 | }; | |
95 | ||
96 | int wpan_phy_sysfs_init(void) | |
97 | { | |
98 | return class_register(&wpan_phy_class); | |
99 | } | |
100 | ||
101 | void wpan_phy_sysfs_exit(void) | |
102 | { | |
103 | class_unregister(&wpan_phy_class); | |
104 | } |