Blame view

net/ieee802154/netlink.c 4.61 KB
2c21d1151   Sergey Lapin   net: add NL802154...
1
  /*
69bb631ef   Varka Bhadram   ieee802154: fix s...
2
   * Netlink interface for IEEE 802.15.4 stack
2c21d1151   Sergey Lapin   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   Sergey Lapin   net: add NL802154...
15
16
17
   * Written by:
   * Sergey Lapin <slapin@ossfans.org>
   * Dmitry Eremin-Solenikov <dbaryshkov@gmail.com>
8e753dd0a   Dmitry Eremin-Solenikov   nl802154: add sup...
18
   * Maxim Osipov <maxim.osipov@siemens.com>
2c21d1151   Sergey Lapin   net: add NL802154...
19
20
21
   */
  
  #include <linux/kernel.h>
5a0e3ad6a   Tejun Heo   include cleanup: ...
22
  #include <linux/gfp.h>
2c21d1151   Sergey Lapin   net: add NL802154...
23
24
  #include <net/genetlink.h>
  #include <linux/nl802154.h>
78fe738d1   Dmitry Eremin-Solenikov   ieee802154: split...
25
26
  
  #include "ieee802154.h"
2c21d1151   Sergey Lapin   net: add NL802154...
27
28
  
  static unsigned int ieee802154_seq_num;
c4835d81e   Dmitry Eremin-Solenikov   ieee802154: add l...
29
  static DEFINE_SPINLOCK(ieee802154_seq_lock);
2c21d1151   Sergey Lapin   net: add NL802154...
30

2c21d1151   Sergey Lapin   net: add NL802154...
31
  /* Requests to userspace */
78fe738d1   Dmitry Eremin-Solenikov   ieee802154: split...
32
  struct sk_buff *ieee802154_nl_create(int flags, u8 req)
2c21d1151   Sergey Lapin   net: add NL802154...
33
34
  {
  	void *hdr;
58050fce3   Thomas Graf   net: Use NLMSG_DE...
35
  	struct sk_buff *msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC);
c4835d81e   Dmitry Eremin-Solenikov   ieee802154: add l...
36
  	unsigned long f;
2c21d1151   Sergey Lapin   net: add NL802154...
37
38
39
  
  	if (!msg)
  		return NULL;
c4835d81e   Dmitry Eremin-Solenikov   ieee802154: add l...
40
  	spin_lock_irqsave(&ieee802154_seq_lock, f);
2c21d1151   Sergey Lapin   net: add NL802154...
41
  	hdr = genlmsg_put(msg, 0, ieee802154_seq_num++,
4710d806f   Varka Bhadram   6lowpan: mac80215...
42
  			  &nl802154_family, flags, req);
c4835d81e   Dmitry Eremin-Solenikov   ieee802154: add l...
43
  	spin_unlock_irqrestore(&ieee802154_seq_lock, f);
2c21d1151   Sergey Lapin   net: add NL802154...
44
45
46
47
48
49
50
  	if (!hdr) {
  		nlmsg_free(msg);
  		return NULL;
  	}
  
  	return msg;
  }
78fe738d1   Dmitry Eremin-Solenikov   ieee802154: split...
51
  int ieee802154_nl_mcast(struct sk_buff *msg, unsigned int group)
2c21d1151   Sergey Lapin   net: add NL802154...
52
  {
10c9cbb10   Hong zhi guo   netlink: fix the ...
53
54
  	struct nlmsghdr *nlh = nlmsg_hdr(msg);
  	void *hdr = genlmsg_data(nlmsg_data(nlh));
2c21d1151   Sergey Lapin   net: add NL802154...
55

053c095a8   Johannes Berg   netlink: make nlm...
56
  	genlmsg_end(msg, hdr);
2c21d1151   Sergey Lapin   net: add NL802154...
57

68eb55031   Johannes Berg   genetlink: pass f...
58
  	return genlmsg_multicast(&nl802154_family, msg, 0, group, GFP_ATOMIC);
2c21d1151   Sergey Lapin   net: add NL802154...
59
  }
339b4ca5f   Dmitry Eremin-Solenikov   ieee802154: add t...
60
  struct sk_buff *ieee802154_nl_new_reply(struct genl_info *info,
cad865dc4   Stefan Schmidt   net/ieee802154: M...
61
  					int flags, u8 req)
339b4ca5f   Dmitry Eremin-Solenikov   ieee802154: add t...
62
63
  {
  	void *hdr;
58050fce3   Thomas Graf   net: Use NLMSG_DE...
64
  	struct sk_buff *msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC);
339b4ca5f   Dmitry Eremin-Solenikov   ieee802154: add t...
65
66
67
68
69
  
  	if (!msg)
  		return NULL;
  
  	hdr = genlmsg_put_reply(msg, info,
4710d806f   Varka Bhadram   6lowpan: mac80215...
70
  				&nl802154_family, flags, req);
339b4ca5f   Dmitry Eremin-Solenikov   ieee802154: add t...
71
72
73
74
75
76
77
78
79
80
  	if (!hdr) {
  		nlmsg_free(msg);
  		return NULL;
  	}
  
  	return msg;
  }
  
  int ieee802154_nl_reply(struct sk_buff *msg, struct genl_info *info)
  {
10c9cbb10   Hong zhi guo   netlink: fix the ...
81
82
  	struct nlmsghdr *nlh = nlmsg_hdr(msg);
  	void *hdr = genlmsg_data(nlmsg_data(nlh));
339b4ca5f   Dmitry Eremin-Solenikov   ieee802154: add t...
83

053c095a8   Johannes Berg   netlink: make nlm...
84
  	genlmsg_end(msg, hdr);
339b4ca5f   Dmitry Eremin-Solenikov   ieee802154: add t...
85
86
  
  	return genlmsg_reply(msg, info);
339b4ca5f   Dmitry Eremin-Solenikov   ieee802154: add t...
87
  }
4534de830   Johannes Berg   genetlink: make a...
88
  static const struct genl_ops ieee8021154_ops[] = {
1c582d915   Johannes Berg   ieee802154: use g...
89
90
91
92
93
94
95
96
97
98
99
100
101
  	/* 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   Phoebe Buckheister   mac802154: make c...
102
  	IEEE802154_OP(IEEE802154_SET_MACPARAMS, ieee802154_set_macparams),
3e9c156e2   Phoebe Buckheister   ieee802154: add n...
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
  	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   Johannes Berg   ieee802154: use g...
123
  };
2a94fe48f   Johannes Berg   genetlink: make m...
124
125
126
127
  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   Sergey Lapin   net: add NL802154...
128

56989f6d8   Johannes Berg   genetlink: mark f...
129
  struct genl_family nl802154_family __ro_after_init = {
489111e5c   Johannes Berg   genetlink: static...
130
131
132
133
134
135
136
137
138
139
  	.hdrsize	= 0,
  	.name		= IEEE802154_NL_NAME,
  	.version	= 1,
  	.maxattr	= IEEE802154_ATTR_MAX,
  	.module		= THIS_MODULE,
  	.ops		= ieee8021154_ops,
  	.n_ops		= ARRAY_SIZE(ieee8021154_ops),
  	.mcgrps		= ieee802154_mcgrps,
  	.n_mcgrps	= ARRAY_SIZE(ieee802154_mcgrps),
  };
2a94fe48f   Johannes Berg   genetlink: make m...
140
141
  int __init ieee802154_nl_init(void)
  {
489111e5c   Johannes Berg   genetlink: static...
142
  	return genl_register_family(&nl802154_family);
2c21d1151   Sergey Lapin   net: add NL802154...
143
  }
2c21d1151   Sergey Lapin   net: add NL802154...
144

79fe1a2aa   Alexander Aring   ieee802154: add n...
145
  void ieee802154_nl_exit(void)
2c21d1151   Sergey Lapin   net: add NL802154...
146
  {
78fe738d1   Dmitry Eremin-Solenikov   ieee802154: split...
147
  	genl_unregister_family(&nl802154_family);
2c21d1151   Sergey Lapin   net: add NL802154...
148
  }