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