aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/ieee802154
diff options
context:
space:
mode:
authorDmitry Eremin-Solenikov <dbaryshkov@gmail.com>2009-08-19 10:56:57 -0400
committerDmitry Eremin-Solenikov <dbaryshkov@gmail.com>2009-08-19 15:08:21 -0400
commit81f9510381ee43205564063f2e8650672b11d453 (patch)
treed4f95da600caa4b488d40d54ca1e211ea61c371f /drivers/ieee802154
parent2bfb1070ba1fdb8cbc2b0b9ff61a3b0701ab40de (diff)
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>
Diffstat (limited to 'drivers/ieee802154')
-rw-r--r--drivers/ieee802154/fakehard.c52
1 files changed, 46 insertions, 6 deletions
diff --git a/drivers/ieee802154/fakehard.c b/drivers/ieee802154/fakehard.c
index 262536fae905..22a93bc764c5 100644
--- a/drivers/ieee802154/fakehard.c
+++ b/drivers/ieee802154/fakehard.c
@@ -30,6 +30,12 @@
30#include <net/ieee802154_netdev.h> 30#include <net/ieee802154_netdev.h>
31#include <net/ieee802154.h> 31#include <net/ieee802154.h>
32#include <net/nl802154.h> 32#include <net/nl802154.h>
33#include <net/wpan-phy.h>
34
35struct wpan_phy *net_to_phy(struct net_device *dev)
36{
37 return container_of(dev->dev.parent, struct wpan_phy, dev);
38}
33 39
34/** 40/**
35 * fake_get_pan_id - Retrieve the PAN ID of the device. 41 * fake_get_pan_id - Retrieve the PAN ID of the device.
@@ -115,6 +121,12 @@ static u8 fake_get_bsn(struct net_device *dev)
115static int fake_assoc_req(struct net_device *dev, 121static int fake_assoc_req(struct net_device *dev,
116 struct ieee802154_addr *addr, u8 channel, u8 cap) 122 struct ieee802154_addr *addr, u8 channel, u8 cap)
117{ 123{
124 struct wpan_phy *phy = net_to_phy(dev);
125
126 mutex_lock(&phy->pib_lock);
127 phy->current_channel = channel;
128 mutex_unlock(&phy->pib_lock);
129
118 /* We simply emulate it here */ 130 /* We simply emulate it here */
119 return ieee802154_nl_assoc_confirm(dev, fake_get_short_addr(dev), 131 return ieee802154_nl_assoc_confirm(dev, fake_get_short_addr(dev),
120 IEEE802154_SUCCESS); 132 IEEE802154_SUCCESS);
@@ -183,6 +195,12 @@ static int fake_start_req(struct net_device *dev, struct ieee802154_addr *addr,
183 u8 bcn_ord, u8 sf_ord, u8 pan_coord, u8 blx, 195 u8 bcn_ord, u8 sf_ord, u8 pan_coord, u8 blx,
184 u8 coord_realign) 196 u8 coord_realign)
185{ 197{
198 struct wpan_phy *phy = net_to_phy(dev);
199
200 mutex_lock(&phy->pib_lock);
201 phy->current_channel = channel;
202 mutex_unlock(&phy->pib_lock);
203
186 /* We don't emulate beacons here at all, so START should fail */ 204 /* We don't emulate beacons here at all, so START should fail */
187 ieee802154_nl_start_confirm(dev, IEEE802154_INVALID_PARAMETER); 205 ieee802154_nl_start_confirm(dev, IEEE802154_INVALID_PARAMETER);
188 return 0; 206 return 0;
@@ -290,6 +308,14 @@ static const struct net_device_ops fake_ops = {
290 .ndo_set_mac_address = ieee802154_fake_mac_addr, 308 .ndo_set_mac_address = ieee802154_fake_mac_addr,
291}; 309};
292 310
311static void ieee802154_fake_destruct(struct net_device *dev)
312{
313 struct wpan_phy *phy = net_to_phy(dev);
314
315 wpan_phy_unregister(phy);
316 free_netdev(dev);
317 wpan_phy_free(phy);
318}
293 319
294static void ieee802154_fake_setup(struct net_device *dev) 320static void ieee802154_fake_setup(struct net_device *dev)
295{ 321{
@@ -302,22 +328,34 @@ static void ieee802154_fake_setup(struct net_device *dev)
302 dev->type = ARPHRD_IEEE802154; 328 dev->type = ARPHRD_IEEE802154;
303 dev->flags = IFF_NOARP | IFF_BROADCAST; 329 dev->flags = IFF_NOARP | IFF_BROADCAST;
304 dev->watchdog_timeo = 0; 330 dev->watchdog_timeo = 0;
331 dev->destructor = ieee802154_fake_destruct;
305} 332}
306 333
307 334
308static int __devinit ieee802154fake_probe(struct platform_device *pdev) 335static int __devinit ieee802154fake_probe(struct platform_device *pdev)
309{ 336{
310 struct net_device *dev = 337 struct net_device *dev;
311 alloc_netdev(0, "hardwpan%d", ieee802154_fake_setup); 338 struct wpan_phy *phy = wpan_phy_alloc(0);
312 int err; 339 int err;
313 340
314 if (!dev) 341 if (!phy)
342 return -ENOMEM;
343
344 dev = alloc_netdev(0, "hardwpan%d", ieee802154_fake_setup);
345 if (!dev) {
346 wpan_phy_free(phy);
315 return -ENOMEM; 347 return -ENOMEM;
348 }
349
350 phy->dev.platform_data = dev;
316 351
317 memcpy(dev->dev_addr, "\xba\xbe\xca\xfe\xde\xad\xbe\xef", 352 memcpy(dev->dev_addr, "\xba\xbe\xca\xfe\xde\xad\xbe\xef",
318 dev->addr_len); 353 dev->addr_len);
319 memcpy(dev->perm_addr, dev->dev_addr, dev->addr_len); 354 memcpy(dev->perm_addr, dev->dev_addr, dev->addr_len);
320 355
356 phy->channels_supported = (1 << 27) - 1;
357 phy->transmit_power = 0xbf;
358
321 dev->netdev_ops = &fake_ops; 359 dev->netdev_ops = &fake_ops;
322 dev->ml_priv = &fake_mlme; 360 dev->ml_priv = &fake_mlme;
323 361
@@ -331,15 +369,18 @@ static int __devinit ieee802154fake_probe(struct platform_device *pdev)
331 goto out; 369 goto out;
332 } 370 }
333 371
334 SET_NETDEV_DEV(dev, &pdev->dev); 372 SET_NETDEV_DEV(dev, &phy->dev);
335 373
336 platform_set_drvdata(pdev, dev); 374 platform_set_drvdata(pdev, dev);
337 375
376 err = wpan_phy_register(&pdev->dev, phy);
377 if (err)
378 goto out;
379
338 err = register_netdev(dev); 380 err = register_netdev(dev);
339 if (err < 0) 381 if (err < 0)
340 goto out; 382 goto out;
341 383
342
343 dev_info(&pdev->dev, "Added ieee802154 HardMAC hardware\n"); 384 dev_info(&pdev->dev, "Added ieee802154 HardMAC hardware\n");
344 return 0; 385 return 0;
345 386
@@ -352,7 +393,6 @@ static int __devexit ieee802154fake_remove(struct platform_device *pdev)
352{ 393{
353 struct net_device *dev = platform_get_drvdata(pdev); 394 struct net_device *dev = platform_get_drvdata(pdev);
354 unregister_netdev(dev); 395 unregister_netdev(dev);
355 free_netdev(dev);
356 return 0; 396 return 0;
357} 397}
358 398