/* Copyright (C) 2012-2013 B.A.T.M.A.N. contributors:
*
* Martin Hundebøll, Jeppe Ledet-Pedersen
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of version 2 of the GNU General Public
* License as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301, USA
*/
#include <linux/debugfs.h>
#include "main.h"
#include "hash.h"
#include "network-coding.h"
#include "send.h"
#include "originator.h"
#include "hard-interface.h"
static struct lock_class_key batadv_nc_coding_hash_lock_class_key;
static void batadv_nc_worker(struct work_struct *work);
/**
* batadv_nc_start_timer - initialise the nc periodic worker
* @bat_priv: the bat priv with all the soft interface information
*/
static void batadv_nc_start_timer(struct batadv_priv *bat_priv)
{
queue_delayed_work(batadv_event_workqueue, &bat_priv->nc.work,
msecs_to_jiffies(10));
}
/**
* batadv_nc_init - initialise coding hash table and start house keeping
* @bat_priv: the bat priv with all the soft interface information
*/
int batadv_nc_init(struct batadv_priv *bat_priv)
{
bat_priv->nc.timestamp_fwd_flush = jiffies;
if (bat_priv->nc.coding_hash)
return 0;
bat_priv->nc.coding_hash = batadv_hash_new(128);
if (!bat_priv->nc.coding_hash)
goto err;
batadv_hash_set_lock_class(bat_priv->nc.coding_hash,
&batadv_nc_coding_hash_lock_class_key);
INIT_DELAYED_WORK(&bat_priv->nc.work, batadv_nc_worker);
batadv_nc_start_timer(bat_priv);
return 0;
err:
return -ENOMEM;
}
/**
* batadv_nc_init_bat_priv - initialise the nc specific bat_priv variables
* @bat_priv: the bat priv with all the soft interface information
*/
void batadv_nc_init_bat_priv(struct batadv_priv *bat_priv)
{
atomic_set(&bat_priv->network_coding, 1);
bat_priv->nc.min_tq = 200;
bat_priv->nc.max_fwd_delay = 10;
}
/**
* batadv_nc_init_orig - initialise the nc fields of an orig_node
* @orig_node: the orig_node which is going to be initialised
*/
void batadv_nc_init_orig(struct batadv_orig_node *orig_node)
{
INIT_LIST_HEAD(&orig_node->in_coding_list);
INIT_LIST_HEAD(&orig_node->out_coding_list);
spin_lock_init(&