blob: d9cb5c4922c18c1c09dc0c31ddadda8e6ca066f6 [file] [log] [blame]
Linus Luessingd6f94d92016-01-16 16:40:09 +08001/* Copyright (C) 2013-2016 B.A.T.M.A.N. contributors:
2 *
3 * Linus Lüssing, Marek Lindner
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, see <http://www.gnu.org/licenses/>.
16 */
17
18#include "bat_algo.h"
19#include "main.h"
20
Antonio Quartulli0b5ecc62016-01-16 16:40:14 +080021#include <linux/atomic.h>
Linus Luessingd6f94d92016-01-16 16:40:09 +080022#include <linux/cache.h>
23#include <linux/init.h>
24
25#include "bat_v_elp.h"
Antonio Quartulli0da00352016-01-16 16:40:12 +080026#include "bat_v_ogm.h"
Linus Luessing162bd642016-01-16 16:40:10 +080027#include "packet.h"
Linus Luessingd6f94d92016-01-16 16:40:09 +080028
29static int batadv_v_iface_enable(struct batadv_hard_iface *hard_iface)
30{
Antonio Quartulli0da00352016-01-16 16:40:12 +080031 int ret;
32
33 ret = batadv_v_elp_iface_enable(hard_iface);
34 if (ret < 0)
35 return ret;
36
37 ret = batadv_v_ogm_iface_enable(hard_iface);
38 if (ret < 0)
39 batadv_v_elp_iface_disable(hard_iface);
40
Antonio Quartulli0b5ecc62016-01-16 16:40:14 +080041 /* enable link throughput auto-detection by setting the throughput
42 * override to zero
43 */
44 atomic_set(&hard_iface->bat_v.throughput_override, 0);
45
Antonio Quartulli0da00352016-01-16 16:40:12 +080046 return ret;
Linus Luessingd6f94d92016-01-16 16:40:09 +080047}
48
49static void batadv_v_iface_disable(struct batadv_hard_iface *hard_iface)
50{
51 batadv_v_elp_iface_disable(hard_iface);
52}
53
54static void batadv_v_iface_update_mac(struct batadv_hard_iface *hard_iface)
55{
56}
57
58static void batadv_v_primary_iface_set(struct batadv_hard_iface *hard_iface)
59{
60 batadv_v_elp_primary_iface_set(hard_iface);
Antonio Quartulli0da00352016-01-16 16:40:12 +080061 batadv_v_ogm_primary_iface_set(hard_iface);
Linus Luessingd6f94d92016-01-16 16:40:09 +080062}
63
Linus Luessing162bd642016-01-16 16:40:10 +080064static void
65batadv_v_hardif_neigh_init(struct batadv_hardif_neigh_node *hardif_neigh)
66{
67 ewma_throughput_init(&hardif_neigh->bat_v.throughput);
68}
69
Linus Luessingd6f94d92016-01-16 16:40:09 +080070static void batadv_v_ogm_schedule(struct batadv_hard_iface *hard_iface)
71{
72}
73
74static void batadv_v_ogm_emit(struct batadv_forw_packet *forw_packet)
75{
76}
77
78static struct batadv_algo_ops batadv_batman_v __read_mostly = {
79 .name = "BATMAN_V",
80 .bat_iface_enable = batadv_v_iface_enable,
81 .bat_iface_disable = batadv_v_iface_disable,
82 .bat_iface_update_mac = batadv_v_iface_update_mac,
83 .bat_primary_iface_set = batadv_v_primary_iface_set,
Linus Luessing162bd642016-01-16 16:40:10 +080084 .bat_hardif_neigh_init = batadv_v_hardif_neigh_init,
Linus Luessingd6f94d92016-01-16 16:40:09 +080085 .bat_ogm_emit = batadv_v_ogm_emit,
86 .bat_ogm_schedule = batadv_v_ogm_schedule,
87};
88
89/**
Antonio Quartulli0da00352016-01-16 16:40:12 +080090 * batadv_v_mesh_init - initialize the B.A.T.M.A.N. V private resources for a
91 * mesh
92 * @bat_priv: the object representing the mesh interface to initialise
93 *
94 * Return: 0 on success or a negative error code otherwise
95 */
96int batadv_v_mesh_init(struct batadv_priv *bat_priv)
97{
98 return batadv_v_ogm_init(bat_priv);
99}
100
101/**
102 * batadv_v_mesh_free - free the B.A.T.M.A.N. V private resources for a mesh
103 * @bat_priv: the object representing the mesh interface to free
104 */
105void batadv_v_mesh_free(struct batadv_priv *bat_priv)
106{
107 batadv_v_ogm_free(bat_priv);
108}
109
110/**
Linus Luessingd6f94d92016-01-16 16:40:09 +0800111 * batadv_v_init - B.A.T.M.A.N. V initialization function
112 *
113 * Description: Takes care of initializing all the subcomponents.
114 * It is invoked upon module load only.
115 *
116 * Return: 0 on success or a negative error code otherwise
117 */
118int __init batadv_v_init(void)
119{
Linus Luessing162bd642016-01-16 16:40:10 +0800120 int ret;
121
122 /* B.A.T.M.A.N. V echo location protocol packet */
123 ret = batadv_recv_handler_register(BATADV_ELP,
124 batadv_v_elp_packet_recv);
125 if (ret < 0)
126 return ret;
127
Antonio Quartulli0da00352016-01-16 16:40:12 +0800128 ret = batadv_recv_handler_register(BATADV_OGM2,
129 batadv_v_ogm_packet_recv);
Linus Luessing162bd642016-01-16 16:40:10 +0800130 if (ret < 0)
Antonio Quartulli0da00352016-01-16 16:40:12 +0800131 goto elp_unregister;
132
133 ret = batadv_algo_register(&batadv_batman_v);
134 if (ret < 0)
135 goto ogm_unregister;
136
137 return ret;
138
139ogm_unregister:
140 batadv_recv_handler_unregister(BATADV_OGM2);
141
142elp_unregister:
143 batadv_recv_handler_unregister(BATADV_ELP);
Linus Luessing162bd642016-01-16 16:40:10 +0800144
145 return ret;
Linus Luessingd6f94d92016-01-16 16:40:09 +0800146}