aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/ieee802154
diff options
context:
space:
mode:
authorDmitry Eremin-Solenikov <dbaryshkov@gmail.com>2009-11-04 09:53:40 -0500
committerDmitry Eremin-Solenikov <dbaryshkov@gmail.com>2009-11-06 06:32:20 -0500
commit405cd39f331826d344f5f55bac5dbbc10a1c2813 (patch)
tree385f46653baae966ce0917cc3a4a8f5ebb5affc1 /drivers/ieee802154
parent42723448b8bacf60c96812196d7725d8d605d0c4 (diff)
fakehard: mlme_ops->get_phy implementation
Signed-off-by: Dmitry Eremin-Solenikov <dbaryshkov@gmail.com>
Diffstat (limited to 'drivers/ieee802154')
-rw-r--r--drivers/ieee802154/fakehard.c38
1 files changed, 32 insertions, 6 deletions
diff --git a/drivers/ieee802154/fakehard.c b/drivers/ieee802154/fakehard.c
index 70a9f9c72fa7..f877f13e3ab3 100644
--- a/drivers/ieee802154/fakehard.c
+++ b/drivers/ieee802154/fakehard.c
@@ -32,9 +32,29 @@
32#include <net/nl802154.h> 32#include <net/nl802154.h>
33#include <net/wpan-phy.h> 33#include <net/wpan-phy.h>
34 34
35static struct wpan_phy *net_to_phy(struct net_device *dev) 35struct fakehard_priv {
36 struct wpan_phy *phy;
37};
38
39static struct wpan_phy *fake_to_phy(const struct net_device *dev)
40{
41 struct fakehard_priv *priv = netdev_priv(dev);
42 return priv->phy;
43}
44
45/**
46 * fake_get_phy - Return a phy corresponding to this device.
47 * @dev: The network device for which to return the wan-phy object
48 *
49 * This function returns a wpan-phy object corresponding to the passed
50 * network device. Reference counter for wpan-phy object is incremented,
51 * so when the wpan-phy isn't necessary, you should drop the reference
52 * via @wpan_phy_put() call.
53 */
54static struct wpan_phy *fake_get_phy(const struct net_device *dev)
36{ 55{
37 return container_of(dev->dev.parent, struct wpan_phy, dev); 56 struct wpan_phy *phy = fake_to_phy(dev);
57 return to_phy(get_device(&phy->dev));
38} 58}
39 59
40/** 60/**
@@ -121,7 +141,7 @@ static u8 fake_get_bsn(const struct net_device *dev)
121static int fake_assoc_req(struct net_device *dev, 141static int fake_assoc_req(struct net_device *dev,
122 struct ieee802154_addr *addr, u8 channel, u8 page, u8 cap) 142 struct ieee802154_addr *addr, u8 channel, u8 page, u8 cap)
123{ 143{
124 struct wpan_phy *phy = net_to_phy(dev); 144 struct wpan_phy *phy = fake_to_phy(dev);
125 145
126 mutex_lock(&phy->pib_lock); 146 mutex_lock(&phy->pib_lock);
127 phy->current_channel = channel; 147 phy->current_channel = channel;
@@ -196,7 +216,7 @@ static int fake_start_req(struct net_device *dev, struct ieee802154_addr *addr,
196 u8 bcn_ord, u8 sf_ord, u8 pan_coord, u8 blx, 216 u8 bcn_ord, u8 sf_ord, u8 pan_coord, u8 blx,
197 u8 coord_realign) 217 u8 coord_realign)
198{ 218{
199 struct wpan_phy *phy = net_to_phy(dev); 219 struct wpan_phy *phy = fake_to_phy(dev);
200 220
201 mutex_lock(&phy->pib_lock); 221 mutex_lock(&phy->pib_lock);
202 phy->current_channel = channel; 222 phy->current_channel = channel;
@@ -239,6 +259,8 @@ static struct ieee802154_mlme_ops fake_mlme = {
239 .start_req = fake_start_req, 259 .start_req = fake_start_req,
240 .scan_req = fake_scan_req, 260 .scan_req = fake_scan_req,
241 261
262 .get_phy = fake_get_phy,
263
242 .get_pan_id = fake_get_pan_id, 264 .get_pan_id = fake_get_pan_id,
243 .get_short_addr = fake_get_short_addr, 265 .get_short_addr = fake_get_short_addr,
244 .get_dsn = fake_get_dsn, 266 .get_dsn = fake_get_dsn,
@@ -313,7 +335,7 @@ static const struct net_device_ops fake_ops = {
313 335
314static void ieee802154_fake_destruct(struct net_device *dev) 336static void ieee802154_fake_destruct(struct net_device *dev)
315{ 337{
316 struct wpan_phy *phy = net_to_phy(dev); 338 struct wpan_phy *phy = fake_to_phy(dev);
317 339
318 wpan_phy_unregister(phy); 340 wpan_phy_unregister(phy);
319 free_netdev(dev); 341 free_netdev(dev);
@@ -338,13 +360,14 @@ static void ieee802154_fake_setup(struct net_device *dev)
338static int __devinit ieee802154fake_probe(struct platform_device *pdev) 360static int __devinit ieee802154fake_probe(struct platform_device *pdev)
339{ 361{
340 struct net_device *dev; 362 struct net_device *dev;
363 struct fakehard_priv *priv;
341 struct wpan_phy *phy = wpan_phy_alloc(0); 364 struct wpan_phy *phy = wpan_phy_alloc(0);
342 int err; 365 int err;
343 366
344 if (!phy) 367 if (!phy)
345 return -ENOMEM; 368 return -ENOMEM;
346 369
347 dev = alloc_netdev(0, "hardwpan%d", ieee802154_fake_setup); 370 dev = alloc_netdev(sizeof(struct fakehard_priv), "hardwpan%d", ieee802154_fake_setup);
348 if (!dev) { 371 if (!dev) {
349 wpan_phy_free(phy); 372 wpan_phy_free(phy);
350 return -ENOMEM; 373 return -ENOMEM;
@@ -370,6 +393,9 @@ static int __devinit ieee802154fake_probe(struct platform_device *pdev)
370 dev->netdev_ops = &fake_ops; 393 dev->netdev_ops = &fake_ops;
371 dev->ml_priv = &fake_mlme; 394 dev->ml_priv = &fake_mlme;
372 395
396 priv = netdev_priv(dev);
397 priv->phy = phy;
398
373 /* 399 /*
374 * If the name is a format string the caller wants us to do a 400 * If the name is a format string the caller wants us to do a
375 * name allocation. 401 * name allocation.