2 * Netlink inteface for IEEE 802.15.4 stack
4 * Copyright 2007, 2008 Siemens AG
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.
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.
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.
20 * Sergey Lapin <slapin@ossfans.org>
21 * Dmitry Eremin-Solenikov <dbaryshkov@gmail.com>
22 * Maxim Osipov <maxim.osipov@siemens.com>
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>
31 #include "ieee802154.h"
33 static int ieee802154_nl_fill_phy(struct sk_buff *msg, u32 pid,
34 u32 seq, int flags, struct wpan_phy *phy)
38 uint32_t *buf = kzalloc(32 * sizeof(uint32_t), GFP_KERNEL);
40 pr_debug("%s\n", __func__);
45 hdr = genlmsg_put(msg, 0, seq, &nl802154_family, flags,
50 mutex_lock(&phy->pib_lock);
51 NLA_PUT_STRING(msg, IEEE802154_ATTR_PHY_NAME, wpan_phy_name(phy));
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);
60 NLA_PUT(msg, IEEE802154_ATTR_CHANNEL_PAGE_LIST,
61 pages * sizeof(uint32_t), buf);
63 mutex_unlock(&phy->pib_lock);
64 return genlmsg_end(msg, hdr);
67 mutex_unlock(&phy->pib_lock);
68 genlmsg_cancel(msg, hdr);
74 static int ieee802154_list_phy(struct sk_buff *skb,
75 struct genl_info *info)
77 /* Request for interface name, index, type, IEEE address,
78 PAN Id, short address */
84 pr_debug("%s\n", __func__);
86 if (!info->attrs[IEEE802154_ATTR_PHY_NAME])
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 */
94 phy = wpan_phy_find(name);
98 msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL);
102 rc = ieee802154_nl_fill_phy(msg, info->snd_pid, info->snd_seq,
109 return genlmsg_reply(msg, info);
118 struct dump_phy_data {
120 struct netlink_callback *cb;
124 static int ieee802154_dump_phy_iter(struct wpan_phy *phy, void *_data)
127 struct dump_phy_data *data = _data;
129 pr_debug("%s\n", __func__);
131 if (data->idx++ < data->s_idx)
134 rc = ieee802154_nl_fill_phy(data->skb,
135 NETLINK_CB(data->cb->skb).pid,
136 data->cb->nlh->nlmsg_seq,
148 static int ieee802154_dump_phy(struct sk_buff *skb,
149 struct netlink_callback *cb)
151 struct dump_phy_data data = {
154 .s_idx = cb->args[0],
158 pr_debug("%s\n", __func__);
160 wpan_phy_for_each(ieee802154_dump_phy_iter, &data);
162 cb->args[0] = data.idx;
167 static struct genl_ops ieee802154_phy_ops[] = {
168 IEEE802154_DUMP(IEEE802154_LIST_PHY, ieee802154_list_phy,
169 ieee802154_dump_phy),
173 * No need to unregister as family unregistration will do it.
175 int nl802154_phy_register(void)
180 for (i = 0; i < ARRAY_SIZE(ieee802154_phy_ops); i++) {
181 rc = genl_register_ops(&nl802154_family,
182 &ieee802154_phy_ops[i]);