Merge branch 'topic/omap3isp' of git://git.kernel.org/pub/scm/linux/kernel/git/mcheha...
[deliverable/linux.git] / net / ieee802154 / netlink.c
CommitLineData
2c21d115
SL
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>
8e753dd0 22 * Maxim Osipov <maxim.osipov@siemens.com>
2c21d115
SL
23 */
24
25#include <linux/kernel.h>
5a0e3ad6 26#include <linux/gfp.h>
2c21d115
SL
27#include <net/genetlink.h>
28#include <linux/nl802154.h>
78fe738d
DES
29
30#include "ieee802154.h"
2c21d115
SL
31
32static unsigned int ieee802154_seq_num;
c4835d81 33static DEFINE_SPINLOCK(ieee802154_seq_lock);
2c21d115 34
78fe738d 35struct genl_family nl802154_family = {
2c21d115
SL
36 .id = GENL_ID_GENERATE,
37 .hdrsize = 0,
38 .name = IEEE802154_NL_NAME,
39 .version = 1,
40 .maxattr = IEEE802154_ATTR_MAX,
41};
42
2c21d115 43/* Requests to userspace */
78fe738d 44struct sk_buff *ieee802154_nl_create(int flags, u8 req)
2c21d115
SL
45{
46 void *hdr;
58050fce 47 struct sk_buff *msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC);
c4835d81 48 unsigned long f;
2c21d115
SL
49
50 if (!msg)
51 return NULL;
52
c4835d81 53 spin_lock_irqsave(&ieee802154_seq_lock, f);
2c21d115 54 hdr = genlmsg_put(msg, 0, ieee802154_seq_num++,
78fe738d 55 &nl802154_family, flags, req);
c4835d81 56 spin_unlock_irqrestore(&ieee802154_seq_lock, f);
2c21d115
SL
57 if (!hdr) {
58 nlmsg_free(msg);
59 return NULL;
60 }
61
62 return msg;
63}
64
78fe738d 65int ieee802154_nl_mcast(struct sk_buff *msg, unsigned int group)
2c21d115 66{
10c9cbb1
H
67 struct nlmsghdr *nlh = nlmsg_hdr(msg);
68 void *hdr = genlmsg_data(nlmsg_data(nlh));
2c21d115 69
8e753dd0 70 if (genlmsg_end(msg, hdr) < 0)
2c21d115
SL
71 goto out;
72
68eb5503 73 return genlmsg_multicast(&nl802154_family, msg, 0, group, GFP_ATOMIC);
2c21d115
SL
74out:
75 nlmsg_free(msg);
76 return -ENOBUFS;
77}
78
339b4ca5
DES
79struct sk_buff *ieee802154_nl_new_reply(struct genl_info *info,
80 int flags, u8 req)
81{
82 void *hdr;
58050fce 83 struct sk_buff *msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC);
339b4ca5
DES
84
85 if (!msg)
86 return NULL;
87
88 hdr = genlmsg_put_reply(msg, info,
89 &nl802154_family, flags, req);
90 if (!hdr) {
91 nlmsg_free(msg);
92 return NULL;
93 }
94
95 return msg;
96}
97
98int ieee802154_nl_reply(struct sk_buff *msg, struct genl_info *info)
99{
10c9cbb1
H
100 struct nlmsghdr *nlh = nlmsg_hdr(msg);
101 void *hdr = genlmsg_data(nlmsg_data(nlh));
339b4ca5
DES
102
103 if (genlmsg_end(msg, hdr) < 0)
104 goto out;
105
106 return genlmsg_reply(msg, info);
107out:
108 nlmsg_free(msg);
109 return -ENOBUFS;
110}
111
4534de83 112static const struct genl_ops ieee8021154_ops[] = {
1c582d91
JB
113 /* see nl-phy.c */
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),
118 /* see nl-mac.c */
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),
e462ded6 126 IEEE802154_OP(IEEE802154_SET_MACPARAMS, ieee802154_set_macparams),
3e9c156e
PB
127 IEEE802154_OP(IEEE802154_LLSEC_GETPARAMS, ieee802154_llsec_getparams),
128 IEEE802154_OP(IEEE802154_LLSEC_SETPARAMS, ieee802154_llsec_setparams),
129 IEEE802154_DUMP(IEEE802154_LLSEC_LIST_KEY, NULL,
130 ieee802154_llsec_dump_keys),
131 IEEE802154_OP(IEEE802154_LLSEC_ADD_KEY, ieee802154_llsec_add_key),
132 IEEE802154_OP(IEEE802154_LLSEC_DEL_KEY, ieee802154_llsec_del_key),
133 IEEE802154_DUMP(IEEE802154_LLSEC_LIST_DEV, NULL,
134 ieee802154_llsec_dump_devs),
135 IEEE802154_OP(IEEE802154_LLSEC_ADD_DEV, ieee802154_llsec_add_dev),
136 IEEE802154_OP(IEEE802154_LLSEC_DEL_DEV, ieee802154_llsec_del_dev),
137 IEEE802154_DUMP(IEEE802154_LLSEC_LIST_DEVKEY, NULL,
138 ieee802154_llsec_dump_devkeys),
139 IEEE802154_OP(IEEE802154_LLSEC_ADD_DEVKEY, ieee802154_llsec_add_devkey),
140 IEEE802154_OP(IEEE802154_LLSEC_DEL_DEVKEY, ieee802154_llsec_del_devkey),
141 IEEE802154_DUMP(IEEE802154_LLSEC_LIST_SECLEVEL, NULL,
142 ieee802154_llsec_dump_seclevels),
143 IEEE802154_OP(IEEE802154_LLSEC_ADD_SECLEVEL,
144 ieee802154_llsec_add_seclevel),
145 IEEE802154_OP(IEEE802154_LLSEC_DEL_SECLEVEL,
146 ieee802154_llsec_del_seclevel),
1c582d91
JB
147};
148
2a94fe48
JB
149static const struct genl_multicast_group ieee802154_mcgrps[] = {
150 [IEEE802154_COORD_MCGRP] = { .name = IEEE802154_MCAST_COORD_NAME, },
151 [IEEE802154_BEACON_MCGRP] = { .name = IEEE802154_MCAST_BEACON_NAME, },
152};
2c21d115 153
2c21d115 154
2a94fe48
JB
155int __init ieee802154_nl_init(void)
156{
157 return genl_register_family_with_ops_groups(&nl802154_family,
158 ieee8021154_ops,
159 ieee802154_mcgrps);
2c21d115 160}
2c21d115 161
cb6b3763 162void __exit ieee802154_nl_exit(void)
2c21d115 163{
78fe738d 164 genl_unregister_family(&nl802154_family);
2c21d115 165}
This page took 0.309243 seconds and 5 git commands to generate.