Release 4.11 net/ieee802154/nl-mac.c
/*
* Netlink interface 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.
*
* Written by:
* Sergey Lapin <slapin@ossfans.org>
* Dmitry Eremin-Solenikov <dbaryshkov@gmail.com>
* Maxim Osipov <maxim.osipov@siemens.com>
*/
#include <linux/gfp.h>
#include <linux/kernel.h>
#include <linux/if_arp.h>
#include <linux/netdevice.h>
#include <linux/ieee802154.h>
#include <net/netlink.h>
#include <net/genetlink.h>
#include <net/sock.h>
#include <linux/nl802154.h>
#include <linux/export.h>
#include <net/af_ieee802154.h>
#include <net/ieee802154_netdev.h>
#include <net/cfg802154.h>
#include "ieee802154.h"
static int nla_put_hwaddr(struct sk_buff *msg, int type, __le64 hwaddr,
int padattr)
{
return nla_put_u64_64bit(msg, type, swab64((__force u64)hwaddr),
padattr);
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Alexander Aring | 16 | 41.03% | 1 | 25.00% |
Phoebe Buckheister | 10 | 25.64% | 1 | 25.00% |
Dmitry Baryshkov | 7 | 17.95% | 1 | 25.00% |
Nicolas Dichtel | 6 | 15.38% | 1 | 25.00% |
Total | 39 | 100.00% | 4 | 100.00% |
static __le64 nla_get_hwaddr(const struct nlattr *nla)
{
return ieee802154_devaddr_from_raw(nla_data(nla));
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Alexander Aring | 15 | 71.43% | 1 | 50.00% |
Dmitry Baryshkov | 6 | 28.57% | 1 | 50.00% |
Total | 21 | 100.00% | 2 | 100.00% |
static int nla_put_shortaddr(struct sk_buff *msg, int type, __le16 addr)
{
return nla_put_u16(msg, type, le16_to_cpu(addr));
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Dmitry Baryshkov | 16 | 53.33% | 1 | 50.00% |
Alexander Aring | 14 | 46.67% | 1 | 50.00% |
Total | 30 | 100.00% | 2 | 100.00% |
static __le16 nla_get_shortaddr(const struct nlattr *nla)
{
return cpu_to_le16(nla_get_u16(nla));
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Alexander Aring | 15 | 71.43% | 1 | 50.00% |
Dmitry Baryshkov | 6 | 28.57% | 1 | 50.00% |
Total | 21 | 100.00% | 2 | 100.00% |
static 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;
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;
return ieee802154_nl_mcast(msg, IEEE802154_COORD_MCGRP);
nla_put_failure:
nlmsg_free(msg);
return -ENOBUFS;
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Dmitry Baryshkov | 97 | 86.61% | 1 | 25.00% |
David S. Miller | 13 | 11.61% | 1 | 25.00% |
Alexander Aring | 1 | 0.89% | 1 | 25.00% |
Johannes Berg | 1 | 0.89% | 1 | 25.00% |
Total | 112 | 100.00% | 4 | 100.00% |
static int ieee802154_nl_fill_iface(struct sk_buff *msg, u32 portid,
u32 seq, int flags, struct net_device *dev)
{
void *hdr;
struct wpan_phy *phy;
struct ieee802154_mlme_ops *ops;
__le16 short_addr, pan_id;
pr_debug("%s\n", __func__);
hdr = genlmsg_put(msg, 0, seq, &nl802154_family, flags,
IEEE802154_LIST_IFACE);
if (!hdr)
goto out;
ops = ieee802154_mlme_ops(dev);
phy = dev->ieee802154_ptr->wpan_phy;
BUG_ON(!phy);
get_device(&phy->dev);
rtnl_lock();
short_addr = dev->ieee802154_ptr->short_addr;
pan_id = dev->ieee802154_ptr->pan_id;
rtnl_unlock();
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) ||
nla_put_shortaddr(msg, IEEE802154_ATTR_SHORT_ADDR, short_addr) ||
nla_put_shortaddr(msg, IEEE802154_ATTR_PAN_ID, pan_id))
goto nla_put_failure;
if (ops->get_mac_params) {
struct ieee802154_mac_params params;
rtnl_lock();
ops->get_mac_params(dev, ¶ms);
rtnl_unlock();
if (nla_put_s8(msg, IEEE802154_ATTR_TXPOWER,
params.transmit_power / 100) ||
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 / 100) ||
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;
}
wpan_phy_put(phy);
genlmsg_end(msg, hdr);
return 0;
nla_put_failure:
wpan_phy_put(phy);
genlmsg_cancel(msg, hdr);
out:
return -EMSGSIZE;
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Dmitry Baryshkov | 162 | 45.00% | 2 | 14.29% |
Phoebe Buckheister | 140 | 38.89% | 3 | 21.43% |
Alexander Aring | 39 | 10.83% | 6 | 42.86% |
David S. Miller | 15 | 4.17% | 1 | 7.14% |
Johannes Berg | 3 | 0.83% | 1 | 7.14% |
Eric W. Biedermann | 1 | 0.28% | 1 | 7.14% |
Total | 360 | 100.00% | 14 | 100.00% |
/* 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];
nla_strlcpy(name, info->attrs[IEEE802154_ATTR_DEV_NAME],
sizeof(name));
dev = dev_get_by_name(&init_net, name);
} else if (info->attrs[IEEE802154_ATTR_DEV_INDEX]) {
dev = dev_get_by_index(&init_net,
nla_get_u32(info->attrs[IEEE802154_ATTR_DEV_INDEX]));
} else {
return NULL;
}
if (!dev)
return NULL;
if (dev->type != ARPHRD_IEEE802154) {
dev_put(dev);
return NULL;
}
return dev;
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Dmitry Baryshkov | 125 | 96.90% | 1 | 50.00% |
Varka Bhadram | 4 | 3.10% | 1 | 50.00% |
Total | 129 | 100.00% | 2 | 100.00% |
int ieee802154_associate_req(struct sk_buff *skb, struct genl_info *info)
{
struct net_device *dev;
struct ieee802154_addr addr;
u8 page;
int ret = -EOPNOTSUPP;
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;
if (!ieee802154_mlme_ops(dev)->assoc_req)
goto out;
if (info->attrs[IEEE802154_ATTR_COORD_HW_ADDR]) {
addr.mode = IEEE802154_ADDR_LONG;
addr.extended_addr = nla_get_hwaddr(
info->attrs[IEEE802154_ATTR_COORD_HW_ADDR]);
} else {
addr.mode = IEEE802154_ADDR_SHORT;
addr.short_addr = nla_get_shortaddr(
info->attrs[IEEE802154_ATTR_COORD_SHORT_ADDR]);
}
addr.pan_id = nla_get_shortaddr(
info->attrs[IEEE802154_ATTR_COORD_PAN_ID]);
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]));
out:
dev_put(dev);
return ret;
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Dmitry Baryshkov | 226 | 90.04% | 1 | 33.33% |
Werner Almesberger | 16 | 6.37% | 1 | 33.33% |
Phoebe Buckheister | 9 | 3.59% | 1 | 33.33% |
Total | 251 | 100.00% | 3 | 100.00% |
int ieee802154_associate_resp(struct sk_buff *skb, struct genl_info *info)
{
struct net_device *dev;
struct ieee802154_addr addr;
int ret = -EOPNOTSUPP;
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;
if (!ieee802154_mlme_ops(dev)->assoc_resp)
goto out;
addr.mode = IEEE802154_ADDR_LONG;
addr.extended_addr = nla_get_hwaddr(
info->attrs[IEEE802154_ATTR_DEST_HW_ADDR]);
rtnl_lock();
addr.pan_id = dev->ieee802154_ptr->pan_id;
rtnl_unlock();
ret = ieee802154_mlme_ops(dev)->assoc_resp(dev, &addr,
nla_get_shortaddr(info->attrs[IEEE802154_ATTR_DEST_SHORT_ADDR]),
nla_get_u8(info->attrs[IEEE802154_ATTR_STATUS]));
out:
dev_put(dev);
return ret;
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Dmitry Baryshkov | 138 | 81.18% | 1 | 25.00% |
Werner Almesberger | 16 | 9.41% | 1 | 25.00% |
Alexander Aring | 9 | 5.29% | 1 | 25.00% |
Phoebe Buckheister | 7 | 4.12% | 1 | 25.00% |
Total | 170 | 100.00% | 4 | 100.00% |
int ieee802154_disassociate_req(struct sk_buff *skb, struct genl_info *info)
{
struct net_device *dev;
struct ieee802154_addr addr;
int ret = -EOPNOTSUPP;
if ((!info->attrs[IEEE802154_ATTR_DEST_HW_ADDR] &&
!info->attrs[IEEE802154_ATTR_DEST_SHORT_ADDR]) ||
!info->attrs[IEEE802154_ATTR_REASON])
return -EINVAL;
dev = ieee802154_nl_get_dev(info);
if (!dev)
return -ENODEV;
if (!ieee802154_mlme_ops(dev)->disassoc_req)
goto out;
if (info->attrs[IEEE802154_ATTR_DEST_HW_ADDR]) {
addr.mode = IEEE802154_ADDR_LONG;
addr.extended_addr = nla_get_hwaddr(
info->attrs[IEEE802154_ATTR_DEST_HW_ADDR]);
} else {
addr.mode = IEEE802154_ADDR_SHORT;
addr.short_addr = nla_get_shortaddr(
info->attrs[IEEE802154_ATTR_DEST_SHORT_ADDR]);
}
rtnl_lock();
addr.pan_id = dev->ieee802154_ptr->pan_id;
rtnl_unlock();
ret = ieee802154_mlme_ops(dev)->disassoc_req(dev, &addr,
nla_get_u8(info->attrs[IEEE802154_ATTR_REASON]));
out:
dev_put(dev);
return ret;
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Dmitry Baryshkov | 163 | 83.16% | 1 | 25.00% |
Werner Almesberger | 16 | 8.16% | 1 | 25.00% |
Alexander Aring | 9 | 4.59% | 1 | 25.00% |
Phoebe Buckheister | 8 | 4.08% | 1 | 25.00% |
Total | 196 | 100.00% | 4 | 100.00% |
/* PANid, channel, beacon_order = 15, superframe_order = 15,
* PAN_coordinator, battery_life_extension = 0,
* coord_realignment = 0, security_enable = 0
*/
int ieee802154_start_req(struct sk_buff *skb, struct genl_info *info)
{
struct net_device *dev;
struct ieee802154_addr addr;
u8 channel, bcn_ord, sf_ord;
u8 page;
int pan_coord, blx, coord_realign;
int ret = -EBUSY;
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;
if (netif_running(dev))
goto out;
if (!ieee802154_mlme_ops(dev)->start_req) {
ret = -EOPNOTSUPP;
goto out;
}
addr.mode = IEEE802154_ADDR_SHORT;
addr.short_addr = nla_get_shortaddr(
info->attrs[IEEE802154_ATTR_COORD_SHORT_ADDR]);
addr.pan_id = nla_get_shortaddr(
info->attrs[IEEE802154_ATTR_COORD_PAN_ID]);
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;
if (addr.short_addr == cpu_to_le16(IEEE802154_ADDR_BROADCAST)) {
ieee802154_nl_start_confirm(dev, IEEE802154_NO_SHORT_ADDRESS);
dev_put(dev);
return -EINVAL;
}
rtnl_lock();
ret = ieee802154_mlme_ops(dev)->start_req(dev, &addr, channel, page,
bcn_ord, sf_ord, pan_coord, blx, coord_realign);
rtnl_unlock();
/* FIXME: add validation for unused parameters to be sane
* for SoftMAC
*/
ieee802154_nl_start_confirm(dev, IEEE802154_SUCCESS);
out:
dev_put(dev);
return ret;
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Dmitry Baryshkov | 321 | 85.15% | 1 | 16.67% |
Alexander Aring | 32 | 8.49% | 3 | 50.00% |
Werner Almesberger | 17 | 4.51% | 1 | 16.67% |
Phoebe Buckheister | 7 | 1.86% | 1 | 16.67% |
Total | 377 | 100.00% | 6 | 100.00% |
int ieee802154_scan_req(struct sk_buff *skb, struct genl_info *info)
{
struct net_device *dev;
int ret = -EOPNOTSUPP;
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;
if (!ieee802154_mlme_ops(dev)->scan_req)
goto out;
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;
ret = ieee802154_mlme_ops(dev)->scan_req(dev, type, channels,
page, duration);
out:
dev_put(dev);
return ret;
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Dmitry Baryshkov | 171 | 90.48% | 1 | 50.00% |
Werner Almesberger | 18 | 9.52% | 1 | 50.00% |
Total | 189 | 100.00% | 2 | 100.00% |
int ieee802154_list_iface(struct sk_buff *skb, struct genl_info *info)
{
/* Request for interface name, index, type, IEEE address,
* PAN Id, short address
*/
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;
msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
if (!msg)
goto out_dev;
rc = ieee802154_nl_fill_iface(msg, info->snd_portid, info->snd_seq,
0, dev);
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;
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Dmitry Baryshkov | 129 | 97.73% | 1 | 25.00% |
Varka Bhadram | 1 | 0.76% | 1 | 25.00% |
Thomas Graf | 1 | 0.76% | 1 | 25.00% |
Eric W. Biedermann | 1 | 0.76% | 1 | 25.00% |
Total | 132 | 100.00% | 4 | 100.00% |
int ieee802154_dump_iface(struct sk_buff *skb, struct netlink_callback *cb)
{
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;
if (ieee802154_nl_fill_iface(skb, NETLINK_CB(cb->skb).portid,
cb->nlh->nlmsg_seq,
NLM_F_MULTI, dev) < 0)
break;
cont:
idx++;
}
cb->args[0] = idx;
return skb->len;
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Dmitry Baryshkov | 126 | 99.21% | 1 | 50.00% |
Eric W. Biedermann | 1 | 0.79% | 1 | 50.00% |
Total | 127 | 100.00% | 2 | 100.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 = dev->ieee802154_ptr->wpan_phy;
get_device(&phy->dev);
rtnl_lock();
ops->get_mac_params(dev, ¶ms);
if (info->attrs[IEEE802154_ATTR_TXPOWER])
params.transmit_power = nla_get_s8(info->attrs[IEEE802154_ATTR_TXPOWER]) * 100;
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]) * 100;
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);
rtnl_unlock();
wpan_phy_put(phy);
dev_put(dev);
return 0;
out:
dev_put(dev);
return rc;
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Phoebe Buckheister | 406 | 94.64% | 1 | 14.29% |
Alexander Aring | 23 | 5.36% | 6 | 85.71% |
Total | 429 | 100.00% | 7 | 100.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]);
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;
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Phoebe Buckheister | 315 | 100.00% | 1 | 100.00% |
Total | 315 | 100.00% | 1 | 100.00% |
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) {