All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH bluetooth-next 0/5] ieee802154: structural directory changes
@ 2015-01-04 16:10 Alexander Aring
  2015-01-04 16:10 ` [PATCH bluetooth-next 1/5] ieee802154: create 6lowpan sub-directory Alexander Aring
                   ` (5 more replies)
  0 siblings, 6 replies; 10+ messages in thread
From: Alexander Aring @ 2015-01-04 16:10 UTC (permalink / raw)
  To: linux-wpan; +Cc: kernel, Alexander Aring

This patch series contains patches to create a 6lowpan sub-directory inside
ieee802154. At least we handle receive and transmit functionality in separate
files.

This series based on previous the previous series:

"ieee802154: 6lowpan: separate receive/transmit functionality" and
"ieee802154: structural directory changes".

I changed PATCH 1/5 "ieee802154: create 6lowpan sub-directory" only to source
the "net/ieee802154/6lowpan/Kconfig" file. Furthermore there will more options
like debugfs etc... available for ieee802154 6lowpan functionality.

- Alex

Alexander Aring (5):
  ieee802154: create 6lowpan sub-directory
  ieee802154: 6lowpan: rename internal header
  ieee802154: 6lowpan: move receive functionality
  ieee802154: 6lowpan: move transmit functionality
  ieee802154: 6lowpan: rename to core

 net/ieee802154/6lowpan/6lowpan_i.h        |  72 +++
 net/ieee802154/6lowpan/Kconfig            |   5 +
 net/ieee802154/6lowpan/Makefile           |   3 +
 net/ieee802154/6lowpan/core.c             | 304 +++++++++++++
 net/ieee802154/{ => 6lowpan}/reassembly.c |   2 +-
 net/ieee802154/6lowpan/rx.c               | 171 +++++++
 net/ieee802154/6lowpan/tx.c               | 271 +++++++++++
 net/ieee802154/6lowpan_rtnl.c             | 729 ------------------------------
 net/ieee802154/Kconfig                    |   6 +-
 net/ieee802154/Makefile                   |   3 +-
 net/ieee802154/reassembly.h               |  41 --
 11 files changed, 829 insertions(+), 778 deletions(-)
 create mode 100644 net/ieee802154/6lowpan/6lowpan_i.h
 create mode 100644 net/ieee802154/6lowpan/Kconfig
 create mode 100644 net/ieee802154/6lowpan/Makefile
 create mode 100644 net/ieee802154/6lowpan/core.c
 rename net/ieee802154/{ => 6lowpan}/reassembly.c (99%)
 create mode 100644 net/ieee802154/6lowpan/rx.c
 create mode 100644 net/ieee802154/6lowpan/tx.c
 delete mode 100644 net/ieee802154/6lowpan_rtnl.c
 delete mode 100644 net/ieee802154/reassembly.h

-- 
2.2.1


^ permalink raw reply	[flat|nested] 10+ messages in thread

* [PATCH bluetooth-next 1/5] ieee802154: create 6lowpan sub-directory
  2015-01-04 16:10 [PATCH bluetooth-next 0/5] ieee802154: structural directory changes Alexander Aring
@ 2015-01-04 16:10 ` Alexander Aring
  2015-01-04 16:10 ` [PATCH bluetooth-next 2/5] ieee802154: 6lowpan: rename internal header Alexander Aring
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 10+ messages in thread
From: Alexander Aring @ 2015-01-04 16:10 UTC (permalink / raw)
  To: linux-wpan; +Cc: kernel, Alexander Aring

This patch creates an 6lowpan sub-directory inside ieee802154.
Additional we move all ieee802154 6lowpan relevant files into
this sub-directory instead of placing the 6lowpan related files
inside ieee802154.

Signed-off-by: Alexander Aring <alex.aring@gmail.com>
---
 net/ieee802154/{ => 6lowpan}/6lowpan_rtnl.c | 0
 net/ieee802154/6lowpan/Kconfig              | 5 +++++
 net/ieee802154/6lowpan/Makefile             | 3 +++
 net/ieee802154/{ => 6lowpan}/reassembly.c   | 0
 net/ieee802154/{ => 6lowpan}/reassembly.h   | 0
 net/ieee802154/Kconfig                      | 6 +-----
 net/ieee802154/Makefile                     | 3 +--
 7 files changed, 10 insertions(+), 7 deletions(-)
 rename net/ieee802154/{ => 6lowpan}/6lowpan_rtnl.c (100%)
 create mode 100644 net/ieee802154/6lowpan/Kconfig
 create mode 100644 net/ieee802154/6lowpan/Makefile
 rename net/ieee802154/{ => 6lowpan}/reassembly.c (100%)
 rename net/ieee802154/{ => 6lowpan}/reassembly.h (100%)

diff --git a/net/ieee802154/6lowpan_rtnl.c b/net/ieee802154/6lowpan/6lowpan_rtnl.c
similarity index 100%
rename from net/ieee802154/6lowpan_rtnl.c
rename to net/ieee802154/6lowpan/6lowpan_rtnl.c
diff --git a/net/ieee802154/6lowpan/Kconfig b/net/ieee802154/6lowpan/Kconfig
new file mode 100644
index 0000000..d24f985
--- /dev/null
+++ b/net/ieee802154/6lowpan/Kconfig
@@ -0,0 +1,5 @@
+config IEEE802154_6LOWPAN
+	tristate "6lowpan support over IEEE 802.15.4"
+	depends on 6LOWPAN
+	---help---
+	  IPv6 compression over IEEE 802.15.4.
diff --git a/net/ieee802154/6lowpan/Makefile b/net/ieee802154/6lowpan/Makefile
new file mode 100644
index 0000000..936959b
--- /dev/null
+++ b/net/ieee802154/6lowpan/Makefile
@@ -0,0 +1,3 @@
+obj-y += ieee802154_6lowpan.o
+
+ieee802154_6lowpan-y := 6lowpan_rtnl.o reassembly.o
diff --git a/net/ieee802154/reassembly.c b/net/ieee802154/6lowpan/reassembly.c
similarity index 100%
rename from net/ieee802154/reassembly.c
rename to net/ieee802154/6lowpan/reassembly.c
diff --git a/net/ieee802154/reassembly.h b/net/ieee802154/6lowpan/reassembly.h
similarity index 100%
rename from net/ieee802154/reassembly.h
rename to net/ieee802154/6lowpan/reassembly.h
diff --git a/net/ieee802154/Kconfig b/net/ieee802154/Kconfig
index 9ea0af4..1370d5b 100644
--- a/net/ieee802154/Kconfig
+++ b/net/ieee802154/Kconfig
@@ -20,10 +20,6 @@ config IEEE802154_SOCKET
 	  for 802.15.4 dataframes. Also RAW socket interface to build MAC
 	  header from userspace.
 
-config IEEE802154_6LOWPAN
-	tristate "6lowpan support over IEEE 802.15.4"
-	depends on 6LOWPAN
-	---help---
-	  IPv6 compression over IEEE 802.15.4.
+source "net/ieee802154/6lowpan/Kconfig"
 
 endif
diff --git a/net/ieee802154/Makefile b/net/ieee802154/Makefile
index 88bde78..3653397 100644
--- a/net/ieee802154/Makefile
+++ b/net/ieee802154/Makefile
@@ -1,8 +1,7 @@
 obj-$(CONFIG_IEEE802154) += ieee802154.o
 obj-$(CONFIG_IEEE802154_SOCKET) += ieee802154_socket.o
-obj-$(CONFIG_IEEE802154_6LOWPAN) += ieee802154_6lowpan.o
+obj-$(CONFIG_IEEE802154_6LOWPAN) += 6lowpan/
 
-ieee802154_6lowpan-y := 6lowpan_rtnl.o reassembly.o
 ieee802154-y := netlink.o nl-mac.o nl-phy.o nl_policy.o core.o \
                 header_ops.o sysfs.o nl802154.o
 ieee802154_socket-y := socket.o
-- 
2.2.1


^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH bluetooth-next 2/5] ieee802154: 6lowpan: rename internal header
  2015-01-04 16:10 [PATCH bluetooth-next 0/5] ieee802154: structural directory changes Alexander Aring
  2015-01-04 16:10 ` [PATCH bluetooth-next 1/5] ieee802154: create 6lowpan sub-directory Alexander Aring
@ 2015-01-04 16:10 ` Alexander Aring
  2015-01-04 16:10 ` [PATCH bluetooth-next 3/5] ieee802154: 6lowpan: move receive functionality Alexander Aring
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 10+ messages in thread
From: Alexander Aring @ 2015-01-04 16:10 UTC (permalink / raw)
  To: linux-wpan; +Cc: kernel, Alexander Aring

This patch renames the internal header for af802154. This naming
convention is like ieee802154_i.h in mac802154 and avoids naming
confusing with the global af802154 header. Furthermore this header
contains more ieee802154 specific definitions.

Signed-off-by: Alexander Aring <alex.aring@gmail.com>
---
 net/ieee802154/6lowpan/{reassembly.h => 6lowpan_i.h} | 6 +++---
 net/ieee802154/6lowpan/6lowpan_rtnl.c                | 2 +-
 net/ieee802154/6lowpan/reassembly.c                  | 2 +-
 3 files changed, 5 insertions(+), 5 deletions(-)
 rename net/ieee802154/6lowpan/{reassembly.h => 6lowpan_i.h} (85%)

diff --git a/net/ieee802154/6lowpan/reassembly.h b/net/ieee802154/6lowpan/6lowpan_i.h
similarity index 85%
rename from net/ieee802154/6lowpan/reassembly.h
rename to net/ieee802154/6lowpan/6lowpan_i.h
index 836b16f..edbe803 100644
--- a/net/ieee802154/6lowpan/reassembly.h
+++ b/net/ieee802154/6lowpan/6lowpan_i.h
@@ -1,5 +1,5 @@
-#ifndef __IEEE802154_6LOWPAN_REASSEMBLY_H__
-#define __IEEE802154_6LOWPAN_REASSEMBLY_H__
+#ifndef __IEEE802154_6LOWPAN_I_H__
+#define __IEEE802154_6LOWPAN_I_H__
 
 #include <net/inet_frag.h>
 
@@ -38,4 +38,4 @@ int lowpan_frag_rcv(struct sk_buff *skb, const u8 frag_type);
 void lowpan_net_frag_exit(void);
 int lowpan_net_frag_init(void);
 
-#endif /* __IEEE802154_6LOWPAN_REASSEMBLY_H__ */
+#endif /* __IEEE802154_6LOWPAN_I_H__ */
diff --git a/net/ieee802154/6lowpan/6lowpan_rtnl.c b/net/ieee802154/6lowpan/6lowpan_rtnl.c
index 27eaa65..1918c43 100644
--- a/net/ieee802154/6lowpan/6lowpan_rtnl.c
+++ b/net/ieee802154/6lowpan/6lowpan_rtnl.c
@@ -55,7 +55,7 @@
 #include <net/6lowpan.h>
 #include <net/ipv6.h>
 
-#include "reassembly.h"
+#include "6lowpan_i.h"
 
 static LIST_HEAD(lowpan_devices);
 static int lowpan_open_count;
diff --git a/net/ieee802154/6lowpan/reassembly.c b/net/ieee802154/6lowpan/reassembly.c
index 9d980ed..f46e4d1 100644
--- a/net/ieee802154/6lowpan/reassembly.c
+++ b/net/ieee802154/6lowpan/reassembly.c
@@ -28,7 +28,7 @@
 #include <net/ipv6.h>
 #include <net/inet_frag.h>
 
-#include "reassembly.h"
+#include "6lowpan_i.h"
 
 static const char lowpan_frags_cache_name[] = "lowpan-frags";
 
-- 
2.2.1


^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH bluetooth-next 3/5] ieee802154: 6lowpan: move receive functionality
  2015-01-04 16:10 [PATCH bluetooth-next 0/5] ieee802154: structural directory changes Alexander Aring
  2015-01-04 16:10 ` [PATCH bluetooth-next 1/5] ieee802154: create 6lowpan sub-directory Alexander Aring
  2015-01-04 16:10 ` [PATCH bluetooth-next 2/5] ieee802154: 6lowpan: rename internal header Alexander Aring
@ 2015-01-04 16:10 ` Alexander Aring
  2015-01-04 16:10 ` [PATCH bluetooth-next 4/5] ieee802154: 6lowpan: move transmit functionality Alexander Aring
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 10+ messages in thread
From: Alexander Aring @ 2015-01-04 16:10 UTC (permalink / raw)
  To: linux-wpan; +Cc: kernel, Alexander Aring

This patch moves all relevant receive functionality into a separate rx.c
file. We can simple separate this functionality like we did it in mac802154.

Signed-off-by: Alexander Aring <alex.aring@gmail.com>
---
 net/ieee802154/6lowpan/6lowpan_i.h    |  25 +++++
 net/ieee802154/6lowpan/6lowpan_rtnl.c | 169 +--------------------------------
 net/ieee802154/6lowpan/Makefile       |   2 +-
 net/ieee802154/6lowpan/rx.c           | 171 ++++++++++++++++++++++++++++++++++
 4 files changed, 200 insertions(+), 167 deletions(-)
 create mode 100644 net/ieee802154/6lowpan/rx.c

diff --git a/net/ieee802154/6lowpan/6lowpan_i.h b/net/ieee802154/6lowpan/6lowpan_i.h
index edbe803..29ec61b 100644
--- a/net/ieee802154/6lowpan/6lowpan_i.h
+++ b/net/ieee802154/6lowpan/6lowpan_i.h
@@ -1,6 +1,8 @@
 #ifndef __IEEE802154_6LOWPAN_I_H__
 #define __IEEE802154_6LOWPAN_I_H__
 
+#include <linux/list.h>
+
 #include <net/inet_frag.h>
 
 struct lowpan_create_arg {
@@ -34,8 +36,31 @@ static inline u32 ieee802154_addr_hash(const struct ieee802154_addr *a)
 	}
 }
 
+struct lowpan_dev_record {
+	struct net_device *ldev;
+	struct list_head list;
+};
+
+/* private device info */
+struct lowpan_dev_info {
+	struct net_device	*real_dev; /* real WPAN device ptr */
+	struct mutex		dev_list_mtx; /* mutex for list ops */
+	u16			fragment_tag;
+};
+
+static inline struct
+lowpan_dev_info *lowpan_dev_info(const struct net_device *dev)
+{
+	return netdev_priv(dev);
+}
+
+extern struct list_head lowpan_devices;
+
 int lowpan_frag_rcv(struct sk_buff *skb, const u8 frag_type);
 void lowpan_net_frag_exit(void);
 int lowpan_net_frag_init(void);
 
+void lowpan_rx_init(void);
+void lowpan_rx_exit(void);
+
 #endif /* __IEEE802154_6LOWPAN_I_H__ */
diff --git a/net/ieee802154/6lowpan/6lowpan_rtnl.c b/net/ieee802154/6lowpan/6lowpan_rtnl.c
index 1918c43..9dce20e 100644
--- a/net/ieee802154/6lowpan/6lowpan_rtnl.c
+++ b/net/ieee802154/6lowpan/6lowpan_rtnl.c
@@ -57,21 +57,9 @@
 
 #include "6lowpan_i.h"
 
-static LIST_HEAD(lowpan_devices);
+LIST_HEAD(lowpan_devices);
 static int lowpan_open_count;
 
-/* private device info */
-struct lowpan_dev_info {
-	struct net_device	*real_dev; /* real WPAN device ptr */
-	struct mutex		dev_list_mtx; /* mutex for list ops */
-	u16			fragment_tag;
-};
-
-struct lowpan_dev_record {
-	struct net_device *ldev;
-	struct list_head list;
-};
-
 /* don't save pan id, it's intra pan */
 struct lowpan_addr {
 	u8 mode;
@@ -88,12 +76,6 @@ struct lowpan_addr_info {
 };
 
 static inline struct
-lowpan_dev_info *lowpan_dev_info(const struct net_device *dev)
-{
-	return netdev_priv(dev);
-}
-
-static inline struct
 lowpan_addr_info *lowpan_skb_priv(const struct sk_buff *skb)
 {
 	WARN_ON_ONCE(skb_headroom(skb) < sizeof(struct lowpan_addr_info));
@@ -134,74 +116,6 @@ static int lowpan_header_create(struct sk_buff *skb, struct net_device *dev,
 	return 0;
 }
 
-static int lowpan_give_skb_to_devices(struct sk_buff *skb,
-				      struct net_device *dev)
-{
-	struct lowpan_dev_record *entry;
-	struct sk_buff *skb_cp;
-	int stat = NET_RX_SUCCESS;
-
-	skb->protocol = htons(ETH_P_IPV6);
-	skb->pkt_type = PACKET_HOST;
-
-	rcu_read_lock();
-	list_for_each_entry_rcu(entry, &lowpan_devices, list)
-		if (lowpan_dev_info(entry->ldev)->real_dev == skb->dev) {
-			skb_cp = skb_copy(skb, GFP_ATOMIC);
-			if (!skb_cp) {
-				kfree_skb(skb);
-				rcu_read_unlock();
-				return NET_RX_DROP;
-			}
-
-			skb_cp->dev = entry->ldev;
-			stat = netif_rx(skb_cp);
-			if (stat == NET_RX_DROP)
-				break;
-		}
-	rcu_read_unlock();
-
-	consume_skb(skb);
-
-	return stat;
-}
-
-static int
-iphc_decompress(struct sk_buff *skb, const struct ieee802154_hdr *hdr)
-{
-	u8 iphc0, iphc1;
-	struct ieee802154_addr_sa sa, da;
-	void *sap, *dap;
-
-	raw_dump_table(__func__, "raw skb data dump", skb->data, skb->len);
-	/* at least two bytes will be used for the encoding */
-	if (skb->len < 2)
-		return -EINVAL;
-
-	if (lowpan_fetch_skb_u8(skb, &iphc0))
-		return -EINVAL;
-
-	if (lowpan_fetch_skb_u8(skb, &iphc1))
-		return -EINVAL;
-
-	ieee802154_addr_to_sa(&sa, &hdr->source);
-	ieee802154_addr_to_sa(&da, &hdr->dest);
-
-	if (sa.addr_type == IEEE802154_ADDR_SHORT)
-		sap = &sa.short_addr;
-	else
-		sap = &sa.hwaddr;
-
-	if (da.addr_type == IEEE802154_ADDR_SHORT)
-		dap = &da.short_addr;
-	else
-		dap = &da.hwaddr;
-
-	return lowpan_header_decompress(skb, skb->dev, sap, sa.addr_type,
-					IEEE802154_ADDR_LEN, dap, da.addr_type,
-					IEEE802154_ADDR_LEN, iphc0, iphc1);
-}
-
 static struct sk_buff*
 lowpan_alloc_frag(struct sk_buff *skb, int size,
 		  const struct ieee802154_hdr *master_hdr)
@@ -485,83 +399,6 @@ static int lowpan_validate(struct nlattr *tb[], struct nlattr *data[])
 	return 0;
 }
 
-static int lowpan_rcv(struct sk_buff *skb, struct net_device *dev,
-		      struct packet_type *pt, struct net_device *orig_dev)
-{
-	struct ieee802154_hdr hdr;
-	int ret;
-
-	skb = skb_share_check(skb, GFP_ATOMIC);
-	if (!skb)
-		goto drop;
-
-	if (!netif_running(dev))
-		goto drop_skb;
-
-	if (skb->pkt_type == PACKET_OTHERHOST)
-		goto drop_skb;
-
-	if (dev->type != ARPHRD_IEEE802154)
-		goto drop_skb;
-
-	if (ieee802154_hdr_peek_addrs(skb, &hdr) < 0)
-		goto drop_skb;
-
-	/* check that it's our buffer */
-	if (skb->data[0] == LOWPAN_DISPATCH_IPV6) {
-		/* Pull off the 1-byte of 6lowpan header. */
-		skb_pull(skb, 1);
-		return lowpan_give_skb_to_devices(skb, NULL);
-	} else {
-		switch (skb->data[0] & 0xe0) {
-		case LOWPAN_DISPATCH_IPHC:	/* ipv6 datagram */
-			ret = iphc_decompress(skb, &hdr);
-			if (ret < 0)
-				goto drop_skb;
-
-			return lowpan_give_skb_to_devices(skb, NULL);
-		case LOWPAN_DISPATCH_FRAG1:	/* first fragment header */
-			ret = lowpan_frag_rcv(skb, LOWPAN_DISPATCH_FRAG1);
-			if (ret == 1) {
-				ret = iphc_decompress(skb, &hdr);
-				if (ret < 0)
-					goto drop_skb;
-
-				return lowpan_give_skb_to_devices(skb, NULL);
-			} else if (ret == -1) {
-				return NET_RX_DROP;
-			} else {
-				return NET_RX_SUCCESS;
-			}
-		case LOWPAN_DISPATCH_FRAGN:	/* next fragments headers */
-			ret = lowpan_frag_rcv(skb, LOWPAN_DISPATCH_FRAGN);
-			if (ret == 1) {
-				ret = iphc_decompress(skb, &hdr);
-				if (ret < 0)
-					goto drop_skb;
-
-				return lowpan_give_skb_to_devices(skb, NULL);
-			} else if (ret == -1) {
-				return NET_RX_DROP;
-			} else {
-				return NET_RX_SUCCESS;
-			}
-		default:
-			break;
-		}
-	}
-
-drop_skb:
-	kfree_skb(skb);
-drop:
-	return NET_RX_DROP;
-}
-
-static struct packet_type lowpan_packet_type = {
-	.type = htons(ETH_P_IEEE802154),
-	.func = lowpan_rcv,
-};
-
 static int lowpan_newlink(struct net *src_net, struct net_device *dev,
 			  struct nlattr *tb[], struct nlattr *data[])
 {
@@ -607,7 +444,7 @@ static int lowpan_newlink(struct net *src_net, struct net_device *dev,
 	ret = register_netdevice(dev);
 	if (ret >= 0) {
 		if (!lowpan_open_count)
-			dev_add_pack(&lowpan_packet_type);
+			lowpan_rx_init();
 		lowpan_open_count++;
 	}
 
@@ -624,7 +461,7 @@ static void lowpan_dellink(struct net_device *dev, struct list_head *head)
 
 	lowpan_open_count--;
 	if (!lowpan_open_count)
-		dev_remove_pack(&lowpan_packet_type);
+		lowpan_rx_exit();
 
 	mutex_lock(&lowpan_dev_info(dev)->dev_list_mtx);
 	list_for_each_entry_safe(entry, tmp, &lowpan_devices, list) {
diff --git a/net/ieee802154/6lowpan/Makefile b/net/ieee802154/6lowpan/Makefile
index 936959b..8e83971 100644
--- a/net/ieee802154/6lowpan/Makefile
+++ b/net/ieee802154/6lowpan/Makefile
@@ -1,3 +1,3 @@
 obj-y += ieee802154_6lowpan.o
 
-ieee802154_6lowpan-y := 6lowpan_rtnl.o reassembly.o
+ieee802154_6lowpan-y := 6lowpan_rtnl.o rx.o reassembly.o
diff --git a/net/ieee802154/6lowpan/rx.c b/net/ieee802154/6lowpan/rx.c
new file mode 100644
index 0000000..4be1d28
--- /dev/null
+++ b/net/ieee802154/6lowpan/rx.c
@@ -0,0 +1,171 @@
+/* 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.
+ */
+
+#include <linux/if_arp.h>
+
+#include <net/6lowpan.h>
+#include <net/ieee802154_netdev.h>
+
+#include "6lowpan_i.h"
+
+static int lowpan_give_skb_to_devices(struct sk_buff *skb,
+				      struct net_device *dev)
+{
+	struct lowpan_dev_record *entry;
+	struct sk_buff *skb_cp;
+	int stat = NET_RX_SUCCESS;
+
+	skb->protocol = htons(ETH_P_IPV6);
+	skb->pkt_type = PACKET_HOST;
+
+	rcu_read_lock();
+	list_for_each_entry_rcu(entry, &lowpan_devices, list)
+		if (lowpan_dev_info(entry->ldev)->real_dev == skb->dev) {
+			skb_cp = skb_copy(skb, GFP_ATOMIC);
+			if (!skb_cp) {
+				kfree_skb(skb);
+				rcu_read_unlock();
+				return NET_RX_DROP;
+			}
+
+			skb_cp->dev = entry->ldev;
+			stat = netif_rx(skb_cp);
+			if (stat == NET_RX_DROP)
+				break;
+		}
+	rcu_read_unlock();
+
+	consume_skb(skb);
+
+	return stat;
+}
+
+static int
+iphc_decompress(struct sk_buff *skb, const struct ieee802154_hdr *hdr)
+{
+	u8 iphc0, iphc1;
+	struct ieee802154_addr_sa sa, da;
+	void *sap, *dap;
+
+	raw_dump_table(__func__, "raw skb data dump", skb->data, skb->len);
+	/* at least two bytes will be used for the encoding */
+	if (skb->len < 2)
+		return -EINVAL;
+
+	if (lowpan_fetch_skb_u8(skb, &iphc0))
+		return -EINVAL;
+
+	if (lowpan_fetch_skb_u8(skb, &iphc1))
+		return -EINVAL;
+
+	ieee802154_addr_to_sa(&sa, &hdr->source);
+	ieee802154_addr_to_sa(&da, &hdr->dest);
+
+	if (sa.addr_type == IEEE802154_ADDR_SHORT)
+		sap = &sa.short_addr;
+	else
+		sap = &sa.hwaddr;
+
+	if (da.addr_type == IEEE802154_ADDR_SHORT)
+		dap = &da.short_addr;
+	else
+		dap = &da.hwaddr;
+
+	return lowpan_header_decompress(skb, skb->dev, sap, sa.addr_type,
+					IEEE802154_ADDR_LEN, dap, da.addr_type,
+					IEEE802154_ADDR_LEN, iphc0, iphc1);
+}
+
+static int lowpan_rcv(struct sk_buff *skb, struct net_device *dev,
+		      struct packet_type *pt, struct net_device *orig_dev)
+{
+	struct ieee802154_hdr hdr;
+	int ret;
+
+	skb = skb_share_check(skb, GFP_ATOMIC);
+	if (!skb)
+		goto drop;
+
+	if (!netif_running(dev))
+		goto drop_skb;
+
+	if (skb->pkt_type == PACKET_OTHERHOST)
+		goto drop_skb;
+
+	if (dev->type != ARPHRD_IEEE802154)
+		goto drop_skb;
+
+	if (ieee802154_hdr_peek_addrs(skb, &hdr) < 0)
+		goto drop_skb;
+
+	/* check that it's our buffer */
+	if (skb->data[0] == LOWPAN_DISPATCH_IPV6) {
+		/* Pull off the 1-byte of 6lowpan header. */
+		skb_pull(skb, 1);
+		return lowpan_give_skb_to_devices(skb, NULL);
+	} else {
+		switch (skb->data[0] & 0xe0) {
+		case LOWPAN_DISPATCH_IPHC:	/* ipv6 datagram */
+			ret = iphc_decompress(skb, &hdr);
+			if (ret < 0)
+				goto drop_skb;
+
+			return lowpan_give_skb_to_devices(skb, NULL);
+		case LOWPAN_DISPATCH_FRAG1:	/* first fragment header */
+			ret = lowpan_frag_rcv(skb, LOWPAN_DISPATCH_FRAG1);
+			if (ret == 1) {
+				ret = iphc_decompress(skb, &hdr);
+				if (ret < 0)
+					goto drop_skb;
+
+				return lowpan_give_skb_to_devices(skb, NULL);
+			} else if (ret == -1) {
+				return NET_RX_DROP;
+			} else {
+				return NET_RX_SUCCESS;
+			}
+		case LOWPAN_DISPATCH_FRAGN:	/* next fragments headers */
+			ret = lowpan_frag_rcv(skb, LOWPAN_DISPATCH_FRAGN);
+			if (ret == 1) {
+				ret = iphc_decompress(skb, &hdr);
+				if (ret < 0)
+					goto drop_skb;
+
+				return lowpan_give_skb_to_devices(skb, NULL);
+			} else if (ret == -1) {
+				return NET_RX_DROP;
+			} else {
+				return NET_RX_SUCCESS;
+			}
+		default:
+			break;
+		}
+	}
+
+drop_skb:
+	kfree_skb(skb);
+drop:
+	return NET_RX_DROP;
+}
+
+static struct packet_type lowpan_packet_type = {
+	.type = htons(ETH_P_IEEE802154),
+	.func = lowpan_rcv,
+};
+
+void lowpan_rx_init(void)
+{
+	dev_add_pack(&lowpan_packet_type);
+}
+
+void lowpan_rx_exit(void)
+{
+	dev_remove_pack(&lowpan_packet_type);
+}
-- 
2.2.1


^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH bluetooth-next 4/5] ieee802154: 6lowpan: move transmit functionality
  2015-01-04 16:10 [PATCH bluetooth-next 0/5] ieee802154: structural directory changes Alexander Aring
                   ` (2 preceding siblings ...)
  2015-01-04 16:10 ` [PATCH bluetooth-next 3/5] ieee802154: 6lowpan: move receive functionality Alexander Aring
@ 2015-01-04 16:10 ` Alexander Aring
  2015-01-04 16:10 ` [PATCH bluetooth-next 5/5] ieee802154: 6lowpan: rename to core Alexander Aring
  2015-01-08  6:29 ` [PATCH bluetooth-next 0/5] ieee802154: structural directory changes Marcel Holtmann
  5 siblings, 0 replies; 10+ messages in thread
From: Alexander Aring @ 2015-01-04 16:10 UTC (permalink / raw)
  To: linux-wpan; +Cc: kernel, Alexander Aring

This patch moves all relevant transmit functionality into a separate tx.c
file. We can simple separate this functionality like we did it in mac802154.

Signed-off-by: Alexander Aring <alex.aring@gmail.com>
---
 net/ieee802154/6lowpan/6lowpan_i.h    |   6 +
 net/ieee802154/6lowpan/6lowpan_rtnl.c | 264 +--------------------------------
 net/ieee802154/6lowpan/Makefile       |   2 +-
 net/ieee802154/6lowpan/tx.c           | 271 ++++++++++++++++++++++++++++++++++
 4 files changed, 279 insertions(+), 264 deletions(-)
 create mode 100644 net/ieee802154/6lowpan/tx.c

diff --git a/net/ieee802154/6lowpan/6lowpan_i.h b/net/ieee802154/6lowpan/6lowpan_i.h
index 29ec61b..e50f69d 100644
--- a/net/ieee802154/6lowpan/6lowpan_i.h
+++ b/net/ieee802154/6lowpan/6lowpan_i.h
@@ -3,6 +3,7 @@
 
 #include <linux/list.h>
 
+#include <net/ieee802154_netdev.h>
 #include <net/inet_frag.h>
 
 struct lowpan_create_arg {
@@ -63,4 +64,9 @@ int lowpan_net_frag_init(void);
 void lowpan_rx_init(void);
 void lowpan_rx_exit(void);
 
+int lowpan_header_create(struct sk_buff *skb, struct net_device *dev,
+			 unsigned short type, const void *_daddr,
+			 const void *_saddr, unsigned int len);
+netdev_tx_t lowpan_xmit(struct sk_buff *skb, struct net_device *dev);
+
 #endif /* __IEEE802154_6LOWPAN_I_H__ */
diff --git a/net/ieee802154/6lowpan/6lowpan_rtnl.c b/net/ieee802154/6lowpan/6lowpan_rtnl.c
index 9dce20e..055fbb7 100644
--- a/net/ieee802154/6lowpan/6lowpan_rtnl.c
+++ b/net/ieee802154/6lowpan/6lowpan_rtnl.c
@@ -44,15 +44,10 @@
  * SUCH DAMAGE.
  */
 
-#include <linux/bitops.h>
-#include <linux/if_arp.h>
 #include <linux/module.h>
-#include <linux/moduleparam.h>
 #include <linux/netdevice.h>
 #include <linux/ieee802154.h>
-#include <net/af_ieee802154.h>
-#include <net/ieee802154_netdev.h>
-#include <net/6lowpan.h>
+
 #include <net/ipv6.h>
 
 #include "6lowpan_i.h"
@@ -60,263 +55,6 @@
 LIST_HEAD(lowpan_devices);
 static int lowpan_open_count;
 
-/* don't save pan id, it's intra pan */
-struct lowpan_addr {
-	u8 mode;
-	union {
-		/* IPv6 needs big endian here */
-		__be64 extended_addr;
-		__be16 short_addr;
-	} u;
-};
-
-struct lowpan_addr_info {
-	struct lowpan_addr daddr;
-	struct lowpan_addr saddr;
-};
-
-static inline struct
-lowpan_addr_info *lowpan_skb_priv(const struct sk_buff *skb)
-{
-	WARN_ON_ONCE(skb_headroom(skb) < sizeof(struct lowpan_addr_info));
-	return (struct lowpan_addr_info *)(skb->data -
-			sizeof(struct lowpan_addr_info));
-}
-
-static int lowpan_header_create(struct sk_buff *skb, struct net_device *dev,
-				unsigned short type, const void *_daddr,
-				const void *_saddr, unsigned int len)
-{
-	const u8 *saddr = _saddr;
-	const u8 *daddr = _daddr;
-	struct lowpan_addr_info *info;
-
-	/* TODO:
-	 * if this package isn't ipv6 one, where should it be routed?
-	 */
-	if (type != ETH_P_IPV6)
-		return 0;
-
-	if (!saddr)
-		saddr = dev->dev_addr;
-
-	raw_dump_inline(__func__, "saddr", (unsigned char *)saddr, 8);
-	raw_dump_inline(__func__, "daddr", (unsigned char *)daddr, 8);
-
-	info = lowpan_skb_priv(skb);
-
-	/* TODO: Currently we only support extended_addr */
-	info->daddr.mode = IEEE802154_ADDR_LONG;
-	memcpy(&info->daddr.u.extended_addr, daddr,
-	       sizeof(info->daddr.u.extended_addr));
-	info->saddr.mode = IEEE802154_ADDR_LONG;
-	memcpy(&info->saddr.u.extended_addr, saddr,
-	       sizeof(info->daddr.u.extended_addr));
-
-	return 0;
-}
-
-static struct sk_buff*
-lowpan_alloc_frag(struct sk_buff *skb, int size,
-		  const struct ieee802154_hdr *master_hdr)
-{
-	struct net_device *real_dev = lowpan_dev_info(skb->dev)->real_dev;
-	struct sk_buff *frag;
-	int rc;
-
-	frag = alloc_skb(real_dev->hard_header_len +
-			 real_dev->needed_tailroom + size,
-			 GFP_ATOMIC);
-
-	if (likely(frag)) {
-		frag->dev = real_dev;
-		frag->priority = skb->priority;
-		skb_reserve(frag, real_dev->hard_header_len);
-		skb_reset_network_header(frag);
-		*mac_cb(frag) = *mac_cb(skb);
-
-		rc = dev_hard_header(frag, real_dev, 0, &master_hdr->dest,
-				     &master_hdr->source, size);
-		if (rc < 0) {
-			kfree_skb(frag);
-			return ERR_PTR(rc);
-		}
-	} else {
-		frag = ERR_PTR(-ENOMEM);
-	}
-
-	return frag;
-}
-
-static int
-lowpan_xmit_fragment(struct sk_buff *skb, const struct ieee802154_hdr *wpan_hdr,
-		     u8 *frag_hdr, int frag_hdrlen,
-		     int offset, int len)
-{
-	struct sk_buff *frag;
-
-	raw_dump_inline(__func__, " fragment header", frag_hdr, frag_hdrlen);
-
-	frag = lowpan_alloc_frag(skb, frag_hdrlen + len, wpan_hdr);
-	if (IS_ERR(frag))
-		return -PTR_ERR(frag);
-
-	memcpy(skb_put(frag, frag_hdrlen), frag_hdr, frag_hdrlen);
-	memcpy(skb_put(frag, len), skb_network_header(skb) + offset, len);
-
-	raw_dump_table(__func__, " fragment dump", frag->data, frag->len);
-
-	return dev_queue_xmit(frag);
-}
-
-static int
-lowpan_xmit_fragmented(struct sk_buff *skb, struct net_device *dev,
-		       const struct ieee802154_hdr *wpan_hdr)
-{
-	u16 dgram_size, dgram_offset;
-	__be16 frag_tag;
-	u8 frag_hdr[5];
-	int frag_cap, frag_len, payload_cap, rc;
-	int skb_unprocessed, skb_offset;
-
-	dgram_size = lowpan_uncompress_size(skb, &dgram_offset) -
-		     skb->mac_len;
-	frag_tag = htons(lowpan_dev_info(dev)->fragment_tag);
-	lowpan_dev_info(dev)->fragment_tag++;
-
-	frag_hdr[0] = LOWPAN_DISPATCH_FRAG1 | ((dgram_size >> 8) & 0x07);
-	frag_hdr[1] = dgram_size & 0xff;
-	memcpy(frag_hdr + 2, &frag_tag, sizeof(frag_tag));
-
-	payload_cap = ieee802154_max_payload(wpan_hdr);
-
-	frag_len = round_down(payload_cap - LOWPAN_FRAG1_HEAD_SIZE -
-			      skb_network_header_len(skb), 8);
-
-	skb_offset = skb_network_header_len(skb);
-	skb_unprocessed = skb->len - skb->mac_len - skb_offset;
-
-	rc = lowpan_xmit_fragment(skb, wpan_hdr, frag_hdr,
-				  LOWPAN_FRAG1_HEAD_SIZE, 0,
-				  frag_len + skb_network_header_len(skb));
-	if (rc) {
-		pr_debug("%s unable to send FRAG1 packet (tag: %d)",
-			 __func__, ntohs(frag_tag));
-		goto err;
-	}
-
-	frag_hdr[0] &= ~LOWPAN_DISPATCH_FRAG1;
-	frag_hdr[0] |= LOWPAN_DISPATCH_FRAGN;
-	frag_cap = round_down(payload_cap - LOWPAN_FRAGN_HEAD_SIZE, 8);
-
-	do {
-		dgram_offset += frag_len;
-		skb_offset += frag_len;
-		skb_unprocessed -= frag_len;
-		frag_len = min(frag_cap, skb_unprocessed);
-
-		frag_hdr[4] = dgram_offset >> 3;
-
-		rc = lowpan_xmit_fragment(skb, wpan_hdr, frag_hdr,
-					  LOWPAN_FRAGN_HEAD_SIZE, skb_offset,
-					  frag_len);
-		if (rc) {
-			pr_debug("%s unable to send a FRAGN packet. (tag: %d, offset: %d)\n",
-				 __func__, ntohs(frag_tag), skb_offset);
-			goto err;
-		}
-	} while (skb_unprocessed > frag_cap);
-
-	consume_skb(skb);
-	return NET_XMIT_SUCCESS;
-
-err:
-	kfree_skb(skb);
-	return rc;
-}
-
-static int lowpan_header(struct sk_buff *skb, struct net_device *dev)
-{
-	struct ieee802154_addr sa, da;
-	struct ieee802154_mac_cb *cb = mac_cb_init(skb);
-	struct lowpan_addr_info info;
-	void *daddr, *saddr;
-
-	memcpy(&info, lowpan_skb_priv(skb), sizeof(info));
-
-	/* TODO: Currently we only support extended_addr */
-	daddr = &info.daddr.u.extended_addr;
-	saddr = &info.saddr.u.extended_addr;
-
-	lowpan_header_compress(skb, dev, ETH_P_IPV6, daddr, saddr, skb->len);
-
-	cb->type = IEEE802154_FC_TYPE_DATA;
-
-	/* prepare wpan address data */
-	sa.mode = IEEE802154_ADDR_LONG;
-	sa.pan_id = ieee802154_mlme_ops(dev)->get_pan_id(dev);
-	sa.extended_addr = ieee802154_devaddr_from_raw(saddr);
-
-	/* intra-PAN communications */
-	da.pan_id = sa.pan_id;
-
-	/* if the destination address is the broadcast address, use the
-	 * corresponding short address
-	 */
-	if (lowpan_is_addr_broadcast((const u8 *)daddr)) {
-		da.mode = IEEE802154_ADDR_SHORT;
-		da.short_addr = cpu_to_le16(IEEE802154_ADDR_BROADCAST);
-		cb->ackreq = false;
-	} else {
-		da.mode = IEEE802154_ADDR_LONG;
-		da.extended_addr = ieee802154_devaddr_from_raw(daddr);
-		cb->ackreq = true;
-	}
-
-	return dev_hard_header(skb, lowpan_dev_info(dev)->real_dev,
-			ETH_P_IPV6, (void *)&da, (void *)&sa, 0);
-}
-
-static netdev_tx_t lowpan_xmit(struct sk_buff *skb, struct net_device *dev)
-{
-	struct ieee802154_hdr wpan_hdr;
-	int max_single, ret;
-
-	pr_debug("package xmit\n");
-
-	/* We must take a copy of the skb before we modify/replace the ipv6
-	 * header as the header could be used elsewhere
-	 */
-	skb = skb_unshare(skb, GFP_ATOMIC);
-	if (!skb)
-		return NET_XMIT_DROP;
-
-	ret = lowpan_header(skb, dev);
-	if (ret < 0) {
-		kfree_skb(skb);
-		return NET_XMIT_DROP;
-	}
-
-	if (ieee802154_hdr_peek(skb, &wpan_hdr) < 0) {
-		kfree_skb(skb);
-		return NET_XMIT_DROP;
-	}
-
-	max_single = ieee802154_max_payload(&wpan_hdr);
-
-	if (skb_tail_pointer(skb) - skb_network_header(skb) <= max_single) {
-		skb->dev = lowpan_dev_info(dev)->real_dev;
-		return dev_queue_xmit(skb);
-	} else {
-		netdev_tx_t rc;
-
-		pr_debug("frame is too big, fragmentation is needed\n");
-		rc = lowpan_xmit_fragmented(skb, dev, &wpan_hdr);
-
-		return rc < 0 ? NET_XMIT_DROP : rc;
-	}
-}
-
 static __le16 lowpan_get_pan_id(const struct net_device *dev)
 {
 	struct net_device *real_dev = lowpan_dev_info(dev)->real_dev;
diff --git a/net/ieee802154/6lowpan/Makefile b/net/ieee802154/6lowpan/Makefile
index 8e83971..7f11c13 100644
--- a/net/ieee802154/6lowpan/Makefile
+++ b/net/ieee802154/6lowpan/Makefile
@@ -1,3 +1,3 @@
 obj-y += ieee802154_6lowpan.o
 
-ieee802154_6lowpan-y := 6lowpan_rtnl.o rx.o reassembly.o
+ieee802154_6lowpan-y := 6lowpan_rtnl.o rx.o reassembly.o tx.o
diff --git a/net/ieee802154/6lowpan/tx.c b/net/ieee802154/6lowpan/tx.c
new file mode 100644
index 0000000..2349070
--- /dev/null
+++ b/net/ieee802154/6lowpan/tx.c
@@ -0,0 +1,271 @@
+/* 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.
+ */
+
+#include <net/6lowpan.h>
+#include <net/ieee802154_netdev.h>
+
+#include "6lowpan_i.h"
+
+/* don't save pan id, it's intra pan */
+struct lowpan_addr {
+	u8 mode;
+	union {
+		/* IPv6 needs big endian here */
+		__be64 extended_addr;
+		__be16 short_addr;
+	} u;
+};
+
+struct lowpan_addr_info {
+	struct lowpan_addr daddr;
+	struct lowpan_addr saddr;
+};
+
+static inline struct
+lowpan_addr_info *lowpan_skb_priv(const struct sk_buff *skb)
+{
+	WARN_ON_ONCE(skb_headroom(skb) < sizeof(struct lowpan_addr_info));
+	return (struct lowpan_addr_info *)(skb->data -
+			sizeof(struct lowpan_addr_info));
+}
+
+int lowpan_header_create(struct sk_buff *skb, struct net_device *dev,
+			 unsigned short type, const void *_daddr,
+			 const void *_saddr, unsigned int len)
+{
+	const u8 *saddr = _saddr;
+	const u8 *daddr = _daddr;
+	struct lowpan_addr_info *info;
+
+	/* TODO:
+	 * if this package isn't ipv6 one, where should it be routed?
+	 */
+	if (type != ETH_P_IPV6)
+		return 0;
+
+	if (!saddr)
+		saddr = dev->dev_addr;
+
+	raw_dump_inline(__func__, "saddr", (unsigned char *)saddr, 8);
+	raw_dump_inline(__func__, "daddr", (unsigned char *)daddr, 8);
+
+	info = lowpan_skb_priv(skb);
+
+	/* TODO: Currently we only support extended_addr */
+	info->daddr.mode = IEEE802154_ADDR_LONG;
+	memcpy(&info->daddr.u.extended_addr, daddr,
+	       sizeof(info->daddr.u.extended_addr));
+	info->saddr.mode = IEEE802154_ADDR_LONG;
+	memcpy(&info->saddr.u.extended_addr, saddr,
+	       sizeof(info->daddr.u.extended_addr));
+
+	return 0;
+}
+
+static struct sk_buff*
+lowpan_alloc_frag(struct sk_buff *skb, int size,
+		  const struct ieee802154_hdr *master_hdr)
+{
+	struct net_device *real_dev = lowpan_dev_info(skb->dev)->real_dev;
+	struct sk_buff *frag;
+	int rc;
+
+	frag = alloc_skb(real_dev->hard_header_len +
+			 real_dev->needed_tailroom + size,
+			 GFP_ATOMIC);
+
+	if (likely(frag)) {
+		frag->dev = real_dev;
+		frag->priority = skb->priority;
+		skb_reserve(frag, real_dev->hard_header_len);
+		skb_reset_network_header(frag);
+		*mac_cb(frag) = *mac_cb(skb);
+
+		rc = dev_hard_header(frag, real_dev, 0, &master_hdr->dest,
+				     &master_hdr->source, size);
+		if (rc < 0) {
+			kfree_skb(frag);
+			return ERR_PTR(rc);
+		}
+	} else {
+		frag = ERR_PTR(-ENOMEM);
+	}
+
+	return frag;
+}
+
+static int
+lowpan_xmit_fragment(struct sk_buff *skb, const struct ieee802154_hdr *wpan_hdr,
+		     u8 *frag_hdr, int frag_hdrlen,
+		     int offset, int len)
+{
+	struct sk_buff *frag;
+
+	raw_dump_inline(__func__, " fragment header", frag_hdr, frag_hdrlen);
+
+	frag = lowpan_alloc_frag(skb, frag_hdrlen + len, wpan_hdr);
+	if (IS_ERR(frag))
+		return -PTR_ERR(frag);
+
+	memcpy(skb_put(frag, frag_hdrlen), frag_hdr, frag_hdrlen);
+	memcpy(skb_put(frag, len), skb_network_header(skb) + offset, len);
+
+	raw_dump_table(__func__, " fragment dump", frag->data, frag->len);
+
+	return dev_queue_xmit(frag);
+}
+
+static int
+lowpan_xmit_fragmented(struct sk_buff *skb, struct net_device *dev,
+		       const struct ieee802154_hdr *wpan_hdr)
+{
+	u16 dgram_size, dgram_offset;
+	__be16 frag_tag;
+	u8 frag_hdr[5];
+	int frag_cap, frag_len, payload_cap, rc;
+	int skb_unprocessed, skb_offset;
+
+	dgram_size = lowpan_uncompress_size(skb, &dgram_offset) -
+		     skb->mac_len;
+	frag_tag = htons(lowpan_dev_info(dev)->fragment_tag);
+	lowpan_dev_info(dev)->fragment_tag++;
+
+	frag_hdr[0] = LOWPAN_DISPATCH_FRAG1 | ((dgram_size >> 8) & 0x07);
+	frag_hdr[1] = dgram_size & 0xff;
+	memcpy(frag_hdr + 2, &frag_tag, sizeof(frag_tag));
+
+	payload_cap = ieee802154_max_payload(wpan_hdr);
+
+	frag_len = round_down(payload_cap - LOWPAN_FRAG1_HEAD_SIZE -
+			      skb_network_header_len(skb), 8);
+
+	skb_offset = skb_network_header_len(skb);
+	skb_unprocessed = skb->len - skb->mac_len - skb_offset;
+
+	rc = lowpan_xmit_fragment(skb, wpan_hdr, frag_hdr,
+				  LOWPAN_FRAG1_HEAD_SIZE, 0,
+				  frag_len + skb_network_header_len(skb));
+	if (rc) {
+		pr_debug("%s unable to send FRAG1 packet (tag: %d)",
+			 __func__, ntohs(frag_tag));
+		goto err;
+	}
+
+	frag_hdr[0] &= ~LOWPAN_DISPATCH_FRAG1;
+	frag_hdr[0] |= LOWPAN_DISPATCH_FRAGN;
+	frag_cap = round_down(payload_cap - LOWPAN_FRAGN_HEAD_SIZE, 8);
+
+	do {
+		dgram_offset += frag_len;
+		skb_offset += frag_len;
+		skb_unprocessed -= frag_len;
+		frag_len = min(frag_cap, skb_unprocessed);
+
+		frag_hdr[4] = dgram_offset >> 3;
+
+		rc = lowpan_xmit_fragment(skb, wpan_hdr, frag_hdr,
+					  LOWPAN_FRAGN_HEAD_SIZE, skb_offset,
+					  frag_len);
+		if (rc) {
+			pr_debug("%s unable to send a FRAGN packet. (tag: %d, offset: %d)\n",
+				 __func__, ntohs(frag_tag), skb_offset);
+			goto err;
+		}
+	} while (skb_unprocessed > frag_cap);
+
+	consume_skb(skb);
+	return NET_XMIT_SUCCESS;
+
+err:
+	kfree_skb(skb);
+	return rc;
+}
+
+static int lowpan_header(struct sk_buff *skb, struct net_device *dev)
+{
+	struct ieee802154_addr sa, da;
+	struct ieee802154_mac_cb *cb = mac_cb_init(skb);
+	struct lowpan_addr_info info;
+	void *daddr, *saddr;
+
+	memcpy(&info, lowpan_skb_priv(skb), sizeof(info));
+
+	/* TODO: Currently we only support extended_addr */
+	daddr = &info.daddr.u.extended_addr;
+	saddr = &info.saddr.u.extended_addr;
+
+	lowpan_header_compress(skb, dev, ETH_P_IPV6, daddr, saddr, skb->len);
+
+	cb->type = IEEE802154_FC_TYPE_DATA;
+
+	/* prepare wpan address data */
+	sa.mode = IEEE802154_ADDR_LONG;
+	sa.pan_id = ieee802154_mlme_ops(dev)->get_pan_id(dev);
+	sa.extended_addr = ieee802154_devaddr_from_raw(saddr);
+
+	/* intra-PAN communications */
+	da.pan_id = sa.pan_id;
+
+	/* if the destination address is the broadcast address, use the
+	 * corresponding short address
+	 */
+	if (lowpan_is_addr_broadcast((const u8 *)daddr)) {
+		da.mode = IEEE802154_ADDR_SHORT;
+		da.short_addr = cpu_to_le16(IEEE802154_ADDR_BROADCAST);
+		cb->ackreq = false;
+	} else {
+		da.mode = IEEE802154_ADDR_LONG;
+		da.extended_addr = ieee802154_devaddr_from_raw(daddr);
+		cb->ackreq = true;
+	}
+
+	return dev_hard_header(skb, lowpan_dev_info(dev)->real_dev,
+			ETH_P_IPV6, (void *)&da, (void *)&sa, 0);
+}
+
+netdev_tx_t lowpan_xmit(struct sk_buff *skb, struct net_device *dev)
+{
+	struct ieee802154_hdr wpan_hdr;
+	int max_single, ret;
+
+	pr_debug("package xmit\n");
+
+	/* We must take a copy of the skb before we modify/replace the ipv6
+	 * header as the header could be used elsewhere
+	 */
+	skb = skb_unshare(skb, GFP_ATOMIC);
+	if (!skb)
+		return NET_XMIT_DROP;
+
+	ret = lowpan_header(skb, dev);
+	if (ret < 0) {
+		kfree_skb(skb);
+		return NET_XMIT_DROP;
+	}
+
+	if (ieee802154_hdr_peek(skb, &wpan_hdr) < 0) {
+		kfree_skb(skb);
+		return NET_XMIT_DROP;
+	}
+
+	max_single = ieee802154_max_payload(&wpan_hdr);
+
+	if (skb_tail_pointer(skb) - skb_network_header(skb) <= max_single) {
+		skb->dev = lowpan_dev_info(dev)->real_dev;
+		return dev_queue_xmit(skb);
+	} else {
+		netdev_tx_t rc;
+
+		pr_debug("frame is too big, fragmentation is needed\n");
+		rc = lowpan_xmit_fragmented(skb, dev, &wpan_hdr);
+
+		return rc < 0 ? NET_XMIT_DROP : rc;
+	}
+}
-- 
2.2.1


^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH bluetooth-next 5/5] ieee802154: 6lowpan: rename to core
  2015-01-04 16:10 [PATCH bluetooth-next 0/5] ieee802154: structural directory changes Alexander Aring
                   ` (3 preceding siblings ...)
  2015-01-04 16:10 ` [PATCH bluetooth-next 4/5] ieee802154: 6lowpan: move transmit functionality Alexander Aring
@ 2015-01-04 16:10 ` Alexander Aring
  2015-01-08  6:29 ` [PATCH bluetooth-next 0/5] ieee802154: structural directory changes Marcel Holtmann
  5 siblings, 0 replies; 10+ messages in thread
From: Alexander Aring @ 2015-01-04 16:10 UTC (permalink / raw)
  To: linux-wpan; +Cc: kernel, Alexander Aring

This patch renames the 6lowpan_rtnl.c file to core.c. 6lowpan_rtnl.c
contains functionality to put all 802.15.4 6LoWPAN functionality
together.

Signed-off-by: Alexander Aring <alex.aring@gmail.com>
---
 net/ieee802154/6lowpan/Makefile                   | 2 +-
 net/ieee802154/6lowpan/{6lowpan_rtnl.c => core.c} | 0
 2 files changed, 1 insertion(+), 1 deletion(-)
 rename net/ieee802154/6lowpan/{6lowpan_rtnl.c => core.c} (100%)

diff --git a/net/ieee802154/6lowpan/Makefile b/net/ieee802154/6lowpan/Makefile
index 7f11c13..2f1b75a 100644
--- a/net/ieee802154/6lowpan/Makefile
+++ b/net/ieee802154/6lowpan/Makefile
@@ -1,3 +1,3 @@
 obj-y += ieee802154_6lowpan.o
 
-ieee802154_6lowpan-y := 6lowpan_rtnl.o rx.o reassembly.o tx.o
+ieee802154_6lowpan-y := core.o rx.o reassembly.o tx.o
diff --git a/net/ieee802154/6lowpan/6lowpan_rtnl.c b/net/ieee802154/6lowpan/core.c
similarity index 100%
rename from net/ieee802154/6lowpan/6lowpan_rtnl.c
rename to net/ieee802154/6lowpan/core.c
-- 
2.2.1


^ permalink raw reply related	[flat|nested] 10+ messages in thread

* Re: [PATCH bluetooth-next 0/5] ieee802154: structural directory changes
  2015-01-04 16:10 [PATCH bluetooth-next 0/5] ieee802154: structural directory changes Alexander Aring
                   ` (4 preceding siblings ...)
  2015-01-04 16:10 ` [PATCH bluetooth-next 5/5] ieee802154: 6lowpan: rename to core Alexander Aring
@ 2015-01-08  6:29 ` Marcel Holtmann
  5 siblings, 0 replies; 10+ messages in thread
From: Marcel Holtmann @ 2015-01-08  6:29 UTC (permalink / raw)
  To: Alexander Aring; +Cc: linux-wpan, kernel

Hi Alex,

> This patch series contains patches to create a 6lowpan sub-directory inside
> ieee802154. At least we handle receive and transmit functionality in separate
> files.
> 
> This series based on previous the previous series:
> 
> "ieee802154: 6lowpan: separate receive/transmit functionality" and
> "ieee802154: structural directory changes".
> 
> I changed PATCH 1/5 "ieee802154: create 6lowpan sub-directory" only to source
> the "net/ieee802154/6lowpan/Kconfig" file. Furthermore there will more options
> like debugfs etc... available for ieee802154 6lowpan functionality.
> 
> - Alex
> 
> Alexander Aring (5):
>  ieee802154: create 6lowpan sub-directory
>  ieee802154: 6lowpan: rename internal header
>  ieee802154: 6lowpan: move receive functionality
>  ieee802154: 6lowpan: move transmit functionality
>  ieee802154: 6lowpan: rename to core
> 
> net/ieee802154/6lowpan/6lowpan_i.h        |  72 +++
> net/ieee802154/6lowpan/Kconfig            |   5 +
> net/ieee802154/6lowpan/Makefile           |   3 +
> net/ieee802154/6lowpan/core.c             | 304 +++++++++++++
> net/ieee802154/{ => 6lowpan}/reassembly.c |   2 +-
> net/ieee802154/6lowpan/rx.c               | 171 +++++++
> net/ieee802154/6lowpan/tx.c               | 271 +++++++++++
> net/ieee802154/6lowpan_rtnl.c             | 729 ------------------------------
> net/ieee802154/Kconfig                    |   6 +-
> net/ieee802154/Makefile                   |   3 +-
> net/ieee802154/reassembly.h               |  41 --
> 11 files changed, 829 insertions(+), 778 deletions(-)
> create mode 100644 net/ieee802154/6lowpan/6lowpan_i.h
> create mode 100644 net/ieee802154/6lowpan/Kconfig
> create mode 100644 net/ieee802154/6lowpan/Makefile
> create mode 100644 net/ieee802154/6lowpan/core.c
> rename net/ieee802154/{ => 6lowpan}/reassembly.c (99%)
> create mode 100644 net/ieee802154/6lowpan/rx.c
> create mode 100644 net/ieee802154/6lowpan/tx.c
> delete mode 100644 net/ieee802154/6lowpan_rtnl.c
> delete mode 100644 net/ieee802154/reassembly.h

all 5 patches haven been applied to bluetooth-next tree.

Regards

Marcel


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH bluetooth-next 0/5] ieee802154: structural directory changes
  2014-12-30  6:18 ` Marcel Holtmann
@ 2014-12-30 15:16   ` Alexander Aring
  0 siblings, 0 replies; 10+ messages in thread
From: Alexander Aring @ 2014-12-30 15:16 UTC (permalink / raw)
  To: Marcel Holtmann; +Cc: linux-wpan, kernel

Hi Marcel,

On Mon, Dec 29, 2014 at 10:18:32PM -0800, Marcel Holtmann wrote:
> Hi Alex,
> 
> > This patch series contains structural changes according the ieee802154
> > directory. The current situation is that this directory contains stuff
> > about ieee802154 6lowpan, ieee802154 address family and netlink interface.
> > This patch series introduce now sub directories for 6lowpan and af802154
> > implementation to getting a better overview about these implementations.
> > The ieee802154 directory contains stuff for nl802154, netlink and sysfs
> > only.
> > 
> > Alexander Aring (5):
> >  ieee802154: create af802154 sub-directory
> >  ieee802154: af802154: rename internal header
> >  ieee802154: af802154: rename af_ieee802154 to core
> >  ieee802154: create 6lowpan sub-directory
> >  ieee802154: 6lowpan: rename internal header
> > 
> > net/ieee802154/{reassembly.h => 6lowpan/6lowpan_i.h} | 6 +++---
> > net/ieee802154/{ => 6lowpan}/6lowpan_rtnl.c          | 2 +-
> > net/ieee802154/6lowpan/Makefile                      | 3 +++
> > net/ieee802154/{ => 6lowpan}/reassembly.c            | 2 +-
> > net/ieee802154/Makefile                              | 6 ++----
> > net/ieee802154/af802154/Makefile                     | 3 +++
> > net/ieee802154/{af802154.h => af802154/af802154_i.h} | 6 +++---
> > net/ieee802154/{af_ieee802154.c => af802154/core.c}  | 2 +-
> > net/ieee802154/{ => af802154}/dgram.c                | 2 +-
> > net/ieee802154/{ => af802154}/raw.c                  | 2 +-
> > 10 files changed, 19 insertions(+), 15 deletions(-)
> > rename net/ieee802154/{reassembly.h => 6lowpan/6lowpan_i.h} (85%)
> > rename net/ieee802154/{ => 6lowpan}/6lowpan_rtnl.c (99%)
> > create mode 100644 net/ieee802154/6lowpan/Makefile
> > rename net/ieee802154/{ => 6lowpan}/reassembly.c (99%)
> > create mode 100644 net/ieee802154/af802154/Makefile
> > rename net/ieee802154/{af802154.h => af802154/af802154_i.h} (93%)
> > rename net/ieee802154/{af_ieee802154.c => af802154/core.c} (99%)
> > rename net/ieee802154/{ => af802154}/dgram.c (99%)
> > rename net/ieee802154/{ => af802154}/raw.c (99%)
> 
> the move of the 6lowpan stuff into net/ieee802154/6lowpan/ I can understand. That should be an optional piece. And I assume for 802.15.4 the 6LoWPAN support is more complex since it has to do segmentation and reassembly.
> 

ok.

> The net/ieee802154/af802154/ part seems pointless to me. What is this trying to achieve? I see that you can build af_802154.ko as a separate module. Which is something that I have not realized until now. So this is something that is intentional. So having ieee802154.ko and ieee802154_6lowpan.ko by itself without the socket is something that is functional?
> 

Yes, the address family functionality can be a separate module.
ieee802154_6lowpan.ko doesn't depends on the address family
functionality.

If only ieee802154.ko would built without address family and
ieee802154_6lowpan.ko then it might be used for receiving monitor mode.

I would change that but add a "default y" to the address family module.

> If so, I find the naming of af_802154.ko and net/ieee802154/af802154/ rather complicated and convoluted. Would ieee802154_socket.ko net/ieee802154/socket/ not something more logical split in this regard?
> 

Don't know, I would keep the naming style to avoid confusing current
users. On the other hand, I think there are not many users outside and I
like the name socket. Many people knows sockets and doesn't know what a
(socket) "address family" is.

I will send a second version of this patch series according these changes.

- Alex

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH bluetooth-next 0/5] ieee802154: structural directory changes
  2014-12-20 14:04 Alexander Aring
@ 2014-12-30  6:18 ` Marcel Holtmann
  2014-12-30 15:16   ` Alexander Aring
  0 siblings, 1 reply; 10+ messages in thread
From: Marcel Holtmann @ 2014-12-30  6:18 UTC (permalink / raw)
  To: Alexander Aring; +Cc: linux-wpan, kernel

Hi Alex,

> This patch series contains structural changes according the ieee802154
> directory. The current situation is that this directory contains stuff
> about ieee802154 6lowpan, ieee802154 address family and netlink interface.
> This patch series introduce now sub directories for 6lowpan and af802154
> implementation to getting a better overview about these implementations.
> The ieee802154 directory contains stuff for nl802154, netlink and sysfs
> only.
> 
> Alexander Aring (5):
>  ieee802154: create af802154 sub-directory
>  ieee802154: af802154: rename internal header
>  ieee802154: af802154: rename af_ieee802154 to core
>  ieee802154: create 6lowpan sub-directory
>  ieee802154: 6lowpan: rename internal header
> 
> net/ieee802154/{reassembly.h => 6lowpan/6lowpan_i.h} | 6 +++---
> net/ieee802154/{ => 6lowpan}/6lowpan_rtnl.c          | 2 +-
> net/ieee802154/6lowpan/Makefile                      | 3 +++
> net/ieee802154/{ => 6lowpan}/reassembly.c            | 2 +-
> net/ieee802154/Makefile                              | 6 ++----
> net/ieee802154/af802154/Makefile                     | 3 +++
> net/ieee802154/{af802154.h => af802154/af802154_i.h} | 6 +++---
> net/ieee802154/{af_ieee802154.c => af802154/core.c}  | 2 +-
> net/ieee802154/{ => af802154}/dgram.c                | 2 +-
> net/ieee802154/{ => af802154}/raw.c                  | 2 +-
> 10 files changed, 19 insertions(+), 15 deletions(-)
> rename net/ieee802154/{reassembly.h => 6lowpan/6lowpan_i.h} (85%)
> rename net/ieee802154/{ => 6lowpan}/6lowpan_rtnl.c (99%)
> create mode 100644 net/ieee802154/6lowpan/Makefile
> rename net/ieee802154/{ => 6lowpan}/reassembly.c (99%)
> create mode 100644 net/ieee802154/af802154/Makefile
> rename net/ieee802154/{af802154.h => af802154/af802154_i.h} (93%)
> rename net/ieee802154/{af_ieee802154.c => af802154/core.c} (99%)
> rename net/ieee802154/{ => af802154}/dgram.c (99%)
> rename net/ieee802154/{ => af802154}/raw.c (99%)

the move of the 6lowpan stuff into net/ieee802154/6lowpan/ I can understand. That should be an optional piece. And I assume for 802.15.4 the 6LoWPAN support is more complex since it has to do segmentation and reassembly.

The net/ieee802154/af802154/ part seems pointless to me. What is this trying to achieve? I see that you can build af_802154.ko as a separate module. Which is something that I have not realized until now. So this is something that is intentional. So having ieee802154.ko and ieee802154_6lowpan.ko by itself without the socket is something that is functional?

If so, I find the naming of af_802154.ko and net/ieee802154/af802154/ rather complicated and convoluted. Would ieee802154_socket.ko net/ieee802154/socket/ not something more logical split in this regard?

Regards

Marcel


^ permalink raw reply	[flat|nested] 10+ messages in thread

* [PATCH bluetooth-next 0/5] ieee802154: structural directory changes
@ 2014-12-20 14:04 Alexander Aring
  2014-12-30  6:18 ` Marcel Holtmann
  0 siblings, 1 reply; 10+ messages in thread
From: Alexander Aring @ 2014-12-20 14:04 UTC (permalink / raw)
  To: linux-wpan; +Cc: kernel, Alexander Aring

This patch series contains structural changes according the ieee802154
directory. The current situation is that this directory contains stuff
about ieee802154 6lowpan, ieee802154 address family and netlink interface.
This patch series introduce now sub directories for 6lowpan and af802154
implementation to getting a better overview about these implementations.
The ieee802154 directory contains stuff for nl802154, netlink and sysfs
only.

Alexander Aring (5):
  ieee802154: create af802154 sub-directory
  ieee802154: af802154: rename internal header
  ieee802154: af802154: rename af_ieee802154 to core
  ieee802154: create 6lowpan sub-directory
  ieee802154: 6lowpan: rename internal header

 net/ieee802154/{reassembly.h => 6lowpan/6lowpan_i.h} | 6 +++---
 net/ieee802154/{ => 6lowpan}/6lowpan_rtnl.c          | 2 +-
 net/ieee802154/6lowpan/Makefile                      | 3 +++
 net/ieee802154/{ => 6lowpan}/reassembly.c            | 2 +-
 net/ieee802154/Makefile                              | 6 ++----
 net/ieee802154/af802154/Makefile                     | 3 +++
 net/ieee802154/{af802154.h => af802154/af802154_i.h} | 6 +++---
 net/ieee802154/{af_ieee802154.c => af802154/core.c}  | 2 +-
 net/ieee802154/{ => af802154}/dgram.c                | 2 +-
 net/ieee802154/{ => af802154}/raw.c                  | 2 +-
 10 files changed, 19 insertions(+), 15 deletions(-)
 rename net/ieee802154/{reassembly.h => 6lowpan/6lowpan_i.h} (85%)
 rename net/ieee802154/{ => 6lowpan}/6lowpan_rtnl.c (99%)
 create mode 100644 net/ieee802154/6lowpan/Makefile
 rename net/ieee802154/{ => 6lowpan}/reassembly.c (99%)
 create mode 100644 net/ieee802154/af802154/Makefile
 rename net/ieee802154/{af802154.h => af802154/af802154_i.h} (93%)
 rename net/ieee802154/{af_ieee802154.c => af802154/core.c} (99%)
 rename net/ieee802154/{ => af802154}/dgram.c (99%)
 rename net/ieee802154/{ => af802154}/raw.c (99%)

-- 
2.2.0


^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2015-01-08  6:29 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-01-04 16:10 [PATCH bluetooth-next 0/5] ieee802154: structural directory changes Alexander Aring
2015-01-04 16:10 ` [PATCH bluetooth-next 1/5] ieee802154: create 6lowpan sub-directory Alexander Aring
2015-01-04 16:10 ` [PATCH bluetooth-next 2/5] ieee802154: 6lowpan: rename internal header Alexander Aring
2015-01-04 16:10 ` [PATCH bluetooth-next 3/5] ieee802154: 6lowpan: move receive functionality Alexander Aring
2015-01-04 16:10 ` [PATCH bluetooth-next 4/5] ieee802154: 6lowpan: move transmit functionality Alexander Aring
2015-01-04 16:10 ` [PATCH bluetooth-next 5/5] ieee802154: 6lowpan: rename to core Alexander Aring
2015-01-08  6:29 ` [PATCH bluetooth-next 0/5] ieee802154: structural directory changes Marcel Holtmann
  -- strict thread matches above, loose matches on Subject: below --
2014-12-20 14:04 Alexander Aring
2014-12-30  6:18 ` Marcel Holtmann
2014-12-30 15:16   ` Alexander Aring

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.