diff options
Diffstat (limited to 'net/ieee802154/wpan-class.c')
-rw-r--r-- | net/ieee802154/wpan-class.c | 75 |
1 files changed, 68 insertions, 7 deletions
diff --git a/net/ieee802154/wpan-class.c b/net/ieee802154/wpan-class.c index f306604da67a..268691256a6d 100644 --- a/net/ieee802154/wpan-class.c +++ b/net/ieee802154/wpan-class.c | |||
@@ -22,6 +22,8 @@ | |||
22 | 22 | ||
23 | #include <net/wpan-phy.h> | 23 | #include <net/wpan-phy.h> |
24 | 24 | ||
25 | #include "ieee802154.h" | ||
26 | |||
25 | #define MASTER_SHOW_COMPLEX(name, format_string, args...) \ | 27 | #define MASTER_SHOW_COMPLEX(name, format_string, args...) \ |
26 | static ssize_t name ## _show(struct device *dev, \ | 28 | static ssize_t name ## _show(struct device *dev, \ |
27 | struct device_attribute *attr, char *buf) \ | 29 | struct device_attribute *attr, char *buf) \ |
@@ -30,7 +32,7 @@ static ssize_t name ## _show(struct device *dev, \ | |||
30 | int ret; \ | 32 | int ret; \ |
31 | \ | 33 | \ |
32 | mutex_lock(&phy->pib_lock); \ | 34 | mutex_lock(&phy->pib_lock); \ |
33 | ret = sprintf(buf, format_string "\n", args); \ | 35 | ret = snprintf(buf, PAGE_SIZE, format_string "\n", args); \ |
34 | mutex_unlock(&phy->pib_lock); \ | 36 | mutex_unlock(&phy->pib_lock); \ |
35 | return ret; \ | 37 | return ret; \ |
36 | } | 38 | } |
@@ -40,12 +42,30 @@ static ssize_t name ## _show(struct device *dev, \ | |||
40 | 42 | ||
41 | MASTER_SHOW(current_channel, "%d"); | 43 | MASTER_SHOW(current_channel, "%d"); |
42 | MASTER_SHOW(current_page, "%d"); | 44 | MASTER_SHOW(current_page, "%d"); |
43 | MASTER_SHOW(channels_supported, "%#x"); | ||
44 | MASTER_SHOW_COMPLEX(transmit_power, "%d +- %d dB", | 45 | MASTER_SHOW_COMPLEX(transmit_power, "%d +- %d dB", |
45 | ((signed char) (phy->transmit_power << 2)) >> 2, | 46 | ((signed char) (phy->transmit_power << 2)) >> 2, |
46 | (phy->transmit_power >> 6) ? (phy->transmit_power >> 6) * 3 : 1 ); | 47 | (phy->transmit_power >> 6) ? (phy->transmit_power >> 6) * 3 : 1 ); |
47 | MASTER_SHOW(cca_mode, "%d"); | 48 | MASTER_SHOW(cca_mode, "%d"); |
48 | 49 | ||
50 | static ssize_t channels_supported_show(struct device *dev, | ||
51 | struct device_attribute *attr, char *buf) | ||
52 | { | ||
53 | struct wpan_phy *phy = container_of(dev, struct wpan_phy, dev); | ||
54 | int ret; | ||
55 | int i, len = 0; | ||
56 | |||
57 | mutex_lock(&phy->pib_lock); | ||
58 | for (i = 0; i < 32; i++) { | ||
59 | ret = snprintf(buf + len, PAGE_SIZE - len, | ||
60 | "%#09x\n", phy->channels_supported[i]); | ||
61 | if (ret < 0) | ||
62 | break; | ||
63 | len += ret; | ||
64 | } | ||
65 | mutex_unlock(&phy->pib_lock); | ||
66 | return len; | ||
67 | } | ||
68 | |||
49 | static struct device_attribute pmib_attrs[] = { | 69 | static struct device_attribute pmib_attrs[] = { |
50 | __ATTR_RO(current_channel), | 70 | __ATTR_RO(current_channel), |
51 | __ATTR_RO(current_page), | 71 | __ATTR_RO(current_page), |
@@ -91,6 +111,31 @@ struct wpan_phy *wpan_phy_find(const char *str) | |||
91 | } | 111 | } |
92 | EXPORT_SYMBOL(wpan_phy_find); | 112 | EXPORT_SYMBOL(wpan_phy_find); |
93 | 113 | ||
114 | struct wpan_phy_iter_data { | ||
115 | int (*fn)(struct wpan_phy *phy, void *data); | ||
116 | void *data; | ||
117 | }; | ||
118 | |||
119 | static int wpan_phy_iter(struct device *dev, void *_data) | ||
120 | { | ||
121 | struct wpan_phy_iter_data *wpid = _data; | ||
122 | struct wpan_phy *phy = container_of(dev, struct wpan_phy, dev); | ||
123 | return wpid->fn(phy, wpid->data); | ||
124 | } | ||
125 | |||
126 | int wpan_phy_for_each(int (*fn)(struct wpan_phy *phy, void *data), | ||
127 | void *data) | ||
128 | { | ||
129 | struct wpan_phy_iter_data wpid = { | ||
130 | .fn = fn, | ||
131 | .data = data, | ||
132 | }; | ||
133 | |||
134 | return class_for_each_device(&wpan_phy_class, NULL, | ||
135 | &wpid, wpan_phy_iter); | ||
136 | } | ||
137 | EXPORT_SYMBOL(wpan_phy_for_each); | ||
138 | |||
94 | static int wpan_phy_idx_valid(int idx) | 139 | static int wpan_phy_idx_valid(int idx) |
95 | { | 140 | { |
96 | return idx >= 0; | 141 | return idx >= 0; |
@@ -118,14 +163,15 @@ struct wpan_phy *wpan_phy_alloc(size_t priv_size) | |||
118 | 163 | ||
119 | phy->dev.class = &wpan_phy_class; | 164 | phy->dev.class = &wpan_phy_class; |
120 | 165 | ||
166 | phy->current_channel = -1; /* not initialised */ | ||
167 | phy->current_page = 0; /* for compatibility */ | ||
168 | |||
121 | return phy; | 169 | return phy; |
122 | } | 170 | } |
123 | EXPORT_SYMBOL(wpan_phy_alloc); | 171 | EXPORT_SYMBOL(wpan_phy_alloc); |
124 | 172 | ||
125 | int wpan_phy_register(struct device *parent, struct wpan_phy *phy) | 173 | int wpan_phy_register(struct wpan_phy *phy) |
126 | { | 174 | { |
127 | phy->dev.parent = parent; | ||
128 | |||
129 | return device_add(&phy->dev); | 175 | return device_add(&phy->dev); |
130 | } | 176 | } |
131 | EXPORT_SYMBOL(wpan_phy_register); | 177 | EXPORT_SYMBOL(wpan_phy_register); |
@@ -144,16 +190,31 @@ EXPORT_SYMBOL(wpan_phy_free); | |||
144 | 190 | ||
145 | static int __init wpan_phy_class_init(void) | 191 | static int __init wpan_phy_class_init(void) |
146 | { | 192 | { |
147 | return class_register(&wpan_phy_class); | 193 | int rc; |
194 | rc = class_register(&wpan_phy_class); | ||
195 | if (rc) | ||
196 | goto err; | ||
197 | |||
198 | rc = ieee802154_nl_init(); | ||
199 | if (rc) | ||
200 | goto err_nl; | ||
201 | |||
202 | return 0; | ||
203 | err_nl: | ||
204 | class_unregister(&wpan_phy_class); | ||
205 | err: | ||
206 | return rc; | ||
148 | } | 207 | } |
149 | subsys_initcall(wpan_phy_class_init); | 208 | subsys_initcall(wpan_phy_class_init); |
150 | 209 | ||
151 | static void __exit wpan_phy_class_exit(void) | 210 | static void __exit wpan_phy_class_exit(void) |
152 | { | 211 | { |
212 | ieee802154_nl_exit(); | ||
153 | class_unregister(&wpan_phy_class); | 213 | class_unregister(&wpan_phy_class); |
154 | } | 214 | } |
155 | module_exit(wpan_phy_class_exit); | 215 | module_exit(wpan_phy_class_exit); |
156 | 216 | ||
157 | MODULE_DESCRIPTION("IEEE 802.15.4 device class"); | ||
158 | MODULE_LICENSE("GPL v2"); | 217 | MODULE_LICENSE("GPL v2"); |
218 | MODULE_DESCRIPTION("IEEE 802.15.4 configuration interface"); | ||
219 | MODULE_AUTHOR("Dmitry Eremin-Solenikov"); | ||
159 | 220 | ||