From: Dmitry Eremin-Solenikov <dbaryshkov@gmail.com>
To: linux-kernel@vger.kernel.org
Cc: netdev@vger.kernel.org, linux-wireless@vger.kernel.org,
slapin@ossfans.org, maxim.osipov@siemens.com,
dmitry.baryshkov@siemens.com, oliver.fendt@siemens.com,
Dmitry Eremin-Solenikov <dbaryshkov@gmail.com>
Subject: [PATCH 05/10] ieee802154: add simple HardMAC driver sample
Date: Mon, 1 Jun 2009 18:54:46 +0400 [thread overview]
Message-ID: <1243868091-5315-6-git-send-email-dbaryshkov@gmail.com> (raw)
In-Reply-To: <1243868091-5315-5-git-send-email-dbaryshkov@gmail.com>
fakehard is a really simple driver implementing only necessary
callbacks and serves the role of an example of driver for HardMAC
IEEE 802.15.4 device.
Signed-off-by: Dmitry Eremin-Solenikov <dbaryshkov@gmail.com>
Signed-off-by: Sergey Lapin <slapin@ossfans.org>
---
drivers/Makefile | 1 +
drivers/ieee802154/Kconfig | 23 ++++
drivers/ieee802154/Makefile | 3 +
drivers/ieee802154/fakehard.c | 253 +++++++++++++++++++++++++++++++++++++++++
drivers/net/Kconfig | 2 +
5 files changed, 282 insertions(+), 0 deletions(-)
create mode 100644 drivers/ieee802154/Kconfig
create mode 100644 drivers/ieee802154/Makefile
create mode 100644 drivers/ieee802154/fakehard.c
diff --git a/drivers/Makefile b/drivers/Makefile
index 1266ead..9e7d4e5 100644
--- a/drivers/Makefile
+++ b/drivers/Makefile
@@ -107,3 +107,4 @@ obj-$(CONFIG_SSB) += ssb/
obj-$(CONFIG_VIRTIO) += virtio/
obj-$(CONFIG_STAGING) += staging/
obj-y += platform/
+obj-y += ieee802154/
diff --git a/drivers/ieee802154/Kconfig b/drivers/ieee802154/Kconfig
new file mode 100644
index 0000000..8610620
--- /dev/null
+++ b/drivers/ieee802154/Kconfig
@@ -0,0 +1,23 @@
+menuconfig IEEE802154_DRIVERS
+ bool "IEEE 802.15.4 drivers"
+ depends on NETDEVICES && IEEE802154
+ default y
+ ---help---
+ Say Y here to get to see options for IEEE 802.15.4 Low-Rate
+ Wireless Personal Area Network device drivers. This option alone
+ does not add any kernel code.
+
+ If you say N, all options in this submenu will be skipped and disabled.
+
+config IEEE802154_FAKEHARD
+ tristate "Fake LR-WPAN driver with several interconnected devices"
+ depends on IEEE802154_DRIVERS
+ ---help---
+ Say Y here to enable the fake driver that serves as an example
+ of HardMAC device driver.
+
+ This driver can also be built as a module. To do so say M here.
+ The module will be called 'fakehard'.
+
+endif
+
diff --git a/drivers/ieee802154/Makefile b/drivers/ieee802154/Makefile
new file mode 100644
index 0000000..e0e8e1a
--- /dev/null
+++ b/drivers/ieee802154/Makefile
@@ -0,0 +1,3 @@
+obj-$(CONFIG_IEEE802154_FAKEHARD) += fakehard.o
+
+EXTRA_CFLAGS += -DDEBUG -DCONFIG_FFD
diff --git a/drivers/ieee802154/fakehard.c b/drivers/ieee802154/fakehard.c
new file mode 100644
index 0000000..e4c08ea
--- /dev/null
+++ b/drivers/ieee802154/fakehard.c
@@ -0,0 +1,253 @@
+/*
+ * Sample driver for HardMAC IEEE 802.15.4 devices
+ *
+ * Copyright (C) 2009 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.
+ *
+ * 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.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Written by:
+ * Dmitry Eremin-Solenikov <dmitry.baryshkov@siemens.com>
+ */
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/platform_device.h>
+#include <linux/netdevice.h>
+#include <linux/skbuff.h>
+#include <linux/if_arp.h>
+
+#include <net/ieee802154/af_ieee802154.h>
+#include <net/ieee802154/netdevice.h>
+
+static u16 fake_get_pan_id(struct net_device *dev)
+{
+ BUG_ON(dev->type != ARPHRD_IEEE802154);
+
+ return 0xeba1;
+}
+
+static u16 fake_get_short_addr(struct net_device *dev)
+{
+ BUG_ON(dev->type != ARPHRD_IEEE802154);
+
+ return 0x1;
+}
+
+static u8 fake_get_dsn(struct net_device *dev)
+{
+ BUG_ON(dev->type != ARPHRD_IEEE802154);
+
+ return 0x00; /* DSN are implemented in HW, so return just 0 */
+}
+
+static u8 fake_get_bsn(struct net_device *dev)
+{
+ BUG_ON(dev->type != ARPHRD_IEEE802154);
+
+ return 0x00; /* BSN are implemented in HW, so return just 0 */
+}
+
+static int fake_assoc_req(struct net_device *dev, struct ieee802154_addr *addr, u8 channel, u8 cap)
+{
+ return 0;
+}
+
+static int fake_assoc_resp(struct net_device *dev, struct ieee802154_addr *addr, u16 short_addr, u8 status)
+{
+ return 0;
+}
+
+static int fake_disassoc_req(struct net_device *dev, struct ieee802154_addr *addr, u8 reason)
+{
+ return 0;
+}
+
+static int fake_start_req(struct net_device *dev, struct ieee802154_addr *addr,
+ u8 channel,
+ u8 bcn_ord, u8 sf_ord, u8 pan_coord, u8 blx,
+ u8 coord_realign)
+{
+ return 0;
+}
+
+static int fake_scan_req(struct net_device *dev, u8 type, u32 channels, u8 duration)
+{
+ return 0;
+}
+
+static struct ieee802154_mlme_ops fake_mlme = {
+ .assoc_req = fake_assoc_req,
+ .assoc_resp = fake_assoc_resp,
+ .disassoc_req = fake_disassoc_req,
+ .start_req = fake_start_req,
+ .scan_req = fake_scan_req,
+
+ .get_pan_id = fake_get_pan_id,
+ .get_short_addr = fake_get_short_addr,
+ .get_dsn = fake_get_dsn,
+ .get_bsn = fake_get_bsn,
+};
+
+static int ieee802154_fake_open(struct net_device *dev)
+{
+ netif_start_queue(dev);
+ return 0;
+}
+
+static int ieee802154_fake_close(struct net_device *dev)
+{
+ netif_stop_queue(dev);
+ return 0;
+}
+
+static int ieee802154_fake_xmit(struct sk_buff *skb, struct net_device *dev)
+{
+ skb->iif = dev->ifindex;
+ skb->dev = dev;
+ dev->stats.tx_packets++;
+ dev->stats.tx_bytes += skb->len;
+
+ dev->trans_start = jiffies;
+
+ /* FIXME: do hardware work here ... */
+
+ return 0;
+}
+
+
+static int ieee802154_fake_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
+{
+ struct sockaddr_ieee802154 *sa = (struct sockaddr_ieee802154 *)&ifr->ifr_addr;
+ u16 pan_id, short_addr;
+
+ switch (cmd) {
+ case SIOCGIFADDR:
+ /* FIXME: fixed here, get from device IRL */
+ pan_id = fake_get_pan_id(dev);
+ short_addr = fake_get_short_addr(dev);
+ if (pan_id == IEEE802154_PANID_BROADCAST || short_addr == IEEE802154_ADDR_BROADCAST)
+ return -EADDRNOTAVAIL;
+
+ sa->family = AF_IEEE802154;
+ sa->addr.addr_type = IEEE802154_ADDR_SHORT;
+ sa->addr.pan_id = pan_id;
+ sa->addr.short_addr = short_addr;
+ return 0;
+ }
+ return -ENOIOCTLCMD;
+}
+
+static int ieee802154_fake_mac_addr(struct net_device *dev, void *p)
+{
+ return -EBUSY; /* HW address is built into the device */
+}
+
+static const struct net_device_ops fake_ops = {
+ .ndo_open = ieee802154_fake_open,
+ .ndo_stop = ieee802154_fake_close,
+ .ndo_start_xmit = ieee802154_fake_xmit,
+ .ndo_do_ioctl = ieee802154_fake_ioctl,
+ .ndo_set_mac_address = ieee802154_fake_mac_addr,
+};
+
+
+static void ieee802154_fake_setup(struct net_device *dev)
+{
+ dev->addr_len = IEEE802154_ADDR_LEN;
+ memset(dev->broadcast, 0xff, IEEE802154_ADDR_LEN);
+ dev->features = NETIF_F_NO_CSUM;
+ dev->needed_tailroom = 2; /* FCS */
+ dev->mtu = 127;
+ dev->tx_queue_len = 10;
+ dev->type = ARPHRD_IEEE802154;
+ dev->flags = IFF_NOARP | IFF_BROADCAST;
+ dev->watchdog_timeo = 0;
+}
+
+
+static int __devinit ieee802154fake_probe(struct platform_device *pdev)
+{
+ struct net_device *dev = alloc_netdev(0, "hardwpan%d", ieee802154_fake_setup);
+ int err;
+
+ if (!dev)
+ return -ENOMEM;
+
+ memcpy(dev->dev_addr, "\xba\xbe\xca\xfe\xde\xad\xbe\xef", dev->addr_len);
+ memcpy(dev->perm_addr, dev->dev_addr, dev->addr_len);
+
+ dev->netdev_ops = &fake_ops;
+ dev->ml_priv = &fake_mlme;
+
+ /*
+ * If the name is a format string the caller wants us to do a
+ * name allocation.
+ */
+ if (strchr(dev->name, '%')) {
+ err = dev_alloc_name(dev, dev->name);
+ if (err < 0)
+ goto out;
+ }
+
+ SET_NETDEV_DEV(dev, &pdev->dev);
+
+ platform_set_drvdata(pdev, dev);
+
+ err = register_netdevice(dev);
+ if (err < 0)
+ goto out;
+
+
+ dev_info(&pdev->dev, "Added ieee802154 HardMAC hardware\n");
+ return 0;
+
+out:
+ unregister_netdev(dev);
+ return err;
+}
+
+static int __devexit ieee802154fake_remove(struct platform_device *pdev)
+{
+ struct net_device *dev = platform_get_drvdata(pdev);
+ unregister_netdev(dev);
+ free_netdev(dev);
+ return 0;
+}
+
+static struct platform_device *ieee802154fake_dev;
+
+static struct platform_driver ieee802154fake_driver = {
+ .probe = ieee802154fake_probe,
+ .remove = __devexit_p(ieee802154fake_remove),
+ .driver = {
+ .name = "ieee802154hardmac",
+ .owner = THIS_MODULE,
+ },
+};
+
+static __init int fake_init(void)
+{
+ ieee802154fake_dev = platform_device_register_simple("ieee802154hardmac", -1, NULL, 0);
+ return platform_driver_register(&ieee802154fake_driver);
+}
+
+static __exit void fake_exit(void)
+{
+ platform_driver_unregister(&ieee802154fake_driver);
+ platform_device_unregister(ieee802154fake_dev);
+}
+
+module_init(fake_init);
+module_exit(fake_exit);
+MODULE_LICENSE("GPL");
+
diff --git a/drivers/net/Kconfig b/drivers/net/Kconfig
index 214a92d..ec8cf21 100644
--- a/drivers/net/Kconfig
+++ b/drivers/net/Kconfig
@@ -2704,6 +2704,8 @@ source "drivers/net/wan/Kconfig"
source "drivers/atm/Kconfig"
+source "drivers/ieee802154/Kconfig"
+
source "drivers/s390/net/Kconfig"
config XEN_NETDEV_FRONTEND
--
1.6.2.4
next prev parent reply other threads:[~2009-06-01 14:55 UTC|newest]
Thread overview: 46+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-06-01 14:54 [RFC][WIP] IEEE 802.15.4 implementation for Linux v1 Dmitry Eremin-Solenikov
2009-06-01 14:54 ` [PATCH 01/10] crc-itu-t: add bit-reversed calculation Dmitry Eremin-Solenikov
2009-06-01 14:54 ` [PATCH 02/10] Add constants for the ieee 802.15.4/ZigBee stack Dmitry Eremin-Solenikov
2009-06-01 14:54 ` [PATCH 03/10] net: add IEEE 802.15.4 socket family implementation Dmitry Eremin-Solenikov
[not found] ` <1243868091-5315-4-git-send-email-dbaryshkov-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2009-06-01 14:54 ` [PATCH 04/10] net: add NL802154 interface for configuration of 802.15.4 devices Dmitry Eremin-Solenikov
2009-06-01 14:54 ` Dmitry Eremin-Solenikov [this message]
2009-06-01 14:54 ` [PATCH 06/10] mac802154: add a software MAC 802.15.4 implementation Dmitry Eremin-Solenikov
[not found] ` <1243868091-5315-7-git-send-email-dbaryshkov-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2009-06-01 14:54 ` [PATCH 07/10] ieee802154: add virtual loopback driver Dmitry Eremin-Solenikov
[not found] ` <1243868091-5315-8-git-send-email-dbaryshkov-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2009-06-01 14:54 ` [PATCH 08/10] tty_io: export tty_class Dmitry Eremin-Solenikov
[not found] ` <1243868091-5315-9-git-send-email-dbaryshkov-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2009-06-01 14:54 ` [PATCH 09/10] ieee802154: add serial dongle driver Dmitry Eremin-Solenikov
[not found] ` <1243868091-5315-10-git-send-email-dbaryshkov-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2009-06-01 14:54 ` [PATCH 10/10] ieee802154: add at86rf230/rf231 spi driver Dmitry Eremin-Solenikov
[not found] ` <1243868091-5315-11-git-send-email-dbaryshkov-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2009-06-01 16:21 ` Gábor Stefanik
[not found] ` <69e28c910906010921r56cf7017gc858cb7ba819c385-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2009-06-01 20:33 ` Dmitry Eremin-Solenikov
[not found] ` <20090601203348.GC7143-nIupHZaCssqR2kOLt6zJ8ErlnG4Plg33XqFh9Ls21Oc@public.gmane.org>
2009-06-02 8:10 ` Holger Schurig
[not found] ` <200906021010.49613.hs4233-x6+DxXLjN1AJvtFkdXX2Hg4jNU5vUVPG@public.gmane.org>
2009-06-02 8:21 ` Marcel Holtmann
[not found] ` <1243930893.3192.62.camel-bi+AKbBUZKY6gyzm1THtWbp2dZbC/Bob@public.gmane.org>
2009-06-02 8:29 ` Ответ: " Dmitry Eremin-Solenikov
2009-06-02 8:36 ` Marcel Holtmann
2009-06-02 8:46 ` Florian Fainelli
2009-06-02 8:49 ` Maxim Osipov
[not found] ` <6097c490906020149j5d614064ied2a4bfebd13ddb0-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2009-06-02 9:15 ` Holger Schurig
2009-06-02 9:29 ` ?????: " Jonathan Cameron
[not found] ` <4A24F106.5040704-KWPb1pKIrIJaa/9Udqfwiw@public.gmane.org>
2009-06-02 11:42 ` Dmitry Eremin-Solenikov
[not found] ` <1243931809.3192.68.camel-bi+AKbBUZKY6gyzm1THtWbp2dZbC/Bob@public.gmane.org>
2009-06-02 8:52 ` Ответ: " Sergey Lapin
2009-06-01 15:27 ` [PATCH 09/10] ieee802154: add serial dongle driver Alan Cox
2009-06-01 20:29 ` Dmitry Eremin-Solenikov
[not found] ` <20090601202946.GB7143-nIupHZaCssqR2kOLt6zJ8ErlnG4Plg33XqFh9Ls21Oc@public.gmane.org>
2009-06-01 21:52 ` Alan Cox
[not found] ` <20090601225205.1e7e8944-qBU/x9rampVanCEyBjwyrvXRex20P6io@public.gmane.org>
2009-06-02 14:43 ` Sergey Lapin
2009-06-01 15:07 ` [PATCH 08/10] tty_io: export tty_class Alan Cox
2009-06-01 15:10 ` Dmitry Eremin-Solenikov
2009-06-01 15:34 ` Alan Cox
[not found] ` <20090601163418.465be751-qBU/x9rampVanCEyBjwyrvXRex20P6io@public.gmane.org>
2009-06-02 14:22 ` Dmitry Eremin-Solenikov
2009-06-02 14:35 ` Alan Cox
2009-06-05 12:24 ` [PATCH 06/10] mac802154: add a software MAC 802.15.4 implementation Pavel Machek
2009-06-04 0:32 ` [PATCH 03/10] net: add IEEE 802.15.4 socket family implementation Andrew Morton
[not found] ` <20090603173214.6d3997f7.akpm-de/tnXTf+JLsfHDXvbKv3WD2FQJk+8+b@public.gmane.org>
2009-06-04 11:16 ` Dmitry Eremin-Solenikov
[not found] ` <20090604111634.GA28064-nIupHZaCssqR2kOLt6zJ8ErlnG4Plg33XqFh9Ls21Oc@public.gmane.org>
2009-06-04 13:46 ` John W. Linville
[not found] ` <20090604134455.GB2839-2XuSBdqkA4R54TAoqtyWWQ@public.gmane.org>
2009-06-04 14:10 ` Dmitry Eremin-Solenikov
[not found] ` <bc64b4640906040710p5c7c941fi3341599bc3157b79-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2009-06-04 14:15 ` Johannes Berg
2009-06-04 0:05 ` [PATCH 01/10] crc-itu-t: add bit-reversed calculation Andrew Morton
2009-06-05 4:03 ` [RFC][WIP] IEEE 802.15.4 implementation for Linux v1 Jon Smirl
[not found] ` <9e4733910906042103q6c21886cia02d33cb278cef1e-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2009-06-05 4:49 ` Dmitry Eremin-Solenikov
[not found] ` <bc64b4640906042149pb83911bk4e0397da11f9fde6-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2009-06-05 12:58 ` Jon Smirl
2009-06-13 3:21 ` Jon Smirl
[not found] ` <9e4733910906122021k4568df6rd80fb915b64ac12-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2009-06-13 5:37 ` Maxim Osipov
2009-06-13 12:39 ` Jon Smirl
2009-06-21 6:40 ` Pavel Machek
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1243868091-5315-6-git-send-email-dbaryshkov@gmail.com \
--to=dbaryshkov@gmail.com \
--cc=dmitry.baryshkov@siemens.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-wireless@vger.kernel.org \
--cc=maxim.osipov@siemens.com \
--cc=netdev@vger.kernel.org \
--cc=oliver.fendt@siemens.com \
--cc=slapin@ossfans.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).