aboutsummaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
authorDavid S. Miller <davem@davemloft.net>2009-11-06 20:57:51 -0500
committerDavid S. Miller <davem@davemloft.net>2009-11-06 20:57:51 -0500
commit10d626f4f444b419046309c10f25515adbffcb16 (patch)
tree216b16bf872bf3b077895443919de0e487da2ea3 /drivers
parent62d83681e53fd87c91927018cfe5ba9f9e8109a3 (diff)
parentbb1cafb8fc414d6dbe933f888df6540c2ef02101 (diff)
Merge branch 'for-next' of git://git.kernel.org/pub/scm/linux/kernel/git/lowpan/lowpan
Diffstat (limited to 'drivers')
-rw-r--r--drivers/ieee802154/fakehard.c59
1 files changed, 47 insertions, 12 deletions
diff --git a/drivers/ieee802154/fakehard.c b/drivers/ieee802154/fakehard.c
index 96a2959ce877..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
35struct 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)
36{ 40{
37 return container_of(dev->dev.parent, struct wpan_phy, dev); 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)
55{
56 struct wpan_phy *phy = fake_to_phy(dev);
57 return to_phy(get_device(&phy->dev));
38} 58}
39 59
40/** 60/**
@@ -43,7 +63,7 @@ struct wpan_phy *net_to_phy(struct net_device *dev)
43 * 63 *
44 * Return the ID of the PAN from the PIB. 64 * Return the ID of the PAN from the PIB.
45 */ 65 */
46static u16 fake_get_pan_id(struct net_device *dev) 66static u16 fake_get_pan_id(const struct net_device *dev)
47{ 67{
48 BUG_ON(dev->type != ARPHRD_IEEE802154); 68 BUG_ON(dev->type != ARPHRD_IEEE802154);
49 69
@@ -58,7 +78,7 @@ static u16 fake_get_pan_id(struct net_device *dev)
58 * device. If the device has not yet had a short address assigned 78 * device. If the device has not yet had a short address assigned
59 * then this should return 0xFFFF to indicate a lack of association. 79 * then this should return 0xFFFF to indicate a lack of association.
60 */ 80 */
61static u16 fake_get_short_addr(struct net_device *dev) 81static u16 fake_get_short_addr(const struct net_device *dev)
62{ 82{
63 BUG_ON(dev->type != ARPHRD_IEEE802154); 83 BUG_ON(dev->type != ARPHRD_IEEE802154);
64 84
@@ -78,7 +98,7 @@ static u16 fake_get_short_addr(struct net_device *dev)
78 * Note: This is in section 7.2.1.2 of the IEEE 802.15.4-2006 98 * Note: This is in section 7.2.1.2 of the IEEE 802.15.4-2006
79 * document. 99 * document.
80 */ 100 */
81static u8 fake_get_dsn(struct net_device *dev) 101static u8 fake_get_dsn(const struct net_device *dev)
82{ 102{
83 BUG_ON(dev->type != ARPHRD_IEEE802154); 103 BUG_ON(dev->type != ARPHRD_IEEE802154);
84 104
@@ -98,7 +118,7 @@ static u8 fake_get_dsn(struct net_device *dev)
98 * Note: This is in section 7.2.1.2 of the IEEE 802.15.4-2006 118 * Note: This is in section 7.2.1.2 of the IEEE 802.15.4-2006
99 * document. 119 * document.
100 */ 120 */
101static u8 fake_get_bsn(struct net_device *dev) 121static u8 fake_get_bsn(const struct net_device *dev)
102{ 122{
103 BUG_ON(dev->type != ARPHRD_IEEE802154); 123 BUG_ON(dev->type != ARPHRD_IEEE802154);
104 124
@@ -121,7 +141,7 @@ static u8 fake_get_bsn(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;
@@ -356,12 +379,23 @@ static int __devinit ieee802154fake_probe(struct platform_device *pdev)
356 dev->addr_len); 379 dev->addr_len);
357 memcpy(dev->perm_addr, dev->dev_addr, dev->addr_len); 380 memcpy(dev->perm_addr, dev->dev_addr, dev->addr_len);
358 381
359 phy->channels_supported = (1 << 27) - 1; 382 /*
383 * For now we'd like to emulate 2.4 GHz-only device,
384 * both O-QPSK and CSS
385 */
386 /* 2.4 GHz O-QPSK 802.15.4-2003 */
387 phy->channels_supported[0] |= 0x7FFF800;
388 /* 2.4 GHz CSS 802.15.4a-2007 */
389 phy->channels_supported[3] |= 0x3fff;
390
360 phy->transmit_power = 0xbf; 391 phy->transmit_power = 0xbf;
361 392
362 dev->netdev_ops = &fake_ops; 393 dev->netdev_ops = &fake_ops;
363 dev->ml_priv = &fake_mlme; 394 dev->ml_priv = &fake_mlme;
364 395
396 priv = netdev_priv(dev);
397 priv->phy = phy;
398
365 /* 399 /*
366 * 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
367 * name allocation. 401 * name allocation.
@@ -372,11 +406,12 @@ static int __devinit ieee802154fake_probe(struct platform_device *pdev)
372 goto out; 406 goto out;
373 } 407 }
374 408
409 wpan_phy_set_dev(phy, &pdev->dev);
375 SET_NETDEV_DEV(dev, &phy->dev); 410 SET_NETDEV_DEV(dev, &phy->dev);
376 411
377 platform_set_drvdata(pdev, dev); 412 platform_set_drvdata(pdev, dev);
378 413
379 err = wpan_phy_register(&pdev->dev, phy); 414 err = wpan_phy_register(phy);
380 if (err) 415 if (err)
381 goto out; 416 goto out;
382 417