diff options
author | Alexander Aring <alex.aring@gmail.com> | 2014-11-05 14:51:15 -0500 |
---|---|---|
committer | Marcel Holtmann <marcel@holtmann.org> | 2014-11-05 15:53:03 -0500 |
commit | 986a8abfc51e66c96f9d39529a6ff0443fcd2591 (patch) | |
tree | 57f3640544539ae4f014603f11e773ba3d4183c6 /net/mac802154 | |
parent | b210b18747cb511bb71f6a49c97e8d38f639b435 (diff) |
mac802154: move interface add handling in iface
This patch moves and renames the mac802154_add_iface and
mac802154_netdev_register functions into iface.c. The function
mac802154_add_iface is renamed to ieee802154_if_add which is a similar naming
convention like mac80211.
Signed-off-by: Alexander Aring <alex.aring@gmail.com>
Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
Diffstat (limited to 'net/mac802154')
-rw-r--r-- | net/mac802154/cfg.c | 4 | ||||
-rw-r--r-- | net/mac802154/ieee802154_i.h | 3 | ||||
-rw-r--r-- | net/mac802154/iface.c | 66 | ||||
-rw-r--r-- | net/mac802154/main.c | 67 |
4 files changed, 72 insertions, 68 deletions
diff --git a/net/mac802154/cfg.c b/net/mac802154/cfg.c index 3f9afad1f612..0a08f66512b3 100644 --- a/net/mac802154/cfg.c +++ b/net/mac802154/cfg.c | |||
@@ -22,7 +22,9 @@ static struct net_device * | |||
22 | ieee802154_add_iface_deprecated(struct wpan_phy *wpan_phy, | 22 | ieee802154_add_iface_deprecated(struct wpan_phy *wpan_phy, |
23 | const char *name, int type) | 23 | const char *name, int type) |
24 | { | 24 | { |
25 | return mac802154_add_iface(wpan_phy, name, type); | 25 | struct ieee802154_local *local = wpan_phy_priv(wpan_phy); |
26 | |||
27 | return ieee802154_if_add(local, name, NULL, type); | ||
26 | } | 28 | } |
27 | 29 | ||
28 | static void ieee802154_del_iface_deprecated(struct wpan_phy *wpan_phy, | 30 | static void ieee802154_del_iface_deprecated(struct wpan_phy *wpan_phy, |
diff --git a/net/mac802154/ieee802154_i.h b/net/mac802154/ieee802154_i.h index 61a6a0fd39ad..3ad85404fc94 100644 --- a/net/mac802154/ieee802154_i.h +++ b/net/mac802154/ieee802154_i.h | |||
@@ -176,5 +176,8 @@ void mac802154_unlock_table(struct net_device *dev); | |||
176 | struct net_device * | 176 | struct net_device * |
177 | mac802154_add_iface(struct wpan_phy *phy, const char *name, int type); | 177 | mac802154_add_iface(struct wpan_phy *phy, const char *name, int type); |
178 | void ieee802154_if_remove(struct ieee802154_sub_if_data *sdata); | 178 | void ieee802154_if_remove(struct ieee802154_sub_if_data *sdata); |
179 | struct net_device * | ||
180 | ieee802154_if_add(struct ieee802154_local *local, const char *name, | ||
181 | struct wpan_dev **new_wpan_dev, int type); | ||
179 | 182 | ||
180 | #endif /* __IEEE802154_I_H */ | 183 | #endif /* __IEEE802154_I_H */ |
diff --git a/net/mac802154/iface.c b/net/mac802154/iface.c index 9d6012e430de..fced04b05275 100644 --- a/net/mac802154/iface.c +++ b/net/mac802154/iface.c | |||
@@ -444,6 +444,72 @@ void mac802154_monitor_setup(struct net_device *dev) | |||
444 | sdata->promisuous_mode = true; | 444 | sdata->promisuous_mode = true; |
445 | } | 445 | } |
446 | 446 | ||
447 | static int | ||
448 | mac802154_netdev_register(struct ieee802154_local *local, | ||
449 | struct net_device *dev) | ||
450 | { | ||
451 | struct ieee802154_sub_if_data *sdata = IEEE802154_DEV_TO_SUB_IF(dev); | ||
452 | int err; | ||
453 | |||
454 | sdata->dev = dev; | ||
455 | sdata->local = local; | ||
456 | |||
457 | dev->needed_headroom = local->hw.extra_tx_headroom; | ||
458 | |||
459 | SET_NETDEV_DEV(dev, &local->phy->dev); | ||
460 | |||
461 | err = register_netdev(dev); | ||
462 | if (err < 0) | ||
463 | return err; | ||
464 | |||
465 | rtnl_lock(); | ||
466 | mutex_lock(&local->iflist_mtx); | ||
467 | list_add_tail_rcu(&sdata->list, &local->interfaces); | ||
468 | mutex_unlock(&local->iflist_mtx); | ||
469 | rtnl_unlock(); | ||
470 | |||
471 | return 0; | ||
472 | } | ||
473 | |||
474 | struct net_device * | ||
475 | ieee802154_if_add(struct ieee802154_local *local, const char *name, | ||
476 | struct wpan_dev **new_wpan_dev, int type) | ||
477 | { | ||
478 | struct net_device *dev; | ||
479 | int err = -ENOMEM; | ||
480 | |||
481 | switch (type) { | ||
482 | case IEEE802154_DEV_MONITOR: | ||
483 | dev = alloc_netdev(sizeof(struct ieee802154_sub_if_data), | ||
484 | name, NET_NAME_UNKNOWN, | ||
485 | mac802154_monitor_setup); | ||
486 | break; | ||
487 | case IEEE802154_DEV_WPAN: | ||
488 | dev = alloc_netdev(sizeof(struct ieee802154_sub_if_data), | ||
489 | name, NET_NAME_UNKNOWN, | ||
490 | mac802154_wpan_setup); | ||
491 | break; | ||
492 | default: | ||
493 | dev = NULL; | ||
494 | err = -EINVAL; | ||
495 | break; | ||
496 | } | ||
497 | if (!dev) | ||
498 | goto err; | ||
499 | |||
500 | err = mac802154_netdev_register(local, dev); | ||
501 | if (err) | ||
502 | goto err_free; | ||
503 | |||
504 | dev_hold(dev); /* we return an incremented device refcount */ | ||
505 | return dev; | ||
506 | |||
507 | err_free: | ||
508 | free_netdev(dev); | ||
509 | err: | ||
510 | return ERR_PTR(err); | ||
511 | } | ||
512 | |||
447 | void ieee802154_if_remove(struct ieee802154_sub_if_data *sdata) | 513 | void ieee802154_if_remove(struct ieee802154_sub_if_data *sdata) |
448 | { | 514 | { |
449 | ASSERT_RTNL(); | 515 | ASSERT_RTNL(); |
diff --git a/net/mac802154/main.c b/net/mac802154/main.c index 333d33daec6e..a371eb5fa053 100644 --- a/net/mac802154/main.c +++ b/net/mac802154/main.c | |||
@@ -30,73 +30,6 @@ | |||
30 | #include "ieee802154_i.h" | 30 | #include "ieee802154_i.h" |
31 | #include "cfg.h" | 31 | #include "cfg.h" |
32 | 32 | ||
33 | static int | ||
34 | mac802154_netdev_register(struct wpan_phy *phy, struct net_device *dev) | ||
35 | { | ||
36 | struct ieee802154_sub_if_data *sdata = IEEE802154_DEV_TO_SUB_IF(dev); | ||
37 | struct ieee802154_local *local; | ||
38 | int err; | ||
39 | |||
40 | local = wpan_phy_priv(phy); | ||
41 | |||
42 | sdata->dev = dev; | ||
43 | sdata->local = local; | ||
44 | |||
45 | dev->needed_headroom = local->hw.extra_tx_headroom; | ||
46 | |||
47 | SET_NETDEV_DEV(dev, &local->phy->dev); | ||
48 | |||
49 | err = register_netdev(dev); | ||
50 | if (err < 0) | ||
51 | return err; | ||
52 | |||
53 | rtnl_lock(); | ||
54 | mutex_lock(&local->iflist_mtx); | ||
55 | list_add_tail_rcu(&sdata->list, &local->interfaces); | ||
56 | mutex_unlock(&local->iflist_mtx); | ||
57 | rtnl_unlock(); | ||
58 | |||
59 | return 0; | ||
60 | } | ||
61 | |||
62 | struct net_device * | ||
63 | mac802154_add_iface(struct wpan_phy *phy, const char *name, int type) | ||
64 | { | ||
65 | struct net_device *dev; | ||
66 | int err = -ENOMEM; | ||
67 | |||
68 | switch (type) { | ||
69 | case IEEE802154_DEV_MONITOR: | ||
70 | dev = alloc_netdev(sizeof(struct ieee802154_sub_if_data), | ||
71 | name, NET_NAME_UNKNOWN, | ||
72 | mac802154_monitor_setup); | ||
73 | break; | ||
74 | case IEEE802154_DEV_WPAN: | ||
75 | dev = alloc_netdev(sizeof(struct ieee802154_sub_if_data), | ||
76 | name, NET_NAME_UNKNOWN, | ||
77 | mac802154_wpan_setup); | ||
78 | break; | ||
79 | default: | ||
80 | dev = NULL; | ||
81 | err = -EINVAL; | ||
82 | break; | ||
83 | } | ||
84 | if (!dev) | ||
85 | goto err; | ||
86 | |||
87 | err = mac802154_netdev_register(phy, dev); | ||
88 | if (err) | ||
89 | goto err_free; | ||
90 | |||
91 | dev_hold(dev); /* we return an incremented device refcount */ | ||
92 | return dev; | ||
93 | |||
94 | err_free: | ||
95 | free_netdev(dev); | ||
96 | err: | ||
97 | return ERR_PTR(err); | ||
98 | } | ||
99 | |||
100 | static void ieee802154_tasklet_handler(unsigned long data) | 33 | static void ieee802154_tasklet_handler(unsigned long data) |
101 | { | 34 | { |
102 | struct ieee802154_local *local = (struct ieee802154_local *)data; | 35 | struct ieee802154_local *local = (struct ieee802154_local *)data; |