Commit 405cd39f331826d344f5f55bac5dbbc10a1c2813
1 parent
42723448b8
Exists in
master
and in
7 other branches
fakehard: mlme_ops->get_phy implementation
Signed-off-by: Dmitry Eremin-Solenikov <dbaryshkov@gmail.com>
Showing 1 changed file with 32 additions and 6 deletions Side-by-side Diff
drivers/ieee802154/fakehard.c
... | ... | @@ -32,12 +32,32 @@ |
32 | 32 | #include <net/nl802154.h> |
33 | 33 | #include <net/wpan-phy.h> |
34 | 34 | |
35 | -static struct wpan_phy *net_to_phy(struct net_device *dev) | |
35 | +struct fakehard_priv { | |
36 | + struct wpan_phy *phy; | |
37 | +}; | |
38 | + | |
39 | +static 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; | |
38 | 43 | } |
39 | 44 | |
40 | 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 | + */ | |
54 | +static 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)); | |
58 | +} | |
59 | + | |
60 | +/** | |
41 | 61 | * fake_get_pan_id - Retrieve the PAN ID of the device. |
42 | 62 | * @dev: The network device to retrieve the PAN of. |
43 | 63 | * |
... | ... | @@ -121,7 +141,7 @@ |
121 | 141 | static int fake_assoc_req(struct net_device *dev, |
122 | 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 | 146 | mutex_lock(&phy->pib_lock); |
127 | 147 | phy->current_channel = channel; |
... | ... | @@ -196,7 +216,7 @@ |
196 | 216 | u8 bcn_ord, u8 sf_ord, u8 pan_coord, u8 blx, |
197 | 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 | 221 | mutex_lock(&phy->pib_lock); |
202 | 222 | phy->current_channel = channel; |
... | ... | @@ -239,6 +259,8 @@ |
239 | 259 | .start_req = fake_start_req, |
240 | 260 | .scan_req = fake_scan_req, |
241 | 261 | |
262 | + .get_phy = fake_get_phy, | |
263 | + | |
242 | 264 | .get_pan_id = fake_get_pan_id, |
243 | 265 | .get_short_addr = fake_get_short_addr, |
244 | 266 | .get_dsn = fake_get_dsn, |
... | ... | @@ -313,7 +335,7 @@ |
313 | 335 | |
314 | 336 | static 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 | 340 | wpan_phy_unregister(phy); |
319 | 341 | free_netdev(dev); |
320 | 342 | |
... | ... | @@ -338,13 +360,14 @@ |
338 | 360 | static int __devinit ieee802154fake_probe(struct platform_device *pdev) |
339 | 361 | { |
340 | 362 | struct net_device *dev; |
363 | + struct fakehard_priv *priv; | |
341 | 364 | struct wpan_phy *phy = wpan_phy_alloc(0); |
342 | 365 | int err; |
343 | 366 | |
344 | 367 | if (!phy) |
345 | 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 | 371 | if (!dev) { |
349 | 372 | wpan_phy_free(phy); |
350 | 373 | return -ENOMEM; |
... | ... | @@ -369,6 +392,9 @@ |
369 | 392 | |
370 | 393 | dev->netdev_ops = &fake_ops; |
371 | 394 | dev->ml_priv = &fake_mlme; |
395 | + | |
396 | + priv = netdev_priv(dev); | |
397 | + priv->phy = phy; | |
372 | 398 | |
373 | 399 | /* |
374 | 400 | * If the name is a format string the caller wants us to do a |