diff options
author | Dmitry Eremin-Solenikov <dbaryshkov@gmail.com> | 2009-09-15 09:04:44 -0400 |
---|---|---|
committer | Dmitry Eremin-Solenikov <dbaryshkov@gmail.com> | 2009-11-06 06:31:22 -0500 |
commit | 1eaa9d03d3ee9156c8c405b006ce892ae28290ad (patch) | |
tree | ec8da53b28c8e88e894152e36864afbd14b44139 /net/ieee802154 | |
parent | 78fe738d1a631ec34a29d830880e38f5c14c1371 (diff) |
ieee802154: add LIST_PHY command support
Add nl802154 command to get information about PHY's present in
the system.
Signed-off-by: Dmitry Eremin-Solenikov <dbaryshkov@gmail.com>
Diffstat (limited to 'net/ieee802154')
-rw-r--r-- | net/ieee802154/Makefile | 2 | ||||
-rw-r--r-- | net/ieee802154/netlink.c | 4 | ||||
-rw-r--r-- | net/ieee802154/nl-phy.c | 188 | ||||
-rw-r--r-- | net/ieee802154/nl_policy.c | 2 |
4 files changed, 195 insertions, 1 deletions
diff --git a/net/ieee802154/Makefile b/net/ieee802154/Makefile index 69af9f6a404b..ce2d33582859 100644 --- a/net/ieee802154/Makefile +++ b/net/ieee802154/Makefile | |||
@@ -1,5 +1,5 @@ | |||
1 | obj-$(CONFIG_IEEE802154) += ieee802154.o af_802154.o | 1 | obj-$(CONFIG_IEEE802154) += ieee802154.o af_802154.o |
2 | ieee802154-y := netlink.o nl-mac.o nl_policy.o wpan-class.o | 2 | ieee802154-y := netlink.o nl-mac.o nl-phy.o nl_policy.o wpan-class.o |
3 | af_802154-y := af_ieee802154.o raw.o dgram.o | 3 | af_802154-y := af_ieee802154.o raw.o dgram.o |
4 | 4 | ||
5 | ccflags-y += -Wall -DDEBUG | 5 | ccflags-y += -Wall -DDEBUG |
diff --git a/net/ieee802154/netlink.c b/net/ieee802154/netlink.c index 5b738ec7d9f1..8a221737f75c 100644 --- a/net/ieee802154/netlink.c +++ b/net/ieee802154/netlink.c | |||
@@ -87,6 +87,10 @@ int __init ieee802154_nl_init(void) | |||
87 | if (rc) | 87 | if (rc) |
88 | goto fail; | 88 | goto fail; |
89 | 89 | ||
90 | rc = nl802154_phy_register(); | ||
91 | if (rc) | ||
92 | goto fail; | ||
93 | |||
90 | return 0; | 94 | return 0; |
91 | 95 | ||
92 | fail: | 96 | fail: |
diff --git a/net/ieee802154/nl-phy.c b/net/ieee802154/nl-phy.c new file mode 100644 index 000000000000..b7af722eb784 --- /dev/null +++ b/net/ieee802154/nl-phy.c | |||
@@ -0,0 +1,188 @@ | |||
1 | /* | ||
2 | * Netlink inteface for IEEE 802.15.4 stack | ||
3 | * | ||
4 | * Copyright 2007, 2008 Siemens AG | ||
5 | * | ||
6 | * This program is free software; you can redistribute it and/or modify | ||
7 | * it under the terms of the GNU General Public License version 2 | ||
8 | * as published by the Free Software Foundation. | ||
9 | * | ||
10 | * This program is distributed in the hope that it will be useful, | ||
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
13 | * GNU General Public License for more details. | ||
14 | * | ||
15 | * You should have received a copy of the GNU General Public License along | ||
16 | * with this program; if not, write to the Free Software Foundation, Inc., | ||
17 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | ||
18 | * | ||
19 | * Written by: | ||
20 | * Sergey Lapin <slapin@ossfans.org> | ||
21 | * Dmitry Eremin-Solenikov <dbaryshkov@gmail.com> | ||
22 | * Maxim Osipov <maxim.osipov@siemens.com> | ||
23 | */ | ||
24 | |||
25 | #include <linux/kernel.h> | ||
26 | #include <net/netlink.h> | ||
27 | #include <net/genetlink.h> | ||
28 | #include <net/wpan-phy.h> | ||
29 | #include <linux/nl802154.h> | ||
30 | |||
31 | #include "ieee802154.h" | ||
32 | |||
33 | static int ieee802154_nl_fill_phy(struct sk_buff *msg, u32 pid, | ||
34 | u32 seq, int flags, struct wpan_phy *phy) | ||
35 | { | ||
36 | void *hdr; | ||
37 | int i, pages = 0; | ||
38 | uint32_t *buf = kzalloc(32 * sizeof(uint32_t), GFP_KERNEL); | ||
39 | |||
40 | pr_debug("%s\n", __func__); | ||
41 | |||
42 | if (!buf) | ||
43 | goto out; | ||
44 | |||
45 | hdr = genlmsg_put(msg, 0, seq, &nl802154_family, flags, | ||
46 | IEEE802154_LIST_PHY); | ||
47 | if (!hdr) | ||
48 | goto out; | ||
49 | |||
50 | mutex_lock(&phy->pib_lock); | ||
51 | NLA_PUT_STRING(msg, IEEE802154_ATTR_PHY_NAME, wpan_phy_name(phy)); | ||
52 | |||
53 | NLA_PUT_U8(msg, IEEE802154_ATTR_PAGE, phy->current_page); | ||
54 | NLA_PUT_U8(msg, IEEE802154_ATTR_CHANNEL, phy->current_channel); | ||
55 | for (i = 0; i < 32; i++) { | ||
56 | if (phy->channels_supported[i]) | ||
57 | buf[pages++] = phy->channels_supported[i] | (i << 27); | ||
58 | } | ||
59 | if (pages) | ||
60 | NLA_PUT(msg, IEEE802154_ATTR_CHANNEL_PAGE_LIST, | ||
61 | pages * sizeof(uint32_t), buf); | ||
62 | |||
63 | mutex_unlock(&phy->pib_lock); | ||
64 | return genlmsg_end(msg, hdr); | ||
65 | |||
66 | nla_put_failure: | ||
67 | mutex_unlock(&phy->pib_lock); | ||
68 | genlmsg_cancel(msg, hdr); | ||
69 | out: | ||
70 | kfree(buf); | ||
71 | return -EMSGSIZE; | ||
72 | } | ||
73 | |||
74 | static int ieee802154_list_phy(struct sk_buff *skb, | ||
75 | struct genl_info *info) | ||
76 | { | ||
77 | /* Request for interface name, index, type, IEEE address, | ||
78 | PAN Id, short address */ | ||
79 | struct sk_buff *msg; | ||
80 | struct wpan_phy *phy; | ||
81 | const char *name; | ||
82 | int rc = -ENOBUFS; | ||
83 | |||
84 | pr_debug("%s\n", __func__); | ||
85 | |||
86 | if (!info->attrs[IEEE802154_ATTR_PHY_NAME]) | ||
87 | return -EINVAL; | ||
88 | |||
89 | name = nla_data(info->attrs[IEEE802154_ATTR_PHY_NAME]); | ||
90 | if (name[nla_len(info->attrs[IEEE802154_ATTR_PHY_NAME]) - 1] != '\0') | ||
91 | return -EINVAL; /* phy name should be null-terminated */ | ||
92 | |||
93 | |||
94 | phy = wpan_phy_find(name); | ||
95 | if (!phy) | ||
96 | return -ENODEV; | ||
97 | |||
98 | msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL); | ||
99 | if (!msg) | ||
100 | goto out_dev; | ||
101 | |||
102 | rc = ieee802154_nl_fill_phy(msg, info->snd_pid, info->snd_seq, | ||
103 | 0, phy); | ||
104 | if (rc < 0) | ||
105 | goto out_free; | ||
106 | |||
107 | wpan_phy_put(phy); | ||
108 | |||
109 | return genlmsg_reply(msg, info); | ||
110 | out_free: | ||
111 | nlmsg_free(msg); | ||
112 | out_dev: | ||
113 | wpan_phy_put(phy); | ||
114 | return rc; | ||
115 | |||
116 | } | ||
117 | |||
118 | struct dump_phy_data { | ||
119 | struct sk_buff *skb; | ||
120 | struct netlink_callback *cb; | ||
121 | int idx, s_idx; | ||
122 | }; | ||
123 | |||
124 | static int ieee802154_dump_phy_iter(struct wpan_phy *phy, void *_data) | ||
125 | { | ||
126 | int rc; | ||
127 | struct dump_phy_data *data = _data; | ||
128 | |||
129 | pr_debug("%s\n", __func__); | ||
130 | |||
131 | if (data->idx++ < data->s_idx) | ||
132 | return 0; | ||
133 | |||
134 | rc = ieee802154_nl_fill_phy(data->skb, | ||
135 | NETLINK_CB(data->cb->skb).pid, | ||
136 | data->cb->nlh->nlmsg_seq, | ||
137 | NLM_F_MULTI, | ||
138 | phy); | ||
139 | |||
140 | if (rc < 0) { | ||
141 | data->idx--; | ||
142 | return rc; | ||
143 | } | ||
144 | |||
145 | return 0; | ||
146 | } | ||
147 | |||
148 | static int ieee802154_dump_phy(struct sk_buff *skb, | ||
149 | struct netlink_callback *cb) | ||
150 | { | ||
151 | struct dump_phy_data data = { | ||
152 | .cb = cb, | ||
153 | .skb = skb, | ||
154 | .s_idx = cb->args[0], | ||
155 | .idx = 0, | ||
156 | }; | ||
157 | |||
158 | pr_debug("%s\n", __func__); | ||
159 | |||
160 | wpan_phy_for_each(ieee802154_dump_phy_iter, &data); | ||
161 | |||
162 | cb->args[0] = data.idx; | ||
163 | |||
164 | return skb->len; | ||
165 | } | ||
166 | |||
167 | static struct genl_ops ieee802154_phy_ops[] = { | ||
168 | IEEE802154_DUMP(IEEE802154_LIST_PHY, ieee802154_list_phy, | ||
169 | ieee802154_dump_phy), | ||
170 | }; | ||
171 | |||
172 | /* | ||
173 | * No need to unregister as family unregistration will do it. | ||
174 | */ | ||
175 | int nl802154_phy_register(void) | ||
176 | { | ||
177 | int i; | ||
178 | int rc; | ||
179 | |||
180 | for (i = 0; i < ARRAY_SIZE(ieee802154_phy_ops); i++) { | ||
181 | rc = genl_register_ops(&nl802154_family, | ||
182 | &ieee802154_phy_ops[i]); | ||
183 | if (rc) | ||
184 | return rc; | ||
185 | } | ||
186 | |||
187 | return 0; | ||
188 | } | ||
diff --git a/net/ieee802154/nl_policy.c b/net/ieee802154/nl_policy.c index 2363ebee02e7..6adda4d46f95 100644 --- a/net/ieee802154/nl_policy.c +++ b/net/ieee802154/nl_policy.c | |||
@@ -27,6 +27,7 @@ | |||
27 | const struct nla_policy ieee802154_policy[IEEE802154_ATTR_MAX + 1] = { | 27 | const struct nla_policy ieee802154_policy[IEEE802154_ATTR_MAX + 1] = { |
28 | [IEEE802154_ATTR_DEV_NAME] = { .type = NLA_STRING, }, | 28 | [IEEE802154_ATTR_DEV_NAME] = { .type = NLA_STRING, }, |
29 | [IEEE802154_ATTR_DEV_INDEX] = { .type = NLA_U32, }, | 29 | [IEEE802154_ATTR_DEV_INDEX] = { .type = NLA_U32, }, |
30 | [IEEE802154_ATTR_PHY_NAME] = { .type = NLA_STRING, }, | ||
30 | 31 | ||
31 | [IEEE802154_ATTR_STATUS] = { .type = NLA_U8, }, | 32 | [IEEE802154_ATTR_STATUS] = { .type = NLA_U8, }, |
32 | [IEEE802154_ATTR_SHORT_ADDR] = { .type = NLA_U16, }, | 33 | [IEEE802154_ATTR_SHORT_ADDR] = { .type = NLA_U16, }, |
@@ -50,5 +51,6 @@ const struct nla_policy ieee802154_policy[IEEE802154_ATTR_MAX + 1] = { | |||
50 | [IEEE802154_ATTR_CHANNELS] = { .type = NLA_U32, }, | 51 | [IEEE802154_ATTR_CHANNELS] = { .type = NLA_U32, }, |
51 | [IEEE802154_ATTR_DURATION] = { .type = NLA_U8, }, | 52 | [IEEE802154_ATTR_DURATION] = { .type = NLA_U8, }, |
52 | [IEEE802154_ATTR_ED_LIST] = { .len = 27 }, | 53 | [IEEE802154_ATTR_ED_LIST] = { .len = 27 }, |
54 | [IEEE802154_ATTR_CHANNEL_PAGE_LIST] = { .len = 32 * 4, }, | ||
53 | }; | 55 | }; |
54 | 56 | ||