mib.c 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. /*
  2. * Copyright 2007-2012 Siemens AG
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License version 2
  6. * as published by the Free Software Foundation.
  7. *
  8. * This program is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * GNU General Public License for more details.
  12. *
  13. * You should have received a copy of the GNU General Public License along
  14. * with this program; if not, write to the Free Software Foundation, Inc.,
  15. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  16. *
  17. * Written by:
  18. * Dmitry Eremin-Solenikov <dbaryshkov@gmail.com>
  19. * Sergey Lapin <slapin@ossfans.org>
  20. * Maxim Gorbachyov <maxim.gorbachev@siemens.com>
  21. * Alexander Smirnov <alex.bluesman.smirnov@gmail.com>
  22. */
  23. #include <linux/if_arp.h>
  24. #include <net/mac802154.h>
  25. #include <net/wpan-phy.h>
  26. #include "mac802154.h"
  27. struct hw_addr_filt_notify_work {
  28. struct work_struct work;
  29. struct net_device *dev;
  30. unsigned long changed;
  31. };
  32. struct mac802154_priv *mac802154_slave_get_priv(struct net_device *dev)
  33. {
  34. struct mac802154_sub_if_data *priv = netdev_priv(dev);
  35. BUG_ON(dev->type != ARPHRD_IEEE802154);
  36. return priv->hw;
  37. }
  38. static void hw_addr_notify(struct work_struct *work)
  39. {
  40. struct hw_addr_filt_notify_work *nw = container_of(work,
  41. struct hw_addr_filt_notify_work, work);
  42. struct mac802154_priv *hw = mac802154_slave_get_priv(nw->dev);
  43. int res;
  44. res = hw->ops->set_hw_addr_filt(&hw->hw,
  45. &hw->hw.hw_filt,
  46. nw->changed);
  47. if (res)
  48. pr_debug("failed changed mask %lx\n", nw->changed);
  49. kfree(nw);
  50. return;
  51. }
  52. static void set_hw_addr_filt(struct net_device *dev, unsigned long changed)
  53. {
  54. struct mac802154_sub_if_data *priv = netdev_priv(dev);
  55. struct hw_addr_filt_notify_work *work;
  56. work = kzalloc(sizeof(*work), GFP_ATOMIC);
  57. if (!work)
  58. return;
  59. INIT_WORK(&work->work, hw_addr_notify);
  60. work->dev = dev;
  61. work->changed = changed;
  62. queue_work(priv->hw->dev_workqueue, &work->work);
  63. return;
  64. }
  65. void mac802154_dev_set_ieee_addr(struct net_device *dev)
  66. {
  67. struct mac802154_sub_if_data *priv = netdev_priv(dev);
  68. struct mac802154_priv *mac = priv->hw;
  69. if (mac->ops->set_hw_addr_filt &&
  70. memcmp(mac->hw.hw_filt.ieee_addr,
  71. dev->dev_addr, IEEE802154_ADDR_LEN)) {
  72. memcpy(mac->hw.hw_filt.ieee_addr,
  73. dev->dev_addr, IEEE802154_ADDR_LEN);
  74. set_hw_addr_filt(dev, IEEE802515_AFILT_IEEEADDR_CHANGED);
  75. }
  76. }