blob: 9c2d54bdd2ce10273a6eae237291957af89c01ad [file] [log] [blame]
Martin Hundebølld353d8d2013-01-25 11:12:38 +01001/* 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
20#include "main.h"
21#include "network-coding.h"
22
23static void batadv_nc_worker(struct work_struct *work);
24
25/**
26 * batadv_nc_start_timer - initialise the nc periodic worker
27 * @bat_priv: the bat priv with all the soft interface information
28 */
29static void batadv_nc_start_timer(struct batadv_priv *bat_priv)
30{
31 queue_delayed_work(batadv_event_workqueue, &bat_priv->nc.work,
32 msecs_to_jiffies(10));
33}
34
35/**
36 * batadv_nc_init - initialise coding hash table and start house keeping
37 * @bat_priv: the bat priv with all the soft interface information
38 */
39int batadv_nc_init(struct batadv_priv *bat_priv)
40{
41 INIT_DELAYED_WORK(&bat_priv->nc.work, batadv_nc_worker);
42 batadv_nc_start_timer(bat_priv);
43
44 return 0;
45}
46
47/**
48 * batadv_nc_init_bat_priv - initialise the nc specific bat_priv variables
49 * @bat_priv: the bat priv with all the soft interface information
50 */
51void batadv_nc_init_bat_priv(struct batadv_priv *bat_priv)
52{
53 atomic_set(&bat_priv->network_coding, 1);
54}
55
56/**
57 * batadv_nc_worker - periodic task for house keeping related to network coding
58 * @work: kernel work struct
59 */
60static void batadv_nc_worker(struct work_struct *work)
61{
62 struct delayed_work *delayed_work;
63 struct batadv_priv_nc *priv_nc;
64 struct batadv_priv *bat_priv;
65
66 delayed_work = container_of(work, struct delayed_work, work);
67 priv_nc = container_of(delayed_work, struct batadv_priv_nc, work);
68 bat_priv = container_of(priv_nc, struct batadv_priv, nc);
69
70 /* Schedule a new check */
71 batadv_nc_start_timer(bat_priv);
72}
73
74/**
75 * batadv_nc_free - clean up network coding memory
76 * @bat_priv: the bat priv with all the soft interface information
77 */
78void batadv_nc_free(struct batadv_priv *bat_priv)
79{
80 cancel_delayed_work_sync(&bat_priv->nc.work);
81}