Skip to content

Commit

Permalink
6lowpan: add generic 6lowpan netdev private data
Browse files Browse the repository at this point in the history
This patch introduced the 6lowpan netdev private data struct. We name it
lowpan_priv and it's placed at the beginning of netdev private data. All
lowpan interfaces should allocate this room at first of netdev private
data. 6LoWPAN LL private data can be allocate by additional netdev private
data, e.g. dev->priv_size should be "sizeof(struct lowpan_priv) +
sizeof(LL_LOWPAN_PRIVATE_DATA)".

Signed-off-by: Alexander Aring <alex.aring@gmail.com>
Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
  • Loading branch information
Alexander Aring authored and Marcel Holtmann committed Aug 11, 2015
1 parent a42bbba commit b72f6f5
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 6 deletions.
23 changes: 23 additions & 0 deletions include/net/6lowpan.h
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,27 @@
#define LOWPAN_NHC_UDP_CS_P_11 0xF3 /* source & dest = 0xF0B + 4bit inline */
#define LOWPAN_NHC_UDP_CS_C 0x04 /* checksum elided */

#define LOWPAN_PRIV_SIZE(llpriv_size) \
(sizeof(struct lowpan_priv) + llpriv_size)

enum lowpan_lltypes {
LOWPAN_LLTYPE_BTLE,
LOWPAN_LLTYPE_IEEE802154,
};

struct lowpan_priv {
enum lowpan_lltypes lltype;

/* must be last */
u8 priv[0] __aligned(sizeof(void *));
};

static inline
struct lowpan_priv *lowpan_priv(const struct net_device *dev)
{
return netdev_priv(dev);
}

#ifdef DEBUG
/* print data in line */
static inline void raw_dump_inline(const char *caller, char *msg,
Expand Down Expand Up @@ -372,6 +393,8 @@ lowpan_uncompress_size(const struct sk_buff *skb, u16 *dgram_offset)
return skb->len + uncomp_header - ret;
}

void lowpan_netdev_setup(struct net_device *dev, enum lowpan_lltypes lltype);

int
lowpan_header_decompress(struct sk_buff *skb, struct net_device *dev,
const u8 *saddr, const u8 saddr_type,
Expand Down
2 changes: 1 addition & 1 deletion net/6lowpan/Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
obj-$(CONFIG_6LOWPAN) += 6lowpan.o

6lowpan-y := iphc.o nhc.o
6lowpan-y := core.o iphc.o nhc.o

#rfc6282 nhcs
obj-$(CONFIG_6LOWPAN_NHC_DEST) += nhc_dest.o
Expand Down
20 changes: 20 additions & 0 deletions net/6lowpan/core.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/* 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.
*
* Authors:
* (C) 2015 Pengutronix, Alexander Aring <aar@pengutronix.de>
*/

#include <net/6lowpan.h>

void lowpan_netdev_setup(struct net_device *dev, enum lowpan_lltypes lltype)
{
lowpan_priv(dev)->lltype = lltype;
}
EXPORT_SYMBOL(lowpan_netdev_setup);
9 changes: 6 additions & 3 deletions net/bluetooth/6lowpan.c
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ struct lowpan_dev {

static inline struct lowpan_dev *lowpan_dev(const struct net_device *netdev)
{
return netdev_priv(netdev);
return (struct lowpan_dev *)lowpan_priv(netdev)->priv;
}

static inline void peer_add(struct lowpan_dev *dev, struct lowpan_peer *peer)
Expand Down Expand Up @@ -848,8 +848,9 @@ static int setup_netdev(struct l2cap_chan *chan, struct lowpan_dev **dev)
struct net_device *netdev;
int err = 0;

netdev = alloc_netdev(sizeof(struct lowpan_dev), IFACE_NAME_TEMPLATE,
NET_NAME_UNKNOWN, netdev_setup);
netdev = alloc_netdev(LOWPAN_PRIV_SIZE(sizeof(struct lowpan_dev)),
IFACE_NAME_TEMPLATE, NET_NAME_UNKNOWN,
netdev_setup);
if (!netdev)
return -ENOMEM;

Expand All @@ -869,6 +870,8 @@ static int setup_netdev(struct l2cap_chan *chan, struct lowpan_dev **dev)
list_add_rcu(&(*dev)->list, &bt_6lowpan_devices);
spin_unlock(&devices_lock);

lowpan_netdev_setup(netdev, LOWPAN_LLTYPE_BTLE);

err = register_netdev(netdev);
if (err < 0) {
BT_INFO("register_netdev failed %d", err);
Expand Down
3 changes: 2 additions & 1 deletion net/ieee802154/6lowpan/6lowpan_i.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

#include <net/ieee802154_netdev.h>
#include <net/inet_frag.h>
#include <net/6lowpan.h>

struct lowpan_create_arg {
u16 tag;
Expand Down Expand Up @@ -46,7 +47,7 @@ struct lowpan_dev_info {
static inline struct
lowpan_dev_info *lowpan_dev_info(const struct net_device *dev)
{
return netdev_priv(dev);
return (struct lowpan_dev_info *)lowpan_priv(dev)->priv;
}

int lowpan_frag_rcv(struct sk_buff *skb, const u8 frag_type);
Expand Down
4 changes: 3 additions & 1 deletion net/ieee802154/6lowpan/core.c
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,8 @@ static int lowpan_newlink(struct net *src_net, struct net_device *dev,
/* Set the lowpan hardware address to the wpan hardware address. */
memcpy(dev->dev_addr, real_dev->dev_addr, IEEE802154_ADDR_LEN);

lowpan_netdev_setup(dev, LOWPAN_LLTYPE_IEEE802154);

ret = register_netdevice(dev);
if (ret >= 0) {
real_dev->ieee802154_ptr->lowpan_dev = dev;
Expand All @@ -162,7 +164,7 @@ static void lowpan_dellink(struct net_device *dev, struct list_head *head)

static struct rtnl_link_ops lowpan_link_ops __read_mostly = {
.kind = "lowpan",
.priv_size = sizeof(struct lowpan_dev_info),
.priv_size = LOWPAN_PRIV_SIZE(sizeof(struct lowpan_dev_info)),
.setup = lowpan_setup,
.newlink = lowpan_newlink,
.dellink = lowpan_dellink,
Expand Down

0 comments on commit b72f6f5

Please sign in to comment.