[Linux-zigbee-devel] [PATCH 2/2] 6lowpan: handle NETDEV_UNREGISTER event

2012-08-29 Thread Alan Ott
Before, it was impossible to remove a wpan device which had lowpan
attached to it.

Signed-off-by: Alan Ott 
---
 net/ieee802154/6lowpan.c |   44 +---
 1 files changed, 37 insertions(+), 7 deletions(-)

diff --git a/net/ieee802154/6lowpan.c b/net/ieee802154/6lowpan.c
index ce33b02..fb41e08 100644
--- a/net/ieee802154/6lowpan.c
+++ b/net/ieee802154/6lowpan.c
@@ -1063,12 +1063,6 @@ out:
return (err < 0 ? NETDEV_TX_BUSY : NETDEV_TX_OK);
 }
 
-static void lowpan_dev_free(struct net_device *dev)
-{
-   dev_put(lowpan_dev_info(dev)->real_dev);
-   free_netdev(dev);
-}
-
 static struct wpan_phy *lowpan_get_phy(const struct net_device *dev)
 {
struct net_device *real_dev = lowpan_dev_info(dev)->real_dev;
@@ -1118,7 +1112,7 @@ static void lowpan_setup(struct net_device *dev)
dev->netdev_ops = &lowpan_netdev_ops;
dev->header_ops = &lowpan_header_ops;
dev->ml_priv= &lowpan_mlme;
-   dev->destructor = lowpan_dev_free;
+   dev->destructor = free_netdev;
 }
 
 static int lowpan_validate(struct nlattr *tb[], struct nlattr *data[])
@@ -1244,6 +1238,34 @@ static inline void __init lowpan_netlink_fini(void)
rtnl_link_unregister(&lowpan_link_ops);
 }
 
+static int lowpan_device_event(struct notifier_block *unused,
+   unsigned long event,
+   void *ptr)
+{
+   struct net_device *dev = ptr;
+   LIST_HEAD(del_list);
+   struct lowpan_dev_record *entry, *tmp;
+
+   if (dev->type != ARPHRD_IEEE802154)
+   goto out;
+
+   if (event == NETDEV_UNREGISTER) {
+   list_for_each_entry_safe(entry, tmp, &lowpan_devices, list) {
+   if (lowpan_dev_info(entry->ldev)->real_dev == dev)
+   lowpan_dellink(entry->ldev, &del_list);
+   }
+
+   unregister_netdevice_many(&del_list);
+   };
+
+out:
+   return NOTIFY_DONE;
+}
+
+static struct notifier_block lowpan_dev_notifier = {
+   .notifier_call = lowpan_device_event,
+};
+
 static struct packet_type lowpan_packet_type = {
.type = __constant_htons(ETH_P_IEEE802154),
.func = lowpan_rcv,
@@ -1258,6 +1280,12 @@ static int __init lowpan_init_module(void)
goto out;
 
dev_add_pack(&lowpan_packet_type);
+
+   err = register_netdevice_notifier(&lowpan_dev_notifier);
+   if (err < 0) {
+   dev_remove_pack(&lowpan_packet_type);
+   lowpan_netlink_fini();
+   }
 out:
return err;
 }
@@ -1270,6 +1298,8 @@ static void __exit lowpan_cleanup_module(void)
 
dev_remove_pack(&lowpan_packet_type);
 
+   unregister_netdevice_notifier(&lowpan_dev_notifier);
+
/* Now 6lowpan packet_type is removed, so no new fragments are
 * expected on RX, therefore that's the time to clean incomplete
 * fragments.
-- 
1.7.0.4


--
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
___
Linux-zigbee-devel mailing list
Linux-zigbee-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-zigbee-devel


[Linux-zigbee-devel] [PATCH] 6lowpan: Make a copy of skb's delivered to 6lowpan

2012-08-29 Thread Alan Ott
Since lowpan_process_data() modifies the skb (by calling skb_pull()), we
need our own copy so that it doesn't affect the data received by other
protcols (in this case, af_ieee802154).

Signed-off-by: Alan Ott 
---
 net/ieee802154/6lowpan.c |9 -
 1 files changed, 8 insertions(+), 1 deletions(-)

diff --git a/net/ieee802154/6lowpan.c b/net/ieee802154/6lowpan.c
index 6a09522..ce33b02 100644
--- a/net/ieee802154/6lowpan.c
+++ b/net/ieee802154/6lowpan.c
@@ -1133,6 +1133,8 @@ static int lowpan_validate(struct nlattr *tb[], struct 
nlattr *data[])
 static int lowpan_rcv(struct sk_buff *skb, struct net_device *dev,
struct packet_type *pt, struct net_device *orig_dev)
 {
+   struct sk_buff *local_skb;
+
if (!netif_running(dev))
goto drop;
 
@@ -1144,7 +1146,12 @@ static int lowpan_rcv(struct sk_buff *skb, struct 
net_device *dev,
case LOWPAN_DISPATCH_IPHC:  /* ipv6 datagram */
case LOWPAN_DISPATCH_FRAG1: /* first fragment header */
case LOWPAN_DISPATCH_FRAGN: /* next fragments headers */
-   lowpan_process_data(skb);
+   local_skb = skb_copy(skb, GFP_ATOMIC);
+   if (!local_skb)
+   goto drop;
+   lowpan_process_data(local_skb);
+
+   kfree_skb(skb);
break;
default:
break;
-- 
1.7.0.4


--
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
___
Linux-zigbee-devel mailing list
Linux-zigbee-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-zigbee-devel


[Linux-zigbee-devel] [PATCH v2 0/2] 6lowpan fixes

2012-08-29 Thread Alan Ott
Fixes for 6lowpan.

I'm sorry about the other two emails that just went out with the same
subject.  One day I'm going to start getting these right on the first try.

Alan Ott (2):
  6lowpan: Make a copy of skb's delivered to 6lowpan
  6lowpan: handle NETDEV_UNREGISTER event

 net/ieee802154/6lowpan.c |   53 +++---
 1 files changed, 45 insertions(+), 8 deletions(-)


--
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
___
Linux-zigbee-devel mailing list
Linux-zigbee-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-zigbee-devel


[Linux-zigbee-devel] [PATCH v2 2/2] 6lowpan: handle NETDEV_UNREGISTER event

2012-08-29 Thread Alan Ott
Before, it was impossible to remove a wpan device which had lowpan
attached to it.

Signed-off-by: Alan Ott 
---
 net/ieee802154/6lowpan.c |   44 +---
 1 files changed, 37 insertions(+), 7 deletions(-)

diff --git a/net/ieee802154/6lowpan.c b/net/ieee802154/6lowpan.c
index ce33b02..fb41e08 100644
--- a/net/ieee802154/6lowpan.c
+++ b/net/ieee802154/6lowpan.c
@@ -1063,12 +1063,6 @@ out:
return (err < 0 ? NETDEV_TX_BUSY : NETDEV_TX_OK);
 }
 
-static void lowpan_dev_free(struct net_device *dev)
-{
-   dev_put(lowpan_dev_info(dev)->real_dev);
-   free_netdev(dev);
-}
-
 static struct wpan_phy *lowpan_get_phy(const struct net_device *dev)
 {
struct net_device *real_dev = lowpan_dev_info(dev)->real_dev;
@@ -1118,7 +1112,7 @@ static void lowpan_setup(struct net_device *dev)
dev->netdev_ops = &lowpan_netdev_ops;
dev->header_ops = &lowpan_header_ops;
dev->ml_priv= &lowpan_mlme;
-   dev->destructor = lowpan_dev_free;
+   dev->destructor = free_netdev;
 }
 
 static int lowpan_validate(struct nlattr *tb[], struct nlattr *data[])
@@ -1244,6 +1238,34 @@ static inline void __init lowpan_netlink_fini(void)
rtnl_link_unregister(&lowpan_link_ops);
 }
 
+static int lowpan_device_event(struct notifier_block *unused,
+   unsigned long event,
+   void *ptr)
+{
+   struct net_device *dev = ptr;
+   LIST_HEAD(del_list);
+   struct lowpan_dev_record *entry, *tmp;
+
+   if (dev->type != ARPHRD_IEEE802154)
+   goto out;
+
+   if (event == NETDEV_UNREGISTER) {
+   list_for_each_entry_safe(entry, tmp, &lowpan_devices, list) {
+   if (lowpan_dev_info(entry->ldev)->real_dev == dev)
+   lowpan_dellink(entry->ldev, &del_list);
+   }
+
+   unregister_netdevice_many(&del_list);
+   };
+
+out:
+   return NOTIFY_DONE;
+}
+
+static struct notifier_block lowpan_dev_notifier = {
+   .notifier_call = lowpan_device_event,
+};
+
 static struct packet_type lowpan_packet_type = {
.type = __constant_htons(ETH_P_IEEE802154),
.func = lowpan_rcv,
@@ -1258,6 +1280,12 @@ static int __init lowpan_init_module(void)
goto out;
 
dev_add_pack(&lowpan_packet_type);
+
+   err = register_netdevice_notifier(&lowpan_dev_notifier);
+   if (err < 0) {
+   dev_remove_pack(&lowpan_packet_type);
+   lowpan_netlink_fini();
+   }
 out:
return err;
 }
@@ -1270,6 +1298,8 @@ static void __exit lowpan_cleanup_module(void)
 
dev_remove_pack(&lowpan_packet_type);
 
+   unregister_netdevice_notifier(&lowpan_dev_notifier);
+
/* Now 6lowpan packet_type is removed, so no new fragments are
 * expected on RX, therefore that's the time to clean incomplete
 * fragments.
-- 
1.7.0.4


--
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
___
Linux-zigbee-devel mailing list
Linux-zigbee-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-zigbee-devel


[Linux-zigbee-devel] [PATCH v2 1/2] 6lowpan: Make a copy of skb's delivered to 6lowpan

2012-08-29 Thread Alan Ott
Since lowpan_process_data() modifies the skb (by calling skb_pull()), we
need our own copy so that it doesn't affect the data received by other
protcols (in this case, af_ieee802154).

Signed-off-by: Alan Ott 
---
 net/ieee802154/6lowpan.c |9 -
 1 files changed, 8 insertions(+), 1 deletions(-)

diff --git a/net/ieee802154/6lowpan.c b/net/ieee802154/6lowpan.c
index 6a09522..ce33b02 100644
--- a/net/ieee802154/6lowpan.c
+++ b/net/ieee802154/6lowpan.c
@@ -1133,6 +1133,8 @@ static int lowpan_validate(struct nlattr *tb[], struct 
nlattr *data[])
 static int lowpan_rcv(struct sk_buff *skb, struct net_device *dev,
struct packet_type *pt, struct net_device *orig_dev)
 {
+   struct sk_buff *local_skb;
+
if (!netif_running(dev))
goto drop;
 
@@ -1144,7 +1146,12 @@ static int lowpan_rcv(struct sk_buff *skb, struct 
net_device *dev,
case LOWPAN_DISPATCH_IPHC:  /* ipv6 datagram */
case LOWPAN_DISPATCH_FRAG1: /* first fragment header */
case LOWPAN_DISPATCH_FRAGN: /* next fragments headers */
-   lowpan_process_data(skb);
+   local_skb = skb_copy(skb, GFP_ATOMIC);
+   if (!local_skb)
+   goto drop;
+   lowpan_process_data(local_skb);
+
+   kfree_skb(skb);
break;
default:
break;
-- 
1.7.0.4


--
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
___
Linux-zigbee-devel mailing list
Linux-zigbee-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-zigbee-devel


[Linux-zigbee-devel] [PATCH v6 0/1] Driver for Microchip MRF24J40

2012-08-29 Thread Alan Ott
This is a driver for the Microchip MRF24J40 802.15.4 transceiver.

Versions 1-5 and discussion can be found on the archives of the linux-zigbee
mailing list:

http://www.mail-archive.com/linux-zigbee-devel@lists.sourceforge.net/msg01014.html

Alan Ott (1):
  ieee802154: MRF24J40 driver

 drivers/ieee802154/Kconfig|   11 +
 drivers/ieee802154/Makefile   |1 +
 drivers/ieee802154/mrf24j40.c |  767 +
 3 files changed, 779 insertions(+), 0 deletions(-)
 create mode 100644 drivers/ieee802154/mrf24j40.c


--
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
___
Linux-zigbee-devel mailing list
Linux-zigbee-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-zigbee-devel


[Linux-zigbee-devel] [PATCH v6 1/1] ieee802154: MRF24J40 driver

2012-08-29 Thread Alan Ott
Driver for the Microchip MRF24J40 802.15.4 WPAN module.

Signed-off-by: Alan Ott 
---
 drivers/ieee802154/Kconfig|   11 +
 drivers/ieee802154/Makefile   |1 +
 drivers/ieee802154/mrf24j40.c |  767 +
 3 files changed, 779 insertions(+), 0 deletions(-)
 create mode 100644 drivers/ieee802154/mrf24j40.c

diff --git a/drivers/ieee802154/Kconfig b/drivers/ieee802154/Kconfig
index 1fc4eef..08ae465 100644
--- a/drivers/ieee802154/Kconfig
+++ b/drivers/ieee802154/Kconfig
@@ -34,3 +34,14 @@ config IEEE802154_AT86RF230
 depends on IEEE802154_DRIVERS && MAC802154
 tristate "AT86RF230/231 transceiver driver"
 depends on SPI
+
+config IEEE802154_MRF24J40
+   tristate "Microchip MRF24J40 transceiver driver"
+   depends on IEEE802154_DRIVERS && MAC802154
+   depends on SPI
+   ---help---
+ Say Y here to enable the MRF24J20 SPI 802.15.4 wireless
+ controller.
+
+ This driver can also be built as a module. To do so, say M here.
+ the module will be called 'mrf24j40'.
diff --git a/drivers/ieee802154/Makefile b/drivers/ieee802154/Makefile
index 4f4371d..abb0c08 100644
--- a/drivers/ieee802154/Makefile
+++ b/drivers/ieee802154/Makefile
@@ -1,3 +1,4 @@
 obj-$(CONFIG_IEEE802154_FAKEHARD) += fakehard.o
 obj-$(CONFIG_IEEE802154_FAKELB) += fakelb.o
 obj-$(CONFIG_IEEE802154_AT86RF230) += at86rf230.o
+obj-$(CONFIG_IEEE802154_MRF24J40) += mrf24j40.o
diff --git a/drivers/ieee802154/mrf24j40.c b/drivers/ieee802154/mrf24j40.c
new file mode 100644
index 000..0e53d4f
--- /dev/null
+++ b/drivers/ieee802154/mrf24j40.c
@@ -0,0 +1,767 @@
+/*
+ * Driver for Microchip MRF24J40 802.15.4 Wireless-PAN Networking controller
+ *
+ * Copyright (C) 2012 Alan Ott 
+ *Signal 11 Software
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * 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., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+
+/* MRF24J40 Short Address Registers */
+#define REG_RXMCR0x00  /* Receive MAC control */
+#define REG_PANIDL   0x01  /* PAN ID (low) */
+#define REG_PANIDH   0x02  /* PAN ID (high) */
+#define REG_SADRL0x03  /* Short address (low) */
+#define REG_SADRH0x04  /* Short address (high) */
+#define REG_EADR00x05  /* Long address (low) (high is EADR7) */
+#define REG_TXMCR0x11  /* Transmit MAC control */
+#define REG_PACON0   0x16  /* Power Amplifier Control */
+#define REG_PACON1   0x17  /* Power Amplifier Control */
+#define REG_PACON2   0x18  /* Power Amplifier Control */
+#define REG_TXNCON   0x1B  /* Transmit Normal FIFO Control */
+#define REG_TXSTAT   0x24  /* TX MAC Status Register */
+#define REG_SOFTRST  0x2A  /* Soft Reset */
+#define REG_TXSTBL   0x2E  /* TX Stabilization */
+#define REG_INTSTAT  0x31  /* Interrupt Status */
+#define REG_INTCON   0x32  /* Interrupt Control */
+#define REG_RFCTL0x36  /* RF Control Mode Register */
+#define REG_BBREG1   0x39  /* Baseband Registers */
+#define REG_BBREG2   0x3A  /* */
+#define REG_BBREG6   0x3E  /* */
+#define REG_CCAEDTH  0x3F  /* Energy Detection Threshold */
+
+/* MRF24J40 Long Address Registers */
+#define REG_RFCON0 0x200  /* RF Control Registers */
+#define REG_RFCON1 0x201
+#define REG_RFCON2 0x202
+#define REG_RFCON3 0x203
+#define REG_RFCON5 0x205
+#define REG_RFCON6 0x206
+#define REG_RFCON7 0x207
+#define REG_RFCON8 0x208
+#define REG_RSSI   0x210
+#define REG_SLPCON00x211  /* Sleep Clock Control Registers */
+#define REG_SLPCON10x220
+#define REG_WAKETIMEL  0x222  /* Wake-up Time Match Value Low */
+#define REG_WAKETIMEH  0x223  /* Wake-up Time Match Value High */
+#define REG_RX_FIFO0x300  /* Receive FIFO */
+
+/* Device configuration: Only channels 11-26 on page 0 are supported. */
+#define MRF24J40_CHAN_MIN 11
+#define MRF24J40_CHAN_MAX 26
+#define CHANNEL_MASK (((u32)1 << (MRF24J40_CHAN_MAX + 1)) \
+ - ((u32)1 << MRF24J40_CHAN_MIN))
+
+#define TX_FIFO_SIZE 128 /* From datasheet */
+#define RX_FIFO_SIZE 144 /* From datasheet */
+#define SET_CHANNEL_DELAY_US 192 /* From datasheet */
+
+/* Device Private Data */
+struct mrf24j40 {
+   struct spi_device *spi;
+   struct ieee802154_dev *dev;
+
+   struct mutex buffer_mutex; /* only used to protect buf */
+   struct completion tx_complete;
+   st