Commit de7de576 authored by David S. Miller's avatar David S. Miller

Merge branch 'ieee802154-for-davem-2018-08-06' of...

Merge branch 'ieee802154-for-davem-2018-08-06' of git://git.kernel.org/pub/scm/linux/kernel/git/sschmidt/wpan-next

Stefan Schmidt says:

====================
pull-request: ieee802154-next 2018-08-06

An update from ieee802154 for *net-next*

Romuald added a socket option to get the LQI value of the received datagram.
Alexander added a new hardware simulation driver modelled after hwsim of the
wireless people. It allows runtime configuration for new nodes and edges over a
netlink interface (a config utlity is making its way into wpan-tools).
We also have three fixes in here. One from Colin which is more of a cleanup and
two from Alex fixing tailroom and single frame space problems.
I would normally put the last two into my fixes tree, but given we are already
in -rc8 I simply put them here and added a cc: stable to them.
====================
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parents 70837ffe be10d5d1
......@@ -115,3 +115,14 @@ config IEEE802154_MCR20A
This driver can also be built as a module. To do so, say M here.
the module will be called 'mcr20a'.
config IEEE802154_HWSIM
depends on IEEE802154_DRIVERS && MAC802154
tristate "Simulated radio testing tool for mac802154"
---help---
This driver is a developer testing tool that can be used to test
IEEE 802.15.4 networking stack (mac802154) functionality. This is not
needed for normal wpan usage and is only for testing.
This driver can also be built as a module. To do so say M here.
The module will be called 'mac802154_hwsim'.
......@@ -7,3 +7,4 @@ obj-$(CONFIG_IEEE802154_ATUSB) += atusb.o
obj-$(CONFIG_IEEE802154_ADF7242) += adf7242.o
obj-$(CONFIG_IEEE802154_CA8210) += ca8210.o
obj-$(CONFIG_IEEE802154_MCR20A) += mcr20a.o
obj-$(CONFIG_IEEE802154_HWSIM) += mac802154_hwsim.o
......@@ -254,6 +254,9 @@ static __init int fakelb_init_module(void)
{
ieee802154fake_dev = platform_device_register_simple(
"ieee802154fakelb", -1, NULL, 0);
pr_warn("fakelb driver is marked as deprecated, please use mac802154_hwsim!\n");
return platform_driver_register(&ieee802154fake_driver);
}
......
This diff is collapsed.
#ifndef __MAC802154_HWSIM_H
#define __MAC802154_HWSIM_H
/* mac802154 hwsim netlink commands
*
* @MAC802154_HWSIM_CMD_UNSPEC: unspecified command to catch error
* @MAC802154_HWSIM_CMD_GET_RADIO: fetch information about existing radios
* @MAC802154_HWSIM_CMD_SET_RADIO: change radio parameters during runtime
* @MAC802154_HWSIM_CMD_NEW_RADIO: create a new radio with the given parameters
* returns the radio ID (>= 0) or negative on errors, if successful
* then multicast the result
* @MAC802154_HWSIM_CMD_DEL_RADIO: destroy a radio, reply is multicasted
* @MAC802154_HWSIM_CMD_GET_EDGE: fetch information about existing edges
* @MAC802154_HWSIM_CMD_SET_EDGE: change edge parameters during runtime
* @MAC802154_HWSIM_CMD_DEL_EDGE: delete edges between radios
* @MAC802154_HWSIM_CMD_NEW_EDGE: create a new edge between two radios
* @__MAC802154_HWSIM_CMD_MAX: enum limit
*/
enum {
MAC802154_HWSIM_CMD_UNSPEC,
MAC802154_HWSIM_CMD_GET_RADIO,
MAC802154_HWSIM_CMD_SET_RADIO,
MAC802154_HWSIM_CMD_NEW_RADIO,
MAC802154_HWSIM_CMD_DEL_RADIO,
MAC802154_HWSIM_CMD_GET_EDGE,
MAC802154_HWSIM_CMD_SET_EDGE,
MAC802154_HWSIM_CMD_DEL_EDGE,
MAC802154_HWSIM_CMD_NEW_EDGE,
__MAC802154_HWSIM_CMD_MAX,
};
#define MAC802154_HWSIM_CMD_MAX (__MAC802154_HWSIM_MAX - 1)
/* mac802154 hwsim netlink attributes
*
* @MAC802154_HWSIM_ATTR_UNSPEC: unspecified attribute to catch error
* @MAC802154_HWSIM_ATTR_RADIO_ID: u32 attribute to identify the radio
* @MAC802154_HWSIM_ATTR_EDGE: nested attribute of edges
* @MAC802154_HWSIM_ATTR_EDGES: list if nested attributes which contains the
* edge information according the radio id
* @__MAC802154_HWSIM_ATTR_MAX: enum limit
*/
enum {
MAC802154_HWSIM_ATTR_UNSPEC,
MAC802154_HWSIM_ATTR_RADIO_ID,
MAC802154_HWSIM_ATTR_RADIO_EDGE,
MAC802154_HWSIM_ATTR_RADIO_EDGES,
__MAC802154_HWSIM_ATTR_MAX,
};
#define MAC802154_HWSIM_ATTR_MAX (__MAC802154_HWSIM_ATTR_MAX - 1)
/* mac802154 hwsim edge netlink attributes
*
* @MAC802154_HWSIM_EDGE_ATTR_UNSPEC: unspecified attribute to catch error
* @MAC802154_HWSIM_EDGE_ATTR_ENDPOINT_ID: radio id where the edge points to
* @MAC802154_HWSIM_EDGE_ATTR_LQI: LQI value which the endpoint radio will
* receive for this edge
* @__MAC802154_HWSIM_ATTR_MAX: enum limit
*/
enum {
MAC802154_HWSIM_EDGE_ATTR_UNSPEC,
MAC802154_HWSIM_EDGE_ATTR_ENDPOINT_ID,
MAC802154_HWSIM_EDGE_ATTR_LQI,
__MAC802154_HWSIM_EDGE_ATTR_MAX,
};
#define MAC802154_HWSIM_EDGE_ATTR_MAX (__MAC802154_HWSIM_EDGE_ATTR_MAX - 1)
#endif /* __MAC802154_HWSIM_H */
......@@ -56,6 +56,7 @@ struct sockaddr_ieee802154 {
#define WPAN_WANTACK 0
#define WPAN_SECURITY 1
#define WPAN_SECURITY_LEVEL 2
#define WPAN_WANTLQI 3
#define WPAN_SECURITY_DEFAULT 0
#define WPAN_SECURITY_OFF 1
......
......@@ -40,9 +40,6 @@ static int lowpan_frag_reasm(struct lowpan_frag_queue *fq,
static void lowpan_frag_init(struct inet_frag_queue *q, const void *a)
{
const struct frag_lowpan_compare_key *key = a;
struct lowpan_frag_queue *fq;
fq = container_of(q, struct lowpan_frag_queue, q);
BUILD_BUG_ON(sizeof(*key) > sizeof(q->key));
memcpy(&q->key, key, sizeof(*key));
......@@ -52,10 +49,8 @@ static void lowpan_frag_expire(struct timer_list *t)
{
struct inet_frag_queue *frag = from_timer(frag, t, timer);
struct frag_queue *fq;
struct net *net;
fq = container_of(frag, struct frag_queue, q);
net = container_of(fq->q.net, struct net, ieee802154_lowpan.frags);
spin_lock(&fq->q.lock);
......
......@@ -265,9 +265,24 @@ netdev_tx_t lowpan_xmit(struct sk_buff *skb, struct net_device *ldev)
/* We must take a copy of the skb before we modify/replace the ipv6
* header as the header could be used elsewhere
*/
if (unlikely(skb_headroom(skb) < ldev->needed_headroom ||
skb_tailroom(skb) < ldev->needed_tailroom)) {
struct sk_buff *nskb;
nskb = skb_copy_expand(skb, ldev->needed_headroom,
ldev->needed_tailroom, GFP_ATOMIC);
if (likely(nskb)) {
consume_skb(skb);
skb = nskb;
} else {
kfree_skb(skb);
return NET_XMIT_DROP;
}
} else {
skb = skb_unshare(skb, GFP_ATOMIC);
if (!skb)
return NET_XMIT_DROP;
}
ret = lowpan_header(skb, ldev, &dgram_size, &dgram_offset);
if (ret < 0) {
......
......@@ -25,6 +25,7 @@
#include <linux/termios.h> /* For TIOCOUTQ/INQ */
#include <linux/list.h>
#include <linux/slab.h>
#include <linux/socket.h>
#include <net/datalink.h>
#include <net/psnap.h>
#include <net/sock.h>
......@@ -452,6 +453,7 @@ struct dgram_sock {
unsigned int bound:1;
unsigned int connected:1;
unsigned int want_ack:1;
unsigned int want_lqi:1;
unsigned int secen:1;
unsigned int secen_override:1;
unsigned int seclevel:3;
......@@ -486,6 +488,7 @@ static int dgram_init(struct sock *sk)
struct dgram_sock *ro = dgram_sk(sk);
ro->want_ack = 1;
ro->want_lqi = 0;
return 0;
}
......@@ -713,6 +716,7 @@ static int dgram_recvmsg(struct sock *sk, struct msghdr *msg, size_t len,
size_t copied = 0;
int err = -EOPNOTSUPP;
struct sk_buff *skb;
struct dgram_sock *ro = dgram_sk(sk);
DECLARE_SOCKADDR(struct sockaddr_ieee802154 *, saddr, msg->msg_name);
skb = skb_recv_datagram(sk, flags, noblock, &err);
......@@ -744,6 +748,13 @@ static int dgram_recvmsg(struct sock *sk, struct msghdr *msg, size_t len,
*addr_len = sizeof(*saddr);
}
if (ro->want_lqi) {
err = put_cmsg(msg, SOL_IEEE802154, WPAN_WANTLQI,
sizeof(uint8_t), &(mac_cb(skb)->lqi));
if (err)
goto done;
}
if (flags & MSG_TRUNC)
copied = skb->len;
done:
......@@ -847,6 +858,9 @@ static int dgram_getsockopt(struct sock *sk, int level, int optname,
case WPAN_WANTACK:
val = ro->want_ack;
break;
case WPAN_WANTLQI:
val = ro->want_lqi;
break;
case WPAN_SECURITY:
if (!ro->secen_override)
val = WPAN_SECURITY_DEFAULT;
......@@ -892,6 +906,9 @@ static int dgram_setsockopt(struct sock *sk, int level, int optname,
case WPAN_WANTACK:
ro->want_ack = !!val;
break;
case WPAN_WANTLQI:
ro->want_lqi = !!val;
break;
case WPAN_SECURITY:
if (!ns_capable(net->user_ns, CAP_NET_ADMIN) &&
!ns_capable(net->user_ns, CAP_NET_RAW)) {
......
......@@ -63,8 +63,21 @@ ieee802154_tx(struct ieee802154_local *local, struct sk_buff *skb)
int ret;
if (!(local->hw.flags & IEEE802154_HW_TX_OMIT_CKSUM)) {
u16 crc = crc_ccitt(0, skb->data, skb->len);
struct sk_buff *nskb;
u16 crc;
if (unlikely(skb_tailroom(skb) < IEEE802154_FCS_LEN)) {
nskb = skb_copy_expand(skb, 0, IEEE802154_FCS_LEN,
GFP_ATOMIC);
if (likely(nskb)) {
consume_skb(skb);
skb = nskb;
} else {
goto err_tx;
}
}
crc = crc_ccitt(0, skb->data, skb->len);
put_unaligned_le16(crc, skb_put(skb, 2));
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment