of: MSI: Simplify irqdomain lookup
[linux/fpc-iii.git] / net / ieee802154 / nl802154.c
blob16ef0d9f566e8436e55f0263c51585ae5ab751b9
1 /* This program is free software; you can redistribute it and/or modify
2 * it under the terms of the GNU General Public License version 2
3 * as published by the Free Software Foundation.
5 * This program is distributed in the hope that it will be useful,
6 * but WITHOUT ANY WARRANTY; without even the implied warranty of
7 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
8 * GNU General Public License for more details.
10 * Authors:
11 * Alexander Aring <aar@pengutronix.de>
13 * Based on: net/wireless/nl80211.c
16 #include <linux/rtnetlink.h>
18 #include <net/cfg802154.h>
19 #include <net/genetlink.h>
20 #include <net/mac802154.h>
21 #include <net/netlink.h>
22 #include <net/nl802154.h>
23 #include <net/sock.h>
25 #include "nl802154.h"
26 #include "rdev-ops.h"
27 #include "core.h"
29 static int nl802154_pre_doit(const struct genl_ops *ops, struct sk_buff *skb,
30 struct genl_info *info);
32 static void nl802154_post_doit(const struct genl_ops *ops, struct sk_buff *skb,
33 struct genl_info *info);
35 /* the netlink family */
36 static struct genl_family nl802154_fam = {
37 .id = GENL_ID_GENERATE, /* don't bother with a hardcoded ID */
38 .name = NL802154_GENL_NAME, /* have users key off the name instead */
39 .hdrsize = 0, /* no private header */
40 .version = 1, /* no particular meaning now */
41 .maxattr = NL802154_ATTR_MAX,
42 .netnsok = true,
43 .pre_doit = nl802154_pre_doit,
44 .post_doit = nl802154_post_doit,
47 /* multicast groups */
48 enum nl802154_multicast_groups {
49 NL802154_MCGRP_CONFIG,
52 static const struct genl_multicast_group nl802154_mcgrps[] = {
53 [NL802154_MCGRP_CONFIG] = { .name = "config", },
56 /* returns ERR_PTR values */
57 static struct wpan_dev *
58 __cfg802154_wpan_dev_from_attrs(struct net *netns, struct nlattr **attrs)
60 struct cfg802154_registered_device *rdev;
61 struct wpan_dev *result = NULL;
62 bool have_ifidx = attrs[NL802154_ATTR_IFINDEX];
63 bool have_wpan_dev_id = attrs[NL802154_ATTR_WPAN_DEV];
64 u64 wpan_dev_id;
65 int wpan_phy_idx = -1;
66 int ifidx = -1;
68 ASSERT_RTNL();
70 if (!have_ifidx && !have_wpan_dev_id)
71 return ERR_PTR(-EINVAL);
73 if (have_ifidx)
74 ifidx = nla_get_u32(attrs[NL802154_ATTR_IFINDEX]);
75 if (have_wpan_dev_id) {
76 wpan_dev_id = nla_get_u64(attrs[NL802154_ATTR_WPAN_DEV]);
77 wpan_phy_idx = wpan_dev_id >> 32;
80 list_for_each_entry(rdev, &cfg802154_rdev_list, list) {
81 struct wpan_dev *wpan_dev;
83 /* TODO netns compare */
85 if (have_wpan_dev_id && rdev->wpan_phy_idx != wpan_phy_idx)
86 continue;
88 list_for_each_entry(wpan_dev, &rdev->wpan_dev_list, list) {
89 if (have_ifidx && wpan_dev->netdev &&
90 wpan_dev->netdev->ifindex == ifidx) {
91 result = wpan_dev;
92 break;
94 if (have_wpan_dev_id &&
95 wpan_dev->identifier == (u32)wpan_dev_id) {
96 result = wpan_dev;
97 break;
101 if (result)
102 break;
105 if (result)
106 return result;
108 return ERR_PTR(-ENODEV);
111 static struct cfg802154_registered_device *
112 __cfg802154_rdev_from_attrs(struct net *netns, struct nlattr **attrs)
114 struct cfg802154_registered_device *rdev = NULL, *tmp;
115 struct net_device *netdev;
117 ASSERT_RTNL();
119 if (!attrs[NL802154_ATTR_WPAN_PHY] &&
120 !attrs[NL802154_ATTR_IFINDEX] &&
121 !attrs[NL802154_ATTR_WPAN_DEV])
122 return ERR_PTR(-EINVAL);
124 if (attrs[NL802154_ATTR_WPAN_PHY])
125 rdev = cfg802154_rdev_by_wpan_phy_idx(
126 nla_get_u32(attrs[NL802154_ATTR_WPAN_PHY]));
128 if (attrs[NL802154_ATTR_WPAN_DEV]) {
129 u64 wpan_dev_id = nla_get_u64(attrs[NL802154_ATTR_WPAN_DEV]);
130 struct wpan_dev *wpan_dev;
131 bool found = false;
133 tmp = cfg802154_rdev_by_wpan_phy_idx(wpan_dev_id >> 32);
134 if (tmp) {
135 /* make sure wpan_dev exists */
136 list_for_each_entry(wpan_dev, &tmp->wpan_dev_list, list) {
137 if (wpan_dev->identifier != (u32)wpan_dev_id)
138 continue;
139 found = true;
140 break;
143 if (!found)
144 tmp = NULL;
146 if (rdev && tmp != rdev)
147 return ERR_PTR(-EINVAL);
148 rdev = tmp;
152 if (attrs[NL802154_ATTR_IFINDEX]) {
153 int ifindex = nla_get_u32(attrs[NL802154_ATTR_IFINDEX]);
155 netdev = __dev_get_by_index(netns, ifindex);
156 if (netdev) {
157 if (netdev->ieee802154_ptr)
158 tmp = wpan_phy_to_rdev(
159 netdev->ieee802154_ptr->wpan_phy);
160 else
161 tmp = NULL;
163 /* not wireless device -- return error */
164 if (!tmp)
165 return ERR_PTR(-EINVAL);
167 /* mismatch -- return error */
168 if (rdev && tmp != rdev)
169 return ERR_PTR(-EINVAL);
171 rdev = tmp;
175 if (!rdev)
176 return ERR_PTR(-ENODEV);
178 /* TODO netns compare */
180 return rdev;
183 /* This function returns a pointer to the driver
184 * that the genl_info item that is passed refers to.
186 * The result of this can be a PTR_ERR and hence must
187 * be checked with IS_ERR() for errors.
189 static struct cfg802154_registered_device *
190 cfg802154_get_dev_from_info(struct net *netns, struct genl_info *info)
192 return __cfg802154_rdev_from_attrs(netns, info->attrs);
195 /* policy for the attributes */
196 static const struct nla_policy nl802154_policy[NL802154_ATTR_MAX+1] = {
197 [NL802154_ATTR_WPAN_PHY] = { .type = NLA_U32 },
198 [NL802154_ATTR_WPAN_PHY_NAME] = { .type = NLA_NUL_STRING,
199 .len = 20-1 },
201 [NL802154_ATTR_IFINDEX] = { .type = NLA_U32 },
202 [NL802154_ATTR_IFTYPE] = { .type = NLA_U32 },
203 [NL802154_ATTR_IFNAME] = { .type = NLA_NUL_STRING, .len = IFNAMSIZ-1 },
205 [NL802154_ATTR_WPAN_DEV] = { .type = NLA_U64 },
207 [NL802154_ATTR_PAGE] = { .type = NLA_U8, },
208 [NL802154_ATTR_CHANNEL] = { .type = NLA_U8, },
210 [NL802154_ATTR_TX_POWER] = { .type = NLA_S32, },
212 [NL802154_ATTR_CCA_MODE] = { .type = NLA_U32, },
213 [NL802154_ATTR_CCA_OPT] = { .type = NLA_U32, },
214 [NL802154_ATTR_CCA_ED_LEVEL] = { .type = NLA_S32, },
216 [NL802154_ATTR_SUPPORTED_CHANNEL] = { .type = NLA_U32, },
218 [NL802154_ATTR_PAN_ID] = { .type = NLA_U16, },
219 [NL802154_ATTR_EXTENDED_ADDR] = { .type = NLA_U64 },
220 [NL802154_ATTR_SHORT_ADDR] = { .type = NLA_U16, },
222 [NL802154_ATTR_MIN_BE] = { .type = NLA_U8, },
223 [NL802154_ATTR_MAX_BE] = { .type = NLA_U8, },
224 [NL802154_ATTR_MAX_CSMA_BACKOFFS] = { .type = NLA_U8, },
226 [NL802154_ATTR_MAX_FRAME_RETRIES] = { .type = NLA_S8, },
228 [NL802154_ATTR_LBT_MODE] = { .type = NLA_U8, },
230 [NL802154_ATTR_WPAN_PHY_CAPS] = { .type = NLA_NESTED },
232 [NL802154_ATTR_SUPPORTED_COMMANDS] = { .type = NLA_NESTED },
234 [NL802154_ATTR_ACKREQ_DEFAULT] = { .type = NLA_U8 },
236 #ifdef CONFIG_IEEE802154_NL802154_EXPERIMENTAL
237 [NL802154_ATTR_SEC_ENABLED] = { .type = NLA_U8, },
238 [NL802154_ATTR_SEC_OUT_LEVEL] = { .type = NLA_U32, },
239 [NL802154_ATTR_SEC_OUT_KEY_ID] = { .type = NLA_NESTED, },
240 [NL802154_ATTR_SEC_FRAME_COUNTER] = { .type = NLA_U32 },
242 [NL802154_ATTR_SEC_LEVEL] = { .type = NLA_NESTED },
243 [NL802154_ATTR_SEC_DEVICE] = { .type = NLA_NESTED },
244 [NL802154_ATTR_SEC_DEVKEY] = { .type = NLA_NESTED },
245 [NL802154_ATTR_SEC_KEY] = { .type = NLA_NESTED },
246 #endif /* CONFIG_IEEE802154_NL802154_EXPERIMENTAL */
249 #ifdef CONFIG_IEEE802154_NL802154_EXPERIMENTAL
250 static int
251 nl802154_prepare_wpan_dev_dump(struct sk_buff *skb,
252 struct netlink_callback *cb,
253 struct cfg802154_registered_device **rdev,
254 struct wpan_dev **wpan_dev)
256 int err;
258 rtnl_lock();
260 if (!cb->args[0]) {
261 err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl802154_fam.hdrsize,
262 nl802154_fam.attrbuf, nl802154_fam.maxattr,
263 nl802154_policy);
264 if (err)
265 goto out_unlock;
267 *wpan_dev = __cfg802154_wpan_dev_from_attrs(sock_net(skb->sk),
268 nl802154_fam.attrbuf);
269 if (IS_ERR(*wpan_dev)) {
270 err = PTR_ERR(*wpan_dev);
271 goto out_unlock;
273 *rdev = wpan_phy_to_rdev((*wpan_dev)->wpan_phy);
274 /* 0 is the first index - add 1 to parse only once */
275 cb->args[0] = (*rdev)->wpan_phy_idx + 1;
276 cb->args[1] = (*wpan_dev)->identifier;
277 } else {
278 /* subtract the 1 again here */
279 struct wpan_phy *wpan_phy = wpan_phy_idx_to_wpan_phy(cb->args[0] - 1);
280 struct wpan_dev *tmp;
282 if (!wpan_phy) {
283 err = -ENODEV;
284 goto out_unlock;
286 *rdev = wpan_phy_to_rdev(wpan_phy);
287 *wpan_dev = NULL;
289 list_for_each_entry(tmp, &(*rdev)->wpan_dev_list, list) {
290 if (tmp->identifier == cb->args[1]) {
291 *wpan_dev = tmp;
292 break;
296 if (!*wpan_dev) {
297 err = -ENODEV;
298 goto out_unlock;
302 return 0;
303 out_unlock:
304 rtnl_unlock();
305 return err;
308 static void
309 nl802154_finish_wpan_dev_dump(struct cfg802154_registered_device *rdev)
311 rtnl_unlock();
313 #endif /* CONFIG_IEEE802154_NL802154_EXPERIMENTAL */
315 /* message building helper */
316 static inline void *nl802154hdr_put(struct sk_buff *skb, u32 portid, u32 seq,
317 int flags, u8 cmd)
319 /* since there is no private header just add the generic one */
320 return genlmsg_put(skb, portid, seq, &nl802154_fam, flags, cmd);
323 static int
324 nl802154_put_flags(struct sk_buff *msg, int attr, u32 mask)
326 struct nlattr *nl_flags = nla_nest_start(msg, attr);
327 int i;
329 if (!nl_flags)
330 return -ENOBUFS;
332 i = 0;
333 while (mask) {
334 if ((mask & 1) && nla_put_flag(msg, i))
335 return -ENOBUFS;
337 mask >>= 1;
338 i++;
341 nla_nest_end(msg, nl_flags);
342 return 0;
345 static int
346 nl802154_send_wpan_phy_channels(struct cfg802154_registered_device *rdev,
347 struct sk_buff *msg)
349 struct nlattr *nl_page;
350 unsigned long page;
352 nl_page = nla_nest_start(msg, NL802154_ATTR_CHANNELS_SUPPORTED);
353 if (!nl_page)
354 return -ENOBUFS;
356 for (page = 0; page <= IEEE802154_MAX_PAGE; page++) {
357 if (nla_put_u32(msg, NL802154_ATTR_SUPPORTED_CHANNEL,
358 rdev->wpan_phy.supported.channels[page]))
359 return -ENOBUFS;
361 nla_nest_end(msg, nl_page);
363 return 0;
366 static int
367 nl802154_put_capabilities(struct sk_buff *msg,
368 struct cfg802154_registered_device *rdev)
370 const struct wpan_phy_supported *caps = &rdev->wpan_phy.supported;
371 struct nlattr *nl_caps, *nl_channels;
372 int i;
374 nl_caps = nla_nest_start(msg, NL802154_ATTR_WPAN_PHY_CAPS);
375 if (!nl_caps)
376 return -ENOBUFS;
378 nl_channels = nla_nest_start(msg, NL802154_CAP_ATTR_CHANNELS);
379 if (!nl_channels)
380 return -ENOBUFS;
382 for (i = 0; i <= IEEE802154_MAX_PAGE; i++) {
383 if (caps->channels[i]) {
384 if (nl802154_put_flags(msg, i, caps->channels[i]))
385 return -ENOBUFS;
389 nla_nest_end(msg, nl_channels);
391 if (rdev->wpan_phy.flags & WPAN_PHY_FLAG_CCA_ED_LEVEL) {
392 struct nlattr *nl_ed_lvls;
394 nl_ed_lvls = nla_nest_start(msg,
395 NL802154_CAP_ATTR_CCA_ED_LEVELS);
396 if (!nl_ed_lvls)
397 return -ENOBUFS;
399 for (i = 0; i < caps->cca_ed_levels_size; i++) {
400 if (nla_put_s32(msg, i, caps->cca_ed_levels[i]))
401 return -ENOBUFS;
404 nla_nest_end(msg, nl_ed_lvls);
407 if (rdev->wpan_phy.flags & WPAN_PHY_FLAG_TXPOWER) {
408 struct nlattr *nl_tx_pwrs;
410 nl_tx_pwrs = nla_nest_start(msg, NL802154_CAP_ATTR_TX_POWERS);
411 if (!nl_tx_pwrs)
412 return -ENOBUFS;
414 for (i = 0; i < caps->tx_powers_size; i++) {
415 if (nla_put_s32(msg, i, caps->tx_powers[i]))
416 return -ENOBUFS;
419 nla_nest_end(msg, nl_tx_pwrs);
422 if (rdev->wpan_phy.flags & WPAN_PHY_FLAG_CCA_MODE) {
423 if (nl802154_put_flags(msg, NL802154_CAP_ATTR_CCA_MODES,
424 caps->cca_modes) ||
425 nl802154_put_flags(msg, NL802154_CAP_ATTR_CCA_OPTS,
426 caps->cca_opts))
427 return -ENOBUFS;
430 if (nla_put_u8(msg, NL802154_CAP_ATTR_MIN_MINBE, caps->min_minbe) ||
431 nla_put_u8(msg, NL802154_CAP_ATTR_MAX_MINBE, caps->max_minbe) ||
432 nla_put_u8(msg, NL802154_CAP_ATTR_MIN_MAXBE, caps->min_maxbe) ||
433 nla_put_u8(msg, NL802154_CAP_ATTR_MAX_MAXBE, caps->max_maxbe) ||
434 nla_put_u8(msg, NL802154_CAP_ATTR_MIN_CSMA_BACKOFFS,
435 caps->min_csma_backoffs) ||
436 nla_put_u8(msg, NL802154_CAP_ATTR_MAX_CSMA_BACKOFFS,
437 caps->max_csma_backoffs) ||
438 nla_put_s8(msg, NL802154_CAP_ATTR_MIN_FRAME_RETRIES,
439 caps->min_frame_retries) ||
440 nla_put_s8(msg, NL802154_CAP_ATTR_MAX_FRAME_RETRIES,
441 caps->max_frame_retries) ||
442 nl802154_put_flags(msg, NL802154_CAP_ATTR_IFTYPES,
443 caps->iftypes) ||
444 nla_put_u32(msg, NL802154_CAP_ATTR_LBT, caps->lbt))
445 return -ENOBUFS;
447 nla_nest_end(msg, nl_caps);
449 return 0;
452 static int nl802154_send_wpan_phy(struct cfg802154_registered_device *rdev,
453 enum nl802154_commands cmd,
454 struct sk_buff *msg, u32 portid, u32 seq,
455 int flags)
457 struct nlattr *nl_cmds;
458 void *hdr;
459 int i;
461 hdr = nl802154hdr_put(msg, portid, seq, flags, cmd);
462 if (!hdr)
463 return -ENOBUFS;
465 if (nla_put_u32(msg, NL802154_ATTR_WPAN_PHY, rdev->wpan_phy_idx) ||
466 nla_put_string(msg, NL802154_ATTR_WPAN_PHY_NAME,
467 wpan_phy_name(&rdev->wpan_phy)) ||
468 nla_put_u32(msg, NL802154_ATTR_GENERATION,
469 cfg802154_rdev_list_generation))
470 goto nla_put_failure;
472 if (cmd != NL802154_CMD_NEW_WPAN_PHY)
473 goto finish;
475 /* DUMP PHY PIB */
477 /* current channel settings */
478 if (nla_put_u8(msg, NL802154_ATTR_PAGE,
479 rdev->wpan_phy.current_page) ||
480 nla_put_u8(msg, NL802154_ATTR_CHANNEL,
481 rdev->wpan_phy.current_channel))
482 goto nla_put_failure;
484 /* TODO remove this behaviour, we still keep support it for a while
485 * so users can change the behaviour to the new one.
487 if (nl802154_send_wpan_phy_channels(rdev, msg))
488 goto nla_put_failure;
490 /* cca mode */
491 if (rdev->wpan_phy.flags & WPAN_PHY_FLAG_CCA_MODE) {
492 if (nla_put_u32(msg, NL802154_ATTR_CCA_MODE,
493 rdev->wpan_phy.cca.mode))
494 goto nla_put_failure;
496 if (rdev->wpan_phy.cca.mode == NL802154_CCA_ENERGY_CARRIER) {
497 if (nla_put_u32(msg, NL802154_ATTR_CCA_OPT,
498 rdev->wpan_phy.cca.opt))
499 goto nla_put_failure;
503 if (rdev->wpan_phy.flags & WPAN_PHY_FLAG_TXPOWER) {
504 if (nla_put_s32(msg, NL802154_ATTR_TX_POWER,
505 rdev->wpan_phy.transmit_power))
506 goto nla_put_failure;
509 if (rdev->wpan_phy.flags & WPAN_PHY_FLAG_CCA_ED_LEVEL) {
510 if (nla_put_s32(msg, NL802154_ATTR_CCA_ED_LEVEL,
511 rdev->wpan_phy.cca_ed_level))
512 goto nla_put_failure;
515 if (nl802154_put_capabilities(msg, rdev))
516 goto nla_put_failure;
518 nl_cmds = nla_nest_start(msg, NL802154_ATTR_SUPPORTED_COMMANDS);
519 if (!nl_cmds)
520 goto nla_put_failure;
522 i = 0;
523 #define CMD(op, n) \
524 do { \
525 if (rdev->ops->op) { \
526 i++; \
527 if (nla_put_u32(msg, i, NL802154_CMD_ ## n)) \
528 goto nla_put_failure; \
530 } while (0)
532 CMD(add_virtual_intf, NEW_INTERFACE);
533 CMD(del_virtual_intf, DEL_INTERFACE);
534 CMD(set_channel, SET_CHANNEL);
535 CMD(set_pan_id, SET_PAN_ID);
536 CMD(set_short_addr, SET_SHORT_ADDR);
537 CMD(set_backoff_exponent, SET_BACKOFF_EXPONENT);
538 CMD(set_max_csma_backoffs, SET_MAX_CSMA_BACKOFFS);
539 CMD(set_max_frame_retries, SET_MAX_FRAME_RETRIES);
540 CMD(set_lbt_mode, SET_LBT_MODE);
541 CMD(set_ackreq_default, SET_ACKREQ_DEFAULT);
543 if (rdev->wpan_phy.flags & WPAN_PHY_FLAG_TXPOWER)
544 CMD(set_tx_power, SET_TX_POWER);
546 if (rdev->wpan_phy.flags & WPAN_PHY_FLAG_CCA_ED_LEVEL)
547 CMD(set_cca_ed_level, SET_CCA_ED_LEVEL);
549 if (rdev->wpan_phy.flags & WPAN_PHY_FLAG_CCA_MODE)
550 CMD(set_cca_mode, SET_CCA_MODE);
552 #undef CMD
553 nla_nest_end(msg, nl_cmds);
555 finish:
556 genlmsg_end(msg, hdr);
557 return 0;
559 nla_put_failure:
560 genlmsg_cancel(msg, hdr);
561 return -EMSGSIZE;
564 struct nl802154_dump_wpan_phy_state {
565 s64 filter_wpan_phy;
566 long start;
570 static int nl802154_dump_wpan_phy_parse(struct sk_buff *skb,
571 struct netlink_callback *cb,
572 struct nl802154_dump_wpan_phy_state *state)
574 struct nlattr **tb = nl802154_fam.attrbuf;
575 int ret = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl802154_fam.hdrsize,
576 tb, nl802154_fam.maxattr, nl802154_policy);
578 /* TODO check if we can handle error here,
579 * we have no backward compatibility
581 if (ret)
582 return 0;
584 if (tb[NL802154_ATTR_WPAN_PHY])
585 state->filter_wpan_phy = nla_get_u32(tb[NL802154_ATTR_WPAN_PHY]);
586 if (tb[NL802154_ATTR_WPAN_DEV])
587 state->filter_wpan_phy = nla_get_u64(tb[NL802154_ATTR_WPAN_DEV]) >> 32;
588 if (tb[NL802154_ATTR_IFINDEX]) {
589 struct net_device *netdev;
590 struct cfg802154_registered_device *rdev;
591 int ifidx = nla_get_u32(tb[NL802154_ATTR_IFINDEX]);
593 /* TODO netns */
594 netdev = __dev_get_by_index(&init_net, ifidx);
595 if (!netdev)
596 return -ENODEV;
597 if (netdev->ieee802154_ptr) {
598 rdev = wpan_phy_to_rdev(
599 netdev->ieee802154_ptr->wpan_phy);
600 state->filter_wpan_phy = rdev->wpan_phy_idx;
604 return 0;
607 static int
608 nl802154_dump_wpan_phy(struct sk_buff *skb, struct netlink_callback *cb)
610 int idx = 0, ret;
611 struct nl802154_dump_wpan_phy_state *state = (void *)cb->args[0];
612 struct cfg802154_registered_device *rdev;
614 rtnl_lock();
615 if (!state) {
616 state = kzalloc(sizeof(*state), GFP_KERNEL);
617 if (!state) {
618 rtnl_unlock();
619 return -ENOMEM;
621 state->filter_wpan_phy = -1;
622 ret = nl802154_dump_wpan_phy_parse(skb, cb, state);
623 if (ret) {
624 kfree(state);
625 rtnl_unlock();
626 return ret;
628 cb->args[0] = (long)state;
631 list_for_each_entry(rdev, &cfg802154_rdev_list, list) {
632 /* TODO net ns compare */
633 if (++idx <= state->start)
634 continue;
635 if (state->filter_wpan_phy != -1 &&
636 state->filter_wpan_phy != rdev->wpan_phy_idx)
637 continue;
638 /* attempt to fit multiple wpan_phy data chunks into the skb */
639 ret = nl802154_send_wpan_phy(rdev,
640 NL802154_CMD_NEW_WPAN_PHY,
641 skb,
642 NETLINK_CB(cb->skb).portid,
643 cb->nlh->nlmsg_seq, NLM_F_MULTI);
644 if (ret < 0) {
645 if ((ret == -ENOBUFS || ret == -EMSGSIZE) &&
646 !skb->len && cb->min_dump_alloc < 4096) {
647 cb->min_dump_alloc = 4096;
648 rtnl_unlock();
649 return 1;
651 idx--;
652 break;
654 break;
656 rtnl_unlock();
658 state->start = idx;
660 return skb->len;
663 static int nl802154_dump_wpan_phy_done(struct netlink_callback *cb)
665 kfree((void *)cb->args[0]);
666 return 0;
669 static int nl802154_get_wpan_phy(struct sk_buff *skb, struct genl_info *info)
671 struct sk_buff *msg;
672 struct cfg802154_registered_device *rdev = info->user_ptr[0];
674 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
675 if (!msg)
676 return -ENOMEM;
678 if (nl802154_send_wpan_phy(rdev, NL802154_CMD_NEW_WPAN_PHY, msg,
679 info->snd_portid, info->snd_seq, 0) < 0) {
680 nlmsg_free(msg);
681 return -ENOBUFS;
684 return genlmsg_reply(msg, info);
687 static inline u64 wpan_dev_id(struct wpan_dev *wpan_dev)
689 return (u64)wpan_dev->identifier |
690 ((u64)wpan_phy_to_rdev(wpan_dev->wpan_phy)->wpan_phy_idx << 32);
693 #ifdef CONFIG_IEEE802154_NL802154_EXPERIMENTAL
694 #include <net/ieee802154_netdev.h>
696 static int
697 ieee802154_llsec_send_key_id(struct sk_buff *msg,
698 const struct ieee802154_llsec_key_id *desc)
700 struct nlattr *nl_dev_addr;
702 if (nla_put_u32(msg, NL802154_KEY_ID_ATTR_MODE, desc->mode))
703 return -ENOBUFS;
705 switch (desc->mode) {
706 case NL802154_KEY_ID_MODE_IMPLICIT:
707 nl_dev_addr = nla_nest_start(msg, NL802154_KEY_ID_ATTR_IMPLICIT);
708 if (!nl_dev_addr)
709 return -ENOBUFS;
711 if (nla_put_le16(msg, NL802154_DEV_ADDR_ATTR_PAN_ID,
712 desc->device_addr.pan_id) ||
713 nla_put_u32(msg, NL802154_DEV_ADDR_ATTR_MODE,
714 desc->device_addr.mode))
715 return -ENOBUFS;
717 switch (desc->device_addr.mode) {
718 case NL802154_DEV_ADDR_SHORT:
719 if (nla_put_le16(msg, NL802154_DEV_ADDR_ATTR_SHORT,
720 desc->device_addr.short_addr))
721 return -ENOBUFS;
722 break;
723 case NL802154_DEV_ADDR_EXTENDED:
724 if (nla_put_le64(msg, NL802154_DEV_ADDR_ATTR_EXTENDED,
725 desc->device_addr.extended_addr))
726 return -ENOBUFS;
727 break;
728 default:
729 /* userspace should handle unknown */
730 break;
733 nla_nest_end(msg, nl_dev_addr);
734 break;
735 case NL802154_KEY_ID_MODE_INDEX:
736 break;
737 case NL802154_KEY_ID_MODE_INDEX_SHORT:
738 /* TODO renmae short_source? */
739 if (nla_put_le32(msg, NL802154_KEY_ID_ATTR_SOURCE_SHORT,
740 desc->short_source))
741 return -ENOBUFS;
742 break;
743 case NL802154_KEY_ID_MODE_INDEX_EXTENDED:
744 if (nla_put_le64(msg, NL802154_KEY_ID_ATTR_SOURCE_EXTENDED,
745 desc->extended_source))
746 return -ENOBUFS;
747 break;
748 default:
749 /* userspace should handle unknown */
750 break;
753 /* TODO key_id to key_idx ? Check naming */
754 if (desc->mode != NL802154_KEY_ID_MODE_IMPLICIT) {
755 if (nla_put_u8(msg, NL802154_KEY_ID_ATTR_INDEX, desc->id))
756 return -ENOBUFS;
759 return 0;
762 static int nl802154_get_llsec_params(struct sk_buff *msg,
763 struct cfg802154_registered_device *rdev,
764 struct wpan_dev *wpan_dev)
766 struct nlattr *nl_key_id;
767 struct ieee802154_llsec_params params;
768 int ret;
770 ret = rdev_get_llsec_params(rdev, wpan_dev, &params);
771 if (ret < 0)
772 return ret;
774 if (nla_put_u8(msg, NL802154_ATTR_SEC_ENABLED, params.enabled) ||
775 nla_put_u32(msg, NL802154_ATTR_SEC_OUT_LEVEL, params.out_level) ||
776 nla_put_be32(msg, NL802154_ATTR_SEC_FRAME_COUNTER,
777 params.frame_counter))
778 return -ENOBUFS;
780 nl_key_id = nla_nest_start(msg, NL802154_ATTR_SEC_OUT_KEY_ID);
781 if (!nl_key_id)
782 return -ENOBUFS;
784 ret = ieee802154_llsec_send_key_id(msg, &params.out_key);
785 if (ret < 0)
786 return ret;
788 nla_nest_end(msg, nl_key_id);
790 return 0;
792 #endif /* CONFIG_IEEE802154_NL802154_EXPERIMENTAL */
794 static int
795 nl802154_send_iface(struct sk_buff *msg, u32 portid, u32 seq, int flags,
796 struct cfg802154_registered_device *rdev,
797 struct wpan_dev *wpan_dev)
799 struct net_device *dev = wpan_dev->netdev;
800 void *hdr;
802 hdr = nl802154hdr_put(msg, portid, seq, flags,
803 NL802154_CMD_NEW_INTERFACE);
804 if (!hdr)
805 return -1;
807 if (dev &&
808 (nla_put_u32(msg, NL802154_ATTR_IFINDEX, dev->ifindex) ||
809 nla_put_string(msg, NL802154_ATTR_IFNAME, dev->name)))
810 goto nla_put_failure;
812 if (nla_put_u32(msg, NL802154_ATTR_WPAN_PHY, rdev->wpan_phy_idx) ||
813 nla_put_u32(msg, NL802154_ATTR_IFTYPE, wpan_dev->iftype) ||
814 nla_put_u64(msg, NL802154_ATTR_WPAN_DEV, wpan_dev_id(wpan_dev)) ||
815 nla_put_u32(msg, NL802154_ATTR_GENERATION,
816 rdev->devlist_generation ^
817 (cfg802154_rdev_list_generation << 2)))
818 goto nla_put_failure;
820 /* address settings */
821 if (nla_put_le64(msg, NL802154_ATTR_EXTENDED_ADDR,
822 wpan_dev->extended_addr) ||
823 nla_put_le16(msg, NL802154_ATTR_SHORT_ADDR,
824 wpan_dev->short_addr) ||
825 nla_put_le16(msg, NL802154_ATTR_PAN_ID, wpan_dev->pan_id))
826 goto nla_put_failure;
828 /* ARET handling */
829 if (nla_put_s8(msg, NL802154_ATTR_MAX_FRAME_RETRIES,
830 wpan_dev->frame_retries) ||
831 nla_put_u8(msg, NL802154_ATTR_MAX_BE, wpan_dev->max_be) ||
832 nla_put_u8(msg, NL802154_ATTR_MAX_CSMA_BACKOFFS,
833 wpan_dev->csma_retries) ||
834 nla_put_u8(msg, NL802154_ATTR_MIN_BE, wpan_dev->min_be))
835 goto nla_put_failure;
837 /* listen before transmit */
838 if (nla_put_u8(msg, NL802154_ATTR_LBT_MODE, wpan_dev->lbt))
839 goto nla_put_failure;
841 /* ackreq default behaviour */
842 if (nla_put_u8(msg, NL802154_ATTR_ACKREQ_DEFAULT, wpan_dev->ackreq))
843 goto nla_put_failure;
845 #ifdef CONFIG_IEEE802154_NL802154_EXPERIMENTAL
846 if (nl802154_get_llsec_params(msg, rdev, wpan_dev) < 0)
847 goto nla_put_failure;
848 #endif /* CONFIG_IEEE802154_NL802154_EXPERIMENTAL */
850 genlmsg_end(msg, hdr);
851 return 0;
853 nla_put_failure:
854 genlmsg_cancel(msg, hdr);
855 return -EMSGSIZE;
858 static int
859 nl802154_dump_interface(struct sk_buff *skb, struct netlink_callback *cb)
861 int wp_idx = 0;
862 int if_idx = 0;
863 int wp_start = cb->args[0];
864 int if_start = cb->args[1];
865 struct cfg802154_registered_device *rdev;
866 struct wpan_dev *wpan_dev;
868 rtnl_lock();
869 list_for_each_entry(rdev, &cfg802154_rdev_list, list) {
870 /* TODO netns compare */
871 if (wp_idx < wp_start) {
872 wp_idx++;
873 continue;
875 if_idx = 0;
877 list_for_each_entry(wpan_dev, &rdev->wpan_dev_list, list) {
878 if (if_idx < if_start) {
879 if_idx++;
880 continue;
882 if (nl802154_send_iface(skb, NETLINK_CB(cb->skb).portid,
883 cb->nlh->nlmsg_seq, NLM_F_MULTI,
884 rdev, wpan_dev) < 0) {
885 goto out;
887 if_idx++;
890 wp_idx++;
892 out:
893 rtnl_unlock();
895 cb->args[0] = wp_idx;
896 cb->args[1] = if_idx;
898 return skb->len;
901 static int nl802154_get_interface(struct sk_buff *skb, struct genl_info *info)
903 struct sk_buff *msg;
904 struct cfg802154_registered_device *rdev = info->user_ptr[0];
905 struct wpan_dev *wdev = info->user_ptr[1];
907 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
908 if (!msg)
909 return -ENOMEM;
911 if (nl802154_send_iface(msg, info->snd_portid, info->snd_seq, 0,
912 rdev, wdev) < 0) {
913 nlmsg_free(msg);
914 return -ENOBUFS;
917 return genlmsg_reply(msg, info);
920 static int nl802154_new_interface(struct sk_buff *skb, struct genl_info *info)
922 struct cfg802154_registered_device *rdev = info->user_ptr[0];
923 enum nl802154_iftype type = NL802154_IFTYPE_UNSPEC;
924 __le64 extended_addr = cpu_to_le64(0x0000000000000000ULL);
926 /* TODO avoid failing a new interface
927 * creation due to pending removal?
930 if (!info->attrs[NL802154_ATTR_IFNAME])
931 return -EINVAL;
933 if (info->attrs[NL802154_ATTR_IFTYPE]) {
934 type = nla_get_u32(info->attrs[NL802154_ATTR_IFTYPE]);
935 if (type > NL802154_IFTYPE_MAX ||
936 !(rdev->wpan_phy.supported.iftypes & BIT(type)))
937 return -EINVAL;
940 if (info->attrs[NL802154_ATTR_EXTENDED_ADDR])
941 extended_addr = nla_get_le64(info->attrs[NL802154_ATTR_EXTENDED_ADDR]);
943 if (!rdev->ops->add_virtual_intf)
944 return -EOPNOTSUPP;
946 return rdev_add_virtual_intf(rdev,
947 nla_data(info->attrs[NL802154_ATTR_IFNAME]),
948 NET_NAME_USER, type, extended_addr);
951 static int nl802154_del_interface(struct sk_buff *skb, struct genl_info *info)
953 struct cfg802154_registered_device *rdev = info->user_ptr[0];
954 struct wpan_dev *wpan_dev = info->user_ptr[1];
956 if (!rdev->ops->del_virtual_intf)
957 return -EOPNOTSUPP;
959 /* If we remove a wpan device without a netdev then clear
960 * user_ptr[1] so that nl802154_post_doit won't dereference it
961 * to check if it needs to do dev_put(). Otherwise it crashes
962 * since the wpan_dev has been freed, unlike with a netdev where
963 * we need the dev_put() for the netdev to really be freed.
965 if (!wpan_dev->netdev)
966 info->user_ptr[1] = NULL;
968 return rdev_del_virtual_intf(rdev, wpan_dev);
971 static int nl802154_set_channel(struct sk_buff *skb, struct genl_info *info)
973 struct cfg802154_registered_device *rdev = info->user_ptr[0];
974 u8 channel, page;
976 if (!info->attrs[NL802154_ATTR_PAGE] ||
977 !info->attrs[NL802154_ATTR_CHANNEL])
978 return -EINVAL;
980 page = nla_get_u8(info->attrs[NL802154_ATTR_PAGE]);
981 channel = nla_get_u8(info->attrs[NL802154_ATTR_CHANNEL]);
983 /* check 802.15.4 constraints */
984 if (page > IEEE802154_MAX_PAGE || channel > IEEE802154_MAX_CHANNEL ||
985 !(rdev->wpan_phy.supported.channels[page] & BIT(channel)))
986 return -EINVAL;
988 return rdev_set_channel(rdev, page, channel);
991 static int nl802154_set_cca_mode(struct sk_buff *skb, struct genl_info *info)
993 struct cfg802154_registered_device *rdev = info->user_ptr[0];
994 struct wpan_phy_cca cca;
996 if (!(rdev->wpan_phy.flags & WPAN_PHY_FLAG_CCA_MODE))
997 return -EOPNOTSUPP;
999 if (!info->attrs[NL802154_ATTR_CCA_MODE])
1000 return -EINVAL;
1002 cca.mode = nla_get_u32(info->attrs[NL802154_ATTR_CCA_MODE]);
1003 /* checking 802.15.4 constraints */
1004 if (cca.mode < NL802154_CCA_ENERGY ||
1005 cca.mode > NL802154_CCA_ATTR_MAX ||
1006 !(rdev->wpan_phy.supported.cca_modes & BIT(cca.mode)))
1007 return -EINVAL;
1009 if (cca.mode == NL802154_CCA_ENERGY_CARRIER) {
1010 if (!info->attrs[NL802154_ATTR_CCA_OPT])
1011 return -EINVAL;
1013 cca.opt = nla_get_u32(info->attrs[NL802154_ATTR_CCA_OPT]);
1014 if (cca.opt > NL802154_CCA_OPT_ATTR_MAX ||
1015 !(rdev->wpan_phy.supported.cca_opts & BIT(cca.opt)))
1016 return -EINVAL;
1019 return rdev_set_cca_mode(rdev, &cca);
1022 static int nl802154_set_cca_ed_level(struct sk_buff *skb, struct genl_info *info)
1024 struct cfg802154_registered_device *rdev = info->user_ptr[0];
1025 s32 ed_level;
1026 int i;
1028 if (!(rdev->wpan_phy.flags & WPAN_PHY_FLAG_CCA_ED_LEVEL))
1029 return -EOPNOTSUPP;
1031 if (!info->attrs[NL802154_ATTR_CCA_ED_LEVEL])
1032 return -EINVAL;
1034 ed_level = nla_get_s32(info->attrs[NL802154_ATTR_CCA_ED_LEVEL]);
1036 for (i = 0; i < rdev->wpan_phy.supported.cca_ed_levels_size; i++) {
1037 if (ed_level == rdev->wpan_phy.supported.cca_ed_levels[i])
1038 return rdev_set_cca_ed_level(rdev, ed_level);
1041 return -EINVAL;
1044 static int nl802154_set_tx_power(struct sk_buff *skb, struct genl_info *info)
1046 struct cfg802154_registered_device *rdev = info->user_ptr[0];
1047 s32 power;
1048 int i;
1050 if (!(rdev->wpan_phy.flags & WPAN_PHY_FLAG_TXPOWER))
1051 return -EOPNOTSUPP;
1053 if (!info->attrs[NL802154_ATTR_TX_POWER])
1054 return -EINVAL;
1056 power = nla_get_s32(info->attrs[NL802154_ATTR_TX_POWER]);
1058 for (i = 0; i < rdev->wpan_phy.supported.tx_powers_size; i++) {
1059 if (power == rdev->wpan_phy.supported.tx_powers[i])
1060 return rdev_set_tx_power(rdev, power);
1063 return -EINVAL;
1066 static int nl802154_set_pan_id(struct sk_buff *skb, struct genl_info *info)
1068 struct cfg802154_registered_device *rdev = info->user_ptr[0];
1069 struct net_device *dev = info->user_ptr[1];
1070 struct wpan_dev *wpan_dev = dev->ieee802154_ptr;
1071 __le16 pan_id;
1073 /* conflict here while tx/rx calls */
1074 if (netif_running(dev))
1075 return -EBUSY;
1077 /* don't change address fields on monitor */
1078 if (wpan_dev->iftype == NL802154_IFTYPE_MONITOR ||
1079 !info->attrs[NL802154_ATTR_PAN_ID])
1080 return -EINVAL;
1082 pan_id = nla_get_le16(info->attrs[NL802154_ATTR_PAN_ID]);
1084 /* TODO
1085 * I am not sure about to check here on broadcast pan_id.
1086 * Broadcast is a valid setting, comment from 802.15.4:
1087 * If this value is 0xffff, the device is not associated.
1089 * This could useful to simple deassociate an device.
1091 if (pan_id == cpu_to_le16(IEEE802154_PAN_ID_BROADCAST))
1092 return -EINVAL;
1094 return rdev_set_pan_id(rdev, wpan_dev, pan_id);
1097 static int nl802154_set_short_addr(struct sk_buff *skb, struct genl_info *info)
1099 struct cfg802154_registered_device *rdev = info->user_ptr[0];
1100 struct net_device *dev = info->user_ptr[1];
1101 struct wpan_dev *wpan_dev = dev->ieee802154_ptr;
1102 __le16 short_addr;
1104 /* conflict here while tx/rx calls */
1105 if (netif_running(dev))
1106 return -EBUSY;
1108 /* don't change address fields on monitor */
1109 if (wpan_dev->iftype == NL802154_IFTYPE_MONITOR ||
1110 !info->attrs[NL802154_ATTR_SHORT_ADDR])
1111 return -EINVAL;
1113 short_addr = nla_get_le16(info->attrs[NL802154_ATTR_SHORT_ADDR]);
1115 /* TODO
1116 * I am not sure about to check here on broadcast short_addr.
1117 * Broadcast is a valid setting, comment from 802.15.4:
1118 * A value of 0xfffe indicates that the device has
1119 * associated but has not been allocated an address. A
1120 * value of 0xffff indicates that the device does not
1121 * have a short address.
1123 * I think we should allow to set these settings but
1124 * don't allow to allow socket communication with it.
1126 if (short_addr == cpu_to_le16(IEEE802154_ADDR_SHORT_UNSPEC) ||
1127 short_addr == cpu_to_le16(IEEE802154_ADDR_SHORT_BROADCAST))
1128 return -EINVAL;
1130 return rdev_set_short_addr(rdev, wpan_dev, short_addr);
1133 static int
1134 nl802154_set_backoff_exponent(struct sk_buff *skb, struct genl_info *info)
1136 struct cfg802154_registered_device *rdev = info->user_ptr[0];
1137 struct net_device *dev = info->user_ptr[1];
1138 struct wpan_dev *wpan_dev = dev->ieee802154_ptr;
1139 u8 min_be, max_be;
1141 /* should be set on netif open inside phy settings */
1142 if (netif_running(dev))
1143 return -EBUSY;
1145 if (!info->attrs[NL802154_ATTR_MIN_BE] ||
1146 !info->attrs[NL802154_ATTR_MAX_BE])
1147 return -EINVAL;
1149 min_be = nla_get_u8(info->attrs[NL802154_ATTR_MIN_BE]);
1150 max_be = nla_get_u8(info->attrs[NL802154_ATTR_MAX_BE]);
1152 /* check 802.15.4 constraints */
1153 if (min_be < rdev->wpan_phy.supported.min_minbe ||
1154 min_be > rdev->wpan_phy.supported.max_minbe ||
1155 max_be < rdev->wpan_phy.supported.min_maxbe ||
1156 max_be > rdev->wpan_phy.supported.max_maxbe ||
1157 min_be > max_be)
1158 return -EINVAL;
1160 return rdev_set_backoff_exponent(rdev, wpan_dev, min_be, max_be);
1163 static int
1164 nl802154_set_max_csma_backoffs(struct sk_buff *skb, struct genl_info *info)
1166 struct cfg802154_registered_device *rdev = info->user_ptr[0];
1167 struct net_device *dev = info->user_ptr[1];
1168 struct wpan_dev *wpan_dev = dev->ieee802154_ptr;
1169 u8 max_csma_backoffs;
1171 /* conflict here while other running iface settings */
1172 if (netif_running(dev))
1173 return -EBUSY;
1175 if (!info->attrs[NL802154_ATTR_MAX_CSMA_BACKOFFS])
1176 return -EINVAL;
1178 max_csma_backoffs = nla_get_u8(
1179 info->attrs[NL802154_ATTR_MAX_CSMA_BACKOFFS]);
1181 /* check 802.15.4 constraints */
1182 if (max_csma_backoffs < rdev->wpan_phy.supported.min_csma_backoffs ||
1183 max_csma_backoffs > rdev->wpan_phy.supported.max_csma_backoffs)
1184 return -EINVAL;
1186 return rdev_set_max_csma_backoffs(rdev, wpan_dev, max_csma_backoffs);
1189 static int
1190 nl802154_set_max_frame_retries(struct sk_buff *skb, struct genl_info *info)
1192 struct cfg802154_registered_device *rdev = info->user_ptr[0];
1193 struct net_device *dev = info->user_ptr[1];
1194 struct wpan_dev *wpan_dev = dev->ieee802154_ptr;
1195 s8 max_frame_retries;
1197 if (netif_running(dev))
1198 return -EBUSY;
1200 if (!info->attrs[NL802154_ATTR_MAX_FRAME_RETRIES])
1201 return -EINVAL;
1203 max_frame_retries = nla_get_s8(
1204 info->attrs[NL802154_ATTR_MAX_FRAME_RETRIES]);
1206 /* check 802.15.4 constraints */
1207 if (max_frame_retries < rdev->wpan_phy.supported.min_frame_retries ||
1208 max_frame_retries > rdev->wpan_phy.supported.max_frame_retries)
1209 return -EINVAL;
1211 return rdev_set_max_frame_retries(rdev, wpan_dev, max_frame_retries);
1214 static int nl802154_set_lbt_mode(struct sk_buff *skb, struct genl_info *info)
1216 struct cfg802154_registered_device *rdev = info->user_ptr[0];
1217 struct net_device *dev = info->user_ptr[1];
1218 struct wpan_dev *wpan_dev = dev->ieee802154_ptr;
1219 int mode;
1221 if (netif_running(dev))
1222 return -EBUSY;
1224 if (!info->attrs[NL802154_ATTR_LBT_MODE])
1225 return -EINVAL;
1227 mode = nla_get_u8(info->attrs[NL802154_ATTR_LBT_MODE]);
1229 if (mode != 0 && mode != 1)
1230 return -EINVAL;
1232 if (!wpan_phy_supported_bool(mode, rdev->wpan_phy.supported.lbt))
1233 return -EINVAL;
1235 return rdev_set_lbt_mode(rdev, wpan_dev, mode);
1238 static int
1239 nl802154_set_ackreq_default(struct sk_buff *skb, struct genl_info *info)
1241 struct cfg802154_registered_device *rdev = info->user_ptr[0];
1242 struct net_device *dev = info->user_ptr[1];
1243 struct wpan_dev *wpan_dev = dev->ieee802154_ptr;
1244 int ackreq;
1246 if (netif_running(dev))
1247 return -EBUSY;
1249 if (!info->attrs[NL802154_ATTR_ACKREQ_DEFAULT])
1250 return -EINVAL;
1252 ackreq = nla_get_u8(info->attrs[NL802154_ATTR_ACKREQ_DEFAULT]);
1254 if (ackreq != 0 && ackreq != 1)
1255 return -EINVAL;
1257 return rdev_set_ackreq_default(rdev, wpan_dev, ackreq);
1260 #ifdef CONFIG_IEEE802154_NL802154_EXPERIMENTAL
1261 static const struct nla_policy nl802154_dev_addr_policy[NL802154_DEV_ADDR_ATTR_MAX + 1] = {
1262 [NL802154_DEV_ADDR_ATTR_PAN_ID] = { .type = NLA_U16 },
1263 [NL802154_DEV_ADDR_ATTR_MODE] = { .type = NLA_U32 },
1264 [NL802154_DEV_ADDR_ATTR_SHORT] = { .type = NLA_U16 },
1265 [NL802154_DEV_ADDR_ATTR_EXTENDED] = { .type = NLA_U64 },
1268 static int
1269 ieee802154_llsec_parse_dev_addr(struct nlattr *nla,
1270 struct ieee802154_addr *addr)
1272 struct nlattr *attrs[NL802154_DEV_ADDR_ATTR_MAX + 1];
1274 if (!nla || nla_parse_nested(attrs, NL802154_DEV_ADDR_ATTR_MAX, nla,
1275 nl802154_dev_addr_policy))
1276 return -EINVAL;
1278 if (!attrs[NL802154_DEV_ADDR_ATTR_PAN_ID] &&
1279 !attrs[NL802154_DEV_ADDR_ATTR_MODE] &&
1280 !(attrs[NL802154_DEV_ADDR_ATTR_SHORT] ||
1281 attrs[NL802154_DEV_ADDR_ATTR_EXTENDED]))
1282 return -EINVAL;
1284 addr->pan_id = nla_get_le16(attrs[NL802154_DEV_ADDR_ATTR_PAN_ID]);
1285 addr->mode = nla_get_u32(attrs[NL802154_DEV_ADDR_ATTR_MODE]);
1286 switch (addr->mode) {
1287 case NL802154_DEV_ADDR_SHORT:
1288 addr->short_addr = nla_get_le16(attrs[NL802154_DEV_ADDR_ATTR_SHORT]);
1289 break;
1290 case NL802154_DEV_ADDR_EXTENDED:
1291 addr->extended_addr = nla_get_le64(attrs[NL802154_DEV_ADDR_ATTR_EXTENDED]);
1292 break;
1293 default:
1294 return -EINVAL;
1297 return 0;
1300 static const struct nla_policy nl802154_key_id_policy[NL802154_KEY_ID_ATTR_MAX + 1] = {
1301 [NL802154_KEY_ID_ATTR_MODE] = { .type = NLA_U32 },
1302 [NL802154_KEY_ID_ATTR_INDEX] = { .type = NLA_U8 },
1303 [NL802154_KEY_ID_ATTR_IMPLICIT] = { .type = NLA_NESTED },
1304 [NL802154_KEY_ID_ATTR_SOURCE_SHORT] = { .type = NLA_U32 },
1305 [NL802154_KEY_ID_ATTR_SOURCE_EXTENDED] = { .type = NLA_U64 },
1308 static int
1309 ieee802154_llsec_parse_key_id(struct nlattr *nla,
1310 struct ieee802154_llsec_key_id *desc)
1312 struct nlattr *attrs[NL802154_KEY_ID_ATTR_MAX + 1];
1314 if (!nla || nla_parse_nested(attrs, NL802154_KEY_ID_ATTR_MAX, nla,
1315 nl802154_key_id_policy))
1316 return -EINVAL;
1318 if (!attrs[NL802154_KEY_ID_ATTR_MODE])
1319 return -EINVAL;
1321 desc->mode = nla_get_u32(attrs[NL802154_KEY_ID_ATTR_MODE]);
1322 switch (desc->mode) {
1323 case NL802154_KEY_ID_MODE_IMPLICIT:
1324 if (!attrs[NL802154_KEY_ID_ATTR_IMPLICIT])
1325 return -EINVAL;
1327 if (ieee802154_llsec_parse_dev_addr(attrs[NL802154_KEY_ID_ATTR_IMPLICIT],
1328 &desc->device_addr) < 0)
1329 return -EINVAL;
1330 break;
1331 case NL802154_KEY_ID_MODE_INDEX:
1332 break;
1333 case NL802154_KEY_ID_MODE_INDEX_SHORT:
1334 if (!attrs[NL802154_KEY_ID_ATTR_SOURCE_SHORT])
1335 return -EINVAL;
1337 desc->short_source = nla_get_le32(attrs[NL802154_KEY_ID_ATTR_SOURCE_SHORT]);
1338 break;
1339 case NL802154_KEY_ID_MODE_INDEX_EXTENDED:
1340 if (!attrs[NL802154_KEY_ID_ATTR_SOURCE_EXTENDED])
1341 return -EINVAL;
1343 desc->extended_source = nla_get_le64(attrs[NL802154_KEY_ID_ATTR_SOURCE_EXTENDED]);
1344 break;
1345 default:
1346 return -EINVAL;
1349 if (desc->mode != NL802154_KEY_ID_MODE_IMPLICIT) {
1350 if (!attrs[NL802154_KEY_ID_ATTR_INDEX])
1351 return -EINVAL;
1353 /* TODO change id to idx */
1354 desc->id = nla_get_u8(attrs[NL802154_KEY_ID_ATTR_INDEX]);
1357 return 0;
1360 static int nl802154_set_llsec_params(struct sk_buff *skb,
1361 struct genl_info *info)
1363 struct cfg802154_registered_device *rdev = info->user_ptr[0];
1364 struct net_device *dev = info->user_ptr[1];
1365 struct wpan_dev *wpan_dev = dev->ieee802154_ptr;
1366 struct ieee802154_llsec_params params;
1367 u32 changed = 0;
1368 int ret;
1370 if (info->attrs[NL802154_ATTR_SEC_ENABLED]) {
1371 u8 enabled;
1373 enabled = nla_get_u8(info->attrs[NL802154_ATTR_SEC_ENABLED]);
1374 if (enabled != 0 && enabled != 1)
1375 return -EINVAL;
1377 params.enabled = nla_get_u8(info->attrs[NL802154_ATTR_SEC_ENABLED]);
1378 changed |= IEEE802154_LLSEC_PARAM_ENABLED;
1381 if (info->attrs[NL802154_ATTR_SEC_OUT_KEY_ID]) {
1382 ret = ieee802154_llsec_parse_key_id(info->attrs[NL802154_ATTR_SEC_OUT_KEY_ID],
1383 &params.out_key);
1384 if (ret < 0)
1385 return ret;
1387 changed |= IEEE802154_LLSEC_PARAM_OUT_KEY;
1390 if (info->attrs[NL802154_ATTR_SEC_OUT_LEVEL]) {
1391 params.out_level = nla_get_u32(info->attrs[NL802154_ATTR_SEC_OUT_LEVEL]);
1392 if (params.out_level > NL802154_SECLEVEL_MAX)
1393 return -EINVAL;
1395 changed |= IEEE802154_LLSEC_PARAM_OUT_LEVEL;
1398 if (info->attrs[NL802154_ATTR_SEC_FRAME_COUNTER]) {
1399 params.frame_counter = nla_get_be32(info->attrs[NL802154_ATTR_SEC_FRAME_COUNTER]);
1400 changed |= IEEE802154_LLSEC_PARAM_FRAME_COUNTER;
1403 return rdev_set_llsec_params(rdev, wpan_dev, &params, changed);
1406 static int nl802154_send_key(struct sk_buff *msg, u32 cmd, u32 portid,
1407 u32 seq, int flags,
1408 struct cfg802154_registered_device *rdev,
1409 struct net_device *dev,
1410 const struct ieee802154_llsec_key_entry *key)
1412 void *hdr;
1413 u32 commands[NL802154_CMD_FRAME_NR_IDS / 32];
1414 struct nlattr *nl_key, *nl_key_id;
1416 hdr = nl802154hdr_put(msg, portid, seq, flags, cmd);
1417 if (!hdr)
1418 return -1;
1420 if (nla_put_u32(msg, NL802154_ATTR_IFINDEX, dev->ifindex))
1421 goto nla_put_failure;
1423 nl_key = nla_nest_start(msg, NL802154_ATTR_SEC_KEY);
1424 if (!nl_key)
1425 goto nla_put_failure;
1427 nl_key_id = nla_nest_start(msg, NL802154_KEY_ATTR_ID);
1428 if (!nl_key_id)
1429 goto nla_put_failure;
1431 if (ieee802154_llsec_send_key_id(msg, &key->id) < 0)
1432 goto nla_put_failure;
1434 nla_nest_end(msg, nl_key_id);
1436 if (nla_put_u8(msg, NL802154_KEY_ATTR_USAGE_FRAMES,
1437 key->key->frame_types))
1438 goto nla_put_failure;
1440 if (key->key->frame_types & BIT(NL802154_FRAME_CMD)) {
1441 /* TODO for each nested */
1442 memset(commands, 0, sizeof(commands));
1443 commands[7] = key->key->cmd_frame_ids;
1444 if (nla_put(msg, NL802154_KEY_ATTR_USAGE_CMDS,
1445 sizeof(commands), commands))
1446 goto nla_put_failure;
1449 if (nla_put(msg, NL802154_KEY_ATTR_BYTES, NL802154_KEY_SIZE,
1450 key->key->key))
1451 goto nla_put_failure;
1453 nla_nest_end(msg, nl_key);
1454 genlmsg_end(msg, hdr);
1456 return 0;
1458 nla_put_failure:
1459 genlmsg_cancel(msg, hdr);
1460 return -EMSGSIZE;
1463 static int
1464 nl802154_dump_llsec_key(struct sk_buff *skb, struct netlink_callback *cb)
1466 struct cfg802154_registered_device *rdev = NULL;
1467 struct ieee802154_llsec_key_entry *key;
1468 struct ieee802154_llsec_table *table;
1469 struct wpan_dev *wpan_dev;
1470 int err;
1472 err = nl802154_prepare_wpan_dev_dump(skb, cb, &rdev, &wpan_dev);
1473 if (err)
1474 return err;
1476 if (!wpan_dev->netdev) {
1477 err = -EINVAL;
1478 goto out_err;
1481 rdev_lock_llsec_table(rdev, wpan_dev);
1482 rdev_get_llsec_table(rdev, wpan_dev, &table);
1484 /* TODO make it like station dump */
1485 if (cb->args[2])
1486 goto out;
1488 list_for_each_entry(key, &table->keys, list) {
1489 if (nl802154_send_key(skb, NL802154_CMD_NEW_SEC_KEY,
1490 NETLINK_CB(cb->skb).portid,
1491 cb->nlh->nlmsg_seq, NLM_F_MULTI,
1492 rdev, wpan_dev->netdev, key) < 0) {
1493 /* TODO */
1494 err = -EIO;
1495 rdev_unlock_llsec_table(rdev, wpan_dev);
1496 goto out_err;
1500 cb->args[2] = 1;
1502 out:
1503 rdev_unlock_llsec_table(rdev, wpan_dev);
1504 err = skb->len;
1505 out_err:
1506 nl802154_finish_wpan_dev_dump(rdev);
1508 return err;
1511 static const struct nla_policy nl802154_key_policy[NL802154_KEY_ATTR_MAX + 1] = {
1512 [NL802154_KEY_ATTR_ID] = { NLA_NESTED },
1513 /* TODO handle it as for_each_nested and NLA_FLAG? */
1514 [NL802154_KEY_ATTR_USAGE_FRAMES] = { NLA_U8 },
1515 /* TODO handle it as for_each_nested, not static array? */
1516 [NL802154_KEY_ATTR_USAGE_CMDS] = { .len = NL802154_CMD_FRAME_NR_IDS / 8 },
1517 [NL802154_KEY_ATTR_BYTES] = { .len = NL802154_KEY_SIZE },
1520 static int nl802154_add_llsec_key(struct sk_buff *skb, struct genl_info *info)
1522 struct cfg802154_registered_device *rdev = info->user_ptr[0];
1523 struct net_device *dev = info->user_ptr[1];
1524 struct wpan_dev *wpan_dev = dev->ieee802154_ptr;
1525 struct nlattr *attrs[NL802154_KEY_ATTR_MAX + 1];
1526 struct ieee802154_llsec_key key = { };
1527 struct ieee802154_llsec_key_id id = { };
1528 u32 commands[NL802154_CMD_FRAME_NR_IDS / 32] = { };
1530 if (nla_parse_nested(attrs, NL802154_KEY_ATTR_MAX,
1531 info->attrs[NL802154_ATTR_SEC_KEY],
1532 nl802154_key_policy))
1533 return -EINVAL;
1535 if (!attrs[NL802154_KEY_ATTR_USAGE_FRAMES] ||
1536 !attrs[NL802154_KEY_ATTR_BYTES])
1537 return -EINVAL;
1539 if (ieee802154_llsec_parse_key_id(attrs[NL802154_KEY_ATTR_ID], &id) < 0)
1540 return -ENOBUFS;
1542 key.frame_types = nla_get_u8(attrs[NL802154_KEY_ATTR_USAGE_FRAMES]);
1543 if (key.frame_types > BIT(NL802154_FRAME_MAX) ||
1544 ((key.frame_types & BIT(NL802154_FRAME_CMD)) &&
1545 !attrs[NL802154_KEY_ATTR_USAGE_CMDS]))
1546 return -EINVAL;
1548 if (attrs[NL802154_KEY_ATTR_USAGE_CMDS]) {
1549 /* TODO for each nested */
1550 nla_memcpy(commands, attrs[NL802154_KEY_ATTR_USAGE_CMDS],
1551 NL802154_CMD_FRAME_NR_IDS / 8);
1553 /* TODO understand the -EINVAL logic here? last condition */
1554 if (commands[0] || commands[1] || commands[2] || commands[3] ||
1555 commands[4] || commands[5] || commands[6] ||
1556 commands[7] > BIT(NL802154_CMD_FRAME_MAX))
1557 return -EINVAL;
1559 key.cmd_frame_ids = commands[7];
1560 } else {
1561 key.cmd_frame_ids = 0;
1564 nla_memcpy(key.key, attrs[NL802154_KEY_ATTR_BYTES], NL802154_KEY_SIZE);
1566 if (ieee802154_llsec_parse_key_id(attrs[NL802154_KEY_ATTR_ID], &id) < 0)
1567 return -ENOBUFS;
1569 return rdev_add_llsec_key(rdev, wpan_dev, &id, &key);
1572 static int nl802154_del_llsec_key(struct sk_buff *skb, struct genl_info *info)
1574 struct cfg802154_registered_device *rdev = info->user_ptr[0];
1575 struct net_device *dev = info->user_ptr[1];
1576 struct wpan_dev *wpan_dev = dev->ieee802154_ptr;
1577 struct nlattr *attrs[NL802154_KEY_ATTR_MAX + 1];
1578 struct ieee802154_llsec_key_id id;
1580 if (nla_parse_nested(attrs, NL802154_KEY_ATTR_MAX,
1581 info->attrs[NL802154_ATTR_SEC_KEY],
1582 nl802154_key_policy))
1583 return -EINVAL;
1585 if (ieee802154_llsec_parse_key_id(attrs[NL802154_KEY_ATTR_ID], &id) < 0)
1586 return -ENOBUFS;
1588 return rdev_del_llsec_key(rdev, wpan_dev, &id);
1591 static int nl802154_send_device(struct sk_buff *msg, u32 cmd, u32 portid,
1592 u32 seq, int flags,
1593 struct cfg802154_registered_device *rdev,
1594 struct net_device *dev,
1595 const struct ieee802154_llsec_device *dev_desc)
1597 void *hdr;
1598 struct nlattr *nl_device;
1600 hdr = nl802154hdr_put(msg, portid, seq, flags, cmd);
1601 if (!hdr)
1602 return -1;
1604 if (nla_put_u32(msg, NL802154_ATTR_IFINDEX, dev->ifindex))
1605 goto nla_put_failure;
1607 nl_device = nla_nest_start(msg, NL802154_ATTR_SEC_DEVICE);
1608 if (!nl_device)
1609 goto nla_put_failure;
1611 if (nla_put_u32(msg, NL802154_DEV_ATTR_FRAME_COUNTER,
1612 dev_desc->frame_counter) ||
1613 nla_put_le16(msg, NL802154_DEV_ATTR_PAN_ID, dev_desc->pan_id) ||
1614 nla_put_le16(msg, NL802154_DEV_ATTR_SHORT_ADDR,
1615 dev_desc->short_addr) ||
1616 nla_put_le64(msg, NL802154_DEV_ATTR_EXTENDED_ADDR,
1617 dev_desc->hwaddr) ||
1618 nla_put_u8(msg, NL802154_DEV_ATTR_SECLEVEL_EXEMPT,
1619 dev_desc->seclevel_exempt) ||
1620 nla_put_u32(msg, NL802154_DEV_ATTR_KEY_MODE, dev_desc->key_mode))
1621 goto nla_put_failure;
1623 nla_nest_end(msg, nl_device);
1624 genlmsg_end(msg, hdr);
1626 return 0;
1628 nla_put_failure:
1629 genlmsg_cancel(msg, hdr);
1630 return -EMSGSIZE;
1633 static int
1634 nl802154_dump_llsec_dev(struct sk_buff *skb, struct netlink_callback *cb)
1636 struct cfg802154_registered_device *rdev = NULL;
1637 struct ieee802154_llsec_device *dev;
1638 struct ieee802154_llsec_table *table;
1639 struct wpan_dev *wpan_dev;
1640 int err;
1642 err = nl802154_prepare_wpan_dev_dump(skb, cb, &rdev, &wpan_dev);
1643 if (err)
1644 return err;
1646 if (!wpan_dev->netdev) {
1647 err = -EINVAL;
1648 goto out_err;
1651 rdev_lock_llsec_table(rdev, wpan_dev);
1652 rdev_get_llsec_table(rdev, wpan_dev, &table);
1654 /* TODO make it like station dump */
1655 if (cb->args[2])
1656 goto out;
1658 list_for_each_entry(dev, &table->devices, list) {
1659 if (nl802154_send_device(skb, NL802154_CMD_NEW_SEC_LEVEL,
1660 NETLINK_CB(cb->skb).portid,
1661 cb->nlh->nlmsg_seq, NLM_F_MULTI,
1662 rdev, wpan_dev->netdev, dev) < 0) {
1663 /* TODO */
1664 err = -EIO;
1665 rdev_unlock_llsec_table(rdev, wpan_dev);
1666 goto out_err;
1670 cb->args[2] = 1;
1672 out:
1673 rdev_unlock_llsec_table(rdev, wpan_dev);
1674 err = skb->len;
1675 out_err:
1676 nl802154_finish_wpan_dev_dump(rdev);
1678 return err;
1681 static const struct nla_policy nl802154_dev_policy[NL802154_DEV_ATTR_MAX + 1] = {
1682 [NL802154_DEV_ATTR_FRAME_COUNTER] = { NLA_U32 },
1683 [NL802154_DEV_ATTR_PAN_ID] = { .type = NLA_U16 },
1684 [NL802154_DEV_ATTR_SHORT_ADDR] = { .type = NLA_U16 },
1685 [NL802154_DEV_ATTR_EXTENDED_ADDR] = { .type = NLA_U64 },
1686 [NL802154_DEV_ATTR_SECLEVEL_EXEMPT] = { NLA_U8 },
1687 [NL802154_DEV_ATTR_KEY_MODE] = { NLA_U32 },
1690 static int
1691 ieee802154_llsec_parse_device(struct nlattr *nla,
1692 struct ieee802154_llsec_device *dev)
1694 struct nlattr *attrs[NL802154_DEV_ATTR_MAX + 1];
1696 if (!nla || nla_parse_nested(attrs, NL802154_DEV_ATTR_MAX, nla,
1697 nl802154_dev_policy))
1698 return -EINVAL;
1700 memset(dev, 0, sizeof(*dev));
1702 if (!attrs[NL802154_DEV_ATTR_FRAME_COUNTER] ||
1703 !attrs[NL802154_DEV_ATTR_PAN_ID] ||
1704 !attrs[NL802154_DEV_ATTR_SHORT_ADDR] ||
1705 !attrs[NL802154_DEV_ATTR_EXTENDED_ADDR] ||
1706 !attrs[NL802154_DEV_ATTR_SECLEVEL_EXEMPT] ||
1707 !attrs[NL802154_DEV_ATTR_KEY_MODE])
1708 return -EINVAL;
1710 /* TODO be32 */
1711 dev->frame_counter = nla_get_u32(attrs[NL802154_DEV_ATTR_FRAME_COUNTER]);
1712 dev->pan_id = nla_get_le16(attrs[NL802154_DEV_ATTR_PAN_ID]);
1713 dev->short_addr = nla_get_le16(attrs[NL802154_DEV_ATTR_SHORT_ADDR]);
1714 /* TODO rename hwaddr to extended_addr */
1715 dev->hwaddr = nla_get_le64(attrs[NL802154_DEV_ATTR_EXTENDED_ADDR]);
1716 dev->seclevel_exempt = nla_get_u8(attrs[NL802154_DEV_ATTR_SECLEVEL_EXEMPT]);
1717 dev->key_mode = nla_get_u32(attrs[NL802154_DEV_ATTR_KEY_MODE]);
1719 if (dev->key_mode > NL802154_DEVKEY_MAX ||
1720 (dev->seclevel_exempt != 0 && dev->seclevel_exempt != 1))
1721 return -EINVAL;
1723 return 0;
1726 static int nl802154_add_llsec_dev(struct sk_buff *skb, struct genl_info *info)
1728 struct cfg802154_registered_device *rdev = info->user_ptr[0];
1729 struct net_device *dev = info->user_ptr[1];
1730 struct wpan_dev *wpan_dev = dev->ieee802154_ptr;
1731 struct ieee802154_llsec_device dev_desc;
1733 if (ieee802154_llsec_parse_device(info->attrs[NL802154_ATTR_SEC_DEVICE],
1734 &dev_desc) < 0)
1735 return -EINVAL;
1737 return rdev_add_device(rdev, wpan_dev, &dev_desc);
1740 static int nl802154_del_llsec_dev(struct sk_buff *skb, struct genl_info *info)
1742 struct cfg802154_registered_device *rdev = info->user_ptr[0];
1743 struct net_device *dev = info->user_ptr[1];
1744 struct wpan_dev *wpan_dev = dev->ieee802154_ptr;
1745 struct nlattr *attrs[NL802154_DEV_ATTR_MAX + 1];
1746 __le64 extended_addr;
1748 if (nla_parse_nested(attrs, NL802154_DEV_ATTR_MAX,
1749 info->attrs[NL802154_ATTR_SEC_DEVICE],
1750 nl802154_dev_policy))
1751 return -EINVAL;
1753 if (!attrs[NL802154_DEV_ATTR_EXTENDED_ADDR])
1754 return -EINVAL;
1756 extended_addr = nla_get_le64(attrs[NL802154_DEV_ATTR_EXTENDED_ADDR]);
1757 return rdev_del_device(rdev, wpan_dev, extended_addr);
1760 static int nl802154_send_devkey(struct sk_buff *msg, u32 cmd, u32 portid,
1761 u32 seq, int flags,
1762 struct cfg802154_registered_device *rdev,
1763 struct net_device *dev, __le64 extended_addr,
1764 const struct ieee802154_llsec_device_key *devkey)
1766 void *hdr;
1767 struct nlattr *nl_devkey, *nl_key_id;
1769 hdr = nl802154hdr_put(msg, portid, seq, flags, cmd);
1770 if (!hdr)
1771 return -1;
1773 if (nla_put_u32(msg, NL802154_ATTR_IFINDEX, dev->ifindex))
1774 goto nla_put_failure;
1776 nl_devkey = nla_nest_start(msg, NL802154_ATTR_SEC_DEVKEY);
1777 if (!nl_devkey)
1778 goto nla_put_failure;
1780 if (nla_put_le64(msg, NL802154_DEVKEY_ATTR_EXTENDED_ADDR,
1781 extended_addr) ||
1782 nla_put_u32(msg, NL802154_DEVKEY_ATTR_FRAME_COUNTER,
1783 devkey->frame_counter))
1784 goto nla_put_failure;
1786 nl_key_id = nla_nest_start(msg, NL802154_DEVKEY_ATTR_ID);
1787 if (!nl_key_id)
1788 goto nla_put_failure;
1790 if (ieee802154_llsec_send_key_id(msg, &devkey->key_id) < 0)
1791 goto nla_put_failure;
1793 nla_nest_end(msg, nl_key_id);
1794 nla_nest_end(msg, nl_devkey);
1795 genlmsg_end(msg, hdr);
1797 return 0;
1799 nla_put_failure:
1800 genlmsg_cancel(msg, hdr);
1801 return -EMSGSIZE;
1804 static int
1805 nl802154_dump_llsec_devkey(struct sk_buff *skb, struct netlink_callback *cb)
1807 struct cfg802154_registered_device *rdev = NULL;
1808 struct ieee802154_llsec_device_key *kpos;
1809 struct ieee802154_llsec_device *dpos;
1810 struct ieee802154_llsec_table *table;
1811 struct wpan_dev *wpan_dev;
1812 int err;
1814 err = nl802154_prepare_wpan_dev_dump(skb, cb, &rdev, &wpan_dev);
1815 if (err)
1816 return err;
1818 if (!wpan_dev->netdev) {
1819 err = -EINVAL;
1820 goto out_err;
1823 rdev_lock_llsec_table(rdev, wpan_dev);
1824 rdev_get_llsec_table(rdev, wpan_dev, &table);
1826 /* TODO make it like station dump */
1827 if (cb->args[2])
1828 goto out;
1830 /* TODO look if remove devkey and do some nested attribute */
1831 list_for_each_entry(dpos, &table->devices, list) {
1832 list_for_each_entry(kpos, &dpos->keys, list) {
1833 if (nl802154_send_devkey(skb,
1834 NL802154_CMD_NEW_SEC_LEVEL,
1835 NETLINK_CB(cb->skb).portid,
1836 cb->nlh->nlmsg_seq,
1837 NLM_F_MULTI, rdev,
1838 wpan_dev->netdev,
1839 dpos->hwaddr,
1840 kpos) < 0) {
1841 /* TODO */
1842 err = -EIO;
1843 rdev_unlock_llsec_table(rdev, wpan_dev);
1844 goto out_err;
1849 cb->args[2] = 1;
1851 out:
1852 rdev_unlock_llsec_table(rdev, wpan_dev);
1853 err = skb->len;
1854 out_err:
1855 nl802154_finish_wpan_dev_dump(rdev);
1857 return err;
1860 static const struct nla_policy nl802154_devkey_policy[NL802154_DEVKEY_ATTR_MAX + 1] = {
1861 [NL802154_DEVKEY_ATTR_FRAME_COUNTER] = { NLA_U32 },
1862 [NL802154_DEVKEY_ATTR_EXTENDED_ADDR] = { NLA_U64 },
1863 [NL802154_DEVKEY_ATTR_ID] = { NLA_NESTED },
1866 static int nl802154_add_llsec_devkey(struct sk_buff *skb, struct genl_info *info)
1868 struct cfg802154_registered_device *rdev = info->user_ptr[0];
1869 struct net_device *dev = info->user_ptr[1];
1870 struct wpan_dev *wpan_dev = dev->ieee802154_ptr;
1871 struct nlattr *attrs[NL802154_DEVKEY_ATTR_MAX + 1];
1872 struct ieee802154_llsec_device_key key;
1873 __le64 extended_addr;
1875 if (!info->attrs[NL802154_ATTR_SEC_DEVKEY] ||
1876 nla_parse_nested(attrs, NL802154_DEVKEY_ATTR_MAX,
1877 info->attrs[NL802154_ATTR_SEC_DEVKEY],
1878 nl802154_devkey_policy) < 0)
1879 return -EINVAL;
1881 if (!attrs[NL802154_DEVKEY_ATTR_FRAME_COUNTER] ||
1882 !attrs[NL802154_DEVKEY_ATTR_EXTENDED_ADDR])
1883 return -EINVAL;
1885 /* TODO change key.id ? */
1886 if (ieee802154_llsec_parse_key_id(attrs[NL802154_DEVKEY_ATTR_ID],
1887 &key.key_id) < 0)
1888 return -ENOBUFS;
1890 /* TODO be32 */
1891 key.frame_counter = nla_get_u32(attrs[NL802154_DEVKEY_ATTR_FRAME_COUNTER]);
1892 /* TODO change naming hwaddr -> extended_addr
1893 * check unique identifier short+pan OR extended_addr
1895 extended_addr = nla_get_le64(attrs[NL802154_DEVKEY_ATTR_EXTENDED_ADDR]);
1896 return rdev_add_devkey(rdev, wpan_dev, extended_addr, &key);
1899 static int nl802154_del_llsec_devkey(struct sk_buff *skb, struct genl_info *info)
1901 struct cfg802154_registered_device *rdev = info->user_ptr[0];
1902 struct net_device *dev = info->user_ptr[1];
1903 struct wpan_dev *wpan_dev = dev->ieee802154_ptr;
1904 struct nlattr *attrs[NL802154_DEVKEY_ATTR_MAX + 1];
1905 struct ieee802154_llsec_device_key key;
1906 __le64 extended_addr;
1908 if (nla_parse_nested(attrs, NL802154_DEVKEY_ATTR_MAX,
1909 info->attrs[NL802154_ATTR_SEC_DEVKEY],
1910 nl802154_devkey_policy))
1911 return -EINVAL;
1913 if (!attrs[NL802154_DEVKEY_ATTR_EXTENDED_ADDR])
1914 return -EINVAL;
1916 /* TODO change key.id ? */
1917 if (ieee802154_llsec_parse_key_id(attrs[NL802154_DEVKEY_ATTR_ID],
1918 &key.key_id) < 0)
1919 return -ENOBUFS;
1921 /* TODO change naming hwaddr -> extended_addr
1922 * check unique identifier short+pan OR extended_addr
1924 extended_addr = nla_get_le64(attrs[NL802154_DEVKEY_ATTR_EXTENDED_ADDR]);
1925 return rdev_del_devkey(rdev, wpan_dev, extended_addr, &key);
1928 static int nl802154_send_seclevel(struct sk_buff *msg, u32 cmd, u32 portid,
1929 u32 seq, int flags,
1930 struct cfg802154_registered_device *rdev,
1931 struct net_device *dev,
1932 const struct ieee802154_llsec_seclevel *sl)
1934 void *hdr;
1935 struct nlattr *nl_seclevel;
1937 hdr = nl802154hdr_put(msg, portid, seq, flags, cmd);
1938 if (!hdr)
1939 return -1;
1941 if (nla_put_u32(msg, NL802154_ATTR_IFINDEX, dev->ifindex))
1942 goto nla_put_failure;
1944 nl_seclevel = nla_nest_start(msg, NL802154_ATTR_SEC_LEVEL);
1945 if (!nl_seclevel)
1946 goto nla_put_failure;
1948 if (nla_put_u32(msg, NL802154_SECLEVEL_ATTR_FRAME, sl->frame_type) ||
1949 nla_put_u32(msg, NL802154_SECLEVEL_ATTR_LEVELS, sl->sec_levels) ||
1950 nla_put_u8(msg, NL802154_SECLEVEL_ATTR_DEV_OVERRIDE,
1951 sl->device_override))
1952 goto nla_put_failure;
1954 if (sl->frame_type == NL802154_FRAME_CMD) {
1955 if (nla_put_u32(msg, NL802154_SECLEVEL_ATTR_CMD_FRAME,
1956 sl->cmd_frame_id))
1957 goto nla_put_failure;
1960 nla_nest_end(msg, nl_seclevel);
1961 genlmsg_end(msg, hdr);
1963 return 0;
1965 nla_put_failure:
1966 genlmsg_cancel(msg, hdr);
1967 return -EMSGSIZE;
1970 static int
1971 nl802154_dump_llsec_seclevel(struct sk_buff *skb, struct netlink_callback *cb)
1973 struct cfg802154_registered_device *rdev = NULL;
1974 struct ieee802154_llsec_seclevel *sl;
1975 struct ieee802154_llsec_table *table;
1976 struct wpan_dev *wpan_dev;
1977 int err;
1979 err = nl802154_prepare_wpan_dev_dump(skb, cb, &rdev, &wpan_dev);
1980 if (err)
1981 return err;
1983 if (!wpan_dev->netdev) {
1984 err = -EINVAL;
1985 goto out_err;
1988 rdev_lock_llsec_table(rdev, wpan_dev);
1989 rdev_get_llsec_table(rdev, wpan_dev, &table);
1991 /* TODO make it like station dump */
1992 if (cb->args[2])
1993 goto out;
1995 list_for_each_entry(sl, &table->security_levels, list) {
1996 if (nl802154_send_seclevel(skb, NL802154_CMD_NEW_SEC_LEVEL,
1997 NETLINK_CB(cb->skb).portid,
1998 cb->nlh->nlmsg_seq, NLM_F_MULTI,
1999 rdev, wpan_dev->netdev, sl) < 0) {
2000 /* TODO */
2001 err = -EIO;
2002 rdev_unlock_llsec_table(rdev, wpan_dev);
2003 goto out_err;
2007 cb->args[2] = 1;
2009 out:
2010 rdev_unlock_llsec_table(rdev, wpan_dev);
2011 err = skb->len;
2012 out_err:
2013 nl802154_finish_wpan_dev_dump(rdev);
2015 return err;
2018 static const struct nla_policy nl802154_seclevel_policy[NL802154_SECLEVEL_ATTR_MAX + 1] = {
2019 [NL802154_SECLEVEL_ATTR_LEVELS] = { .type = NLA_U8 },
2020 [NL802154_SECLEVEL_ATTR_FRAME] = { .type = NLA_U32 },
2021 [NL802154_SECLEVEL_ATTR_CMD_FRAME] = { .type = NLA_U32 },
2022 [NL802154_SECLEVEL_ATTR_DEV_OVERRIDE] = { .type = NLA_U8 },
2025 static int
2026 llsec_parse_seclevel(struct nlattr *nla, struct ieee802154_llsec_seclevel *sl)
2028 struct nlattr *attrs[NL802154_SECLEVEL_ATTR_MAX + 1];
2030 if (!nla || nla_parse_nested(attrs, NL802154_SECLEVEL_ATTR_MAX, nla,
2031 nl802154_seclevel_policy))
2032 return -EINVAL;
2034 memset(sl, 0, sizeof(*sl));
2036 if (!attrs[NL802154_SECLEVEL_ATTR_LEVELS] ||
2037 !attrs[NL802154_SECLEVEL_ATTR_FRAME] ||
2038 !attrs[NL802154_SECLEVEL_ATTR_DEV_OVERRIDE])
2039 return -EINVAL;
2041 sl->sec_levels = nla_get_u8(attrs[NL802154_SECLEVEL_ATTR_LEVELS]);
2042 sl->frame_type = nla_get_u32(attrs[NL802154_SECLEVEL_ATTR_FRAME]);
2043 sl->device_override = nla_get_u8(attrs[NL802154_SECLEVEL_ATTR_DEV_OVERRIDE]);
2044 if (sl->frame_type > NL802154_FRAME_MAX ||
2045 (sl->device_override != 0 && sl->device_override != 1))
2046 return -EINVAL;
2048 if (sl->frame_type == NL802154_FRAME_CMD) {
2049 if (!attrs[NL802154_SECLEVEL_ATTR_CMD_FRAME])
2050 return -EINVAL;
2052 sl->cmd_frame_id = nla_get_u32(attrs[NL802154_SECLEVEL_ATTR_CMD_FRAME]);
2053 if (sl->cmd_frame_id > NL802154_CMD_FRAME_MAX)
2054 return -EINVAL;
2057 return 0;
2060 static int nl802154_add_llsec_seclevel(struct sk_buff *skb,
2061 struct genl_info *info)
2063 struct cfg802154_registered_device *rdev = info->user_ptr[0];
2064 struct net_device *dev = info->user_ptr[1];
2065 struct wpan_dev *wpan_dev = dev->ieee802154_ptr;
2066 struct ieee802154_llsec_seclevel sl;
2068 if (llsec_parse_seclevel(info->attrs[NL802154_ATTR_SEC_LEVEL],
2069 &sl) < 0)
2070 return -EINVAL;
2072 return rdev_add_seclevel(rdev, wpan_dev, &sl);
2075 static int nl802154_del_llsec_seclevel(struct sk_buff *skb,
2076 struct genl_info *info)
2078 struct cfg802154_registered_device *rdev = info->user_ptr[0];
2079 struct net_device *dev = info->user_ptr[1];
2080 struct wpan_dev *wpan_dev = dev->ieee802154_ptr;
2081 struct ieee802154_llsec_seclevel sl;
2083 if (!info->attrs[NL802154_ATTR_SEC_LEVEL] ||
2084 llsec_parse_seclevel(info->attrs[NL802154_ATTR_SEC_LEVEL],
2085 &sl) < 0)
2086 return -EINVAL;
2088 return rdev_del_seclevel(rdev, wpan_dev, &sl);
2090 #endif /* CONFIG_IEEE802154_NL802154_EXPERIMENTAL */
2092 #define NL802154_FLAG_NEED_WPAN_PHY 0x01
2093 #define NL802154_FLAG_NEED_NETDEV 0x02
2094 #define NL802154_FLAG_NEED_RTNL 0x04
2095 #define NL802154_FLAG_CHECK_NETDEV_UP 0x08
2096 #define NL802154_FLAG_NEED_NETDEV_UP (NL802154_FLAG_NEED_NETDEV |\
2097 NL802154_FLAG_CHECK_NETDEV_UP)
2098 #define NL802154_FLAG_NEED_WPAN_DEV 0x10
2099 #define NL802154_FLAG_NEED_WPAN_DEV_UP (NL802154_FLAG_NEED_WPAN_DEV |\
2100 NL802154_FLAG_CHECK_NETDEV_UP)
2102 static int nl802154_pre_doit(const struct genl_ops *ops, struct sk_buff *skb,
2103 struct genl_info *info)
2105 struct cfg802154_registered_device *rdev;
2106 struct wpan_dev *wpan_dev;
2107 struct net_device *dev;
2108 bool rtnl = ops->internal_flags & NL802154_FLAG_NEED_RTNL;
2110 if (rtnl)
2111 rtnl_lock();
2113 if (ops->internal_flags & NL802154_FLAG_NEED_WPAN_PHY) {
2114 rdev = cfg802154_get_dev_from_info(genl_info_net(info), info);
2115 if (IS_ERR(rdev)) {
2116 if (rtnl)
2117 rtnl_unlock();
2118 return PTR_ERR(rdev);
2120 info->user_ptr[0] = rdev;
2121 } else if (ops->internal_flags & NL802154_FLAG_NEED_NETDEV ||
2122 ops->internal_flags & NL802154_FLAG_NEED_WPAN_DEV) {
2123 ASSERT_RTNL();
2124 wpan_dev = __cfg802154_wpan_dev_from_attrs(genl_info_net(info),
2125 info->attrs);
2126 if (IS_ERR(wpan_dev)) {
2127 if (rtnl)
2128 rtnl_unlock();
2129 return PTR_ERR(wpan_dev);
2132 dev = wpan_dev->netdev;
2133 rdev = wpan_phy_to_rdev(wpan_dev->wpan_phy);
2135 if (ops->internal_flags & NL802154_FLAG_NEED_NETDEV) {
2136 if (!dev) {
2137 if (rtnl)
2138 rtnl_unlock();
2139 return -EINVAL;
2142 info->user_ptr[1] = dev;
2143 } else {
2144 info->user_ptr[1] = wpan_dev;
2147 if (dev) {
2148 if (ops->internal_flags & NL802154_FLAG_CHECK_NETDEV_UP &&
2149 !netif_running(dev)) {
2150 if (rtnl)
2151 rtnl_unlock();
2152 return -ENETDOWN;
2155 dev_hold(dev);
2158 info->user_ptr[0] = rdev;
2161 return 0;
2164 static void nl802154_post_doit(const struct genl_ops *ops, struct sk_buff *skb,
2165 struct genl_info *info)
2167 if (info->user_ptr[1]) {
2168 if (ops->internal_flags & NL802154_FLAG_NEED_WPAN_DEV) {
2169 struct wpan_dev *wpan_dev = info->user_ptr[1];
2171 if (wpan_dev->netdev)
2172 dev_put(wpan_dev->netdev);
2173 } else {
2174 dev_put(info->user_ptr[1]);
2178 if (ops->internal_flags & NL802154_FLAG_NEED_RTNL)
2179 rtnl_unlock();
2182 static const struct genl_ops nl802154_ops[] = {
2184 .cmd = NL802154_CMD_GET_WPAN_PHY,
2185 .doit = nl802154_get_wpan_phy,
2186 .dumpit = nl802154_dump_wpan_phy,
2187 .done = nl802154_dump_wpan_phy_done,
2188 .policy = nl802154_policy,
2189 /* can be retrieved by unprivileged users */
2190 .internal_flags = NL802154_FLAG_NEED_WPAN_PHY |
2191 NL802154_FLAG_NEED_RTNL,
2194 .cmd = NL802154_CMD_GET_INTERFACE,
2195 .doit = nl802154_get_interface,
2196 .dumpit = nl802154_dump_interface,
2197 .policy = nl802154_policy,
2198 /* can be retrieved by unprivileged users */
2199 .internal_flags = NL802154_FLAG_NEED_WPAN_DEV |
2200 NL802154_FLAG_NEED_RTNL,
2203 .cmd = NL802154_CMD_NEW_INTERFACE,
2204 .doit = nl802154_new_interface,
2205 .policy = nl802154_policy,
2206 .flags = GENL_ADMIN_PERM,
2207 .internal_flags = NL802154_FLAG_NEED_WPAN_PHY |
2208 NL802154_FLAG_NEED_RTNL,
2211 .cmd = NL802154_CMD_DEL_INTERFACE,
2212 .doit = nl802154_del_interface,
2213 .policy = nl802154_policy,
2214 .flags = GENL_ADMIN_PERM,
2215 .internal_flags = NL802154_FLAG_NEED_WPAN_DEV |
2216 NL802154_FLAG_NEED_RTNL,
2219 .cmd = NL802154_CMD_SET_CHANNEL,
2220 .doit = nl802154_set_channel,
2221 .policy = nl802154_policy,
2222 .flags = GENL_ADMIN_PERM,
2223 .internal_flags = NL802154_FLAG_NEED_WPAN_PHY |
2224 NL802154_FLAG_NEED_RTNL,
2227 .cmd = NL802154_CMD_SET_CCA_MODE,
2228 .doit = nl802154_set_cca_mode,
2229 .policy = nl802154_policy,
2230 .flags = GENL_ADMIN_PERM,
2231 .internal_flags = NL802154_FLAG_NEED_WPAN_PHY |
2232 NL802154_FLAG_NEED_RTNL,
2235 .cmd = NL802154_CMD_SET_CCA_ED_LEVEL,
2236 .doit = nl802154_set_cca_ed_level,
2237 .policy = nl802154_policy,
2238 .flags = GENL_ADMIN_PERM,
2239 .internal_flags = NL802154_FLAG_NEED_WPAN_PHY |
2240 NL802154_FLAG_NEED_RTNL,
2243 .cmd = NL802154_CMD_SET_TX_POWER,
2244 .doit = nl802154_set_tx_power,
2245 .policy = nl802154_policy,
2246 .flags = GENL_ADMIN_PERM,
2247 .internal_flags = NL802154_FLAG_NEED_WPAN_PHY |
2248 NL802154_FLAG_NEED_RTNL,
2251 .cmd = NL802154_CMD_SET_PAN_ID,
2252 .doit = nl802154_set_pan_id,
2253 .policy = nl802154_policy,
2254 .flags = GENL_ADMIN_PERM,
2255 .internal_flags = NL802154_FLAG_NEED_NETDEV |
2256 NL802154_FLAG_NEED_RTNL,
2259 .cmd = NL802154_CMD_SET_SHORT_ADDR,
2260 .doit = nl802154_set_short_addr,
2261 .policy = nl802154_policy,
2262 .flags = GENL_ADMIN_PERM,
2263 .internal_flags = NL802154_FLAG_NEED_NETDEV |
2264 NL802154_FLAG_NEED_RTNL,
2267 .cmd = NL802154_CMD_SET_BACKOFF_EXPONENT,
2268 .doit = nl802154_set_backoff_exponent,
2269 .policy = nl802154_policy,
2270 .flags = GENL_ADMIN_PERM,
2271 .internal_flags = NL802154_FLAG_NEED_NETDEV |
2272 NL802154_FLAG_NEED_RTNL,
2275 .cmd = NL802154_CMD_SET_MAX_CSMA_BACKOFFS,
2276 .doit = nl802154_set_max_csma_backoffs,
2277 .policy = nl802154_policy,
2278 .flags = GENL_ADMIN_PERM,
2279 .internal_flags = NL802154_FLAG_NEED_NETDEV |
2280 NL802154_FLAG_NEED_RTNL,
2283 .cmd = NL802154_CMD_SET_MAX_FRAME_RETRIES,
2284 .doit = nl802154_set_max_frame_retries,
2285 .policy = nl802154_policy,
2286 .flags = GENL_ADMIN_PERM,
2287 .internal_flags = NL802154_FLAG_NEED_NETDEV |
2288 NL802154_FLAG_NEED_RTNL,
2291 .cmd = NL802154_CMD_SET_LBT_MODE,
2292 .doit = nl802154_set_lbt_mode,
2293 .policy = nl802154_policy,
2294 .flags = GENL_ADMIN_PERM,
2295 .internal_flags = NL802154_FLAG_NEED_NETDEV |
2296 NL802154_FLAG_NEED_RTNL,
2299 .cmd = NL802154_CMD_SET_ACKREQ_DEFAULT,
2300 .doit = nl802154_set_ackreq_default,
2301 .policy = nl802154_policy,
2302 .flags = GENL_ADMIN_PERM,
2303 .internal_flags = NL802154_FLAG_NEED_NETDEV |
2304 NL802154_FLAG_NEED_RTNL,
2306 #ifdef CONFIG_IEEE802154_NL802154_EXPERIMENTAL
2308 .cmd = NL802154_CMD_SET_SEC_PARAMS,
2309 .doit = nl802154_set_llsec_params,
2310 .policy = nl802154_policy,
2311 .flags = GENL_ADMIN_PERM,
2312 .internal_flags = NL802154_FLAG_NEED_NETDEV |
2313 NL802154_FLAG_NEED_RTNL,
2316 .cmd = NL802154_CMD_GET_SEC_KEY,
2317 /* TODO .doit by matching key id? */
2318 .dumpit = nl802154_dump_llsec_key,
2319 .policy = nl802154_policy,
2320 .flags = GENL_ADMIN_PERM,
2321 .internal_flags = NL802154_FLAG_NEED_NETDEV |
2322 NL802154_FLAG_NEED_RTNL,
2325 .cmd = NL802154_CMD_NEW_SEC_KEY,
2326 .doit = nl802154_add_llsec_key,
2327 .policy = nl802154_policy,
2328 .flags = GENL_ADMIN_PERM,
2329 .internal_flags = NL802154_FLAG_NEED_NETDEV |
2330 NL802154_FLAG_NEED_RTNL,
2333 .cmd = NL802154_CMD_DEL_SEC_KEY,
2334 .doit = nl802154_del_llsec_key,
2335 .policy = nl802154_policy,
2336 .flags = GENL_ADMIN_PERM,
2337 .internal_flags = NL802154_FLAG_NEED_NETDEV |
2338 NL802154_FLAG_NEED_RTNL,
2340 /* TODO unique identifier must short+pan OR extended_addr */
2342 .cmd = NL802154_CMD_GET_SEC_DEV,
2343 /* TODO .doit by matching extended_addr? */
2344 .dumpit = nl802154_dump_llsec_dev,
2345 .policy = nl802154_policy,
2346 .flags = GENL_ADMIN_PERM,
2347 .internal_flags = NL802154_FLAG_NEED_NETDEV |
2348 NL802154_FLAG_NEED_RTNL,
2351 .cmd = NL802154_CMD_NEW_SEC_DEV,
2352 .doit = nl802154_add_llsec_dev,
2353 .policy = nl802154_policy,
2354 .flags = GENL_ADMIN_PERM,
2355 .internal_flags = NL802154_FLAG_NEED_NETDEV |
2356 NL802154_FLAG_NEED_RTNL,
2359 .cmd = NL802154_CMD_DEL_SEC_DEV,
2360 .doit = nl802154_del_llsec_dev,
2361 .policy = nl802154_policy,
2362 .flags = GENL_ADMIN_PERM,
2363 .internal_flags = NL802154_FLAG_NEED_NETDEV |
2364 NL802154_FLAG_NEED_RTNL,
2366 /* TODO remove complete devkey, put it as nested? */
2368 .cmd = NL802154_CMD_GET_SEC_DEVKEY,
2369 /* TODO doit by matching ??? */
2370 .dumpit = nl802154_dump_llsec_devkey,
2371 .policy = nl802154_policy,
2372 .flags = GENL_ADMIN_PERM,
2373 .internal_flags = NL802154_FLAG_NEED_NETDEV |
2374 NL802154_FLAG_NEED_RTNL,
2377 .cmd = NL802154_CMD_NEW_SEC_DEVKEY,
2378 .doit = nl802154_add_llsec_devkey,
2379 .policy = nl802154_policy,
2380 .flags = GENL_ADMIN_PERM,
2381 .internal_flags = NL802154_FLAG_NEED_NETDEV |
2382 NL802154_FLAG_NEED_RTNL,
2385 .cmd = NL802154_CMD_DEL_SEC_DEVKEY,
2386 .doit = nl802154_del_llsec_devkey,
2387 .policy = nl802154_policy,
2388 .flags = GENL_ADMIN_PERM,
2389 .internal_flags = NL802154_FLAG_NEED_NETDEV |
2390 NL802154_FLAG_NEED_RTNL,
2393 .cmd = NL802154_CMD_GET_SEC_LEVEL,
2394 /* TODO .doit by matching frame_type? */
2395 .dumpit = nl802154_dump_llsec_seclevel,
2396 .policy = nl802154_policy,
2397 .flags = GENL_ADMIN_PERM,
2398 .internal_flags = NL802154_FLAG_NEED_NETDEV |
2399 NL802154_FLAG_NEED_RTNL,
2402 .cmd = NL802154_CMD_NEW_SEC_LEVEL,
2403 .doit = nl802154_add_llsec_seclevel,
2404 .policy = nl802154_policy,
2405 .flags = GENL_ADMIN_PERM,
2406 .internal_flags = NL802154_FLAG_NEED_NETDEV |
2407 NL802154_FLAG_NEED_RTNL,
2410 .cmd = NL802154_CMD_DEL_SEC_LEVEL,
2411 /* TODO match frame_type only? */
2412 .doit = nl802154_del_llsec_seclevel,
2413 .policy = nl802154_policy,
2414 .flags = GENL_ADMIN_PERM,
2415 .internal_flags = NL802154_FLAG_NEED_NETDEV |
2416 NL802154_FLAG_NEED_RTNL,
2418 #endif /* CONFIG_IEEE802154_NL802154_EXPERIMENTAL */
2421 /* initialisation/exit functions */
2422 int nl802154_init(void)
2424 return genl_register_family_with_ops_groups(&nl802154_fam, nl802154_ops,
2425 nl802154_mcgrps);
2428 void nl802154_exit(void)
2430 genl_unregister_family(&nl802154_fam);