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/iface.c | |
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/iface.c')
-rw-r--r-- | net/mac802154/iface.c | 66 |
1 files changed, 66 insertions, 0 deletions
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(); |