Linus Luessing | d6f94d9 | 2016-01-16 16:40:09 +0800 | [diff] [blame] | 1 | /* 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 Quartulli | 0b5ecc6 | 2016-01-16 16:40:14 +0800 | [diff] [blame] | 21 | #include <linux/atomic.h> |
Linus Luessing | d6f94d9 | 2016-01-16 16:40:09 +0800 | [diff] [blame] | 22 | #include <linux/cache.h> |
| 23 | #include <linux/init.h> |
Antonio Quartulli | c833484 | 2015-11-10 18:50:51 +0100 | [diff] [blame^] | 24 | #include <linux/workqueue.h> |
Linus Luessing | d6f94d9 | 2016-01-16 16:40:09 +0800 | [diff] [blame] | 25 | |
| 26 | #include "bat_v_elp.h" |
Antonio Quartulli | 0da0035 | 2016-01-16 16:40:12 +0800 | [diff] [blame] | 27 | #include "bat_v_ogm.h" |
Linus Luessing | 162bd64 | 2016-01-16 16:40:10 +0800 | [diff] [blame] | 28 | #include "packet.h" |
Linus Luessing | d6f94d9 | 2016-01-16 16:40:09 +0800 | [diff] [blame] | 29 | |
| 30 | static int batadv_v_iface_enable(struct batadv_hard_iface *hard_iface) |
| 31 | { |
Antonio Quartulli | 0da0035 | 2016-01-16 16:40:12 +0800 | [diff] [blame] | 32 | int ret; |
| 33 | |
| 34 | ret = batadv_v_elp_iface_enable(hard_iface); |
| 35 | if (ret < 0) |
| 36 | return ret; |
| 37 | |
| 38 | ret = batadv_v_ogm_iface_enable(hard_iface); |
| 39 | if (ret < 0) |
| 40 | batadv_v_elp_iface_disable(hard_iface); |
| 41 | |
Antonio Quartulli | 0b5ecc6 | 2016-01-16 16:40:14 +0800 | [diff] [blame] | 42 | /* enable link throughput auto-detection by setting the throughput |
| 43 | * override to zero |
| 44 | */ |
| 45 | atomic_set(&hard_iface->bat_v.throughput_override, 0); |
| 46 | |
Antonio Quartulli | 0da0035 | 2016-01-16 16:40:12 +0800 | [diff] [blame] | 47 | return ret; |
Linus Luessing | d6f94d9 | 2016-01-16 16:40:09 +0800 | [diff] [blame] | 48 | } |
| 49 | |
| 50 | static void batadv_v_iface_disable(struct batadv_hard_iface *hard_iface) |
| 51 | { |
| 52 | batadv_v_elp_iface_disable(hard_iface); |
| 53 | } |
| 54 | |
| 55 | static void batadv_v_iface_update_mac(struct batadv_hard_iface *hard_iface) |
| 56 | { |
| 57 | } |
| 58 | |
| 59 | static void batadv_v_primary_iface_set(struct batadv_hard_iface *hard_iface) |
| 60 | { |
| 61 | batadv_v_elp_primary_iface_set(hard_iface); |
Antonio Quartulli | 0da0035 | 2016-01-16 16:40:12 +0800 | [diff] [blame] | 62 | batadv_v_ogm_primary_iface_set(hard_iface); |
Linus Luessing | d6f94d9 | 2016-01-16 16:40:09 +0800 | [diff] [blame] | 63 | } |
| 64 | |
Linus Luessing | 162bd64 | 2016-01-16 16:40:10 +0800 | [diff] [blame] | 65 | static void |
| 66 | batadv_v_hardif_neigh_init(struct batadv_hardif_neigh_node *hardif_neigh) |
| 67 | { |
| 68 | ewma_throughput_init(&hardif_neigh->bat_v.throughput); |
Antonio Quartulli | c833484 | 2015-11-10 18:50:51 +0100 | [diff] [blame^] | 69 | INIT_WORK(&hardif_neigh->bat_v.metric_work, |
| 70 | batadv_v_elp_throughput_metric_update); |
Linus Luessing | 162bd64 | 2016-01-16 16:40:10 +0800 | [diff] [blame] | 71 | } |
| 72 | |
Linus Luessing | d6f94d9 | 2016-01-16 16:40:09 +0800 | [diff] [blame] | 73 | static void batadv_v_ogm_schedule(struct batadv_hard_iface *hard_iface) |
| 74 | { |
| 75 | } |
| 76 | |
| 77 | static void batadv_v_ogm_emit(struct batadv_forw_packet *forw_packet) |
| 78 | { |
| 79 | } |
| 80 | |
| 81 | static struct batadv_algo_ops batadv_batman_v __read_mostly = { |
| 82 | .name = "BATMAN_V", |
| 83 | .bat_iface_enable = batadv_v_iface_enable, |
| 84 | .bat_iface_disable = batadv_v_iface_disable, |
| 85 | .bat_iface_update_mac = batadv_v_iface_update_mac, |
| 86 | .bat_primary_iface_set = batadv_v_primary_iface_set, |
Linus Luessing | 162bd64 | 2016-01-16 16:40:10 +0800 | [diff] [blame] | 87 | .bat_hardif_neigh_init = batadv_v_hardif_neigh_init, |
Linus Luessing | d6f94d9 | 2016-01-16 16:40:09 +0800 | [diff] [blame] | 88 | .bat_ogm_emit = batadv_v_ogm_emit, |
| 89 | .bat_ogm_schedule = batadv_v_ogm_schedule, |
| 90 | }; |
| 91 | |
| 92 | /** |
Antonio Quartulli | 0da0035 | 2016-01-16 16:40:12 +0800 | [diff] [blame] | 93 | * batadv_v_mesh_init - initialize the B.A.T.M.A.N. V private resources for a |
| 94 | * mesh |
| 95 | * @bat_priv: the object representing the mesh interface to initialise |
| 96 | * |
| 97 | * Return: 0 on success or a negative error code otherwise |
| 98 | */ |
| 99 | int batadv_v_mesh_init(struct batadv_priv *bat_priv) |
| 100 | { |
| 101 | return batadv_v_ogm_init(bat_priv); |
| 102 | } |
| 103 | |
| 104 | /** |
| 105 | * batadv_v_mesh_free - free the B.A.T.M.A.N. V private resources for a mesh |
| 106 | * @bat_priv: the object representing the mesh interface to free |
| 107 | */ |
| 108 | void batadv_v_mesh_free(struct batadv_priv *bat_priv) |
| 109 | { |
| 110 | batadv_v_ogm_free(bat_priv); |
| 111 | } |
| 112 | |
| 113 | /** |
Linus Luessing | d6f94d9 | 2016-01-16 16:40:09 +0800 | [diff] [blame] | 114 | * batadv_v_init - B.A.T.M.A.N. V initialization function |
| 115 | * |
| 116 | * Description: Takes care of initializing all the subcomponents. |
| 117 | * It is invoked upon module load only. |
| 118 | * |
| 119 | * Return: 0 on success or a negative error code otherwise |
| 120 | */ |
| 121 | int __init batadv_v_init(void) |
| 122 | { |
Linus Luessing | 162bd64 | 2016-01-16 16:40:10 +0800 | [diff] [blame] | 123 | int ret; |
| 124 | |
| 125 | /* B.A.T.M.A.N. V echo location protocol packet */ |
| 126 | ret = batadv_recv_handler_register(BATADV_ELP, |
| 127 | batadv_v_elp_packet_recv); |
| 128 | if (ret < 0) |
| 129 | return ret; |
| 130 | |
Antonio Quartulli | 0da0035 | 2016-01-16 16:40:12 +0800 | [diff] [blame] | 131 | ret = batadv_recv_handler_register(BATADV_OGM2, |
| 132 | batadv_v_ogm_packet_recv); |
Linus Luessing | 162bd64 | 2016-01-16 16:40:10 +0800 | [diff] [blame] | 133 | if (ret < 0) |
Antonio Quartulli | 0da0035 | 2016-01-16 16:40:12 +0800 | [diff] [blame] | 134 | goto elp_unregister; |
| 135 | |
| 136 | ret = batadv_algo_register(&batadv_batman_v); |
| 137 | if (ret < 0) |
| 138 | goto ogm_unregister; |
| 139 | |
| 140 | return ret; |
| 141 | |
| 142 | ogm_unregister: |
| 143 | batadv_recv_handler_unregister(BATADV_OGM2); |
| 144 | |
| 145 | elp_unregister: |
| 146 | batadv_recv_handler_unregister(BATADV_ELP); |
Linus Luessing | 162bd64 | 2016-01-16 16:40:10 +0800 | [diff] [blame] | 147 | |
| 148 | return ret; |
Linus Luessing | d6f94d9 | 2016-01-16 16:40:09 +0800 | [diff] [blame] | 149 | } |