2009-09-14 18:17:36 +04:00
|
|
|
/*
|
|
|
|
* Netlink inteface for IEEE 802.15.4 stack
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
*
|
|
|
|
* Written by:
|
|
|
|
* Sergey Lapin <slapin@ossfans.org>
|
|
|
|
* Dmitry Eremin-Solenikov <dbaryshkov@gmail.com>
|
|
|
|
* Maxim Osipov <maxim.osipov@siemens.com>
|
|
|
|
*/
|
|
|
|
|
include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit slab.h inclusion from percpu.h
percpu.h is included by sched.h and module.h and thus ends up being
included when building most .c files. percpu.h includes slab.h which
in turn includes gfp.h making everything defined by the two files
universally available and complicating inclusion dependencies.
percpu.h -> slab.h dependency is about to be removed. Prepare for
this change by updating users of gfp and slab facilities include those
headers directly instead of assuming availability. As this conversion
needs to touch large number of source files, the following script is
used as the basis of conversion.
http://userweb.kernel.org/~tj/misc/slabh-sweep.py
The script does the followings.
* Scan files for gfp and slab usages and update includes such that
only the necessary includes are there. ie. if only gfp is used,
gfp.h, if slab is used, slab.h.
* When the script inserts a new include, it looks at the include
blocks and try to put the new include such that its order conforms
to its surrounding. It's put in the include block which contains
core kernel includes, in the same order that the rest are ordered -
alphabetical, Christmas tree, rev-Xmas-tree or at the end if there
doesn't seem to be any matching order.
* If the script can't find a place to put a new include (mostly
because the file doesn't have fitting include block), it prints out
an error message indicating which .h file needs to be added to the
file.
The conversion was done in the following steps.
1. The initial automatic conversion of all .c files updated slightly
over 4000 files, deleting around 700 includes and adding ~480 gfp.h
and ~3000 slab.h inclusions. The script emitted errors for ~400
files.
2. Each error was manually checked. Some didn't need the inclusion,
some needed manual addition while adding it to implementation .h or
embedding .c file was more appropriate for others. This step added
inclusions to around 150 files.
3. The script was run again and the output was compared to the edits
from #2 to make sure no file was left behind.
4. Several build tests were done and a couple of problems were fixed.
e.g. lib/decompress_*.c used malloc/free() wrappers around slab
APIs requiring slab.h to be added manually.
5. The script was run on all .h files but without automatically
editing them as sprinkling gfp.h and slab.h inclusions around .h
files could easily lead to inclusion dependency hell. Most gfp.h
inclusion directives were ignored as stuff from gfp.h was usually
wildly available and often used in preprocessor macros. Each
slab.h inclusion directive was examined and added manually as
necessary.
6. percpu.h was updated not to include slab.h.
7. Build test were done on the following configurations and failures
were fixed. CONFIG_GCOV_KERNEL was turned off for all tests (as my
distributed build env didn't work with gcov compiles) and a few
more options had to be turned off depending on archs to make things
build (like ipr on powerpc/64 which failed due to missing writeq).
* x86 and x86_64 UP and SMP allmodconfig and a custom test config.
* powerpc and powerpc64 SMP allmodconfig
* sparc and sparc64 SMP allmodconfig
* ia64 SMP allmodconfig
* s390 SMP allmodconfig
* alpha SMP allmodconfig
* um on x86_64 SMP allmodconfig
8. percpu.h modifications were reverted so that it could be applied as
a separate patch and serve as bisection point.
Given the fact that I had only a couple of failures from tests on step
6, I'm fairly confident about the coverage of this conversion patch.
If there is a breakage, it's likely to be something in one of the arch
headers which should be easily discoverable easily on most builds of
the specific arch.
Signed-off-by: Tejun Heo <tj@kernel.org>
Guess-its-ok-by: Christoph Lameter <cl@linux-foundation.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Lee Schermerhorn <Lee.Schermerhorn@hp.com>
2010-03-24 11:04:11 +03:00
|
|
|
#include <linux/gfp.h>
|
2009-09-14 18:17:36 +04:00
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/if_arp.h>
|
|
|
|
#include <linux/netdevice.h>
|
|
|
|
#include <net/netlink.h>
|
|
|
|
#include <net/genetlink.h>
|
|
|
|
#include <net/sock.h>
|
|
|
|
#include <linux/nl802154.h>
|
2011-07-15 19:47:34 +04:00
|
|
|
#include <linux/export.h>
|
2009-09-14 18:17:36 +04:00
|
|
|
#include <net/af_ieee802154.h>
|
|
|
|
#include <net/nl802154.h>
|
|
|
|
#include <net/ieee802154.h>
|
|
|
|
#include <net/ieee802154_netdev.h>
|
2009-10-29 16:28:52 +03:00
|
|
|
#include <net/wpan-phy.h>
|
2009-09-14 18:17:36 +04:00
|
|
|
|
|
|
|
#include "ieee802154.h"
|
|
|
|
|
2014-03-15 00:24:02 +04:00
|
|
|
static int nla_put_hwaddr(struct sk_buff *msg, int type, __le64 hwaddr)
|
|
|
|
{
|
|
|
|
return nla_put_u64(msg, type, swab64((__force u64)hwaddr));
|
|
|
|
}
|
|
|
|
|
|
|
|
static __le64 nla_get_hwaddr(const struct nlattr *nla)
|
|
|
|
{
|
|
|
|
return ieee802154_devaddr_from_raw(nla_data(nla));
|
|
|
|
}
|
|
|
|
|
|
|
|
static int nla_put_shortaddr(struct sk_buff *msg, int type, __le16 addr)
|
|
|
|
{
|
|
|
|
return nla_put_u16(msg, type, le16_to_cpu(addr));
|
|
|
|
}
|
|
|
|
|
|
|
|
static __le16 nla_get_shortaddr(const struct nlattr *nla)
|
|
|
|
{
|
|
|
|
return cpu_to_le16(nla_get_u16(nla));
|
|
|
|
}
|
|
|
|
|
2009-09-14 18:17:36 +04:00
|
|
|
int ieee802154_nl_assoc_indic(struct net_device *dev,
|
2014-07-02 07:31:09 +04:00
|
|
|
struct ieee802154_addr *addr,
|
|
|
|
u8 cap)
|
2009-09-14 18:17:36 +04:00
|
|
|
{
|
|
|
|
struct sk_buff *msg;
|
|
|
|
|
|
|
|
pr_debug("%s\n", __func__);
|
|
|
|
|
2014-03-15 00:24:02 +04:00
|
|
|
if (addr->mode != IEEE802154_ADDR_LONG) {
|
2009-09-14 18:17:36 +04:00
|
|
|
pr_err("%s: received non-long source address!\n", __func__);
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
msg = ieee802154_nl_create(0, IEEE802154_ASSOCIATE_INDIC);
|
|
|
|
if (!msg)
|
|
|
|
return -ENOBUFS;
|
|
|
|
|
2012-04-02 04:45:25 +04:00
|
|
|
if (nla_put_string(msg, IEEE802154_ATTR_DEV_NAME, dev->name) ||
|
|
|
|
nla_put_u32(msg, IEEE802154_ATTR_DEV_INDEX, dev->ifindex) ||
|
|
|
|
nla_put(msg, IEEE802154_ATTR_HW_ADDR, IEEE802154_ADDR_LEN,
|
|
|
|
dev->dev_addr) ||
|
2014-03-15 00:24:02 +04:00
|
|
|
nla_put_hwaddr(msg, IEEE802154_ATTR_SRC_HW_ADDR,
|
|
|
|
addr->extended_addr) ||
|
2012-04-02 04:45:25 +04:00
|
|
|
nla_put_u8(msg, IEEE802154_ATTR_CAPABILITY, cap))
|
|
|
|
goto nla_put_failure;
|
2009-09-14 18:17:36 +04:00
|
|
|
|
2013-11-19 18:19:39 +04:00
|
|
|
return ieee802154_nl_mcast(msg, IEEE802154_COORD_MCGRP);
|
2009-09-14 18:17:36 +04:00
|
|
|
|
|
|
|
nla_put_failure:
|
|
|
|
nlmsg_free(msg);
|
|
|
|
return -ENOBUFS;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(ieee802154_nl_assoc_indic);
|
|
|
|
|
2014-03-15 00:23:59 +04:00
|
|
|
int ieee802154_nl_assoc_confirm(struct net_device *dev, __le16 short_addr,
|
2014-07-02 07:31:09 +04:00
|
|
|
u8 status)
|
2009-09-14 18:17:36 +04:00
|
|
|
{
|
|
|
|
struct sk_buff *msg;
|
|
|
|
|
|
|
|
pr_debug("%s\n", __func__);
|
|
|
|
|
|
|
|
msg = ieee802154_nl_create(0, IEEE802154_ASSOCIATE_CONF);
|
|
|
|
if (!msg)
|
|
|
|
return -ENOBUFS;
|
|
|
|
|
2012-04-02 04:45:25 +04:00
|
|
|
if (nla_put_string(msg, IEEE802154_ATTR_DEV_NAME, dev->name) ||
|
|
|
|
nla_put_u32(msg, IEEE802154_ATTR_DEV_INDEX, dev->ifindex) ||
|
|
|
|
nla_put(msg, IEEE802154_ATTR_HW_ADDR, IEEE802154_ADDR_LEN,
|
|
|
|
dev->dev_addr) ||
|
2014-03-15 00:24:02 +04:00
|
|
|
nla_put_shortaddr(msg, IEEE802154_ATTR_SHORT_ADDR, short_addr) ||
|
2012-04-02 04:45:25 +04:00
|
|
|
nla_put_u8(msg, IEEE802154_ATTR_STATUS, status))
|
|
|
|
goto nla_put_failure;
|
2013-11-19 18:19:39 +04:00
|
|
|
return ieee802154_nl_mcast(msg, IEEE802154_COORD_MCGRP);
|
2009-09-14 18:17:36 +04:00
|
|
|
|
|
|
|
nla_put_failure:
|
|
|
|
nlmsg_free(msg);
|
|
|
|
return -ENOBUFS;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(ieee802154_nl_assoc_confirm);
|
|
|
|
|
|
|
|
int ieee802154_nl_disassoc_indic(struct net_device *dev,
|
2014-07-02 07:31:09 +04:00
|
|
|
struct ieee802154_addr *addr,
|
|
|
|
u8 reason)
|
2009-09-14 18:17:36 +04:00
|
|
|
{
|
|
|
|
struct sk_buff *msg;
|
|
|
|
|
|
|
|
pr_debug("%s\n", __func__);
|
|
|
|
|
|
|
|
msg = ieee802154_nl_create(0, IEEE802154_DISASSOCIATE_INDIC);
|
|
|
|
if (!msg)
|
|
|
|
return -ENOBUFS;
|
|
|
|
|
2012-04-02 04:45:25 +04:00
|
|
|
if (nla_put_string(msg, IEEE802154_ATTR_DEV_NAME, dev->name) ||
|
|
|
|
nla_put_u32(msg, IEEE802154_ATTR_DEV_INDEX, dev->ifindex) ||
|
|
|
|
nla_put(msg, IEEE802154_ATTR_HW_ADDR, IEEE802154_ADDR_LEN,
|
|
|
|
dev->dev_addr))
|
|
|
|
goto nla_put_failure;
|
2014-03-15 00:24:02 +04:00
|
|
|
if (addr->mode == IEEE802154_ADDR_LONG) {
|
|
|
|
if (nla_put_hwaddr(msg, IEEE802154_ATTR_SRC_HW_ADDR,
|
|
|
|
addr->extended_addr))
|
2012-04-02 04:45:25 +04:00
|
|
|
goto nla_put_failure;
|
|
|
|
} else {
|
2014-03-15 00:24:02 +04:00
|
|
|
if (nla_put_shortaddr(msg, IEEE802154_ATTR_SRC_SHORT_ADDR,
|
|
|
|
addr->short_addr))
|
2012-04-02 04:45:25 +04:00
|
|
|
goto nla_put_failure;
|
|
|
|
}
|
|
|
|
if (nla_put_u8(msg, IEEE802154_ATTR_REASON, reason))
|
|
|
|
goto nla_put_failure;
|
2013-11-19 18:19:39 +04:00
|
|
|
return ieee802154_nl_mcast(msg, IEEE802154_COORD_MCGRP);
|
2009-09-14 18:17:36 +04:00
|
|
|
|
|
|
|
nla_put_failure:
|
|
|
|
nlmsg_free(msg);
|
|
|
|
return -ENOBUFS;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(ieee802154_nl_disassoc_indic);
|
|
|
|
|
|
|
|
int ieee802154_nl_disassoc_confirm(struct net_device *dev, u8 status)
|
|
|
|
{
|
|
|
|
struct sk_buff *msg;
|
|
|
|
|
|
|
|
pr_debug("%s\n", __func__);
|
|
|
|
|
|
|
|
msg = ieee802154_nl_create(0, IEEE802154_DISASSOCIATE_CONF);
|
|
|
|
if (!msg)
|
|
|
|
return -ENOBUFS;
|
|
|
|
|
2012-04-02 04:45:25 +04:00
|
|
|
if (nla_put_string(msg, IEEE802154_ATTR_DEV_NAME, dev->name) ||
|
|
|
|
nla_put_u32(msg, IEEE802154_ATTR_DEV_INDEX, dev->ifindex) ||
|
|
|
|
nla_put(msg, IEEE802154_ATTR_HW_ADDR, IEEE802154_ADDR_LEN,
|
|
|
|
dev->dev_addr) ||
|
|
|
|
nla_put_u8(msg, IEEE802154_ATTR_STATUS, status))
|
|
|
|
goto nla_put_failure;
|
2013-11-19 18:19:39 +04:00
|
|
|
return ieee802154_nl_mcast(msg, IEEE802154_COORD_MCGRP);
|
2009-09-14 18:17:36 +04:00
|
|
|
|
|
|
|
nla_put_failure:
|
|
|
|
nlmsg_free(msg);
|
|
|
|
return -ENOBUFS;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(ieee802154_nl_disassoc_confirm);
|
|
|
|
|
2014-03-15 00:23:59 +04:00
|
|
|
int ieee802154_nl_beacon_indic(struct net_device *dev, __le16 panid,
|
|
|
|
__le16 coord_addr)
|
2009-09-14 18:17:36 +04:00
|
|
|
{
|
|
|
|
struct sk_buff *msg;
|
|
|
|
|
|
|
|
pr_debug("%s\n", __func__);
|
|
|
|
|
|
|
|
msg = ieee802154_nl_create(0, IEEE802154_BEACON_NOTIFY_INDIC);
|
|
|
|
if (!msg)
|
|
|
|
return -ENOBUFS;
|
|
|
|
|
2012-04-02 04:45:25 +04:00
|
|
|
if (nla_put_string(msg, IEEE802154_ATTR_DEV_NAME, dev->name) ||
|
|
|
|
nla_put_u32(msg, IEEE802154_ATTR_DEV_INDEX, dev->ifindex) ||
|
|
|
|
nla_put(msg, IEEE802154_ATTR_HW_ADDR, IEEE802154_ADDR_LEN,
|
|
|
|
dev->dev_addr) ||
|
2014-03-15 00:24:02 +04:00
|
|
|
nla_put_shortaddr(msg, IEEE802154_ATTR_COORD_SHORT_ADDR,
|
|
|
|
coord_addr) ||
|
|
|
|
nla_put_shortaddr(msg, IEEE802154_ATTR_COORD_PAN_ID, panid))
|
2012-04-02 04:45:25 +04:00
|
|
|
goto nla_put_failure;
|
2013-11-19 18:19:39 +04:00
|
|
|
return ieee802154_nl_mcast(msg, IEEE802154_COORD_MCGRP);
|
2009-09-14 18:17:36 +04:00
|
|
|
|
|
|
|
nla_put_failure:
|
|
|
|
nlmsg_free(msg);
|
|
|
|
return -ENOBUFS;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(ieee802154_nl_beacon_indic);
|
|
|
|
|
|
|
|
int ieee802154_nl_scan_confirm(struct net_device *dev,
|
2014-07-02 07:31:09 +04:00
|
|
|
u8 status, u8 scan_type,
|
|
|
|
u32 unscanned, u8 page,
|
|
|
|
u8 *edl/* , struct list_head *pan_desc_list */)
|
2009-09-14 18:17:36 +04:00
|
|
|
{
|
|
|
|
struct sk_buff *msg;
|
|
|
|
|
|
|
|
pr_debug("%s\n", __func__);
|
|
|
|
|
|
|
|
msg = ieee802154_nl_create(0, IEEE802154_SCAN_CONF);
|
|
|
|
if (!msg)
|
|
|
|
return -ENOBUFS;
|
|
|
|
|
2012-04-02 04:45:25 +04:00
|
|
|
if (nla_put_string(msg, IEEE802154_ATTR_DEV_NAME, dev->name) ||
|
|
|
|
nla_put_u32(msg, IEEE802154_ATTR_DEV_INDEX, dev->ifindex) ||
|
|
|
|
nla_put(msg, IEEE802154_ATTR_HW_ADDR, IEEE802154_ADDR_LEN,
|
|
|
|
dev->dev_addr) ||
|
|
|
|
nla_put_u8(msg, IEEE802154_ATTR_STATUS, status) ||
|
|
|
|
nla_put_u8(msg, IEEE802154_ATTR_SCAN_TYPE, scan_type) ||
|
|
|
|
nla_put_u32(msg, IEEE802154_ATTR_CHANNELS, unscanned) ||
|
|
|
|
nla_put_u8(msg, IEEE802154_ATTR_PAGE, page) ||
|
|
|
|
(edl &&
|
|
|
|
nla_put(msg, IEEE802154_ATTR_ED_LIST, 27, edl)))
|
|
|
|
goto nla_put_failure;
|
2013-11-19 18:19:39 +04:00
|
|
|
return ieee802154_nl_mcast(msg, IEEE802154_COORD_MCGRP);
|
2009-09-14 18:17:36 +04:00
|
|
|
|
|
|
|
nla_put_failure:
|
|
|
|
nlmsg_free(msg);
|
|
|
|
return -ENOBUFS;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(ieee802154_nl_scan_confirm);
|
|
|
|
|
|
|
|
int ieee802154_nl_start_confirm(struct net_device *dev, u8 status)
|
|
|
|
{
|
|
|
|
struct sk_buff *msg;
|
|
|
|
|
|
|
|
pr_debug("%s\n", __func__);
|
|
|
|
|
|
|
|
msg = ieee802154_nl_create(0, IEEE802154_START_CONF);
|
|
|
|
if (!msg)
|
|
|
|
return -ENOBUFS;
|
|
|
|
|
2012-04-02 04:45:25 +04:00
|
|
|
if (nla_put_string(msg, IEEE802154_ATTR_DEV_NAME, dev->name) ||
|
|
|
|
nla_put_u32(msg, IEEE802154_ATTR_DEV_INDEX, dev->ifindex) ||
|
|
|
|
nla_put(msg, IEEE802154_ATTR_HW_ADDR, IEEE802154_ADDR_LEN,
|
|
|
|
dev->dev_addr) ||
|
|
|
|
nla_put_u8(msg, IEEE802154_ATTR_STATUS, status))
|
|
|
|
goto nla_put_failure;
|
2013-11-19 18:19:39 +04:00
|
|
|
return ieee802154_nl_mcast(msg, IEEE802154_COORD_MCGRP);
|
2009-09-14 18:17:36 +04:00
|
|
|
|
|
|
|
nla_put_failure:
|
|
|
|
nlmsg_free(msg);
|
|
|
|
return -ENOBUFS;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(ieee802154_nl_start_confirm);
|
|
|
|
|
2012-09-08 00:12:54 +04:00
|
|
|
static int ieee802154_nl_fill_iface(struct sk_buff *msg, u32 portid,
|
2014-07-02 07:31:09 +04:00
|
|
|
u32 seq, int flags, struct net_device *dev)
|
2009-09-14 18:17:36 +04:00
|
|
|
{
|
|
|
|
void *hdr;
|
2009-10-29 16:28:52 +03:00
|
|
|
struct wpan_phy *phy;
|
2014-03-31 23:37:46 +04:00
|
|
|
struct ieee802154_mlme_ops *ops;
|
2014-03-15 00:24:02 +04:00
|
|
|
__le16 short_addr, pan_id;
|
2009-09-14 18:17:36 +04:00
|
|
|
|
|
|
|
pr_debug("%s\n", __func__);
|
|
|
|
|
|
|
|
hdr = genlmsg_put(msg, 0, seq, &nl802154_family, flags,
|
2014-07-02 07:31:09 +04:00
|
|
|
IEEE802154_LIST_IFACE);
|
2009-09-14 18:17:36 +04:00
|
|
|
if (!hdr)
|
|
|
|
goto out;
|
|
|
|
|
2014-03-31 23:37:46 +04:00
|
|
|
ops = ieee802154_mlme_ops(dev);
|
|
|
|
phy = ops->get_phy(dev);
|
2009-10-29 16:28:52 +03:00
|
|
|
BUG_ON(!phy);
|
|
|
|
|
2014-03-31 23:37:46 +04:00
|
|
|
short_addr = ops->get_short_addr(dev);
|
|
|
|
pan_id = ops->get_pan_id(dev);
|
2014-03-15 00:23:59 +04:00
|
|
|
|
2012-04-02 04:45:25 +04:00
|
|
|
if (nla_put_string(msg, IEEE802154_ATTR_DEV_NAME, dev->name) ||
|
|
|
|
nla_put_string(msg, IEEE802154_ATTR_PHY_NAME, wpan_phy_name(phy)) ||
|
|
|
|
nla_put_u32(msg, IEEE802154_ATTR_DEV_INDEX, dev->ifindex) ||
|
|
|
|
nla_put(msg, IEEE802154_ATTR_HW_ADDR, IEEE802154_ADDR_LEN,
|
|
|
|
dev->dev_addr) ||
|
2014-03-15 00:24:02 +04:00
|
|
|
nla_put_shortaddr(msg, IEEE802154_ATTR_SHORT_ADDR, short_addr) ||
|
|
|
|
nla_put_shortaddr(msg, IEEE802154_ATTR_PAN_ID, pan_id))
|
2012-04-02 04:45:25 +04:00
|
|
|
goto nla_put_failure;
|
2014-03-31 23:37:46 +04:00
|
|
|
|
|
|
|
if (ops->get_mac_params) {
|
|
|
|
struct ieee802154_mac_params params;
|
|
|
|
|
|
|
|
ops->get_mac_params(dev, ¶ms);
|
|
|
|
|
|
|
|
if (nla_put_s8(msg, IEEE802154_ATTR_TXPOWER,
|
|
|
|
params.transmit_power) ||
|
|
|
|
nla_put_u8(msg, IEEE802154_ATTR_LBT_ENABLED, params.lbt) ||
|
|
|
|
nla_put_u8(msg, IEEE802154_ATTR_CCA_MODE,
|
|
|
|
params.cca_mode) ||
|
|
|
|
nla_put_s32(msg, IEEE802154_ATTR_CCA_ED_LEVEL,
|
|
|
|
params.cca_ed_level) ||
|
|
|
|
nla_put_u8(msg, IEEE802154_ATTR_CSMA_RETRIES,
|
|
|
|
params.csma_retries) ||
|
|
|
|
nla_put_u8(msg, IEEE802154_ATTR_CSMA_MIN_BE,
|
|
|
|
params.min_be) ||
|
|
|
|
nla_put_u8(msg, IEEE802154_ATTR_CSMA_MAX_BE,
|
|
|
|
params.max_be) ||
|
|
|
|
nla_put_s8(msg, IEEE802154_ATTR_FRAME_RETRIES,
|
|
|
|
params.frame_retries))
|
|
|
|
goto nla_put_failure;
|
|
|
|
}
|
|
|
|
|
2009-10-29 16:28:52 +03:00
|
|
|
wpan_phy_put(phy);
|
2009-09-14 18:17:36 +04:00
|
|
|
return genlmsg_end(msg, hdr);
|
|
|
|
|
|
|
|
nla_put_failure:
|
2009-10-29 16:28:52 +03:00
|
|
|
wpan_phy_put(phy);
|
2009-09-14 18:17:36 +04:00
|
|
|
genlmsg_cancel(msg, hdr);
|
|
|
|
out:
|
|
|
|
return -EMSGSIZE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Requests from userspace */
|
|
|
|
static struct net_device *ieee802154_nl_get_dev(struct genl_info *info)
|
|
|
|
{
|
|
|
|
struct net_device *dev;
|
|
|
|
|
|
|
|
if (info->attrs[IEEE802154_ATTR_DEV_NAME]) {
|
|
|
|
char name[IFNAMSIZ + 1];
|
2014-07-02 07:31:09 +04:00
|
|
|
|
2009-09-14 18:17:36 +04:00
|
|
|
nla_strlcpy(name, info->attrs[IEEE802154_ATTR_DEV_NAME],
|
2014-07-02 07:31:09 +04:00
|
|
|
sizeof(name));
|
2009-09-14 18:17:36 +04:00
|
|
|
dev = dev_get_by_name(&init_net, name);
|
2014-07-02 07:31:09 +04:00
|
|
|
} else if (info->attrs[IEEE802154_ATTR_DEV_INDEX]) {
|
2009-09-14 18:17:36 +04:00
|
|
|
dev = dev_get_by_index(&init_net,
|
|
|
|
nla_get_u32(info->attrs[IEEE802154_ATTR_DEV_INDEX]));
|
2014-07-02 07:31:09 +04:00
|
|
|
} else {
|
2009-09-14 18:17:36 +04:00
|
|
|
return NULL;
|
2014-07-02 07:31:09 +04:00
|
|
|
}
|
2009-09-14 18:17:36 +04:00
|
|
|
|
|
|
|
if (!dev)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
if (dev->type != ARPHRD_IEEE802154) {
|
|
|
|
dev_put(dev);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return dev;
|
|
|
|
}
|
|
|
|
|
2013-11-14 20:14:41 +04:00
|
|
|
int ieee802154_associate_req(struct sk_buff *skb, struct genl_info *info)
|
2009-09-14 18:17:36 +04:00
|
|
|
{
|
|
|
|
struct net_device *dev;
|
2014-03-15 00:24:02 +04:00
|
|
|
struct ieee802154_addr addr;
|
2009-09-14 18:17:36 +04:00
|
|
|
u8 page;
|
2013-04-04 10:32:35 +04:00
|
|
|
int ret = -EOPNOTSUPP;
|
2009-09-14 18:17:36 +04:00
|
|
|
|
|
|
|
if (!info->attrs[IEEE802154_ATTR_CHANNEL] ||
|
|
|
|
!info->attrs[IEEE802154_ATTR_COORD_PAN_ID] ||
|
|
|
|
(!info->attrs[IEEE802154_ATTR_COORD_HW_ADDR] &&
|
|
|
|
!info->attrs[IEEE802154_ATTR_COORD_SHORT_ADDR]) ||
|
|
|
|
!info->attrs[IEEE802154_ATTR_CAPABILITY])
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
dev = ieee802154_nl_get_dev(info);
|
|
|
|
if (!dev)
|
|
|
|
return -ENODEV;
|
2013-04-04 10:32:35 +04:00
|
|
|
if (!ieee802154_mlme_ops(dev)->assoc_req)
|
|
|
|
goto out;
|
2009-09-14 18:17:36 +04:00
|
|
|
|
|
|
|
if (info->attrs[IEEE802154_ATTR_COORD_HW_ADDR]) {
|
2014-03-15 00:24:02 +04:00
|
|
|
addr.mode = IEEE802154_ADDR_LONG;
|
|
|
|
addr.extended_addr = nla_get_hwaddr(
|
|
|
|
info->attrs[IEEE802154_ATTR_COORD_HW_ADDR]);
|
2009-09-14 18:17:36 +04:00
|
|
|
} else {
|
2014-03-15 00:24:02 +04:00
|
|
|
addr.mode = IEEE802154_ADDR_SHORT;
|
|
|
|
addr.short_addr = nla_get_shortaddr(
|
2009-09-14 18:17:36 +04:00
|
|
|
info->attrs[IEEE802154_ATTR_COORD_SHORT_ADDR]);
|
|
|
|
}
|
2014-03-15 00:24:02 +04:00
|
|
|
addr.pan_id = nla_get_shortaddr(
|
|
|
|
info->attrs[IEEE802154_ATTR_COORD_PAN_ID]);
|
2009-09-14 18:17:36 +04:00
|
|
|
|
|
|
|
if (info->attrs[IEEE802154_ATTR_PAGE])
|
|
|
|
page = nla_get_u8(info->attrs[IEEE802154_ATTR_PAGE]);
|
|
|
|
else
|
|
|
|
page = 0;
|
|
|
|
|
|
|
|
ret = ieee802154_mlme_ops(dev)->assoc_req(dev, &addr,
|
|
|
|
nla_get_u8(info->attrs[IEEE802154_ATTR_CHANNEL]),
|
|
|
|
page,
|
|
|
|
nla_get_u8(info->attrs[IEEE802154_ATTR_CAPABILITY]));
|
|
|
|
|
2013-04-04 10:32:35 +04:00
|
|
|
out:
|
2009-09-14 18:17:36 +04:00
|
|
|
dev_put(dev);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2013-11-14 20:14:41 +04:00
|
|
|
int ieee802154_associate_resp(struct sk_buff *skb, struct genl_info *info)
|
2009-09-14 18:17:36 +04:00
|
|
|
{
|
|
|
|
struct net_device *dev;
|
2014-03-15 00:24:02 +04:00
|
|
|
struct ieee802154_addr addr;
|
2013-04-04 10:32:35 +04:00
|
|
|
int ret = -EOPNOTSUPP;
|
2009-09-14 18:17:36 +04:00
|
|
|
|
|
|
|
if (!info->attrs[IEEE802154_ATTR_STATUS] ||
|
|
|
|
!info->attrs[IEEE802154_ATTR_DEST_HW_ADDR] ||
|
|
|
|
!info->attrs[IEEE802154_ATTR_DEST_SHORT_ADDR])
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
dev = ieee802154_nl_get_dev(info);
|
|
|
|
if (!dev)
|
|
|
|
return -ENODEV;
|
2013-04-04 10:32:35 +04:00
|
|
|
if (!ieee802154_mlme_ops(dev)->assoc_resp)
|
|
|
|
goto out;
|
2009-09-14 18:17:36 +04:00
|
|
|
|
2014-03-15 00:24:02 +04:00
|
|
|
addr.mode = IEEE802154_ADDR_LONG;
|
|
|
|
addr.extended_addr = nla_get_hwaddr(
|
|
|
|
info->attrs[IEEE802154_ATTR_DEST_HW_ADDR]);
|
|
|
|
addr.pan_id = ieee802154_mlme_ops(dev)->get_pan_id(dev);
|
2009-09-14 18:17:36 +04:00
|
|
|
|
|
|
|
ret = ieee802154_mlme_ops(dev)->assoc_resp(dev, &addr,
|
2014-03-15 00:24:02 +04:00
|
|
|
nla_get_shortaddr(info->attrs[IEEE802154_ATTR_DEST_SHORT_ADDR]),
|
2009-09-14 18:17:36 +04:00
|
|
|
nla_get_u8(info->attrs[IEEE802154_ATTR_STATUS]));
|
|
|
|
|
2013-04-04 10:32:35 +04:00
|
|
|
out:
|
2009-09-14 18:17:36 +04:00
|
|
|
dev_put(dev);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2013-11-14 20:14:41 +04:00
|
|
|
int ieee802154_disassociate_req(struct sk_buff *skb, struct genl_info *info)
|
2009-09-14 18:17:36 +04:00
|
|
|
{
|
|
|
|
struct net_device *dev;
|
2014-03-15 00:24:02 +04:00
|
|
|
struct ieee802154_addr addr;
|
2013-04-04 10:32:35 +04:00
|
|
|
int ret = -EOPNOTSUPP;
|
2009-09-14 18:17:36 +04:00
|
|
|
|
|
|
|
if ((!info->attrs[IEEE802154_ATTR_DEST_HW_ADDR] &&
|
2014-07-02 07:31:09 +04:00
|
|
|
!info->attrs[IEEE802154_ATTR_DEST_SHORT_ADDR]) ||
|
2009-09-14 18:17:36 +04:00
|
|
|
!info->attrs[IEEE802154_ATTR_REASON])
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
dev = ieee802154_nl_get_dev(info);
|
|
|
|
if (!dev)
|
|
|
|
return -ENODEV;
|
2013-04-04 10:32:35 +04:00
|
|
|
if (!ieee802154_mlme_ops(dev)->disassoc_req)
|
|
|
|
goto out;
|
2009-09-14 18:17:36 +04:00
|
|
|
|
|
|
|
if (info->attrs[IEEE802154_ATTR_DEST_HW_ADDR]) {
|
2014-03-15 00:24:02 +04:00
|
|
|
addr.mode = IEEE802154_ADDR_LONG;
|
|
|
|
addr.extended_addr = nla_get_hwaddr(
|
|
|
|
info->attrs[IEEE802154_ATTR_DEST_HW_ADDR]);
|
2009-09-14 18:17:36 +04:00
|
|
|
} else {
|
2014-03-15 00:24:02 +04:00
|
|
|
addr.mode = IEEE802154_ADDR_SHORT;
|
|
|
|
addr.short_addr = nla_get_shortaddr(
|
2009-09-14 18:17:36 +04:00
|
|
|
info->attrs[IEEE802154_ATTR_DEST_SHORT_ADDR]);
|
|
|
|
}
|
2014-03-15 00:24:02 +04:00
|
|
|
addr.pan_id = ieee802154_mlme_ops(dev)->get_pan_id(dev);
|
2009-09-14 18:17:36 +04:00
|
|
|
|
|
|
|
ret = ieee802154_mlme_ops(dev)->disassoc_req(dev, &addr,
|
|
|
|
nla_get_u8(info->attrs[IEEE802154_ATTR_REASON]));
|
|
|
|
|
2013-04-04 10:32:35 +04:00
|
|
|
out:
|
2009-09-14 18:17:36 +04:00
|
|
|
dev_put(dev);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2014-07-02 07:31:09 +04:00
|
|
|
/* PANid, channel, beacon_order = 15, superframe_order = 15,
|
2009-09-14 18:17:36 +04:00
|
|
|
* PAN_coordinator, battery_life_extension = 0,
|
|
|
|
* coord_realignment = 0, security_enable = 0
|
|
|
|
*/
|
2013-11-14 20:14:41 +04:00
|
|
|
int ieee802154_start_req(struct sk_buff *skb, struct genl_info *info)
|
2009-09-14 18:17:36 +04:00
|
|
|
{
|
|
|
|
struct net_device *dev;
|
2014-03-15 00:24:02 +04:00
|
|
|
struct ieee802154_addr addr;
|
2009-09-14 18:17:36 +04:00
|
|
|
|
|
|
|
u8 channel, bcn_ord, sf_ord;
|
|
|
|
u8 page;
|
|
|
|
int pan_coord, blx, coord_realign;
|
2013-04-04 10:32:35 +04:00
|
|
|
int ret = -EOPNOTSUPP;
|
2009-09-14 18:17:36 +04:00
|
|
|
|
|
|
|
if (!info->attrs[IEEE802154_ATTR_COORD_PAN_ID] ||
|
|
|
|
!info->attrs[IEEE802154_ATTR_COORD_SHORT_ADDR] ||
|
|
|
|
!info->attrs[IEEE802154_ATTR_CHANNEL] ||
|
|
|
|
!info->attrs[IEEE802154_ATTR_BCN_ORD] ||
|
|
|
|
!info->attrs[IEEE802154_ATTR_SF_ORD] ||
|
|
|
|
!info->attrs[IEEE802154_ATTR_PAN_COORD] ||
|
|
|
|
!info->attrs[IEEE802154_ATTR_BAT_EXT] ||
|
|
|
|
!info->attrs[IEEE802154_ATTR_COORD_REALIGN]
|
|
|
|
)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
dev = ieee802154_nl_get_dev(info);
|
|
|
|
if (!dev)
|
|
|
|
return -ENODEV;
|
2013-04-04 10:32:35 +04:00
|
|
|
if (!ieee802154_mlme_ops(dev)->start_req)
|
|
|
|
goto out;
|
2009-09-14 18:17:36 +04:00
|
|
|
|
2014-03-15 00:24:02 +04:00
|
|
|
addr.mode = IEEE802154_ADDR_SHORT;
|
|
|
|
addr.short_addr = nla_get_shortaddr(
|
2009-09-14 18:17:36 +04:00
|
|
|
info->attrs[IEEE802154_ATTR_COORD_SHORT_ADDR]);
|
2014-03-15 00:24:02 +04:00
|
|
|
addr.pan_id = nla_get_shortaddr(
|
|
|
|
info->attrs[IEEE802154_ATTR_COORD_PAN_ID]);
|
2009-09-14 18:17:36 +04:00
|
|
|
|
|
|
|
channel = nla_get_u8(info->attrs[IEEE802154_ATTR_CHANNEL]);
|
|
|
|
bcn_ord = nla_get_u8(info->attrs[IEEE802154_ATTR_BCN_ORD]);
|
|
|
|
sf_ord = nla_get_u8(info->attrs[IEEE802154_ATTR_SF_ORD]);
|
|
|
|
pan_coord = nla_get_u8(info->attrs[IEEE802154_ATTR_PAN_COORD]);
|
|
|
|
blx = nla_get_u8(info->attrs[IEEE802154_ATTR_BAT_EXT]);
|
|
|
|
coord_realign = nla_get_u8(info->attrs[IEEE802154_ATTR_COORD_REALIGN]);
|
|
|
|
|
|
|
|
if (info->attrs[IEEE802154_ATTR_PAGE])
|
|
|
|
page = nla_get_u8(info->attrs[IEEE802154_ATTR_PAGE]);
|
|
|
|
else
|
|
|
|
page = 0;
|
|
|
|
|
|
|
|
|
2014-03-15 00:24:02 +04:00
|
|
|
if (addr.short_addr == cpu_to_le16(IEEE802154_ADDR_BROADCAST)) {
|
2009-09-14 18:17:36 +04:00
|
|
|
ieee802154_nl_start_confirm(dev, IEEE802154_NO_SHORT_ADDRESS);
|
|
|
|
dev_put(dev);
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = ieee802154_mlme_ops(dev)->start_req(dev, &addr, channel, page,
|
|
|
|
bcn_ord, sf_ord, pan_coord, blx, coord_realign);
|
|
|
|
|
2013-04-04 10:32:35 +04:00
|
|
|
out:
|
2009-09-14 18:17:36 +04:00
|
|
|
dev_put(dev);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2013-11-14 20:14:41 +04:00
|
|
|
int ieee802154_scan_req(struct sk_buff *skb, struct genl_info *info)
|
2009-09-14 18:17:36 +04:00
|
|
|
{
|
|
|
|
struct net_device *dev;
|
2013-04-04 10:32:35 +04:00
|
|
|
int ret = -EOPNOTSUPP;
|
2009-09-14 18:17:36 +04:00
|
|
|
u8 type;
|
|
|
|
u32 channels;
|
|
|
|
u8 duration;
|
|
|
|
u8 page;
|
|
|
|
|
|
|
|
if (!info->attrs[IEEE802154_ATTR_SCAN_TYPE] ||
|
|
|
|
!info->attrs[IEEE802154_ATTR_CHANNELS] ||
|
|
|
|
!info->attrs[IEEE802154_ATTR_DURATION])
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
dev = ieee802154_nl_get_dev(info);
|
|
|
|
if (!dev)
|
|
|
|
return -ENODEV;
|
2013-04-04 10:32:35 +04:00
|
|
|
if (!ieee802154_mlme_ops(dev)->scan_req)
|
|
|
|
goto out;
|
2009-09-14 18:17:36 +04:00
|
|
|
|
|
|
|
type = nla_get_u8(info->attrs[IEEE802154_ATTR_SCAN_TYPE]);
|
|
|
|
channels = nla_get_u32(info->attrs[IEEE802154_ATTR_CHANNELS]);
|
|
|
|
duration = nla_get_u8(info->attrs[IEEE802154_ATTR_DURATION]);
|
|
|
|
|
|
|
|
if (info->attrs[IEEE802154_ATTR_PAGE])
|
|
|
|
page = nla_get_u8(info->attrs[IEEE802154_ATTR_PAGE]);
|
|
|
|
else
|
|
|
|
page = 0;
|
|
|
|
|
|
|
|
|
2014-07-02 07:31:09 +04:00
|
|
|
ret = ieee802154_mlme_ops(dev)->scan_req(dev, type, channels,
|
|
|
|
page, duration);
|
2009-09-14 18:17:36 +04:00
|
|
|
|
2013-04-04 10:32:35 +04:00
|
|
|
out:
|
2009-09-14 18:17:36 +04:00
|
|
|
dev_put(dev);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2013-11-14 20:14:41 +04:00
|
|
|
int ieee802154_list_iface(struct sk_buff *skb, struct genl_info *info)
|
2009-09-14 18:17:36 +04:00
|
|
|
{
|
|
|
|
/* Request for interface name, index, type, IEEE address,
|
2014-07-02 07:31:09 +04:00
|
|
|
* PAN Id, short address
|
|
|
|
*/
|
2009-09-14 18:17:36 +04:00
|
|
|
struct sk_buff *msg;
|
|
|
|
struct net_device *dev = NULL;
|
|
|
|
int rc = -ENOBUFS;
|
|
|
|
|
|
|
|
pr_debug("%s\n", __func__);
|
|
|
|
|
|
|
|
dev = ieee802154_nl_get_dev(info);
|
|
|
|
if (!dev)
|
|
|
|
return -ENODEV;
|
|
|
|
|
2012-06-28 07:57:45 +04:00
|
|
|
msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
|
2009-09-14 18:17:36 +04:00
|
|
|
if (!msg)
|
|
|
|
goto out_dev;
|
|
|
|
|
2012-09-08 00:12:54 +04:00
|
|
|
rc = ieee802154_nl_fill_iface(msg, info->snd_portid, info->snd_seq,
|
2014-07-02 07:31:09 +04:00
|
|
|
0, dev);
|
2009-09-14 18:17:36 +04:00
|
|
|
if (rc < 0)
|
|
|
|
goto out_free;
|
|
|
|
|
|
|
|
dev_put(dev);
|
|
|
|
|
|
|
|
return genlmsg_reply(msg, info);
|
|
|
|
out_free:
|
|
|
|
nlmsg_free(msg);
|
|
|
|
out_dev:
|
|
|
|
dev_put(dev);
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2013-11-14 20:14:41 +04:00
|
|
|
int ieee802154_dump_iface(struct sk_buff *skb, struct netlink_callback *cb)
|
2009-09-14 18:17:36 +04:00
|
|
|
{
|
|
|
|
struct net *net = sock_net(skb->sk);
|
|
|
|
struct net_device *dev;
|
|
|
|
int idx;
|
|
|
|
int s_idx = cb->args[0];
|
|
|
|
|
|
|
|
pr_debug("%s\n", __func__);
|
|
|
|
|
|
|
|
idx = 0;
|
|
|
|
for_each_netdev(net, dev) {
|
|
|
|
if (idx < s_idx || (dev->type != ARPHRD_IEEE802154))
|
|
|
|
goto cont;
|
|
|
|
|
2012-09-08 00:12:54 +04:00
|
|
|
if (ieee802154_nl_fill_iface(skb, NETLINK_CB(cb->skb).portid,
|
2014-07-02 07:31:09 +04:00
|
|
|
cb->nlh->nlmsg_seq,
|
|
|
|
NLM_F_MULTI, dev) < 0)
|
2009-09-14 18:17:36 +04:00
|
|
|
break;
|
|
|
|
cont:
|
|
|
|
idx++;
|
|
|
|
}
|
|
|
|
cb->args[0] = idx;
|
|
|
|
|
|
|
|
return skb->len;
|
|
|
|
}
|
2014-03-31 23:37:46 +04:00
|
|
|
|
|
|
|
int ieee802154_set_macparams(struct sk_buff *skb, struct genl_info *info)
|
|
|
|
{
|
|
|
|
struct net_device *dev = NULL;
|
|
|
|
struct ieee802154_mlme_ops *ops;
|
|
|
|
struct ieee802154_mac_params params;
|
|
|
|
struct wpan_phy *phy;
|
|
|
|
int rc = -EINVAL;
|
|
|
|
|
|
|
|
pr_debug("%s\n", __func__);
|
|
|
|
|
|
|
|
dev = ieee802154_nl_get_dev(info);
|
|
|
|
if (!dev)
|
|
|
|
return -ENODEV;
|
|
|
|
|
|
|
|
ops = ieee802154_mlme_ops(dev);
|
|
|
|
|
|
|
|
if (!ops->get_mac_params || !ops->set_mac_params) {
|
|
|
|
rc = -EOPNOTSUPP;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (netif_running(dev)) {
|
|
|
|
rc = -EBUSY;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!info->attrs[IEEE802154_ATTR_LBT_ENABLED] &&
|
|
|
|
!info->attrs[IEEE802154_ATTR_CCA_MODE] &&
|
|
|
|
!info->attrs[IEEE802154_ATTR_CCA_ED_LEVEL] &&
|
|
|
|
!info->attrs[IEEE802154_ATTR_CSMA_RETRIES] &&
|
|
|
|
!info->attrs[IEEE802154_ATTR_CSMA_MIN_BE] &&
|
|
|
|
!info->attrs[IEEE802154_ATTR_CSMA_MAX_BE] &&
|
|
|
|
!info->attrs[IEEE802154_ATTR_FRAME_RETRIES])
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
phy = ops->get_phy(dev);
|
|
|
|
|
|
|
|
if ((!phy->set_lbt && info->attrs[IEEE802154_ATTR_LBT_ENABLED]) ||
|
|
|
|
(!phy->set_cca_mode && info->attrs[IEEE802154_ATTR_CCA_MODE]) ||
|
|
|
|
(!phy->set_cca_ed_level &&
|
|
|
|
info->attrs[IEEE802154_ATTR_CCA_ED_LEVEL]) ||
|
|
|
|
(!phy->set_csma_params &&
|
|
|
|
(info->attrs[IEEE802154_ATTR_CSMA_RETRIES] ||
|
|
|
|
info->attrs[IEEE802154_ATTR_CSMA_MIN_BE] ||
|
|
|
|
info->attrs[IEEE802154_ATTR_CSMA_MAX_BE])) ||
|
|
|
|
(!phy->set_frame_retries &&
|
|
|
|
info->attrs[IEEE802154_ATTR_FRAME_RETRIES])) {
|
|
|
|
rc = -EOPNOTSUPP;
|
|
|
|
goto out_phy;
|
|
|
|
}
|
|
|
|
|
|
|
|
ops->get_mac_params(dev, ¶ms);
|
|
|
|
|
|
|
|
if (info->attrs[IEEE802154_ATTR_TXPOWER])
|
|
|
|
params.transmit_power = nla_get_s8(info->attrs[IEEE802154_ATTR_TXPOWER]);
|
|
|
|
|
|
|
|
if (info->attrs[IEEE802154_ATTR_LBT_ENABLED])
|
|
|
|
params.lbt = nla_get_u8(info->attrs[IEEE802154_ATTR_LBT_ENABLED]);
|
|
|
|
|
|
|
|
if (info->attrs[IEEE802154_ATTR_CCA_MODE])
|
|
|
|
params.cca_mode = nla_get_u8(info->attrs[IEEE802154_ATTR_CCA_MODE]);
|
|
|
|
|
|
|
|
if (info->attrs[IEEE802154_ATTR_CCA_ED_LEVEL])
|
|
|
|
params.cca_ed_level = nla_get_s32(info->attrs[IEEE802154_ATTR_CCA_ED_LEVEL]);
|
|
|
|
|
|
|
|
if (info->attrs[IEEE802154_ATTR_CSMA_RETRIES])
|
|
|
|
params.csma_retries = nla_get_u8(info->attrs[IEEE802154_ATTR_CSMA_RETRIES]);
|
|
|
|
|
|
|
|
if (info->attrs[IEEE802154_ATTR_CSMA_MIN_BE])
|
|
|
|
params.min_be = nla_get_u8(info->attrs[IEEE802154_ATTR_CSMA_MIN_BE]);
|
|
|
|
|
|
|
|
if (info->attrs[IEEE802154_ATTR_CSMA_MAX_BE])
|
|
|
|
params.max_be = nla_get_u8(info->attrs[IEEE802154_ATTR_CSMA_MAX_BE]);
|
|
|
|
|
|
|
|
if (info->attrs[IEEE802154_ATTR_FRAME_RETRIES])
|
|
|
|
params.frame_retries = nla_get_s8(info->attrs[IEEE802154_ATTR_FRAME_RETRIES]);
|
|
|
|
|
|
|
|
rc = ops->set_mac_params(dev, ¶ms);
|
|
|
|
|
|
|
|
wpan_phy_put(phy);
|
|
|
|
dev_put(dev);
|
|
|
|
return rc;
|
|
|
|
|
|
|
|
out_phy:
|
|
|
|
wpan_phy_put(phy);
|
|
|
|
out:
|
|
|
|
dev_put(dev);
|
|
|
|
return rc;
|
|
|
|
}
|
2014-05-16 19:46:44 +04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
ieee802154_llsec_parse_key_id(struct genl_info *info,
|
|
|
|
struct ieee802154_llsec_key_id *desc)
|
|
|
|
{
|
|
|
|
memset(desc, 0, sizeof(*desc));
|
|
|
|
|
|
|
|
if (!info->attrs[IEEE802154_ATTR_LLSEC_KEY_MODE])
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
desc->mode = nla_get_u8(info->attrs[IEEE802154_ATTR_LLSEC_KEY_MODE]);
|
|
|
|
|
|
|
|
if (desc->mode == IEEE802154_SCF_KEY_IMPLICIT) {
|
|
|
|
if (!info->attrs[IEEE802154_ATTR_PAN_ID] &&
|
|
|
|
!(info->attrs[IEEE802154_ATTR_SHORT_ADDR] ||
|
|
|
|
info->attrs[IEEE802154_ATTR_HW_ADDR]))
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
desc->device_addr.pan_id = nla_get_shortaddr(info->attrs[IEEE802154_ATTR_PAN_ID]);
|
|
|
|
|
|
|
|
if (info->attrs[IEEE802154_ATTR_SHORT_ADDR]) {
|
|
|
|
desc->device_addr.mode = IEEE802154_ADDR_SHORT;
|
|
|
|
desc->device_addr.short_addr = nla_get_shortaddr(info->attrs[IEEE802154_ATTR_SHORT_ADDR]);
|
|
|
|
} else {
|
|
|
|
desc->device_addr.mode = IEEE802154_ADDR_LONG;
|
|
|
|
desc->device_addr.extended_addr = nla_get_hwaddr(info->attrs[IEEE802154_ATTR_HW_ADDR]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (desc->mode != IEEE802154_SCF_KEY_IMPLICIT &&
|
|
|
|
!info->attrs[IEEE802154_ATTR_LLSEC_KEY_ID])
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
if (desc->mode == IEEE802154_SCF_KEY_SHORT_INDEX &&
|
|
|
|
!info->attrs[IEEE802154_ATTR_LLSEC_KEY_SOURCE_SHORT])
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
if (desc->mode == IEEE802154_SCF_KEY_HW_INDEX &&
|
|
|
|
!info->attrs[IEEE802154_ATTR_LLSEC_KEY_SOURCE_EXTENDED])
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
if (desc->mode != IEEE802154_SCF_KEY_IMPLICIT)
|
|
|
|
desc->id = nla_get_u8(info->attrs[IEEE802154_ATTR_LLSEC_KEY_ID]);
|
|
|
|
|
|
|
|
switch (desc->mode) {
|
|
|
|
case IEEE802154_SCF_KEY_SHORT_INDEX:
|
|
|
|
{
|
|
|
|
u32 source = nla_get_u32(info->attrs[IEEE802154_ATTR_LLSEC_KEY_SOURCE_SHORT]);
|
2014-07-02 07:31:09 +04:00
|
|
|
|
2014-05-16 19:46:44 +04:00
|
|
|
desc->short_source = cpu_to_le32(source);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case IEEE802154_SCF_KEY_HW_INDEX:
|
|
|
|
desc->extended_source = nla_get_hwaddr(info->attrs[IEEE802154_ATTR_LLSEC_KEY_SOURCE_EXTENDED]);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
ieee802154_llsec_fill_key_id(struct sk_buff *msg,
|
|
|
|
const struct ieee802154_llsec_key_id *desc)
|
|
|
|
{
|
|
|
|
if (nla_put_u8(msg, IEEE802154_ATTR_LLSEC_KEY_MODE, desc->mode))
|
|
|
|
return -EMSGSIZE;
|
|
|
|
|
|
|
|
if (desc->mode == IEEE802154_SCF_KEY_IMPLICIT) {
|
|
|
|
if (nla_put_shortaddr(msg, IEEE802154_ATTR_PAN_ID,
|
|
|
|
desc->device_addr.pan_id))
|
|
|
|
return -EMSGSIZE;
|
|
|
|
|
|
|
|
if (desc->device_addr.mode == IEEE802154_ADDR_SHORT &&
|
|
|
|
nla_put_shortaddr(msg, IEEE802154_ATTR_SHORT_ADDR,
|
|
|
|
desc->device_addr.short_addr))
|
|
|
|
return -EMSGSIZE;
|
|
|
|
|
|
|
|
if (desc->device_addr.mode == IEEE802154_ADDR_LONG &&
|
|
|
|
nla_put_hwaddr(msg, IEEE802154_ATTR_HW_ADDR,
|
|
|
|
desc->device_addr.extended_addr))
|
|
|
|
return -EMSGSIZE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (desc->mode != IEEE802154_SCF_KEY_IMPLICIT &&
|
|
|
|
nla_put_u8(msg, IEEE802154_ATTR_LLSEC_KEY_ID, desc->id))
|
|
|
|
return -EMSGSIZE;
|
|
|
|
|
|
|
|
if (desc->mode == IEEE802154_SCF_KEY_SHORT_INDEX &&
|
|
|
|
nla_put_u32(msg, IEEE802154_ATTR_LLSEC_KEY_SOURCE_SHORT,
|
|
|
|
le32_to_cpu(desc->short_source)))
|
|
|
|
return -EMSGSIZE;
|
|
|
|
|
|
|
|
if (desc->mode == IEEE802154_SCF_KEY_HW_INDEX &&
|
|
|
|
nla_put_hwaddr(msg, IEEE802154_ATTR_LLSEC_KEY_SOURCE_EXTENDED,
|
|
|
|
desc->extended_source))
|
|
|
|
return -EMSGSIZE;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int ieee802154_llsec_getparams(struct sk_buff *skb, struct genl_info *info)
|
|
|
|
{
|
|
|
|
struct sk_buff *msg;
|
|
|
|
struct net_device *dev = NULL;
|
|
|
|
int rc = -ENOBUFS;
|
|
|
|
struct ieee802154_mlme_ops *ops;
|
|
|
|
void *hdr;
|
|
|
|
struct ieee802154_llsec_params params;
|
|
|
|
|
|
|
|
pr_debug("%s\n", __func__);
|
|
|
|
|
|
|
|
dev = ieee802154_nl_get_dev(info);
|
|
|
|
if (!dev)
|
|
|
|
return -ENODEV;
|
|
|
|
|
|
|
|
ops = ieee802154_mlme_ops(dev);
|
2014-05-22 11:53:06 +04:00
|
|
|
if (!ops->llsec) {
|
|
|
|
rc = -EOPNOTSUPP;
|
|
|
|
goto out_dev;
|
|
|
|
}
|
2014-05-16 19:46:44 +04:00
|
|
|
|
|
|
|
msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
|
|
|
|
if (!msg)
|
|
|
|
goto out_dev;
|
|
|
|
|
|
|
|
hdr = genlmsg_put(msg, 0, info->snd_seq, &nl802154_family, 0,
|
2014-07-02 07:31:09 +04:00
|
|
|
IEEE802154_LLSEC_GETPARAMS);
|
2014-05-16 19:46:44 +04:00
|
|
|
if (!hdr)
|
|
|
|
goto out_free;
|
|
|
|
|
|
|
|
rc = ops->llsec->get_params(dev, ¶ms);
|
|
|
|
if (rc < 0)
|
|
|
|
goto out_free;
|
|
|
|
|
|
|
|
if (nla_put_string(msg, IEEE802154_ATTR_DEV_NAME, dev->name) ||
|
|
|
|
nla_put_u32(msg, IEEE802154_ATTR_DEV_INDEX, dev->ifindex) ||
|
|
|
|
nla_put_u8(msg, IEEE802154_ATTR_LLSEC_ENABLED, params.enabled) ||
|
|
|
|
nla_put_u8(msg, IEEE802154_ATTR_LLSEC_SECLEVEL, params.out_level) ||
|
|
|
|
nla_put_u32(msg, IEEE802154_ATTR_LLSEC_FRAME_COUNTER,
|
|
|
|
be32_to_cpu(params.frame_counter)) ||
|
|
|
|
ieee802154_llsec_fill_key_id(msg, ¶ms.out_key))
|
|
|
|
goto out_free;
|
|
|
|
|
|
|
|
dev_put(dev);
|
|
|
|
|
|
|
|
return ieee802154_nl_reply(msg, info);
|
|
|
|
out_free:
|
|
|
|
nlmsg_free(msg);
|
|
|
|
out_dev:
|
|
|
|
dev_put(dev);
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
int ieee802154_llsec_setparams(struct sk_buff *skb, struct genl_info *info)
|
|
|
|
{
|
|
|
|
struct net_device *dev = NULL;
|
|
|
|
int rc = -EINVAL;
|
|
|
|
struct ieee802154_mlme_ops *ops;
|
|
|
|
struct ieee802154_llsec_params params;
|
|
|
|
int changed = 0;
|
|
|
|
|
|
|
|
pr_debug("%s\n", __func__);
|
|
|
|
|
|
|
|
dev = ieee802154_nl_get_dev(info);
|
|
|
|
if (!dev)
|
|
|
|
return -ENODEV;
|
|
|
|
|
|
|
|
if (!info->attrs[IEEE802154_ATTR_LLSEC_ENABLED] &&
|
|
|
|
!info->attrs[IEEE802154_ATTR_LLSEC_KEY_MODE] &&
|
|
|
|
!info->attrs[IEEE802154_ATTR_LLSEC_SECLEVEL])
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
ops = ieee802154_mlme_ops(dev);
|
|
|
|
if (!ops->llsec) {
|
|
|
|
rc = -EOPNOTSUPP;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (info->attrs[IEEE802154_ATTR_LLSEC_SECLEVEL] &&
|
|
|
|
nla_get_u8(info->attrs[IEEE802154_ATTR_LLSEC_SECLEVEL]) > 7)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
if (info->attrs[IEEE802154_ATTR_LLSEC_ENABLED]) {
|
|
|
|
params.enabled = nla_get_u8(info->attrs[IEEE802154_ATTR_LLSEC_ENABLED]);
|
|
|
|
changed |= IEEE802154_LLSEC_PARAM_ENABLED;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (info->attrs[IEEE802154_ATTR_LLSEC_KEY_MODE]) {
|
|
|
|
if (ieee802154_llsec_parse_key_id(info, ¶ms.out_key))
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
changed |= IEEE802154_LLSEC_PARAM_OUT_KEY;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (info->attrs[IEEE802154_ATTR_LLSEC_SECLEVEL]) {
|
|
|
|
params.out_level = nla_get_u8(info->attrs[IEEE802154_ATTR_LLSEC_SECLEVEL]);
|
|
|
|
changed |= IEEE802154_LLSEC_PARAM_OUT_LEVEL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (info->attrs[IEEE802154_ATTR_LLSEC_FRAME_COUNTER]) {
|
|
|
|
u32 fc = nla_get_u32(info->attrs[IEEE802154_ATTR_LLSEC_FRAME_COUNTER]);
|
|
|
|
|
|
|
|
params.frame_counter = cpu_to_be32(fc);
|
|
|
|
changed |= IEEE802154_LLSEC_PARAM_FRAME_COUNTER;
|
|
|
|
}
|
|
|
|
|
|
|
|
rc = ops->llsec->set_params(dev, ¶ms, changed);
|
|
|
|
|
|
|
|
dev_put(dev);
|
|
|
|
|
|
|
|
return rc;
|
|
|
|
out:
|
|
|
|
dev_put(dev);
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
struct llsec_dump_data {
|
|
|
|
struct sk_buff *skb;
|
|
|
|
int s_idx, s_idx2;
|
|
|
|
int portid;
|
|
|
|
int nlmsg_seq;
|
|
|
|
struct net_device *dev;
|
|
|
|
struct ieee802154_mlme_ops *ops;
|
|
|
|
struct ieee802154_llsec_table *table;
|
|
|
|
};
|
|
|
|
|
|
|
|
static int
|
|
|
|
ieee802154_llsec_dump_table(struct sk_buff *skb, struct netlink_callback *cb,
|
2014-07-02 07:31:09 +04:00
|
|
|
int (*step)(struct llsec_dump_data *))
|
2014-05-16 19:46:44 +04:00
|
|
|
{
|
|
|
|
struct net *net = sock_net(skb->sk);
|
|
|
|
struct net_device *dev;
|
|
|
|
struct llsec_dump_data data;
|
|
|
|
int idx = 0;
|
|
|
|
int first_dev = cb->args[0];
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
for_each_netdev(net, dev) {
|
|
|
|
if (idx < first_dev || dev->type != ARPHRD_IEEE802154)
|
|
|
|
goto skip;
|
|
|
|
|
|
|
|
data.ops = ieee802154_mlme_ops(dev);
|
|
|
|
if (!data.ops->llsec)
|
|
|
|
goto skip;
|
|
|
|
|
|
|
|
data.skb = skb;
|
|
|
|
data.s_idx = cb->args[1];
|
|
|
|
data.s_idx2 = cb->args[2];
|
|
|
|
data.dev = dev;
|
|
|
|
data.portid = NETLINK_CB(cb->skb).portid;
|
|
|
|
data.nlmsg_seq = cb->nlh->nlmsg_seq;
|
|
|
|
|
|
|
|
data.ops->llsec->lock_table(dev);
|
|
|
|
data.ops->llsec->get_table(data.dev, &data.table);
|
|
|
|
rc = step(&data);
|
|
|
|
data.ops->llsec->unlock_table(dev);
|
|
|
|
|
|
|
|
if (rc < 0)
|
|
|
|
break;
|
|
|
|
|
|
|
|
skip:
|
|
|
|
idx++;
|
|
|
|
}
|
|
|
|
cb->args[0] = idx;
|
|
|
|
|
|
|
|
return skb->len;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
ieee802154_nl_llsec_change(struct sk_buff *skb, struct genl_info *info,
|
|
|
|
int (*fn)(struct net_device*, struct genl_info*))
|
|
|
|
{
|
|
|
|
struct net_device *dev = NULL;
|
|
|
|
int rc = -EINVAL;
|
|
|
|
|
|
|
|
dev = ieee802154_nl_get_dev(info);
|
|
|
|
if (!dev)
|
|
|
|
return -ENODEV;
|
|
|
|
|
|
|
|
if (!ieee802154_mlme_ops(dev)->llsec)
|
|
|
|
rc = -EOPNOTSUPP;
|
|
|
|
else
|
|
|
|
rc = fn(dev, info);
|
|
|
|
|
|
|
|
dev_put(dev);
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
ieee802154_llsec_parse_key(struct genl_info *info,
|
|
|
|
struct ieee802154_llsec_key *key)
|
|
|
|
{
|
|
|
|
u8 frames;
|
|
|
|
u32 commands[256 / 32];
|
|
|
|
|
|
|
|
memset(key, 0, sizeof(*key));
|
|
|
|
|
|
|
|
if (!info->attrs[IEEE802154_ATTR_LLSEC_KEY_USAGE_FRAME_TYPES] ||
|
|
|
|
!info->attrs[IEEE802154_ATTR_LLSEC_KEY_BYTES])
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
frames = nla_get_u8(info->attrs[IEEE802154_ATTR_LLSEC_KEY_USAGE_FRAME_TYPES]);
|
|
|
|
if ((frames & BIT(IEEE802154_FC_TYPE_MAC_CMD)) &&
|
|
|
|
!info->attrs[IEEE802154_ATTR_LLSEC_KEY_USAGE_COMMANDS])
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
if (info->attrs[IEEE802154_ATTR_LLSEC_KEY_USAGE_COMMANDS]) {
|
|
|
|
nla_memcpy(commands,
|
|
|
|
info->attrs[IEEE802154_ATTR_LLSEC_KEY_USAGE_COMMANDS],
|
|
|
|
256 / 8);
|
|
|
|
|
|
|
|
if (commands[0] || commands[1] || commands[2] || commands[3] ||
|
|
|
|
commands[4] || commands[5] || commands[6] ||
|
|
|
|
commands[7] >= BIT(IEEE802154_CMD_GTS_REQ + 1))
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
key->cmd_frame_ids = commands[7];
|
|
|
|
}
|
|
|
|
|
|
|
|
key->frame_types = frames;
|
|
|
|
|
|
|
|
nla_memcpy(key->key, info->attrs[IEEE802154_ATTR_LLSEC_KEY_BYTES],
|
|
|
|
IEEE802154_LLSEC_KEY_SIZE);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int llsec_add_key(struct net_device *dev, struct genl_info *info)
|
|
|
|
{
|
|
|
|
struct ieee802154_mlme_ops *ops = ieee802154_mlme_ops(dev);
|
|
|
|
struct ieee802154_llsec_key key;
|
|
|
|
struct ieee802154_llsec_key_id id;
|
|
|
|
|
|
|
|
if (ieee802154_llsec_parse_key(info, &key) ||
|
|
|
|
ieee802154_llsec_parse_key_id(info, &id))
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
return ops->llsec->add_key(dev, &id, &key);
|
|
|
|
}
|
|
|
|
|
|
|
|
int ieee802154_llsec_add_key(struct sk_buff *skb, struct genl_info *info)
|
|
|
|
{
|
|
|
|
if ((info->nlhdr->nlmsg_flags & (NLM_F_CREATE | NLM_F_EXCL)) !=
|
|
|
|
(NLM_F_CREATE | NLM_F_EXCL))
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
return ieee802154_nl_llsec_change(skb, info, llsec_add_key);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int llsec_remove_key(struct net_device *dev, struct genl_info *info)
|
|
|
|
{
|
|
|
|
struct ieee802154_mlme_ops *ops = ieee802154_mlme_ops(dev);
|
|
|
|
struct ieee802154_llsec_key_id id;
|
|
|
|
|
|
|
|
if (ieee802154_llsec_parse_key_id(info, &id))
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
return ops->llsec->del_key(dev, &id);
|
|
|
|
}
|
|
|
|
|
|
|
|
int ieee802154_llsec_del_key(struct sk_buff *skb, struct genl_info *info)
|
|
|
|
{
|
|
|
|
return ieee802154_nl_llsec_change(skb, info, llsec_remove_key);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
ieee802154_nl_fill_key(struct sk_buff *msg, u32 portid, u32 seq,
|
|
|
|
const struct ieee802154_llsec_key_entry *key,
|
|
|
|
const struct net_device *dev)
|
|
|
|
{
|
|
|
|
void *hdr;
|
|
|
|
u32 commands[256 / 32];
|
|
|
|
|
|
|
|
hdr = genlmsg_put(msg, 0, seq, &nl802154_family, NLM_F_MULTI,
|
|
|
|
IEEE802154_LLSEC_LIST_KEY);
|
|
|
|
if (!hdr)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
if (nla_put_string(msg, IEEE802154_ATTR_DEV_NAME, dev->name) ||
|
|
|
|
nla_put_u32(msg, IEEE802154_ATTR_DEV_INDEX, dev->ifindex) ||
|
|
|
|
ieee802154_llsec_fill_key_id(msg, &key->id) ||
|
|
|
|
nla_put_u8(msg, IEEE802154_ATTR_LLSEC_KEY_USAGE_FRAME_TYPES,
|
|
|
|
key->key->frame_types))
|
|
|
|
goto nla_put_failure;
|
|
|
|
|
|
|
|
if (key->key->frame_types & BIT(IEEE802154_FC_TYPE_MAC_CMD)) {
|
|
|
|
memset(commands, 0, sizeof(commands));
|
|
|
|
commands[7] = key->key->cmd_frame_ids;
|
|
|
|
if (nla_put(msg, IEEE802154_ATTR_LLSEC_KEY_USAGE_COMMANDS,
|
|
|
|
sizeof(commands), commands))
|
|
|
|
goto nla_put_failure;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (nla_put(msg, IEEE802154_ATTR_LLSEC_KEY_BYTES,
|
|
|
|
IEEE802154_LLSEC_KEY_SIZE, key->key->key))
|
|
|
|
goto nla_put_failure;
|
|
|
|
|
|
|
|
genlmsg_end(msg, hdr);
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
nla_put_failure:
|
|
|
|
genlmsg_cancel(msg, hdr);
|
|
|
|
out:
|
|
|
|
return -EMSGSIZE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int llsec_iter_keys(struct llsec_dump_data *data)
|
|
|
|
{
|
|
|
|
struct ieee802154_llsec_key_entry *pos;
|
|
|
|
int rc = 0, idx = 0;
|
|
|
|
|
|
|
|
list_for_each_entry(pos, &data->table->keys, list) {
|
|
|
|
if (idx++ < data->s_idx)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (ieee802154_nl_fill_key(data->skb, data->portid,
|
|
|
|
data->nlmsg_seq, pos, data->dev)) {
|
|
|
|
rc = -EMSGSIZE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
data->s_idx++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
int ieee802154_llsec_dump_keys(struct sk_buff *skb, struct netlink_callback *cb)
|
|
|
|
{
|
|
|
|
return ieee802154_llsec_dump_table(skb, cb, llsec_iter_keys);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
llsec_parse_dev(struct genl_info *info,
|
|
|
|
struct ieee802154_llsec_device *dev)
|
|
|
|
{
|
|
|
|
memset(dev, 0, sizeof(*dev));
|
|
|
|
|
|
|
|
if (!info->attrs[IEEE802154_ATTR_LLSEC_FRAME_COUNTER] ||
|
|
|
|
!info->attrs[IEEE802154_ATTR_HW_ADDR] ||
|
|
|
|
!info->attrs[IEEE802154_ATTR_LLSEC_DEV_OVERRIDE] ||
|
|
|
|
!info->attrs[IEEE802154_ATTR_LLSEC_DEV_KEY_MODE] ||
|
|
|
|
(!!info->attrs[IEEE802154_ATTR_PAN_ID] !=
|
|
|
|
!!info->attrs[IEEE802154_ATTR_SHORT_ADDR]))
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
if (info->attrs[IEEE802154_ATTR_PAN_ID]) {
|
|
|
|
dev->pan_id = nla_get_shortaddr(info->attrs[IEEE802154_ATTR_PAN_ID]);
|
|
|
|
dev->short_addr = nla_get_shortaddr(info->attrs[IEEE802154_ATTR_SHORT_ADDR]);
|
|
|
|
} else {
|
|
|
|
dev->short_addr = cpu_to_le16(IEEE802154_ADDR_UNDEF);
|
|
|
|
}
|
|
|
|
|
|
|
|
dev->hwaddr = nla_get_hwaddr(info->attrs[IEEE802154_ATTR_HW_ADDR]);
|
|
|
|
dev->frame_counter = nla_get_u32(info->attrs[IEEE802154_ATTR_LLSEC_FRAME_COUNTER]);
|
|
|
|
dev->seclevel_exempt = !!nla_get_u8(info->attrs[IEEE802154_ATTR_LLSEC_DEV_OVERRIDE]);
|
|
|
|
dev->key_mode = nla_get_u8(info->attrs[IEEE802154_ATTR_LLSEC_DEV_KEY_MODE]);
|
|
|
|
|
|
|
|
if (dev->key_mode >= __IEEE802154_LLSEC_DEVKEY_MAX)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int llsec_add_dev(struct net_device *dev, struct genl_info *info)
|
|
|
|
{
|
|
|
|
struct ieee802154_mlme_ops *ops = ieee802154_mlme_ops(dev);
|
|
|
|
struct ieee802154_llsec_device desc;
|
|
|
|
|
|
|
|
if (llsec_parse_dev(info, &desc))
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
return ops->llsec->add_dev(dev, &desc);
|
|
|
|
}
|
|
|
|
|
|
|
|
int ieee802154_llsec_add_dev(struct sk_buff *skb, struct genl_info *info)
|
|
|
|
{
|
|
|
|
if ((info->nlhdr->nlmsg_flags & (NLM_F_CREATE | NLM_F_EXCL)) !=
|
|
|
|
(NLM_F_CREATE | NLM_F_EXCL))
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
return ieee802154_nl_llsec_change(skb, info, llsec_add_dev);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int llsec_del_dev(struct net_device *dev, struct genl_info *info)
|
|
|
|
{
|
|
|
|
struct ieee802154_mlme_ops *ops = ieee802154_mlme_ops(dev);
|
|
|
|
__le64 devaddr;
|
|
|
|
|
|
|
|
if (!info->attrs[IEEE802154_ATTR_HW_ADDR])
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
devaddr = nla_get_hwaddr(info->attrs[IEEE802154_ATTR_HW_ADDR]);
|
|
|
|
|
|
|
|
return ops->llsec->del_dev(dev, devaddr);
|
|
|
|
}
|
|
|
|
|
|
|
|
int ieee802154_llsec_del_dev(struct sk_buff *skb, struct genl_info *info)
|
|
|
|
{
|
|
|
|
return ieee802154_nl_llsec_change(skb, info, llsec_del_dev);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
ieee802154_nl_fill_dev(struct sk_buff *msg, u32 portid, u32 seq,
|
|
|
|
const struct ieee802154_llsec_device *desc,
|
|
|
|
const struct net_device *dev)
|
|
|
|
{
|
|
|
|
void *hdr;
|
|
|
|
|
|
|
|
hdr = genlmsg_put(msg, 0, seq, &nl802154_family, NLM_F_MULTI,
|
|
|
|
IEEE802154_LLSEC_LIST_DEV);
|
|
|
|
if (!hdr)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
if (nla_put_string(msg, IEEE802154_ATTR_DEV_NAME, dev->name) ||
|
|
|
|
nla_put_u32(msg, IEEE802154_ATTR_DEV_INDEX, dev->ifindex) ||
|
|
|
|
nla_put_shortaddr(msg, IEEE802154_ATTR_PAN_ID, desc->pan_id) ||
|
|
|
|
nla_put_shortaddr(msg, IEEE802154_ATTR_SHORT_ADDR,
|
|
|
|
desc->short_addr) ||
|
|
|
|
nla_put_hwaddr(msg, IEEE802154_ATTR_HW_ADDR, desc->hwaddr) ||
|
|
|
|
nla_put_u32(msg, IEEE802154_ATTR_LLSEC_FRAME_COUNTER,
|
|
|
|
desc->frame_counter) ||
|
|
|
|
nla_put_u8(msg, IEEE802154_ATTR_LLSEC_DEV_OVERRIDE,
|
|
|
|
desc->seclevel_exempt) ||
|
|
|
|
nla_put_u8(msg, IEEE802154_ATTR_LLSEC_DEV_KEY_MODE, desc->key_mode))
|
|
|
|
goto nla_put_failure;
|
|
|
|
|
|
|
|
genlmsg_end(msg, hdr);
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
nla_put_failure:
|
|
|
|
genlmsg_cancel(msg, hdr);
|
|
|
|
out:
|
|
|
|
return -EMSGSIZE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int llsec_iter_devs(struct llsec_dump_data *data)
|
|
|
|
{
|
|
|
|
struct ieee802154_llsec_device *pos;
|
|
|
|
int rc = 0, idx = 0;
|
|
|
|
|
|
|
|
list_for_each_entry(pos, &data->table->devices, list) {
|
|
|
|
if (idx++ < data->s_idx)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (ieee802154_nl_fill_dev(data->skb, data->portid,
|
|
|
|
data->nlmsg_seq, pos, data->dev)) {
|
|
|
|
rc = -EMSGSIZE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
data->s_idx++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
int ieee802154_llsec_dump_devs(struct sk_buff *skb, struct netlink_callback *cb)
|
|
|
|
{
|
|
|
|
return ieee802154_llsec_dump_table(skb, cb, llsec_iter_devs);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static int llsec_add_devkey(struct net_device *dev, struct genl_info *info)
|
|
|
|
{
|
|
|
|
struct ieee802154_mlme_ops *ops = ieee802154_mlme_ops(dev);
|
|
|
|
struct ieee802154_llsec_device_key key;
|
|
|
|
__le64 devaddr;
|
|
|
|
|
|
|
|
if (!info->attrs[IEEE802154_ATTR_LLSEC_FRAME_COUNTER] ||
|
|
|
|
!info->attrs[IEEE802154_ATTR_HW_ADDR] ||
|
|
|
|
ieee802154_llsec_parse_key_id(info, &key.key_id))
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
devaddr = nla_get_hwaddr(info->attrs[IEEE802154_ATTR_HW_ADDR]);
|
|
|
|
key.frame_counter = nla_get_u32(info->attrs[IEEE802154_ATTR_LLSEC_FRAME_COUNTER]);
|
|
|
|
|
|
|
|
return ops->llsec->add_devkey(dev, devaddr, &key);
|
|
|
|
}
|
|
|
|
|
|
|
|
int ieee802154_llsec_add_devkey(struct sk_buff *skb, struct genl_info *info)
|
|
|
|
{
|
|
|
|
if ((info->nlhdr->nlmsg_flags & (NLM_F_CREATE | NLM_F_EXCL)) !=
|
|
|
|
(NLM_F_CREATE | NLM_F_EXCL))
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
return ieee802154_nl_llsec_change(skb, info, llsec_add_devkey);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int llsec_del_devkey(struct net_device *dev, struct genl_info *info)
|
|
|
|
{
|
|
|
|
struct ieee802154_mlme_ops *ops = ieee802154_mlme_ops(dev);
|
|
|
|
struct ieee802154_llsec_device_key key;
|
|
|
|
__le64 devaddr;
|
|
|
|
|
|
|
|
if (!info->attrs[IEEE802154_ATTR_HW_ADDR] ||
|
|
|
|
ieee802154_llsec_parse_key_id(info, &key.key_id))
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
devaddr = nla_get_hwaddr(info->attrs[IEEE802154_ATTR_HW_ADDR]);
|
|
|
|
|
|
|
|
return ops->llsec->del_devkey(dev, devaddr, &key);
|
|
|
|
}
|
|
|
|
|
|
|
|
int ieee802154_llsec_del_devkey(struct sk_buff *skb, struct genl_info *info)
|
|
|
|
{
|
|
|
|
return ieee802154_nl_llsec_change(skb, info, llsec_del_devkey);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
ieee802154_nl_fill_devkey(struct sk_buff *msg, u32 portid, u32 seq,
|
|
|
|
__le64 devaddr,
|
|
|
|
const struct ieee802154_llsec_device_key *devkey,
|
|
|
|
const struct net_device *dev)
|
|
|
|
{
|
|
|
|
void *hdr;
|
|
|
|
|
|
|
|
hdr = genlmsg_put(msg, 0, seq, &nl802154_family, NLM_F_MULTI,
|
|
|
|
IEEE802154_LLSEC_LIST_DEVKEY);
|
|
|
|
if (!hdr)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
if (nla_put_string(msg, IEEE802154_ATTR_DEV_NAME, dev->name) ||
|
|
|
|
nla_put_u32(msg, IEEE802154_ATTR_DEV_INDEX, dev->ifindex) ||
|
|
|
|
nla_put_hwaddr(msg, IEEE802154_ATTR_HW_ADDR, devaddr) ||
|
|
|
|
nla_put_u32(msg, IEEE802154_ATTR_LLSEC_FRAME_COUNTER,
|
|
|
|
devkey->frame_counter) ||
|
|
|
|
ieee802154_llsec_fill_key_id(msg, &devkey->key_id))
|
|
|
|
goto nla_put_failure;
|
|
|
|
|
|
|
|
genlmsg_end(msg, hdr);
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
nla_put_failure:
|
|
|
|
genlmsg_cancel(msg, hdr);
|
|
|
|
out:
|
|
|
|
return -EMSGSIZE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int llsec_iter_devkeys(struct llsec_dump_data *data)
|
|
|
|
{
|
|
|
|
struct ieee802154_llsec_device *dpos;
|
|
|
|
struct ieee802154_llsec_device_key *kpos;
|
|
|
|
int rc = 0, idx = 0, idx2;
|
|
|
|
|
|
|
|
list_for_each_entry(dpos, &data->table->devices, list) {
|
|
|
|
if (idx++ < data->s_idx)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
idx2 = 0;
|
|
|
|
|
|
|
|
list_for_each_entry(kpos, &dpos->keys, list) {
|
|
|
|
if (idx2++ < data->s_idx2)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (ieee802154_nl_fill_devkey(data->skb, data->portid,
|
|
|
|
data->nlmsg_seq,
|
|
|
|
dpos->hwaddr, kpos,
|
|
|
|
data->dev)) {
|
|
|
|
return rc = -EMSGSIZE;
|
|
|
|
}
|
|
|
|
|
|
|
|
data->s_idx2++;
|
|
|
|
}
|
|
|
|
|
|
|
|
data->s_idx++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
int ieee802154_llsec_dump_devkeys(struct sk_buff *skb,
|
|
|
|
struct netlink_callback *cb)
|
|
|
|
{
|
|
|
|
return ieee802154_llsec_dump_table(skb, cb, llsec_iter_devkeys);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
llsec_parse_seclevel(struct genl_info *info,
|
|
|
|
struct ieee802154_llsec_seclevel *sl)
|
|
|
|
{
|
|
|
|
memset(sl, 0, sizeof(*sl));
|
|
|
|
|
|
|
|
if (!info->attrs[IEEE802154_ATTR_LLSEC_FRAME_TYPE] ||
|
|
|
|
!info->attrs[IEEE802154_ATTR_LLSEC_SECLEVELS] ||
|
|
|
|
!info->attrs[IEEE802154_ATTR_LLSEC_DEV_OVERRIDE])
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
sl->frame_type = nla_get_u8(info->attrs[IEEE802154_ATTR_LLSEC_FRAME_TYPE]);
|
|
|
|
if (sl->frame_type == IEEE802154_FC_TYPE_MAC_CMD) {
|
|
|
|
if (!info->attrs[IEEE802154_ATTR_LLSEC_CMD_FRAME_ID])
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
sl->cmd_frame_id = nla_get_u8(info->attrs[IEEE802154_ATTR_LLSEC_CMD_FRAME_ID]);
|
|
|
|
}
|
|
|
|
|
|
|
|
sl->sec_levels = nla_get_u8(info->attrs[IEEE802154_ATTR_LLSEC_SECLEVELS]);
|
|
|
|
sl->device_override = nla_get_u8(info->attrs[IEEE802154_ATTR_LLSEC_DEV_OVERRIDE]);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int llsec_add_seclevel(struct net_device *dev, struct genl_info *info)
|
|
|
|
{
|
|
|
|
struct ieee802154_mlme_ops *ops = ieee802154_mlme_ops(dev);
|
|
|
|
struct ieee802154_llsec_seclevel sl;
|
|
|
|
|
|
|
|
if (llsec_parse_seclevel(info, &sl))
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
return ops->llsec->add_seclevel(dev, &sl);
|
|
|
|
}
|
|
|
|
|
|
|
|
int ieee802154_llsec_add_seclevel(struct sk_buff *skb, struct genl_info *info)
|
|
|
|
{
|
|
|
|
if ((info->nlhdr->nlmsg_flags & (NLM_F_CREATE | NLM_F_EXCL)) !=
|
|
|
|
(NLM_F_CREATE | NLM_F_EXCL))
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
return ieee802154_nl_llsec_change(skb, info, llsec_add_seclevel);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int llsec_del_seclevel(struct net_device *dev, struct genl_info *info)
|
|
|
|
{
|
|
|
|
struct ieee802154_mlme_ops *ops = ieee802154_mlme_ops(dev);
|
|
|
|
struct ieee802154_llsec_seclevel sl;
|
|
|
|
|
|
|
|
if (llsec_parse_seclevel(info, &sl))
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
return ops->llsec->del_seclevel(dev, &sl);
|
|
|
|
}
|
|
|
|
|
|
|
|
int ieee802154_llsec_del_seclevel(struct sk_buff *skb, struct genl_info *info)
|
|
|
|
{
|
|
|
|
return ieee802154_nl_llsec_change(skb, info, llsec_del_seclevel);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
ieee802154_nl_fill_seclevel(struct sk_buff *msg, u32 portid, u32 seq,
|
|
|
|
const struct ieee802154_llsec_seclevel *sl,
|
|
|
|
const struct net_device *dev)
|
|
|
|
{
|
|
|
|
void *hdr;
|
|
|
|
|
|
|
|
hdr = genlmsg_put(msg, 0, seq, &nl802154_family, NLM_F_MULTI,
|
|
|
|
IEEE802154_LLSEC_LIST_SECLEVEL);
|
|
|
|
if (!hdr)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
if (nla_put_string(msg, IEEE802154_ATTR_DEV_NAME, dev->name) ||
|
|
|
|
nla_put_u32(msg, IEEE802154_ATTR_DEV_INDEX, dev->ifindex) ||
|
|
|
|
nla_put_u8(msg, IEEE802154_ATTR_LLSEC_FRAME_TYPE, sl->frame_type) ||
|
|
|
|
nla_put_u8(msg, IEEE802154_ATTR_LLSEC_SECLEVELS, sl->sec_levels) ||
|
|
|
|
nla_put_u8(msg, IEEE802154_ATTR_LLSEC_DEV_OVERRIDE,
|
|
|
|
sl->device_override))
|
|
|
|
goto nla_put_failure;
|
|
|
|
|
|
|
|
if (sl->frame_type == IEEE802154_FC_TYPE_MAC_CMD &&
|
|
|
|
nla_put_u8(msg, IEEE802154_ATTR_LLSEC_CMD_FRAME_ID,
|
|
|
|
sl->cmd_frame_id))
|
|
|
|
goto nla_put_failure;
|
|
|
|
|
|
|
|
genlmsg_end(msg, hdr);
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
nla_put_failure:
|
|
|
|
genlmsg_cancel(msg, hdr);
|
|
|
|
out:
|
|
|
|
return -EMSGSIZE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int llsec_iter_seclevels(struct llsec_dump_data *data)
|
|
|
|
{
|
|
|
|
struct ieee802154_llsec_seclevel *pos;
|
|
|
|
int rc = 0, idx = 0;
|
|
|
|
|
|
|
|
list_for_each_entry(pos, &data->table->security_levels, list) {
|
|
|
|
if (idx++ < data->s_idx)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (ieee802154_nl_fill_seclevel(data->skb, data->portid,
|
|
|
|
data->nlmsg_seq, pos,
|
|
|
|
data->dev)) {
|
|
|
|
rc = -EMSGSIZE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
data->s_idx++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
int ieee802154_llsec_dump_seclevels(struct sk_buff *skb,
|
|
|
|
struct netlink_callback *cb)
|
|
|
|
{
|
|
|
|
return ieee802154_llsec_dump_table(skb, cb, llsec_iter_seclevels);
|
|
|
|
}
|