Commit 81f9510381ee43205564063f2e8650672b11d453

Authored by Dmitry Eremin-Solenikov
1 parent 2bfb1070ba

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>

Showing 1 changed file with 46 additions and 6 deletions Side-by-side Diff

drivers/ieee802154/fakehard.c
... ... @@ -30,7 +30,13 @@
30 30 #include <net/ieee802154_netdev.h>
31 31 #include <net/ieee802154.h>
32 32 #include <net/nl802154.h>
  33 +#include <net/wpan-phy.h>
33 34  
  35 +struct wpan_phy *net_to_phy(struct net_device *dev)
  36 +{
  37 + return container_of(dev->dev.parent, struct wpan_phy, dev);
  38 +}
  39 +
34 40 /**
35 41 * fake_get_pan_id - Retrieve the PAN ID of the device.
36 42 * @dev: The network device to retrieve the PAN of.
... ... @@ -115,6 +121,12 @@
115 121 static int fake_assoc_req(struct net_device *dev,
116 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 130 /* We simply emulate it here */
119 131 return ieee802154_nl_assoc_confirm(dev, fake_get_short_addr(dev),
120 132 IEEE802154_SUCCESS);
... ... @@ -183,6 +195,12 @@
183 195 u8 bcn_ord, u8 sf_ord, u8 pan_coord, u8 blx,
184 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 204 /* We don't emulate beacons here at all, so START should fail */
187 205 ieee802154_nl_start_confirm(dev, IEEE802154_INVALID_PARAMETER);
188 206 return 0;
189 207  
... ... @@ -290,7 +308,15 @@
290 308 .ndo_set_mac_address = ieee802154_fake_mac_addr,
291 309 };
292 310  
  311 +static void ieee802154_fake_destruct(struct net_device *dev)
  312 +{
  313 + struct wpan_phy *phy = net_to_phy(dev);
293 314  
  315 + wpan_phy_unregister(phy);
  316 + free_netdev(dev);
  317 + wpan_phy_free(phy);
  318 +}
  319 +
294 320 static void ieee802154_fake_setup(struct net_device *dev)
295 321 {
296 322 dev->addr_len = IEEE802154_ADDR_LEN;
297 323  
298 324  
299 325  
300 326  
... ... @@ -302,22 +328,34 @@
302 328 dev->type = ARPHRD_IEEE802154;
303 329 dev->flags = IFF_NOARP | IFF_BROADCAST;
304 330 dev->watchdog_timeo = 0;
  331 + dev->destructor = ieee802154_fake_destruct;
305 332 }
306 333  
307 334  
308 335 static int __devinit ieee802154fake_probe(struct platform_device *pdev)
309 336 {
310   - struct net_device *dev =
311   - alloc_netdev(0, "hardwpan%d", ieee802154_fake_setup);
  337 + struct net_device *dev;
  338 + struct wpan_phy *phy = wpan_phy_alloc(0);
312 339 int err;
313 340  
314   - if (!dev)
  341 + if (!phy)
315 342 return -ENOMEM;
316 343  
  344 + dev = alloc_netdev(0, "hardwpan%d", ieee802154_fake_setup);
  345 + if (!dev) {
  346 + wpan_phy_free(phy);
  347 + return -ENOMEM;
  348 + }
  349 +
  350 + phy->dev.platform_data = dev;
  351 +
317 352 memcpy(dev->dev_addr, "\xba\xbe\xca\xfe\xde\xad\xbe\xef",
318 353 dev->addr_len);
319 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 359 dev->netdev_ops = &fake_ops;
322 360 dev->ml_priv = &fake_mlme;
323 361  
324 362  
325 363  
... ... @@ -331,15 +369,18 @@
331 369 goto out;
332 370 }
333 371  
334   - SET_NETDEV_DEV(dev, &pdev->dev);
  372 + SET_NETDEV_DEV(dev, &phy->dev);
335 373  
336 374 platform_set_drvdata(pdev, dev);
337 375  
  376 + err = wpan_phy_register(&pdev->dev, phy);
  377 + if (err)
  378 + goto out;
  379 +
338 380 err = register_netdev(dev);
339 381 if (err < 0)
340 382 goto out;
341 383  
342   -
343 384 dev_info(&pdev->dev, "Added ieee802154 HardMAC hardware\n");
344 385 return 0;
345 386  
... ... @@ -352,7 +393,6 @@
352 393 {
353 394 struct net_device *dev = platform_get_drvdata(pdev);
354 395 unregister_netdev(dev);
355   - free_netdev(dev);
356 396 return 0;
357 397 }
358 398