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