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 <linux/gfp.h>
27 #include <net/genetlink.h>
28 #include <linux/nl802154.h>
30 #include "ieee802154.h"
32 static unsigned int ieee802154_seq_num
;
33 static DEFINE_SPINLOCK(ieee802154_seq_lock
);
35 struct genl_family nl802154_family
= {
36 .id
= GENL_ID_GENERATE
,
38 .name
= IEEE802154_NL_NAME
,
40 .maxattr
= IEEE802154_ATTR_MAX
,
43 /* Requests to userspace */
44 struct sk_buff
*ieee802154_nl_create(int flags
, u8 req
)
47 struct sk_buff
*msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_ATOMIC
);
53 spin_lock_irqsave(&ieee802154_seq_lock
, f
);
54 hdr
= genlmsg_put(msg
, 0, ieee802154_seq_num
++,
55 &nl802154_family
, flags
, req
);
56 spin_unlock_irqrestore(&ieee802154_seq_lock
, f
);
65 int ieee802154_nl_mcast(struct sk_buff
*msg
, unsigned int group
)
67 struct nlmsghdr
*nlh
= nlmsg_hdr(msg
);
68 void *hdr
= genlmsg_data(nlmsg_data(nlh
));
70 if (genlmsg_end(msg
, hdr
) < 0)
73 return genlmsg_multicast(&nl802154_family
, msg
, 0, group
, GFP_ATOMIC
);
79 struct sk_buff
*ieee802154_nl_new_reply(struct genl_info
*info
,
83 struct sk_buff
*msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_ATOMIC
);
88 hdr
= genlmsg_put_reply(msg
, info
,
89 &nl802154_family
, flags
, req
);
98 int ieee802154_nl_reply(struct sk_buff
*msg
, struct genl_info
*info
)
100 struct nlmsghdr
*nlh
= nlmsg_hdr(msg
);
101 void *hdr
= genlmsg_data(nlmsg_data(nlh
));
103 if (genlmsg_end(msg
, hdr
) < 0)
106 return genlmsg_reply(msg
, info
);
112 static const struct genl_ops ieee8021154_ops
[] = {
114 IEEE802154_DUMP(IEEE802154_LIST_PHY
, ieee802154_list_phy
,
115 ieee802154_dump_phy
),
116 IEEE802154_OP(IEEE802154_ADD_IFACE
, ieee802154_add_iface
),
117 IEEE802154_OP(IEEE802154_DEL_IFACE
, ieee802154_del_iface
),
119 IEEE802154_OP(IEEE802154_ASSOCIATE_REQ
, ieee802154_associate_req
),
120 IEEE802154_OP(IEEE802154_ASSOCIATE_RESP
, ieee802154_associate_resp
),
121 IEEE802154_OP(IEEE802154_DISASSOCIATE_REQ
, ieee802154_disassociate_req
),
122 IEEE802154_OP(IEEE802154_SCAN_REQ
, ieee802154_scan_req
),
123 IEEE802154_OP(IEEE802154_START_REQ
, ieee802154_start_req
),
124 IEEE802154_DUMP(IEEE802154_LIST_IFACE
, ieee802154_list_iface
,
125 ieee802154_dump_iface
),
128 static const struct genl_multicast_group ieee802154_mcgrps
[] = {
129 [IEEE802154_COORD_MCGRP
] = { .name
= IEEE802154_MCAST_COORD_NAME
, },
130 [IEEE802154_BEACON_MCGRP
] = { .name
= IEEE802154_MCAST_BEACON_NAME
, },
134 int __init
ieee802154_nl_init(void)
136 return genl_register_family_with_ops_groups(&nl802154_family
,
141 void __exit
ieee802154_nl_exit(void)
143 genl_unregister_family(&nl802154_family
);