network-coding.c 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /* Copyright (C) 2012-2013 B.A.T.M.A.N. contributors:
  2. *
  3. * Martin Hundebøll, Jeppe Ledet-Pedersen
  4. *
  5. * This program is free software; you can redistribute it and/or
  6. * modify it under the terms of version 2 of the GNU General Public
  7. * License as published by the Free Software Foundation.
  8. *
  9. * This program is distributed in the hope that it will be useful, but
  10. * WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. * General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program; if not, write to the Free Software
  16. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  17. * 02110-1301, USA
  18. */
  19. #include "main.h"
  20. #include "network-coding.h"
  21. static void batadv_nc_worker(struct work_struct *work);
  22. /**
  23. * batadv_nc_start_timer - initialise the nc periodic worker
  24. * @bat_priv: the bat priv with all the soft interface information
  25. */
  26. static void batadv_nc_start_timer(struct batadv_priv *bat_priv)
  27. {
  28. queue_delayed_work(batadv_event_workqueue, &bat_priv->nc.work,
  29. msecs_to_jiffies(10));
  30. }
  31. /**
  32. * batadv_nc_init - initialise coding hash table and start house keeping
  33. * @bat_priv: the bat priv with all the soft interface information
  34. */
  35. int batadv_nc_init(struct batadv_priv *bat_priv)
  36. {
  37. INIT_DELAYED_WORK(&bat_priv->nc.work, batadv_nc_worker);
  38. batadv_nc_start_timer(bat_priv);
  39. return 0;
  40. }
  41. /**
  42. * batadv_nc_init_bat_priv - initialise the nc specific bat_priv variables
  43. * @bat_priv: the bat priv with all the soft interface information
  44. */
  45. void batadv_nc_init_bat_priv(struct batadv_priv *bat_priv)
  46. {
  47. atomic_set(&bat_priv->network_coding, 1);
  48. }
  49. /**
  50. * batadv_nc_worker - periodic task for house keeping related to network coding
  51. * @work: kernel work struct
  52. */
  53. static void batadv_nc_worker(struct work_struct *work)
  54. {
  55. struct delayed_work *delayed_work;
  56. struct batadv_priv_nc *priv_nc;
  57. struct batadv_priv *bat_priv;
  58. delayed_work = container_of(work, struct delayed_work, work);
  59. priv_nc = container_of(delayed_work, struct batadv_priv_nc, work);
  60. bat_priv = container_of(priv_nc, struct batadv_priv, nc);
  61. /* Schedule a new check */
  62. batadv_nc_start_timer(bat_priv);
  63. }
  64. /**
  65. * batadv_nc_free - clean up network coding memory
  66. * @bat_priv: the bat priv with all the soft interface information
  67. */
  68. void batadv_nc_free(struct batadv_priv *bat_priv)
  69. {
  70. cancel_delayed_work_sync(&bat_priv->nc.work);
  71. }