forked from torvalds/linux
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
mac802154: allocation of ieee802154 device
An interface to allocate and register ieee802154 compatible device. The allocated device has the following representation in memory: +-----------------------+ | struct wpan_phy | +-----------------------+ | struct mac802154_priv | +-----------------------+ | driver's private data | +-----------------------+ Used by device drivers to register new instance in the stack. Signed-off-by: Alexander Smirnov <[email protected]> Signed-off-by: David S. Miller <[email protected]>
- Loading branch information
1 parent
0afd7ad
commit 1010f54
Showing
7 changed files
with
239 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
config MAC802154 | ||
tristate "Generic IEEE 802.15.4 Soft Networking Stack (mac802154)" | ||
depends on IEEE802154 && EXPERIMENTAL | ||
select CRC_CCITT | ||
---help--- | ||
This option enables the hardware independent IEEE 802.15.4 | ||
networking stack for SoftMAC devices (the ones implementing | ||
only PHY level of IEEE 802.15.4 standard). | ||
|
||
Note: this implementation is neither certified, nor feature | ||
complete! Compatibility with other implementations hasn't | ||
been tested yet! | ||
|
||
If you plan to use HardMAC IEEE 802.15.4 devices, you can | ||
say N here. Alternatievly you can say M to compile it as | ||
module. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
obj-$(CONFIG_MAC802154) += mac802154.o | ||
mac802154-objs := ieee802154_dev.o |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,149 @@ | ||
/* | ||
* Copyright (C) 2007-2012 Siemens AG | ||
* | ||
* Written by: | ||
* Alexander Smirnov <[email protected]> | ||
* | ||
* Based on the code from 'linux-zigbee.sourceforge.net' project. | ||
* | ||
* 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. | ||
*/ | ||
|
||
#include <linux/kernel.h> | ||
#include <linux/module.h> | ||
#include <linux/netdevice.h> | ||
|
||
#include <net/mac802154.h> | ||
#include <net/route.h> | ||
#include <net/wpan-phy.h> | ||
|
||
#include "mac802154.h" | ||
|
||
struct ieee802154_dev * | ||
ieee802154_alloc_device(size_t priv_data_len, struct ieee802154_ops *ops) | ||
{ | ||
struct wpan_phy *phy; | ||
struct mac802154_priv *priv; | ||
size_t priv_size; | ||
|
||
if (!ops || !ops->xmit || !ops->ed || !ops->start || | ||
!ops->stop || !ops->set_channel) { | ||
printk(KERN_ERR | ||
"undefined IEEE802.15.4 device operations\n"); | ||
return NULL; | ||
} | ||
|
||
/* Ensure 32-byte alignment of our private data and hw private data. | ||
* We use the wpan_phy priv data for both our mac802154_priv and for | ||
* the driver's private data | ||
* | ||
* in memory it'll be like this: | ||
* | ||
* +-----------------------+ | ||
* | struct wpan_phy | | ||
* +-----------------------+ | ||
* | struct mac802154_priv | | ||
* +-----------------------+ | ||
* | driver's private data | | ||
* +-----------------------+ | ||
* | ||
* Due to ieee802154 layer isn't aware of driver and MAC structures, | ||
* so lets allign them here. | ||
*/ | ||
|
||
priv_size = ALIGN(sizeof(*priv), NETDEV_ALIGN) + priv_data_len; | ||
|
||
phy = wpan_phy_alloc(priv_size); | ||
if (!phy) { | ||
printk(KERN_ERR | ||
"failure to allocate master IEEE802.15.4 device\n"); | ||
return NULL; | ||
} | ||
|
||
priv = wpan_phy_priv(phy); | ||
priv->hw.phy = priv->phy = phy; | ||
priv->hw.priv = (char *)priv + ALIGN(sizeof(*priv), NETDEV_ALIGN); | ||
priv->ops = ops; | ||
|
||
INIT_LIST_HEAD(&priv->slaves); | ||
mutex_init(&priv->slaves_mtx); | ||
|
||
return &priv->hw; | ||
} | ||
EXPORT_SYMBOL(ieee802154_alloc_device); | ||
|
||
void ieee802154_free_device(struct ieee802154_dev *hw) | ||
{ | ||
struct mac802154_priv *priv = mac802154_to_priv(hw); | ||
|
||
wpan_phy_free(priv->phy); | ||
|
||
mutex_destroy(&priv->slaves_mtx); | ||
} | ||
EXPORT_SYMBOL(ieee802154_free_device); | ||
|
||
int ieee802154_register_device(struct ieee802154_dev *dev) | ||
{ | ||
struct mac802154_priv *priv = mac802154_to_priv(dev); | ||
int rc = -ENOMEM; | ||
|
||
priv->dev_workqueue = | ||
create_singlethread_workqueue(wpan_phy_name(priv->phy)); | ||
if (!priv->dev_workqueue) | ||
goto out; | ||
|
||
wpan_phy_set_dev(priv->phy, priv->hw.parent); | ||
|
||
rc = wpan_phy_register(priv->phy); | ||
if (rc < 0) | ||
goto out_wq; | ||
|
||
rtnl_lock(); | ||
|
||
mutex_lock(&priv->slaves_mtx); | ||
priv->running = MAC802154_DEVICE_RUN; | ||
mutex_unlock(&priv->slaves_mtx); | ||
|
||
rtnl_unlock(); | ||
|
||
return 0; | ||
|
||
out_wq: | ||
destroy_workqueue(priv->dev_workqueue); | ||
out: | ||
return rc; | ||
} | ||
EXPORT_SYMBOL(ieee802154_register_device); | ||
|
||
void ieee802154_unregister_device(struct ieee802154_dev *dev) | ||
{ | ||
struct mac802154_priv *priv = mac802154_to_priv(dev); | ||
|
||
flush_workqueue(priv->dev_workqueue); | ||
destroy_workqueue(priv->dev_workqueue); | ||
|
||
rtnl_lock(); | ||
|
||
mutex_lock(&priv->slaves_mtx); | ||
priv->running = MAC802154_DEVICE_STOPPED; | ||
mutex_unlock(&priv->slaves_mtx); | ||
|
||
rtnl_unlock(); | ||
|
||
wpan_phy_unregister(priv->phy); | ||
} | ||
EXPORT_SYMBOL(ieee802154_unregister_device); | ||
|
||
MODULE_DESCRIPTION("IEEE 802.15.4 implementation"); | ||
MODULE_LICENSE("GPL v2"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/* | ||
* Copyright (C) 2007-2012 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: | ||
* Pavel Smolenskiy <[email protected]> | ||
* Maxim Gorbachyov <[email protected]> | ||
* Dmitry Eremin-Solenikov <[email protected]> | ||
* Alexander Smirnov <[email protected]> | ||
*/ | ||
#ifndef MAC802154_H | ||
#define MAC802154_H | ||
|
||
/* mac802154 device private data */ | ||
struct mac802154_priv { | ||
struct ieee802154_dev hw; | ||
struct ieee802154_ops *ops; | ||
|
||
/* ieee802154 phy */ | ||
struct wpan_phy *phy; | ||
|
||
int open_count; | ||
|
||
/* As in mac80211 slaves list is modified: | ||
* 1) under the RTNL | ||
* 2) protected by slaves_mtx; | ||
* 3) in an RCU manner | ||
* | ||
* So atomic readers can use any of this protection methods. | ||
*/ | ||
struct list_head slaves; | ||
struct mutex slaves_mtx; | ||
|
||
/* This one is used for scanning and other jobs not to be interfered | ||
* with serial driver. | ||
*/ | ||
struct workqueue_struct *dev_workqueue; | ||
|
||
/* SoftMAC device is registered and running. One can add subinterfaces. | ||
* This flag should be modified under slaves_mtx and RTNL, so you can | ||
* read them using any of protection methods. | ||
*/ | ||
bool running; | ||
}; | ||
|
||
#define MAC802154_DEVICE_STOPPED 0x00 | ||
#define MAC802154_DEVICE_RUN 0x01 | ||
|
||
#define mac802154_to_priv(_hw) container_of(_hw, struct mac802154_priv, hw) | ||
|
||
#endif /* MAC802154_H */ |