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/genetlink.h>
27 #include <linux/nl802154.h>
29 #include "ieee802154.h"
31 static unsigned int ieee802154_seq_num
;
32 static DEFINE_SPINLOCK(ieee802154_seq_lock
);
34 struct genl_family nl802154_family
= {
35 .id
= GENL_ID_GENERATE
,
37 .name
= IEEE802154_NL_NAME
,
39 .maxattr
= IEEE802154_ATTR_MAX
,
42 /* Requests to userspace */
43 struct sk_buff
*ieee802154_nl_create(int flags
, u8 req
)
46 struct sk_buff
*msg
= nlmsg_new(NLMSG_GOODSIZE
, GFP_ATOMIC
);
52 spin_lock_irqsave(&ieee802154_seq_lock
, f
);
53 hdr
= genlmsg_put(msg
, 0, ieee802154_seq_num
++,
54 &nl802154_family
, flags
, req
);
55 spin_unlock_irqrestore(&ieee802154_seq_lock
, f
);
64 int ieee802154_nl_mcast(struct sk_buff
*msg
, unsigned int group
)
66 /* XXX: nlh is right at the start of msg */
67 void *hdr
= genlmsg_data(NLMSG_DATA(msg
->data
));
69 if (genlmsg_end(msg
, hdr
) < 0)
72 return genlmsg_multicast(msg
, 0, group
, GFP_ATOMIC
);
78 struct sk_buff
*ieee802154_nl_new_reply(struct genl_info
*info
,
82 struct sk_buff
*msg
= nlmsg_new(NLMSG_GOODSIZE
, GFP_ATOMIC
);
87 hdr
= genlmsg_put_reply(msg
, info
,
88 &nl802154_family
, flags
, req
);
97 int ieee802154_nl_reply(struct sk_buff
*msg
, struct genl_info
*info
)
99 /* XXX: nlh is right at the start of msg */
100 void *hdr
= genlmsg_data(NLMSG_DATA(msg
->data
));
102 if (genlmsg_end(msg
, hdr
) < 0)
105 return genlmsg_reply(msg
, info
);
111 int __init
ieee802154_nl_init(void)
115 rc
= genl_register_family(&nl802154_family
);
119 rc
= nl802154_mac_register();
123 rc
= nl802154_phy_register();
130 genl_unregister_family(&nl802154_family
);
134 void __exit
ieee802154_nl_exit(void)
136 genl_unregister_family(&nl802154_family
);