Blame view
net/ieee802154/netlink.c
4.52 KB
2c21d1151 net: add NL802154... |
1 |
/* |
69bb631ef ieee802154: fix s... |
2 |
* Netlink interface for IEEE 802.15.4 stack |
2c21d1151 net: add NL802154... |
3 4 5 6 7 8 9 10 11 12 13 14 |
* * Copyright 2007, 2008 Siemens AG * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2 * as published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * |
2c21d1151 net: add NL802154... |
15 16 17 |
* Written by: * Sergey Lapin <slapin@ossfans.org> * Dmitry Eremin-Solenikov <dbaryshkov@gmail.com> |
8e753dd0a nl802154: add sup... |
18 |
* Maxim Osipov <maxim.osipov@siemens.com> |
2c21d1151 net: add NL802154... |
19 20 21 |
*/ #include <linux/kernel.h> |
5a0e3ad6a include cleanup: ... |
22 |
#include <linux/gfp.h> |
2c21d1151 net: add NL802154... |
23 24 |
#include <net/genetlink.h> #include <linux/nl802154.h> |
78fe738d1 ieee802154: split... |
25 26 |
#include "ieee802154.h" |
2c21d1151 net: add NL802154... |
27 28 |
static unsigned int ieee802154_seq_num; |
c4835d81e ieee802154: add l... |
29 |
static DEFINE_SPINLOCK(ieee802154_seq_lock); |
2c21d1151 net: add NL802154... |
30 |
|
78fe738d1 ieee802154: split... |
31 |
struct genl_family nl802154_family = { |
2c21d1151 net: add NL802154... |
32 33 34 35 36 37 |
.id = GENL_ID_GENERATE, .hdrsize = 0, .name = IEEE802154_NL_NAME, .version = 1, .maxattr = IEEE802154_ATTR_MAX, }; |
2c21d1151 net: add NL802154... |
38 |
/* Requests to userspace */ |
78fe738d1 ieee802154: split... |
39 |
struct sk_buff *ieee802154_nl_create(int flags, u8 req) |
2c21d1151 net: add NL802154... |
40 41 |
{ void *hdr; |
58050fce3 net: Use NLMSG_DE... |
42 |
struct sk_buff *msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC); |
c4835d81e ieee802154: add l... |
43 |
unsigned long f; |
2c21d1151 net: add NL802154... |
44 45 46 |
if (!msg) return NULL; |
c4835d81e ieee802154: add l... |
47 |
spin_lock_irqsave(&ieee802154_seq_lock, f); |
2c21d1151 net: add NL802154... |
48 |
hdr = genlmsg_put(msg, 0, ieee802154_seq_num++, |
4710d806f 6lowpan: mac80215... |
49 |
&nl802154_family, flags, req); |
c4835d81e ieee802154: add l... |
50 |
spin_unlock_irqrestore(&ieee802154_seq_lock, f); |
2c21d1151 net: add NL802154... |
51 52 53 54 55 56 57 |
if (!hdr) { nlmsg_free(msg); return NULL; } return msg; } |
78fe738d1 ieee802154: split... |
58 |
int ieee802154_nl_mcast(struct sk_buff *msg, unsigned int group) |
2c21d1151 net: add NL802154... |
59 |
{ |
10c9cbb10 netlink: fix the ... |
60 61 |
struct nlmsghdr *nlh = nlmsg_hdr(msg); void *hdr = genlmsg_data(nlmsg_data(nlh)); |
2c21d1151 net: add NL802154... |
62 |
|
053c095a8 netlink: make nlm... |
63 |
genlmsg_end(msg, hdr); |
2c21d1151 net: add NL802154... |
64 |
|
68eb55031 genetlink: pass f... |
65 |
return genlmsg_multicast(&nl802154_family, msg, 0, group, GFP_ATOMIC); |
2c21d1151 net: add NL802154... |
66 |
} |
339b4ca5f ieee802154: add t... |
67 |
struct sk_buff *ieee802154_nl_new_reply(struct genl_info *info, |
cad865dc4 net/ieee802154: M... |
68 |
int flags, u8 req) |
339b4ca5f ieee802154: add t... |
69 70 |
{ void *hdr; |
58050fce3 net: Use NLMSG_DE... |
71 |
struct sk_buff *msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC); |
339b4ca5f ieee802154: add t... |
72 73 74 75 76 |
if (!msg) return NULL; hdr = genlmsg_put_reply(msg, info, |
4710d806f 6lowpan: mac80215... |
77 |
&nl802154_family, flags, req); |
339b4ca5f ieee802154: add t... |
78 79 80 81 82 83 84 85 86 87 |
if (!hdr) { nlmsg_free(msg); return NULL; } return msg; } int ieee802154_nl_reply(struct sk_buff *msg, struct genl_info *info) { |
10c9cbb10 netlink: fix the ... |
88 89 |
struct nlmsghdr *nlh = nlmsg_hdr(msg); void *hdr = genlmsg_data(nlmsg_data(nlh)); |
339b4ca5f ieee802154: add t... |
90 |
|
053c095a8 netlink: make nlm... |
91 |
genlmsg_end(msg, hdr); |
339b4ca5f ieee802154: add t... |
92 93 |
return genlmsg_reply(msg, info); |
339b4ca5f ieee802154: add t... |
94 |
} |
4534de830 genetlink: make a... |
95 |
static const struct genl_ops ieee8021154_ops[] = { |
1c582d915 ieee802154: use g... |
96 97 98 99 100 101 102 103 104 105 106 107 108 |
/* see nl-phy.c */ IEEE802154_DUMP(IEEE802154_LIST_PHY, ieee802154_list_phy, ieee802154_dump_phy), IEEE802154_OP(IEEE802154_ADD_IFACE, ieee802154_add_iface), IEEE802154_OP(IEEE802154_DEL_IFACE, ieee802154_del_iface), /* see nl-mac.c */ IEEE802154_OP(IEEE802154_ASSOCIATE_REQ, ieee802154_associate_req), IEEE802154_OP(IEEE802154_ASSOCIATE_RESP, ieee802154_associate_resp), IEEE802154_OP(IEEE802154_DISASSOCIATE_REQ, ieee802154_disassociate_req), IEEE802154_OP(IEEE802154_SCAN_REQ, ieee802154_scan_req), IEEE802154_OP(IEEE802154_START_REQ, ieee802154_start_req), IEEE802154_DUMP(IEEE802154_LIST_IFACE, ieee802154_list_iface, ieee802154_dump_iface), |
e462ded69 mac802154: make c... |
109 |
IEEE802154_OP(IEEE802154_SET_MACPARAMS, ieee802154_set_macparams), |
3e9c156e2 ieee802154: add n... |
110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 |
IEEE802154_OP(IEEE802154_LLSEC_GETPARAMS, ieee802154_llsec_getparams), IEEE802154_OP(IEEE802154_LLSEC_SETPARAMS, ieee802154_llsec_setparams), IEEE802154_DUMP(IEEE802154_LLSEC_LIST_KEY, NULL, ieee802154_llsec_dump_keys), IEEE802154_OP(IEEE802154_LLSEC_ADD_KEY, ieee802154_llsec_add_key), IEEE802154_OP(IEEE802154_LLSEC_DEL_KEY, ieee802154_llsec_del_key), IEEE802154_DUMP(IEEE802154_LLSEC_LIST_DEV, NULL, ieee802154_llsec_dump_devs), IEEE802154_OP(IEEE802154_LLSEC_ADD_DEV, ieee802154_llsec_add_dev), IEEE802154_OP(IEEE802154_LLSEC_DEL_DEV, ieee802154_llsec_del_dev), IEEE802154_DUMP(IEEE802154_LLSEC_LIST_DEVKEY, NULL, ieee802154_llsec_dump_devkeys), IEEE802154_OP(IEEE802154_LLSEC_ADD_DEVKEY, ieee802154_llsec_add_devkey), IEEE802154_OP(IEEE802154_LLSEC_DEL_DEVKEY, ieee802154_llsec_del_devkey), IEEE802154_DUMP(IEEE802154_LLSEC_LIST_SECLEVEL, NULL, ieee802154_llsec_dump_seclevels), IEEE802154_OP(IEEE802154_LLSEC_ADD_SECLEVEL, ieee802154_llsec_add_seclevel), IEEE802154_OP(IEEE802154_LLSEC_DEL_SECLEVEL, ieee802154_llsec_del_seclevel), |
1c582d915 ieee802154: use g... |
130 |
}; |
2a94fe48f genetlink: make m... |
131 132 133 134 |
static const struct genl_multicast_group ieee802154_mcgrps[] = { [IEEE802154_COORD_MCGRP] = { .name = IEEE802154_MCAST_COORD_NAME, }, [IEEE802154_BEACON_MCGRP] = { .name = IEEE802154_MCAST_BEACON_NAME, }, }; |
2c21d1151 net: add NL802154... |
135 |
|
2a94fe48f genetlink: make m... |
136 137 138 139 140 |
int __init ieee802154_nl_init(void) { return genl_register_family_with_ops_groups(&nl802154_family, ieee8021154_ops, ieee802154_mcgrps); |
2c21d1151 net: add NL802154... |
141 |
} |
2c21d1151 net: add NL802154... |
142 |
|
79fe1a2aa ieee802154: add n... |
143 |
void ieee802154_nl_exit(void) |
2c21d1151 net: add NL802154... |
144 |
{ |
78fe738d1 ieee802154: split... |
145 |
genl_unregister_family(&nl802154_family); |
2c21d1151 net: add NL802154... |
146 |
} |