Sven Eckelmann | 9cfc7bd | 2012-05-12 02:09:43 +0200 | [diff] [blame] | 1 | /* Copyright (C) 2010-2012 B.A.T.M.A.N. contributors: |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 2 | * |
| 3 | * 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, write to the Free Software |
| 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
| 17 | * 02110-1301, USA |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 18 | */ |
| 19 | |
| 20 | #include "main.h" |
| 21 | #include "bat_sysfs.h" |
| 22 | #include "translation-table.h" |
| 23 | #include "originator.h" |
| 24 | #include "hard-interface.h" |
| 25 | #include "gateway_common.h" |
| 26 | #include "gateway_client.h" |
| 27 | #include "vis.h" |
| 28 | |
Sven Eckelmann | 0ff9b86 | 2012-05-12 18:33:52 +0200 | [diff] [blame] | 29 | static struct net_device *batadv_kobj_to_netdev(struct kobject *obj) |
Sven Eckelmann | 3d222bb | 2011-06-05 10:20:19 +0200 | [diff] [blame] | 30 | { |
| 31 | struct device *dev = container_of(obj->parent, struct device, kobj); |
| 32 | return to_net_dev(dev); |
| 33 | } |
| 34 | |
Sven Eckelmann | 0ff9b86 | 2012-05-12 18:33:52 +0200 | [diff] [blame] | 35 | static struct bat_priv *batadv_kobj_to_batpriv(struct kobject *obj) |
Sven Eckelmann | 3d222bb | 2011-06-05 10:20:19 +0200 | [diff] [blame] | 36 | { |
Sven Eckelmann | 0ff9b86 | 2012-05-12 18:33:52 +0200 | [diff] [blame] | 37 | struct net_device *net_dev = batadv_kobj_to_netdev(obj); |
Sven Eckelmann | 3d222bb | 2011-06-05 10:20:19 +0200 | [diff] [blame] | 38 | return netdev_priv(net_dev); |
| 39 | } |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 40 | |
Antonio Quartulli | c6bda68 | 2011-04-26 18:26:01 +0200 | [diff] [blame] | 41 | #define UEV_TYPE_VAR "BATTYPE=" |
| 42 | #define UEV_ACTION_VAR "BATACTION=" |
| 43 | #define UEV_DATA_VAR "BATDATA=" |
| 44 | |
Sven Eckelmann | 0ff9b86 | 2012-05-12 18:33:52 +0200 | [diff] [blame] | 45 | static char *batadv_uev_action_str[] = { |
Antonio Quartulli | c6bda68 | 2011-04-26 18:26:01 +0200 | [diff] [blame] | 46 | "add", |
| 47 | "del", |
| 48 | "change" |
| 49 | }; |
| 50 | |
Sven Eckelmann | 0ff9b86 | 2012-05-12 18:33:52 +0200 | [diff] [blame] | 51 | static char *batadv_uev_type_str[] = { |
Antonio Quartulli | c6bda68 | 2011-04-26 18:26:01 +0200 | [diff] [blame] | 52 | "gw" |
| 53 | }; |
| 54 | |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 55 | /* Use this, if you have customized show and store functions */ |
| 56 | #define BAT_ATTR(_name, _mode, _show, _store) \ |
Sven Eckelmann | 0ff9b86 | 2012-05-12 18:33:52 +0200 | [diff] [blame] | 57 | struct bat_attribute batadv_attr_##_name = { \ |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 58 | .attr = {.name = __stringify(_name), \ |
| 59 | .mode = _mode }, \ |
| 60 | .show = _show, \ |
| 61 | .store = _store, \ |
| 62 | }; |
| 63 | |
Marek Lindner | f245c38 | 2012-03-11 06:17:51 +0800 | [diff] [blame] | 64 | #define BAT_ATTR_SIF_STORE_BOOL(_name, _post_func) \ |
Sven Eckelmann | 0ff9b86 | 2012-05-12 18:33:52 +0200 | [diff] [blame] | 65 | ssize_t batadv_store_##_name(struct kobject *kobj, \ |
| 66 | struct attribute *attr, char *buff, \ |
| 67 | size_t count) \ |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 68 | { \ |
Sven Eckelmann | 0ff9b86 | 2012-05-12 18:33:52 +0200 | [diff] [blame] | 69 | struct net_device *net_dev = batadv_kobj_to_netdev(kobj); \ |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 70 | struct bat_priv *bat_priv = netdev_priv(net_dev); \ |
Sven Eckelmann | 0ff9b86 | 2012-05-12 18:33:52 +0200 | [diff] [blame] | 71 | return __batadv_store_bool_attr(buff, count, _post_func, attr, \ |
| 72 | &bat_priv->_name, net_dev); \ |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 73 | } |
| 74 | |
Marek Lindner | f245c38 | 2012-03-11 06:17:51 +0800 | [diff] [blame] | 75 | #define BAT_ATTR_SIF_SHOW_BOOL(_name) \ |
Sven Eckelmann | 0ff9b86 | 2012-05-12 18:33:52 +0200 | [diff] [blame] | 76 | ssize_t batadv_show_##_name(struct kobject *kobj, \ |
| 77 | struct attribute *attr, char *buff) \ |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 78 | { \ |
Sven Eckelmann | 0ff9b86 | 2012-05-12 18:33:52 +0200 | [diff] [blame] | 79 | struct bat_priv *bat_priv = batadv_kobj_to_batpriv(kobj); \ |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 80 | return sprintf(buff, "%s\n", \ |
| 81 | atomic_read(&bat_priv->_name) == 0 ? \ |
| 82 | "disabled" : "enabled"); \ |
| 83 | } \ |
| 84 | |
Marek Lindner | f245c38 | 2012-03-11 06:17:51 +0800 | [diff] [blame] | 85 | /* Use this, if you are going to turn a [name] in the soft-interface |
Sven Eckelmann | 9cfc7bd | 2012-05-12 02:09:43 +0200 | [diff] [blame] | 86 | * (bat_priv) on or off |
| 87 | */ |
Marek Lindner | f245c38 | 2012-03-11 06:17:51 +0800 | [diff] [blame] | 88 | #define BAT_ATTR_SIF_BOOL(_name, _mode, _post_func) \ |
| 89 | static BAT_ATTR_SIF_STORE_BOOL(_name, _post_func) \ |
| 90 | static BAT_ATTR_SIF_SHOW_BOOL(_name) \ |
Sven Eckelmann | 0ff9b86 | 2012-05-12 18:33:52 +0200 | [diff] [blame] | 91 | static BAT_ATTR(_name, _mode, batadv_show_##_name, \ |
| 92 | batadv_store_##_name) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 93 | |
| 94 | |
Marek Lindner | f245c38 | 2012-03-11 06:17:51 +0800 | [diff] [blame] | 95 | #define BAT_ATTR_SIF_STORE_UINT(_name, _min, _max, _post_func) \ |
Sven Eckelmann | 0ff9b86 | 2012-05-12 18:33:52 +0200 | [diff] [blame] | 96 | ssize_t batadv_store_##_name(struct kobject *kobj, \ |
| 97 | struct attribute *attr, char *buff, \ |
| 98 | size_t count) \ |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 99 | { \ |
Sven Eckelmann | 0ff9b86 | 2012-05-12 18:33:52 +0200 | [diff] [blame] | 100 | struct net_device *net_dev = batadv_kobj_to_netdev(kobj); \ |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 101 | struct bat_priv *bat_priv = netdev_priv(net_dev); \ |
Sven Eckelmann | 0ff9b86 | 2012-05-12 18:33:52 +0200 | [diff] [blame] | 102 | return __batadv_store_uint_attr(buff, count, _min, _max, \ |
| 103 | _post_func, attr, \ |
| 104 | &bat_priv->_name, net_dev); \ |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 105 | } |
| 106 | |
Marek Lindner | f245c38 | 2012-03-11 06:17:51 +0800 | [diff] [blame] | 107 | #define BAT_ATTR_SIF_SHOW_UINT(_name) \ |
Sven Eckelmann | 0ff9b86 | 2012-05-12 18:33:52 +0200 | [diff] [blame] | 108 | ssize_t batadv_show_##_name(struct kobject *kobj, \ |
| 109 | struct attribute *attr, char *buff) \ |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 110 | { \ |
Sven Eckelmann | 0ff9b86 | 2012-05-12 18:33:52 +0200 | [diff] [blame] | 111 | struct bat_priv *bat_priv = batadv_kobj_to_batpriv(kobj); \ |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 112 | return sprintf(buff, "%i\n", atomic_read(&bat_priv->_name)); \ |
| 113 | } \ |
| 114 | |
Marek Lindner | f245c38 | 2012-03-11 06:17:51 +0800 | [diff] [blame] | 115 | /* Use this, if you are going to set [name] in the soft-interface |
Sven Eckelmann | 9cfc7bd | 2012-05-12 02:09:43 +0200 | [diff] [blame] | 116 | * (bat_priv) to an unsigned integer value |
| 117 | */ |
Marek Lindner | f245c38 | 2012-03-11 06:17:51 +0800 | [diff] [blame] | 118 | #define BAT_ATTR_SIF_UINT(_name, _mode, _min, _max, _post_func) \ |
| 119 | static BAT_ATTR_SIF_STORE_UINT(_name, _min, _max, _post_func) \ |
| 120 | static BAT_ATTR_SIF_SHOW_UINT(_name) \ |
Sven Eckelmann | 0ff9b86 | 2012-05-12 18:33:52 +0200 | [diff] [blame] | 121 | static BAT_ATTR(_name, _mode, batadv_show_##_name, \ |
| 122 | batadv_store_##_name) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 123 | |
| 124 | |
Linus Luessing | 9d853f62 | 2012-03-11 06:17:52 +0800 | [diff] [blame] | 125 | #define BAT_ATTR_HIF_STORE_UINT(_name, _min, _max, _post_func) \ |
Sven Eckelmann | 0ff9b86 | 2012-05-12 18:33:52 +0200 | [diff] [blame] | 126 | ssize_t batadv_store_##_name(struct kobject *kobj, \ |
| 127 | struct attribute *attr, char *buff, \ |
| 128 | size_t count) \ |
Linus Luessing | 9d853f62 | 2012-03-11 06:17:52 +0800 | [diff] [blame] | 129 | { \ |
Sven Eckelmann | 0ff9b86 | 2012-05-12 18:33:52 +0200 | [diff] [blame] | 130 | struct net_device *net_dev = batadv_kobj_to_netdev(kobj); \ |
Sven Eckelmann | 9563877 | 2012-05-12 02:09:31 +0200 | [diff] [blame] | 131 | struct hard_iface *hard_iface; \ |
Linus Luessing | 9d853f62 | 2012-03-11 06:17:52 +0800 | [diff] [blame] | 132 | ssize_t length; \ |
| 133 | \ |
Sven Eckelmann | 9563877 | 2012-05-12 02:09:31 +0200 | [diff] [blame] | 134 | hard_iface = batadv_hardif_get_by_netdev(net_dev); \ |
Linus Luessing | 9d853f62 | 2012-03-11 06:17:52 +0800 | [diff] [blame] | 135 | if (!hard_iface) \ |
| 136 | return 0; \ |
| 137 | \ |
Sven Eckelmann | 0ff9b86 | 2012-05-12 18:33:52 +0200 | [diff] [blame] | 138 | length = __batadv_store_uint_attr(buff, count, _min, _max, \ |
| 139 | _post_func, attr, \ |
| 140 | &hard_iface->_name, net_dev); \ |
Linus Luessing | 9d853f62 | 2012-03-11 06:17:52 +0800 | [diff] [blame] | 141 | \ |
Sven Eckelmann | e5d8925 | 2012-05-12 13:48:54 +0200 | [diff] [blame] | 142 | batadv_hardif_free_ref(hard_iface); \ |
Linus Luessing | 9d853f62 | 2012-03-11 06:17:52 +0800 | [diff] [blame] | 143 | return length; \ |
| 144 | } |
| 145 | |
| 146 | #define BAT_ATTR_HIF_SHOW_UINT(_name) \ |
Sven Eckelmann | 0ff9b86 | 2012-05-12 18:33:52 +0200 | [diff] [blame] | 147 | ssize_t batadv_show_##_name(struct kobject *kobj, \ |
| 148 | struct attribute *attr, char *buff) \ |
Linus Luessing | 9d853f62 | 2012-03-11 06:17:52 +0800 | [diff] [blame] | 149 | { \ |
Sven Eckelmann | 0ff9b86 | 2012-05-12 18:33:52 +0200 | [diff] [blame] | 150 | struct net_device *net_dev = batadv_kobj_to_netdev(kobj); \ |
Sven Eckelmann | 9563877 | 2012-05-12 02:09:31 +0200 | [diff] [blame] | 151 | struct hard_iface *hard_iface; \ |
Linus Luessing | 9d853f62 | 2012-03-11 06:17:52 +0800 | [diff] [blame] | 152 | ssize_t length; \ |
| 153 | \ |
Sven Eckelmann | 9563877 | 2012-05-12 02:09:31 +0200 | [diff] [blame] | 154 | hard_iface = batadv_hardif_get_by_netdev(net_dev); \ |
Linus Luessing | 9d853f62 | 2012-03-11 06:17:52 +0800 | [diff] [blame] | 155 | if (!hard_iface) \ |
| 156 | return 0; \ |
| 157 | \ |
| 158 | length = sprintf(buff, "%i\n", atomic_read(&hard_iface->_name));\ |
| 159 | \ |
Sven Eckelmann | e5d8925 | 2012-05-12 13:48:54 +0200 | [diff] [blame] | 160 | batadv_hardif_free_ref(hard_iface); \ |
Linus Luessing | 9d853f62 | 2012-03-11 06:17:52 +0800 | [diff] [blame] | 161 | return length; \ |
| 162 | } |
| 163 | |
| 164 | /* Use this, if you are going to set [name] in hard_iface to an |
Sven Eckelmann | 9cfc7bd | 2012-05-12 02:09:43 +0200 | [diff] [blame] | 165 | * unsigned integer value |
| 166 | */ |
Linus Luessing | 9d853f62 | 2012-03-11 06:17:52 +0800 | [diff] [blame] | 167 | #define BAT_ATTR_HIF_UINT(_name, _mode, _min, _max, _post_func) \ |
| 168 | static BAT_ATTR_HIF_STORE_UINT(_name, _min, _max, _post_func) \ |
| 169 | static BAT_ATTR_HIF_SHOW_UINT(_name) \ |
Sven Eckelmann | 0ff9b86 | 2012-05-12 18:33:52 +0200 | [diff] [blame] | 170 | static BAT_ATTR(_name, _mode, batadv_show_##_name, \ |
| 171 | batadv_store_##_name) |
Linus Luessing | 9d853f62 | 2012-03-11 06:17:52 +0800 | [diff] [blame] | 172 | |
| 173 | |
Sven Eckelmann | 0ff9b86 | 2012-05-12 18:33:52 +0200 | [diff] [blame] | 174 | static int batadv_store_bool_attr(char *buff, size_t count, |
| 175 | struct net_device *net_dev, |
| 176 | const char *attr_name, atomic_t *attr) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 177 | { |
| 178 | int enabled = -1; |
| 179 | |
| 180 | if (buff[count - 1] == '\n') |
| 181 | buff[count - 1] = '\0'; |
| 182 | |
| 183 | if ((strncmp(buff, "1", 2) == 0) || |
| 184 | (strncmp(buff, "enable", 7) == 0) || |
| 185 | (strncmp(buff, "enabled", 8) == 0)) |
| 186 | enabled = 1; |
| 187 | |
| 188 | if ((strncmp(buff, "0", 2) == 0) || |
| 189 | (strncmp(buff, "disable", 8) == 0) || |
| 190 | (strncmp(buff, "disabled", 9) == 0)) |
| 191 | enabled = 0; |
| 192 | |
| 193 | if (enabled < 0) { |
Sven Eckelmann | 3e34819 | 2012-05-16 20:23:22 +0200 | [diff] [blame^] | 194 | batadv_info(net_dev, "%s: Invalid parameter received: %s\n", |
| 195 | attr_name, buff); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 196 | return -EINVAL; |
| 197 | } |
| 198 | |
| 199 | if (atomic_read(attr) == enabled) |
| 200 | return count; |
| 201 | |
Sven Eckelmann | 3e34819 | 2012-05-16 20:23:22 +0200 | [diff] [blame^] | 202 | batadv_info(net_dev, "%s: Changing from: %s to: %s\n", attr_name, |
| 203 | atomic_read(attr) == 1 ? "enabled" : "disabled", |
| 204 | enabled == 1 ? "enabled" : "disabled"); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 205 | |
Eric Dumazet | 95c9617 | 2012-04-15 05:58:06 +0000 | [diff] [blame] | 206 | atomic_set(attr, (unsigned int)enabled); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 207 | return count; |
| 208 | } |
| 209 | |
Sven Eckelmann | 0ff9b86 | 2012-05-12 18:33:52 +0200 | [diff] [blame] | 210 | static inline ssize_t |
| 211 | __batadv_store_bool_attr(char *buff, size_t count, |
| 212 | void (*post_func)(struct net_device *), |
| 213 | struct attribute *attr, |
| 214 | atomic_t *attr_store, struct net_device *net_dev) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 215 | { |
| 216 | int ret; |
| 217 | |
Sven Eckelmann | 0ff9b86 | 2012-05-12 18:33:52 +0200 | [diff] [blame] | 218 | ret = batadv_store_bool_attr(buff, count, net_dev, attr->name, |
| 219 | attr_store); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 220 | if (post_func && ret) |
| 221 | post_func(net_dev); |
| 222 | |
| 223 | return ret; |
| 224 | } |
| 225 | |
Sven Eckelmann | 0ff9b86 | 2012-05-12 18:33:52 +0200 | [diff] [blame] | 226 | static int batadv_store_uint_attr(const char *buff, size_t count, |
| 227 | struct net_device *net_dev, |
| 228 | const char *attr_name, |
| 229 | unsigned int min, unsigned int max, |
| 230 | atomic_t *attr) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 231 | { |
| 232 | unsigned long uint_val; |
| 233 | int ret; |
| 234 | |
Sven Eckelmann | 25a92b1 | 2011-09-30 13:32:01 +0200 | [diff] [blame] | 235 | ret = kstrtoul(buff, 10, &uint_val); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 236 | if (ret) { |
Sven Eckelmann | 3e34819 | 2012-05-16 20:23:22 +0200 | [diff] [blame^] | 237 | batadv_info(net_dev, "%s: Invalid parameter received: %s\n", |
| 238 | attr_name, buff); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 239 | return -EINVAL; |
| 240 | } |
| 241 | |
| 242 | if (uint_val < min) { |
Sven Eckelmann | 3e34819 | 2012-05-16 20:23:22 +0200 | [diff] [blame^] | 243 | batadv_info(net_dev, "%s: Value is too small: %lu min: %u\n", |
| 244 | attr_name, uint_val, min); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 245 | return -EINVAL; |
| 246 | } |
| 247 | |
| 248 | if (uint_val > max) { |
Sven Eckelmann | 3e34819 | 2012-05-16 20:23:22 +0200 | [diff] [blame^] | 249 | batadv_info(net_dev, "%s: Value is too big: %lu max: %u\n", |
| 250 | attr_name, uint_val, max); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 251 | return -EINVAL; |
| 252 | } |
| 253 | |
| 254 | if (atomic_read(attr) == uint_val) |
| 255 | return count; |
| 256 | |
Sven Eckelmann | 3e34819 | 2012-05-16 20:23:22 +0200 | [diff] [blame^] | 257 | batadv_info(net_dev, "%s: Changing from: %i to: %lu\n", |
| 258 | attr_name, atomic_read(attr), uint_val); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 259 | |
| 260 | atomic_set(attr, uint_val); |
| 261 | return count; |
| 262 | } |
| 263 | |
Sven Eckelmann | 0ff9b86 | 2012-05-12 18:33:52 +0200 | [diff] [blame] | 264 | static inline ssize_t |
| 265 | __batadv_store_uint_attr(const char *buff, size_t count, |
| 266 | int min, int max, |
| 267 | void (*post_func)(struct net_device *), |
| 268 | const struct attribute *attr, |
| 269 | atomic_t *attr_store, struct net_device *net_dev) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 270 | { |
| 271 | int ret; |
| 272 | |
Sven Eckelmann | 0ff9b86 | 2012-05-12 18:33:52 +0200 | [diff] [blame] | 273 | ret = batadv_store_uint_attr(buff, count, net_dev, attr->name, min, max, |
| 274 | attr_store); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 275 | if (post_func && ret) |
| 276 | post_func(net_dev); |
| 277 | |
| 278 | return ret; |
| 279 | } |
| 280 | |
Sven Eckelmann | 0ff9b86 | 2012-05-12 18:33:52 +0200 | [diff] [blame] | 281 | static ssize_t batadv_show_vis_mode(struct kobject *kobj, |
| 282 | struct attribute *attr, char *buff) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 283 | { |
Sven Eckelmann | 0ff9b86 | 2012-05-12 18:33:52 +0200 | [diff] [blame] | 284 | struct bat_priv *bat_priv = batadv_kobj_to_batpriv(kobj); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 285 | int vis_mode = atomic_read(&bat_priv->vis_mode); |
| 286 | |
| 287 | return sprintf(buff, "%s\n", |
| 288 | vis_mode == VIS_TYPE_CLIENT_UPDATE ? |
| 289 | "client" : "server"); |
| 290 | } |
| 291 | |
Sven Eckelmann | 0ff9b86 | 2012-05-12 18:33:52 +0200 | [diff] [blame] | 292 | static ssize_t batadv_store_vis_mode(struct kobject *kobj, |
| 293 | struct attribute *attr, char *buff, |
| 294 | size_t count) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 295 | { |
Sven Eckelmann | 0ff9b86 | 2012-05-12 18:33:52 +0200 | [diff] [blame] | 296 | struct net_device *net_dev = batadv_kobj_to_netdev(kobj); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 297 | struct bat_priv *bat_priv = netdev_priv(net_dev); |
| 298 | unsigned long val; |
| 299 | int ret, vis_mode_tmp = -1; |
Sven Eckelmann | 3e34819 | 2012-05-16 20:23:22 +0200 | [diff] [blame^] | 300 | const char *old_mode, *new_mode; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 301 | |
Sven Eckelmann | 25a92b1 | 2011-09-30 13:32:01 +0200 | [diff] [blame] | 302 | ret = kstrtoul(buff, 10, &val); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 303 | |
| 304 | if (((count == 2) && (!ret) && (val == VIS_TYPE_CLIENT_UPDATE)) || |
| 305 | (strncmp(buff, "client", 6) == 0) || |
| 306 | (strncmp(buff, "off", 3) == 0)) |
| 307 | vis_mode_tmp = VIS_TYPE_CLIENT_UPDATE; |
| 308 | |
| 309 | if (((count == 2) && (!ret) && (val == VIS_TYPE_SERVER_SYNC)) || |
| 310 | (strncmp(buff, "server", 6) == 0)) |
| 311 | vis_mode_tmp = VIS_TYPE_SERVER_SYNC; |
| 312 | |
| 313 | if (vis_mode_tmp < 0) { |
| 314 | if (buff[count - 1] == '\n') |
| 315 | buff[count - 1] = '\0'; |
| 316 | |
Sven Eckelmann | 3e34819 | 2012-05-16 20:23:22 +0200 | [diff] [blame^] | 317 | batadv_info(net_dev, |
| 318 | "Invalid parameter for 'vis mode' setting received: %s\n", |
| 319 | buff); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 320 | return -EINVAL; |
| 321 | } |
| 322 | |
| 323 | if (atomic_read(&bat_priv->vis_mode) == vis_mode_tmp) |
| 324 | return count; |
| 325 | |
Sven Eckelmann | 3e34819 | 2012-05-16 20:23:22 +0200 | [diff] [blame^] | 326 | if (atomic_read(&bat_priv->vis_mode) == VIS_TYPE_CLIENT_UPDATE) |
| 327 | old_mode = "client"; |
| 328 | else |
| 329 | old_mode = "server"; |
| 330 | |
| 331 | if (vis_mode_tmp == VIS_TYPE_CLIENT_UPDATE) |
| 332 | new_mode = "client"; |
| 333 | else |
| 334 | new_mode = "server"; |
| 335 | |
| 336 | batadv_info(net_dev, "Changing vis mode from: %s to: %s\n", old_mode, |
| 337 | new_mode); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 338 | |
Eric Dumazet | 95c9617 | 2012-04-15 05:58:06 +0000 | [diff] [blame] | 339 | atomic_set(&bat_priv->vis_mode, (unsigned int)vis_mode_tmp); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 340 | return count; |
| 341 | } |
| 342 | |
Sven Eckelmann | 0ff9b86 | 2012-05-12 18:33:52 +0200 | [diff] [blame] | 343 | static ssize_t batadv_show_bat_algo(struct kobject *kobj, |
| 344 | struct attribute *attr, char *buff) |
Marek Lindner | ea3d2fd | 2011-11-29 00:15:37 +0800 | [diff] [blame] | 345 | { |
Sven Eckelmann | 0ff9b86 | 2012-05-12 18:33:52 +0200 | [diff] [blame] | 346 | struct bat_priv *bat_priv = batadv_kobj_to_batpriv(kobj); |
Marek Lindner | ea3d2fd | 2011-11-29 00:15:37 +0800 | [diff] [blame] | 347 | return sprintf(buff, "%s\n", bat_priv->bat_algo_ops->name); |
| 348 | } |
| 349 | |
Sven Eckelmann | 0ff9b86 | 2012-05-12 18:33:52 +0200 | [diff] [blame] | 350 | static void batadv_post_gw_deselect(struct net_device *net_dev) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 351 | { |
| 352 | struct bat_priv *bat_priv = netdev_priv(net_dev); |
Sven Eckelmann | 7cf06bc | 2012-05-12 02:09:29 +0200 | [diff] [blame] | 353 | batadv_gw_deselect(bat_priv); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 354 | } |
| 355 | |
Sven Eckelmann | 0ff9b86 | 2012-05-12 18:33:52 +0200 | [diff] [blame] | 356 | static ssize_t batadv_show_gw_mode(struct kobject *kobj, struct attribute *attr, |
| 357 | char *buff) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 358 | { |
Sven Eckelmann | 0ff9b86 | 2012-05-12 18:33:52 +0200 | [diff] [blame] | 359 | struct bat_priv *bat_priv = batadv_kobj_to_batpriv(kobj); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 360 | int bytes_written; |
| 361 | |
| 362 | switch (atomic_read(&bat_priv->gw_mode)) { |
| 363 | case GW_MODE_CLIENT: |
| 364 | bytes_written = sprintf(buff, "%s\n", GW_MODE_CLIENT_NAME); |
| 365 | break; |
| 366 | case GW_MODE_SERVER: |
| 367 | bytes_written = sprintf(buff, "%s\n", GW_MODE_SERVER_NAME); |
| 368 | break; |
| 369 | default: |
| 370 | bytes_written = sprintf(buff, "%s\n", GW_MODE_OFF_NAME); |
| 371 | break; |
| 372 | } |
| 373 | |
| 374 | return bytes_written; |
| 375 | } |
| 376 | |
Sven Eckelmann | 0ff9b86 | 2012-05-12 18:33:52 +0200 | [diff] [blame] | 377 | static ssize_t batadv_store_gw_mode(struct kobject *kobj, |
| 378 | struct attribute *attr, char *buff, |
| 379 | size_t count) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 380 | { |
Sven Eckelmann | 0ff9b86 | 2012-05-12 18:33:52 +0200 | [diff] [blame] | 381 | struct net_device *net_dev = batadv_kobj_to_netdev(kobj); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 382 | struct bat_priv *bat_priv = netdev_priv(net_dev); |
| 383 | char *curr_gw_mode_str; |
| 384 | int gw_mode_tmp = -1; |
| 385 | |
| 386 | if (buff[count - 1] == '\n') |
| 387 | buff[count - 1] = '\0'; |
| 388 | |
| 389 | if (strncmp(buff, GW_MODE_OFF_NAME, strlen(GW_MODE_OFF_NAME)) == 0) |
| 390 | gw_mode_tmp = GW_MODE_OFF; |
| 391 | |
| 392 | if (strncmp(buff, GW_MODE_CLIENT_NAME, |
Sven Eckelmann | 7c64fd9 | 2012-02-28 10:55:36 +0100 | [diff] [blame] | 393 | strlen(GW_MODE_CLIENT_NAME)) == 0) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 394 | gw_mode_tmp = GW_MODE_CLIENT; |
| 395 | |
| 396 | if (strncmp(buff, GW_MODE_SERVER_NAME, |
Sven Eckelmann | 7c64fd9 | 2012-02-28 10:55:36 +0100 | [diff] [blame] | 397 | strlen(GW_MODE_SERVER_NAME)) == 0) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 398 | gw_mode_tmp = GW_MODE_SERVER; |
| 399 | |
| 400 | if (gw_mode_tmp < 0) { |
Sven Eckelmann | 3e34819 | 2012-05-16 20:23:22 +0200 | [diff] [blame^] | 401 | batadv_info(net_dev, |
| 402 | "Invalid parameter for 'gw mode' setting received: %s\n", |
| 403 | buff); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 404 | return -EINVAL; |
| 405 | } |
| 406 | |
| 407 | if (atomic_read(&bat_priv->gw_mode) == gw_mode_tmp) |
| 408 | return count; |
| 409 | |
| 410 | switch (atomic_read(&bat_priv->gw_mode)) { |
| 411 | case GW_MODE_CLIENT: |
| 412 | curr_gw_mode_str = GW_MODE_CLIENT_NAME; |
| 413 | break; |
| 414 | case GW_MODE_SERVER: |
| 415 | curr_gw_mode_str = GW_MODE_SERVER_NAME; |
| 416 | break; |
| 417 | default: |
| 418 | curr_gw_mode_str = GW_MODE_OFF_NAME; |
| 419 | break; |
| 420 | } |
| 421 | |
Sven Eckelmann | 3e34819 | 2012-05-16 20:23:22 +0200 | [diff] [blame^] | 422 | batadv_info(net_dev, "Changing gw mode from: %s to: %s\n", |
| 423 | curr_gw_mode_str, buff); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 424 | |
Sven Eckelmann | 7cf06bc | 2012-05-12 02:09:29 +0200 | [diff] [blame] | 425 | batadv_gw_deselect(bat_priv); |
Eric Dumazet | 95c9617 | 2012-04-15 05:58:06 +0000 | [diff] [blame] | 426 | atomic_set(&bat_priv->gw_mode, (unsigned int)gw_mode_tmp); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 427 | return count; |
| 428 | } |
| 429 | |
Sven Eckelmann | 0ff9b86 | 2012-05-12 18:33:52 +0200 | [diff] [blame] | 430 | static ssize_t batadv_show_gw_bwidth(struct kobject *kobj, |
| 431 | struct attribute *attr, char *buff) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 432 | { |
Sven Eckelmann | 0ff9b86 | 2012-05-12 18:33:52 +0200 | [diff] [blame] | 433 | struct bat_priv *bat_priv = batadv_kobj_to_batpriv(kobj); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 434 | int down, up; |
| 435 | int gw_bandwidth = atomic_read(&bat_priv->gw_bandwidth); |
| 436 | |
Sven Eckelmann | 84d5e5e | 2012-05-12 02:09:30 +0200 | [diff] [blame] | 437 | batadv_gw_bandwidth_to_kbit(gw_bandwidth, &down, &up); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 438 | return sprintf(buff, "%i%s/%i%s\n", |
| 439 | (down > 2048 ? down / 1024 : down), |
| 440 | (down > 2048 ? "MBit" : "KBit"), |
| 441 | (up > 2048 ? up / 1024 : up), |
| 442 | (up > 2048 ? "MBit" : "KBit")); |
| 443 | } |
| 444 | |
Sven Eckelmann | 0ff9b86 | 2012-05-12 18:33:52 +0200 | [diff] [blame] | 445 | static ssize_t batadv_store_gw_bwidth(struct kobject *kobj, |
| 446 | struct attribute *attr, char *buff, |
| 447 | size_t count) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 448 | { |
Sven Eckelmann | 0ff9b86 | 2012-05-12 18:33:52 +0200 | [diff] [blame] | 449 | struct net_device *net_dev = batadv_kobj_to_netdev(kobj); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 450 | |
| 451 | if (buff[count - 1] == '\n') |
| 452 | buff[count - 1] = '\0'; |
| 453 | |
Sven Eckelmann | 84d5e5e | 2012-05-12 02:09:30 +0200 | [diff] [blame] | 454 | return batadv_gw_bandwidth_set(net_dev, buff, count); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 455 | } |
| 456 | |
Marek Lindner | f245c38 | 2012-03-11 06:17:51 +0800 | [diff] [blame] | 457 | BAT_ATTR_SIF_BOOL(aggregated_ogms, S_IRUGO | S_IWUSR, NULL); |
| 458 | BAT_ATTR_SIF_BOOL(bonding, S_IRUGO | S_IWUSR, NULL); |
Simon Wunderlich | 7a5cc24 | 2012-01-22 20:00:27 +0100 | [diff] [blame] | 459 | #ifdef CONFIG_BATMAN_ADV_BLA |
Marek Lindner | f245c38 | 2012-03-11 06:17:51 +0800 | [diff] [blame] | 460 | BAT_ATTR_SIF_BOOL(bridge_loop_avoidance, S_IRUGO | S_IWUSR, NULL); |
Simon Wunderlich | 7a5cc24 | 2012-01-22 20:00:27 +0100 | [diff] [blame] | 461 | #endif |
Sven Eckelmann | 9563877 | 2012-05-12 02:09:31 +0200 | [diff] [blame] | 462 | BAT_ATTR_SIF_BOOL(fragmentation, S_IRUGO | S_IWUSR, batadv_update_min_mtu); |
Marek Lindner | f245c38 | 2012-03-11 06:17:51 +0800 | [diff] [blame] | 463 | BAT_ATTR_SIF_BOOL(ap_isolation, S_IRUGO | S_IWUSR, NULL); |
Sven Eckelmann | 0ff9b86 | 2012-05-12 18:33:52 +0200 | [diff] [blame] | 464 | static BAT_ATTR(vis_mode, S_IRUGO | S_IWUSR, batadv_show_vis_mode, |
| 465 | batadv_store_vis_mode); |
| 466 | static BAT_ATTR(routing_algo, S_IRUGO, batadv_show_bat_algo, NULL); |
| 467 | static BAT_ATTR(gw_mode, S_IRUGO | S_IWUSR, batadv_show_gw_mode, |
| 468 | batadv_store_gw_mode); |
Marek Lindner | f245c38 | 2012-03-11 06:17:51 +0800 | [diff] [blame] | 469 | BAT_ATTR_SIF_UINT(orig_interval, S_IRUGO | S_IWUSR, 2 * JITTER, INT_MAX, NULL); |
| 470 | BAT_ATTR_SIF_UINT(hop_penalty, S_IRUGO | S_IWUSR, 0, TQ_MAX_VALUE, NULL); |
| 471 | BAT_ATTR_SIF_UINT(gw_sel_class, S_IRUGO | S_IWUSR, 1, TQ_MAX_VALUE, |
Sven Eckelmann | 0ff9b86 | 2012-05-12 18:33:52 +0200 | [diff] [blame] | 472 | batadv_post_gw_deselect); |
| 473 | static BAT_ATTR(gw_bandwidth, S_IRUGO | S_IWUSR, batadv_show_gw_bwidth, |
| 474 | batadv_store_gw_bwidth); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 475 | #ifdef CONFIG_BATMAN_ADV_DEBUG |
Antonio Quartulli | ef3a409 | 2012-05-09 09:50:45 +0200 | [diff] [blame] | 476 | BAT_ATTR_SIF_UINT(log_level, S_IRUGO | S_IWUSR, 0, DBG_ALL, NULL); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 477 | #endif |
| 478 | |
Sven Eckelmann | 0ff9b86 | 2012-05-12 18:33:52 +0200 | [diff] [blame] | 479 | static struct bat_attribute *batadv_mesh_attrs[] = { |
| 480 | &batadv_attr_aggregated_ogms, |
| 481 | &batadv_attr_bonding, |
Simon Wunderlich | 7a5cc24 | 2012-01-22 20:00:27 +0100 | [diff] [blame] | 482 | #ifdef CONFIG_BATMAN_ADV_BLA |
Sven Eckelmann | 0ff9b86 | 2012-05-12 18:33:52 +0200 | [diff] [blame] | 483 | &batadv_attr_bridge_loop_avoidance, |
Simon Wunderlich | 7a5cc24 | 2012-01-22 20:00:27 +0100 | [diff] [blame] | 484 | #endif |
Sven Eckelmann | 0ff9b86 | 2012-05-12 18:33:52 +0200 | [diff] [blame] | 485 | &batadv_attr_fragmentation, |
| 486 | &batadv_attr_ap_isolation, |
| 487 | &batadv_attr_vis_mode, |
| 488 | &batadv_attr_routing_algo, |
| 489 | &batadv_attr_gw_mode, |
| 490 | &batadv_attr_orig_interval, |
| 491 | &batadv_attr_hop_penalty, |
| 492 | &batadv_attr_gw_sel_class, |
| 493 | &batadv_attr_gw_bandwidth, |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 494 | #ifdef CONFIG_BATMAN_ADV_DEBUG |
Sven Eckelmann | 0ff9b86 | 2012-05-12 18:33:52 +0200 | [diff] [blame] | 495 | &batadv_attr_log_level, |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 496 | #endif |
| 497 | NULL, |
| 498 | }; |
| 499 | |
Sven Eckelmann | 5853e22 | 2012-05-12 02:09:24 +0200 | [diff] [blame] | 500 | int batadv_sysfs_add_meshif(struct net_device *dev) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 501 | { |
| 502 | struct kobject *batif_kobject = &dev->dev.kobj; |
| 503 | struct bat_priv *bat_priv = netdev_priv(dev); |
| 504 | struct bat_attribute **bat_attr; |
| 505 | int err; |
| 506 | |
| 507 | bat_priv->mesh_obj = kobject_create_and_add(SYSFS_IF_MESH_SUBDIR, |
| 508 | batif_kobject); |
| 509 | if (!bat_priv->mesh_obj) { |
Sven Eckelmann | 3e34819 | 2012-05-16 20:23:22 +0200 | [diff] [blame^] | 510 | batadv_err(dev, "Can't add sysfs directory: %s/%s\n", dev->name, |
| 511 | SYSFS_IF_MESH_SUBDIR); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 512 | goto out; |
| 513 | } |
| 514 | |
Sven Eckelmann | 0ff9b86 | 2012-05-12 18:33:52 +0200 | [diff] [blame] | 515 | for (bat_attr = batadv_mesh_attrs; *bat_attr; ++bat_attr) { |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 516 | err = sysfs_create_file(bat_priv->mesh_obj, |
| 517 | &((*bat_attr)->attr)); |
| 518 | if (err) { |
Sven Eckelmann | 3e34819 | 2012-05-16 20:23:22 +0200 | [diff] [blame^] | 519 | batadv_err(dev, "Can't add sysfs file: %s/%s/%s\n", |
| 520 | dev->name, SYSFS_IF_MESH_SUBDIR, |
| 521 | ((*bat_attr)->attr).name); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 522 | goto rem_attr; |
| 523 | } |
| 524 | } |
| 525 | |
| 526 | return 0; |
| 527 | |
| 528 | rem_attr: |
Sven Eckelmann | 0ff9b86 | 2012-05-12 18:33:52 +0200 | [diff] [blame] | 529 | for (bat_attr = batadv_mesh_attrs; *bat_attr; ++bat_attr) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 530 | sysfs_remove_file(bat_priv->mesh_obj, &((*bat_attr)->attr)); |
| 531 | |
| 532 | kobject_put(bat_priv->mesh_obj); |
| 533 | bat_priv->mesh_obj = NULL; |
| 534 | out: |
| 535 | return -ENOMEM; |
| 536 | } |
| 537 | |
Sven Eckelmann | 5853e22 | 2012-05-12 02:09:24 +0200 | [diff] [blame] | 538 | void batadv_sysfs_del_meshif(struct net_device *dev) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 539 | { |
| 540 | struct bat_priv *bat_priv = netdev_priv(dev); |
| 541 | struct bat_attribute **bat_attr; |
| 542 | |
Sven Eckelmann | 0ff9b86 | 2012-05-12 18:33:52 +0200 | [diff] [blame] | 543 | for (bat_attr = batadv_mesh_attrs; *bat_attr; ++bat_attr) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 544 | sysfs_remove_file(bat_priv->mesh_obj, &((*bat_attr)->attr)); |
| 545 | |
| 546 | kobject_put(bat_priv->mesh_obj); |
| 547 | bat_priv->mesh_obj = NULL; |
| 548 | } |
| 549 | |
Sven Eckelmann | 0ff9b86 | 2012-05-12 18:33:52 +0200 | [diff] [blame] | 550 | static ssize_t batadv_show_mesh_iface(struct kobject *kobj, |
| 551 | struct attribute *attr, char *buff) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 552 | { |
Sven Eckelmann | 0ff9b86 | 2012-05-12 18:33:52 +0200 | [diff] [blame] | 553 | struct net_device *net_dev = batadv_kobj_to_netdev(kobj); |
Sven Eckelmann | 9563877 | 2012-05-12 02:09:31 +0200 | [diff] [blame] | 554 | struct hard_iface *hard_iface = batadv_hardif_get_by_netdev(net_dev); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 555 | ssize_t length; |
| 556 | |
Marek Lindner | e6c10f4 | 2011-02-18 12:33:20 +0000 | [diff] [blame] | 557 | if (!hard_iface) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 558 | return 0; |
| 559 | |
Marek Lindner | e6c10f4 | 2011-02-18 12:33:20 +0000 | [diff] [blame] | 560 | length = sprintf(buff, "%s\n", hard_iface->if_status == IF_NOT_IN_USE ? |
| 561 | "none" : hard_iface->soft_iface->name); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 562 | |
Sven Eckelmann | e5d8925 | 2012-05-12 13:48:54 +0200 | [diff] [blame] | 563 | batadv_hardif_free_ref(hard_iface); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 564 | |
| 565 | return length; |
| 566 | } |
| 567 | |
Sven Eckelmann | 0ff9b86 | 2012-05-12 18:33:52 +0200 | [diff] [blame] | 568 | static ssize_t batadv_store_mesh_iface(struct kobject *kobj, |
| 569 | struct attribute *attr, char *buff, |
| 570 | size_t count) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 571 | { |
Sven Eckelmann | 0ff9b86 | 2012-05-12 18:33:52 +0200 | [diff] [blame] | 572 | struct net_device *net_dev = batadv_kobj_to_netdev(kobj); |
Sven Eckelmann | 9563877 | 2012-05-12 02:09:31 +0200 | [diff] [blame] | 573 | struct hard_iface *hard_iface = batadv_hardif_get_by_netdev(net_dev); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 574 | int status_tmp = -1; |
Marek Lindner | ed75ccb | 2011-02-10 14:33:51 +0000 | [diff] [blame] | 575 | int ret = count; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 576 | |
Marek Lindner | e6c10f4 | 2011-02-18 12:33:20 +0000 | [diff] [blame] | 577 | if (!hard_iface) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 578 | return count; |
| 579 | |
| 580 | if (buff[count - 1] == '\n') |
| 581 | buff[count - 1] = '\0'; |
| 582 | |
| 583 | if (strlen(buff) >= IFNAMSIZ) { |
Sven Eckelmann | 86ceb36 | 2012-03-07 09:07:45 +0100 | [diff] [blame] | 584 | pr_err("Invalid parameter for 'mesh_iface' setting received: interface name too long '%s'\n", |
| 585 | buff); |
Sven Eckelmann | e5d8925 | 2012-05-12 13:48:54 +0200 | [diff] [blame] | 586 | batadv_hardif_free_ref(hard_iface); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 587 | return -EINVAL; |
| 588 | } |
| 589 | |
| 590 | if (strncmp(buff, "none", 4) == 0) |
| 591 | status_tmp = IF_NOT_IN_USE; |
| 592 | else |
| 593 | status_tmp = IF_I_WANT_YOU; |
| 594 | |
Marek Lindner | e6c10f4 | 2011-02-18 12:33:20 +0000 | [diff] [blame] | 595 | if (hard_iface->if_status == status_tmp) |
| 596 | goto out; |
| 597 | |
| 598 | if ((hard_iface->soft_iface) && |
| 599 | (strncmp(hard_iface->soft_iface->name, buff, IFNAMSIZ) == 0)) |
Marek Lindner | ed75ccb | 2011-02-10 14:33:51 +0000 | [diff] [blame] | 600 | goto out; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 601 | |
Sven Eckelmann | 3a4375a | 2011-05-03 13:10:06 +0200 | [diff] [blame] | 602 | if (!rtnl_trylock()) { |
| 603 | ret = -ERESTARTSYS; |
Marek Lindner | ed75ccb | 2011-02-10 14:33:51 +0000 | [diff] [blame] | 604 | goto out; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 605 | } |
| 606 | |
Sven Eckelmann | 3a4375a | 2011-05-03 13:10:06 +0200 | [diff] [blame] | 607 | if (status_tmp == IF_NOT_IN_USE) { |
Sven Eckelmann | 9563877 | 2012-05-12 02:09:31 +0200 | [diff] [blame] | 608 | batadv_hardif_disable_interface(hard_iface); |
Sven Eckelmann | 3a4375a | 2011-05-03 13:10:06 +0200 | [diff] [blame] | 609 | goto unlock; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 610 | } |
| 611 | |
Sven Eckelmann | 3a4375a | 2011-05-03 13:10:06 +0200 | [diff] [blame] | 612 | /* if the interface already is in use */ |
| 613 | if (hard_iface->if_status != IF_NOT_IN_USE) |
Sven Eckelmann | 9563877 | 2012-05-12 02:09:31 +0200 | [diff] [blame] | 614 | batadv_hardif_disable_interface(hard_iface); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 615 | |
Sven Eckelmann | 9563877 | 2012-05-12 02:09:31 +0200 | [diff] [blame] | 616 | ret = batadv_hardif_enable_interface(hard_iface, buff); |
Sven Eckelmann | 3a4375a | 2011-05-03 13:10:06 +0200 | [diff] [blame] | 617 | |
| 618 | unlock: |
| 619 | rtnl_unlock(); |
Marek Lindner | ed75ccb | 2011-02-10 14:33:51 +0000 | [diff] [blame] | 620 | out: |
Sven Eckelmann | e5d8925 | 2012-05-12 13:48:54 +0200 | [diff] [blame] | 621 | batadv_hardif_free_ref(hard_iface); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 622 | return ret; |
| 623 | } |
| 624 | |
Sven Eckelmann | 0ff9b86 | 2012-05-12 18:33:52 +0200 | [diff] [blame] | 625 | static ssize_t batadv_show_iface_status(struct kobject *kobj, |
| 626 | struct attribute *attr, char *buff) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 627 | { |
Sven Eckelmann | 0ff9b86 | 2012-05-12 18:33:52 +0200 | [diff] [blame] | 628 | struct net_device *net_dev = batadv_kobj_to_netdev(kobj); |
Sven Eckelmann | 9563877 | 2012-05-12 02:09:31 +0200 | [diff] [blame] | 629 | struct hard_iface *hard_iface = batadv_hardif_get_by_netdev(net_dev); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 630 | ssize_t length; |
| 631 | |
Marek Lindner | e6c10f4 | 2011-02-18 12:33:20 +0000 | [diff] [blame] | 632 | if (!hard_iface) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 633 | return 0; |
| 634 | |
Marek Lindner | e6c10f4 | 2011-02-18 12:33:20 +0000 | [diff] [blame] | 635 | switch (hard_iface->if_status) { |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 636 | case IF_TO_BE_REMOVED: |
| 637 | length = sprintf(buff, "disabling\n"); |
| 638 | break; |
| 639 | case IF_INACTIVE: |
| 640 | length = sprintf(buff, "inactive\n"); |
| 641 | break; |
| 642 | case IF_ACTIVE: |
| 643 | length = sprintf(buff, "active\n"); |
| 644 | break; |
| 645 | case IF_TO_BE_ACTIVATED: |
| 646 | length = sprintf(buff, "enabling\n"); |
| 647 | break; |
| 648 | case IF_NOT_IN_USE: |
| 649 | default: |
| 650 | length = sprintf(buff, "not in use\n"); |
| 651 | break; |
| 652 | } |
| 653 | |
Sven Eckelmann | e5d8925 | 2012-05-12 13:48:54 +0200 | [diff] [blame] | 654 | batadv_hardif_free_ref(hard_iface); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 655 | |
| 656 | return length; |
| 657 | } |
| 658 | |
| 659 | static BAT_ATTR(mesh_iface, S_IRUGO | S_IWUSR, |
Sven Eckelmann | 0ff9b86 | 2012-05-12 18:33:52 +0200 | [diff] [blame] | 660 | batadv_show_mesh_iface, batadv_store_mesh_iface); |
| 661 | static BAT_ATTR(iface_status, S_IRUGO, batadv_show_iface_status, NULL); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 662 | |
Sven Eckelmann | 0ff9b86 | 2012-05-12 18:33:52 +0200 | [diff] [blame] | 663 | static struct bat_attribute *batadv_batman_attrs[] = { |
| 664 | &batadv_attr_mesh_iface, |
| 665 | &batadv_attr_iface_status, |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 666 | NULL, |
| 667 | }; |
| 668 | |
Sven Eckelmann | 5853e22 | 2012-05-12 02:09:24 +0200 | [diff] [blame] | 669 | int batadv_sysfs_add_hardif(struct kobject **hardif_obj, struct net_device *dev) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 670 | { |
| 671 | struct kobject *hardif_kobject = &dev->dev.kobj; |
| 672 | struct bat_attribute **bat_attr; |
| 673 | int err; |
| 674 | |
| 675 | *hardif_obj = kobject_create_and_add(SYSFS_IF_BAT_SUBDIR, |
| 676 | hardif_kobject); |
| 677 | |
| 678 | if (!*hardif_obj) { |
Sven Eckelmann | 3e34819 | 2012-05-16 20:23:22 +0200 | [diff] [blame^] | 679 | batadv_err(dev, "Can't add sysfs directory: %s/%s\n", dev->name, |
| 680 | SYSFS_IF_BAT_SUBDIR); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 681 | goto out; |
| 682 | } |
| 683 | |
Sven Eckelmann | 0ff9b86 | 2012-05-12 18:33:52 +0200 | [diff] [blame] | 684 | for (bat_attr = batadv_batman_attrs; *bat_attr; ++bat_attr) { |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 685 | err = sysfs_create_file(*hardif_obj, &((*bat_attr)->attr)); |
| 686 | if (err) { |
Sven Eckelmann | 3e34819 | 2012-05-16 20:23:22 +0200 | [diff] [blame^] | 687 | batadv_err(dev, "Can't add sysfs file: %s/%s/%s\n", |
| 688 | dev->name, SYSFS_IF_BAT_SUBDIR, |
| 689 | ((*bat_attr)->attr).name); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 690 | goto rem_attr; |
| 691 | } |
| 692 | } |
| 693 | |
| 694 | return 0; |
| 695 | |
| 696 | rem_attr: |
Sven Eckelmann | 0ff9b86 | 2012-05-12 18:33:52 +0200 | [diff] [blame] | 697 | for (bat_attr = batadv_batman_attrs; *bat_attr; ++bat_attr) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 698 | sysfs_remove_file(*hardif_obj, &((*bat_attr)->attr)); |
| 699 | out: |
| 700 | return -ENOMEM; |
| 701 | } |
| 702 | |
Sven Eckelmann | 5853e22 | 2012-05-12 02:09:24 +0200 | [diff] [blame] | 703 | void batadv_sysfs_del_hardif(struct kobject **hardif_obj) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 704 | { |
| 705 | kobject_put(*hardif_obj); |
| 706 | *hardif_obj = NULL; |
| 707 | } |
Antonio Quartulli | c6bda68 | 2011-04-26 18:26:01 +0200 | [diff] [blame] | 708 | |
Sven Eckelmann | 5853e22 | 2012-05-12 02:09:24 +0200 | [diff] [blame] | 709 | int batadv_throw_uevent(struct bat_priv *bat_priv, enum uev_type type, |
| 710 | enum uev_action action, const char *data) |
Antonio Quartulli | c6bda68 | 2011-04-26 18:26:01 +0200 | [diff] [blame] | 711 | { |
Sven Eckelmann | 5346c35 | 2012-05-05 13:27:28 +0200 | [diff] [blame] | 712 | int ret = -ENOMEM; |
Antonio Quartulli | c6bda68 | 2011-04-26 18:26:01 +0200 | [diff] [blame] | 713 | struct hard_iface *primary_if = NULL; |
| 714 | struct kobject *bat_kobj; |
| 715 | char *uevent_env[4] = { NULL, NULL, NULL, NULL }; |
| 716 | |
Sven Eckelmann | e5d8925 | 2012-05-12 13:48:54 +0200 | [diff] [blame] | 717 | primary_if = batadv_primary_if_get_selected(bat_priv); |
Antonio Quartulli | c6bda68 | 2011-04-26 18:26:01 +0200 | [diff] [blame] | 718 | if (!primary_if) |
| 719 | goto out; |
| 720 | |
| 721 | bat_kobj = &primary_if->soft_iface->dev.kobj; |
| 722 | |
| 723 | uevent_env[0] = kmalloc(strlen(UEV_TYPE_VAR) + |
Sven Eckelmann | 0ff9b86 | 2012-05-12 18:33:52 +0200 | [diff] [blame] | 724 | strlen(batadv_uev_type_str[type]) + 1, |
Antonio Quartulli | c6bda68 | 2011-04-26 18:26:01 +0200 | [diff] [blame] | 725 | GFP_ATOMIC); |
| 726 | if (!uevent_env[0]) |
| 727 | goto out; |
| 728 | |
Sven Eckelmann | 0ff9b86 | 2012-05-12 18:33:52 +0200 | [diff] [blame] | 729 | sprintf(uevent_env[0], "%s%s", UEV_TYPE_VAR, batadv_uev_type_str[type]); |
Antonio Quartulli | c6bda68 | 2011-04-26 18:26:01 +0200 | [diff] [blame] | 730 | |
| 731 | uevent_env[1] = kmalloc(strlen(UEV_ACTION_VAR) + |
Sven Eckelmann | 0ff9b86 | 2012-05-12 18:33:52 +0200 | [diff] [blame] | 732 | strlen(batadv_uev_action_str[action]) + 1, |
Antonio Quartulli | c6bda68 | 2011-04-26 18:26:01 +0200 | [diff] [blame] | 733 | GFP_ATOMIC); |
| 734 | if (!uevent_env[1]) |
| 735 | goto out; |
| 736 | |
Sven Eckelmann | 0ff9b86 | 2012-05-12 18:33:52 +0200 | [diff] [blame] | 737 | sprintf(uevent_env[1], "%s%s", UEV_ACTION_VAR, |
| 738 | batadv_uev_action_str[action]); |
Antonio Quartulli | c6bda68 | 2011-04-26 18:26:01 +0200 | [diff] [blame] | 739 | |
| 740 | /* If the event is DEL, ignore the data field */ |
| 741 | if (action != UEV_DEL) { |
| 742 | uevent_env[2] = kmalloc(strlen(UEV_DATA_VAR) + |
| 743 | strlen(data) + 1, GFP_ATOMIC); |
| 744 | if (!uevent_env[2]) |
| 745 | goto out; |
| 746 | |
| 747 | sprintf(uevent_env[2], "%s%s", UEV_DATA_VAR, data); |
| 748 | } |
| 749 | |
| 750 | ret = kobject_uevent_env(bat_kobj, KOBJ_CHANGE, uevent_env); |
| 751 | out: |
| 752 | kfree(uevent_env[0]); |
| 753 | kfree(uevent_env[1]); |
| 754 | kfree(uevent_env[2]); |
| 755 | |
| 756 | if (primary_if) |
Sven Eckelmann | e5d8925 | 2012-05-12 13:48:54 +0200 | [diff] [blame] | 757 | batadv_hardif_free_ref(primary_if); |
Antonio Quartulli | c6bda68 | 2011-04-26 18:26:01 +0200 | [diff] [blame] | 758 | |
| 759 | if (ret) |
Sven Eckelmann | 1eda58b | 2012-05-12 13:48:58 +0200 | [diff] [blame] | 760 | batadv_dbg(DBG_BATMAN, bat_priv, |
| 761 | "Impossible to send uevent for (%s,%s,%s) event (err: %d)\n", |
Sven Eckelmann | 0ff9b86 | 2012-05-12 18:33:52 +0200 | [diff] [blame] | 762 | batadv_uev_type_str[type], |
| 763 | batadv_uev_action_str[action], |
Sven Eckelmann | 1eda58b | 2012-05-12 13:48:58 +0200 | [diff] [blame] | 764 | (action == UEV_DEL ? "NULL" : data), ret); |
Antonio Quartulli | c6bda68 | 2011-04-26 18:26:01 +0200 | [diff] [blame] | 765 | return ret; |
| 766 | } |