fakehard: add binding to wpan-phy device
Make fakehard create and maintain wpan-phy node, thus representing it's phy in the sysfs. Signed-off-by: Dmitry Eremin-Solenikov <dbaryshkov@gmail.com>
This commit is contained in:
parent
2bfb1070ba
commit
81f9510381
1 changed files with 46 additions and 6 deletions
|
@ -30,6 +30,12 @@
|
||||||
#include <net/ieee802154_netdev.h>
|
#include <net/ieee802154_netdev.h>
|
||||||
#include <net/ieee802154.h>
|
#include <net/ieee802154.h>
|
||||||
#include <net/nl802154.h>
|
#include <net/nl802154.h>
|
||||||
|
#include <net/wpan-phy.h>
|
||||||
|
|
||||||
|
struct wpan_phy *net_to_phy(struct net_device *dev)
|
||||||
|
{
|
||||||
|
return container_of(dev->dev.parent, struct wpan_phy, dev);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* fake_get_pan_id - Retrieve the PAN ID of the device.
|
* fake_get_pan_id - Retrieve the PAN ID of the device.
|
||||||
|
@ -115,6 +121,12 @@ static u8 fake_get_bsn(struct net_device *dev)
|
||||||
static int fake_assoc_req(struct net_device *dev,
|
static int fake_assoc_req(struct net_device *dev,
|
||||||
struct ieee802154_addr *addr, u8 channel, u8 cap)
|
struct ieee802154_addr *addr, u8 channel, u8 cap)
|
||||||
{
|
{
|
||||||
|
struct wpan_phy *phy = net_to_phy(dev);
|
||||||
|
|
||||||
|
mutex_lock(&phy->pib_lock);
|
||||||
|
phy->current_channel = channel;
|
||||||
|
mutex_unlock(&phy->pib_lock);
|
||||||
|
|
||||||
/* We simply emulate it here */
|
/* We simply emulate it here */
|
||||||
return ieee802154_nl_assoc_confirm(dev, fake_get_short_addr(dev),
|
return ieee802154_nl_assoc_confirm(dev, fake_get_short_addr(dev),
|
||||||
IEEE802154_SUCCESS);
|
IEEE802154_SUCCESS);
|
||||||
|
@ -183,6 +195,12 @@ static int fake_start_req(struct net_device *dev, struct ieee802154_addr *addr,
|
||||||
u8 bcn_ord, u8 sf_ord, u8 pan_coord, u8 blx,
|
u8 bcn_ord, u8 sf_ord, u8 pan_coord, u8 blx,
|
||||||
u8 coord_realign)
|
u8 coord_realign)
|
||||||
{
|
{
|
||||||
|
struct wpan_phy *phy = net_to_phy(dev);
|
||||||
|
|
||||||
|
mutex_lock(&phy->pib_lock);
|
||||||
|
phy->current_channel = channel;
|
||||||
|
mutex_unlock(&phy->pib_lock);
|
||||||
|
|
||||||
/* We don't emulate beacons here at all, so START should fail */
|
/* We don't emulate beacons here at all, so START should fail */
|
||||||
ieee802154_nl_start_confirm(dev, IEEE802154_INVALID_PARAMETER);
|
ieee802154_nl_start_confirm(dev, IEEE802154_INVALID_PARAMETER);
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -290,6 +308,14 @@ static const struct net_device_ops fake_ops = {
|
||||||
.ndo_set_mac_address = ieee802154_fake_mac_addr,
|
.ndo_set_mac_address = ieee802154_fake_mac_addr,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static void ieee802154_fake_destruct(struct net_device *dev)
|
||||||
|
{
|
||||||
|
struct wpan_phy *phy = net_to_phy(dev);
|
||||||
|
|
||||||
|
wpan_phy_unregister(phy);
|
||||||
|
free_netdev(dev);
|
||||||
|
wpan_phy_free(phy);
|
||||||
|
}
|
||||||
|
|
||||||
static void ieee802154_fake_setup(struct net_device *dev)
|
static void ieee802154_fake_setup(struct net_device *dev)
|
||||||
{
|
{
|
||||||
|
@ -302,22 +328,34 @@ static void ieee802154_fake_setup(struct net_device *dev)
|
||||||
dev->type = ARPHRD_IEEE802154;
|
dev->type = ARPHRD_IEEE802154;
|
||||||
dev->flags = IFF_NOARP | IFF_BROADCAST;
|
dev->flags = IFF_NOARP | IFF_BROADCAST;
|
||||||
dev->watchdog_timeo = 0;
|
dev->watchdog_timeo = 0;
|
||||||
|
dev->destructor = ieee802154_fake_destruct;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static int __devinit ieee802154fake_probe(struct platform_device *pdev)
|
static int __devinit ieee802154fake_probe(struct platform_device *pdev)
|
||||||
{
|
{
|
||||||
struct net_device *dev =
|
struct net_device *dev;
|
||||||
alloc_netdev(0, "hardwpan%d", ieee802154_fake_setup);
|
struct wpan_phy *phy = wpan_phy_alloc(0);
|
||||||
int err;
|
int err;
|
||||||
|
|
||||||
if (!dev)
|
if (!phy)
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
|
|
||||||
|
dev = alloc_netdev(0, "hardwpan%d", ieee802154_fake_setup);
|
||||||
|
if (!dev) {
|
||||||
|
wpan_phy_free(phy);
|
||||||
|
return -ENOMEM;
|
||||||
|
}
|
||||||
|
|
||||||
|
phy->dev.platform_data = dev;
|
||||||
|
|
||||||
memcpy(dev->dev_addr, "\xba\xbe\xca\xfe\xde\xad\xbe\xef",
|
memcpy(dev->dev_addr, "\xba\xbe\xca\xfe\xde\xad\xbe\xef",
|
||||||
dev->addr_len);
|
dev->addr_len);
|
||||||
memcpy(dev->perm_addr, dev->dev_addr, dev->addr_len);
|
memcpy(dev->perm_addr, dev->dev_addr, dev->addr_len);
|
||||||
|
|
||||||
|
phy->channels_supported = (1 << 27) - 1;
|
||||||
|
phy->transmit_power = 0xbf;
|
||||||
|
|
||||||
dev->netdev_ops = &fake_ops;
|
dev->netdev_ops = &fake_ops;
|
||||||
dev->ml_priv = &fake_mlme;
|
dev->ml_priv = &fake_mlme;
|
||||||
|
|
||||||
|
@ -331,15 +369,18 @@ static int __devinit ieee802154fake_probe(struct platform_device *pdev)
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
SET_NETDEV_DEV(dev, &pdev->dev);
|
SET_NETDEV_DEV(dev, &phy->dev);
|
||||||
|
|
||||||
platform_set_drvdata(pdev, dev);
|
platform_set_drvdata(pdev, dev);
|
||||||
|
|
||||||
|
err = wpan_phy_register(&pdev->dev, phy);
|
||||||
|
if (err)
|
||||||
|
goto out;
|
||||||
|
|
||||||
err = register_netdev(dev);
|
err = register_netdev(dev);
|
||||||
if (err < 0)
|
if (err < 0)
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
|
|
||||||
dev_info(&pdev->dev, "Added ieee802154 HardMAC hardware\n");
|
dev_info(&pdev->dev, "Added ieee802154 HardMAC hardware\n");
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
|
@ -352,7 +393,6 @@ static int __devexit ieee802154fake_remove(struct platform_device *pdev)
|
||||||
{
|
{
|
||||||
struct net_device *dev = platform_get_drvdata(pdev);
|
struct net_device *dev = platform_get_drvdata(pdev);
|
||||||
unregister_netdev(dev);
|
unregister_netdev(dev);
|
||||||
free_netdev(dev);
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue