blob: 6f70560ef5087503ed3de35952eda6fc1023292a [file] [log] [blame]
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +00001/*
Sven Eckelmann64afe352011-01-27 10:38:15 +01002 * Copyright (C) 2010-2011 B.A.T.M.A.N. contributors:
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +00003 *
4 * Marek Lindner
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of version 2 of the GNU General Public
8 * License as published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
18 * 02110-1301, USA
19 *
20 */
21
22#include "main.h"
23#include "bat_sysfs.h"
24#include "translation-table.h"
25#include "originator.h"
26#include "hard-interface.h"
27#include "gateway_common.h"
28#include "gateway_client.h"
29#include "vis.h"
30
31#define to_dev(obj) container_of(obj, struct device, kobj)
32#define kobj_to_netdev(obj) to_net_dev(to_dev(obj->parent))
33#define kobj_to_batpriv(obj) netdev_priv(kobj_to_netdev(obj))
34
35/* Use this, if you have customized show and store functions */
36#define BAT_ATTR(_name, _mode, _show, _store) \
37struct bat_attribute bat_attr_##_name = { \
38 .attr = {.name = __stringify(_name), \
39 .mode = _mode }, \
40 .show = _show, \
41 .store = _store, \
42};
43
44#define BAT_ATTR_STORE_BOOL(_name, _post_func) \
45ssize_t store_##_name(struct kobject *kobj, struct attribute *attr, \
46 char *buff, size_t count) \
47{ \
48 struct net_device *net_dev = kobj_to_netdev(kobj); \
49 struct bat_priv *bat_priv = netdev_priv(net_dev); \
50 return __store_bool_attr(buff, count, _post_func, attr, \
51 &bat_priv->_name, net_dev); \
52}
53
54#define BAT_ATTR_SHOW_BOOL(_name) \
55ssize_t show_##_name(struct kobject *kobj, struct attribute *attr, \
56 char *buff) \
57{ \
58 struct bat_priv *bat_priv = kobj_to_batpriv(kobj); \
59 return sprintf(buff, "%s\n", \
60 atomic_read(&bat_priv->_name) == 0 ? \
61 "disabled" : "enabled"); \
62} \
63
64/* Use this, if you are going to turn a [name] in bat_priv on or off */
65#define BAT_ATTR_BOOL(_name, _mode, _post_func) \
66 static BAT_ATTR_STORE_BOOL(_name, _post_func) \
67 static BAT_ATTR_SHOW_BOOL(_name) \
68 static BAT_ATTR(_name, _mode, show_##_name, store_##_name)
69
70
71#define BAT_ATTR_STORE_UINT(_name, _min, _max, _post_func) \
72ssize_t store_##_name(struct kobject *kobj, struct attribute *attr, \
73 char *buff, size_t count) \
74{ \
75 struct net_device *net_dev = kobj_to_netdev(kobj); \
76 struct bat_priv *bat_priv = netdev_priv(net_dev); \
77 return __store_uint_attr(buff, count, _min, _max, _post_func, \
78 attr, &bat_priv->_name, net_dev); \
79}
80
81#define BAT_ATTR_SHOW_UINT(_name) \
82ssize_t show_##_name(struct kobject *kobj, struct attribute *attr, \
83 char *buff) \
84{ \
85 struct bat_priv *bat_priv = kobj_to_batpriv(kobj); \
86 return sprintf(buff, "%i\n", atomic_read(&bat_priv->_name)); \
87} \
88
89/* Use this, if you are going to set [name] in bat_priv to unsigned integer
90 * values only */
91#define BAT_ATTR_UINT(_name, _mode, _min, _max, _post_func) \
92 static BAT_ATTR_STORE_UINT(_name, _min, _max, _post_func) \
93 static BAT_ATTR_SHOW_UINT(_name) \
94 static BAT_ATTR(_name, _mode, show_##_name, store_##_name)
95
96
97static int store_bool_attr(char *buff, size_t count,
98 struct net_device *net_dev,
Sven Eckelmann747e4222011-05-14 23:14:50 +020099 const char *attr_name, atomic_t *attr)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000100{
101 int enabled = -1;
102
103 if (buff[count - 1] == '\n')
104 buff[count - 1] = '\0';
105
106 if ((strncmp(buff, "1", 2) == 0) ||
107 (strncmp(buff, "enable", 7) == 0) ||
108 (strncmp(buff, "enabled", 8) == 0))
109 enabled = 1;
110
111 if ((strncmp(buff, "0", 2) == 0) ||
112 (strncmp(buff, "disable", 8) == 0) ||
113 (strncmp(buff, "disabled", 9) == 0))
114 enabled = 0;
115
116 if (enabled < 0) {
117 bat_info(net_dev,
118 "%s: Invalid parameter received: %s\n",
119 attr_name, buff);
120 return -EINVAL;
121 }
122
123 if (atomic_read(attr) == enabled)
124 return count;
125
126 bat_info(net_dev, "%s: Changing from: %s to: %s\n", attr_name,
127 atomic_read(attr) == 1 ? "enabled" : "disabled",
128 enabled == 1 ? "enabled" : "disabled");
129
130 atomic_set(attr, (unsigned)enabled);
131 return count;
132}
133
134static inline ssize_t __store_bool_attr(char *buff, size_t count,
135 void (*post_func)(struct net_device *),
136 struct attribute *attr,
137 atomic_t *attr_store, struct net_device *net_dev)
138{
139 int ret;
140
Sven Eckelmann747e4222011-05-14 23:14:50 +0200141 ret = store_bool_attr(buff, count, net_dev, attr->name, attr_store);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000142 if (post_func && ret)
143 post_func(net_dev);
144
145 return ret;
146}
147
Sven Eckelmann747e4222011-05-14 23:14:50 +0200148static int store_uint_attr(const char *buff, size_t count,
149 struct net_device *net_dev, const char *attr_name,
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000150 unsigned int min, unsigned int max, atomic_t *attr)
151{
152 unsigned long uint_val;
153 int ret;
154
155 ret = strict_strtoul(buff, 10, &uint_val);
156 if (ret) {
157 bat_info(net_dev,
158 "%s: Invalid parameter received: %s\n",
159 attr_name, buff);
160 return -EINVAL;
161 }
162
163 if (uint_val < min) {
164 bat_info(net_dev, "%s: Value is too small: %lu min: %u\n",
165 attr_name, uint_val, min);
166 return -EINVAL;
167 }
168
169 if (uint_val > max) {
170 bat_info(net_dev, "%s: Value is too big: %lu max: %u\n",
171 attr_name, uint_val, max);
172 return -EINVAL;
173 }
174
175 if (atomic_read(attr) == uint_val)
176 return count;
177
178 bat_info(net_dev, "%s: Changing from: %i to: %lu\n",
179 attr_name, atomic_read(attr), uint_val);
180
181 atomic_set(attr, uint_val);
182 return count;
183}
184
Sven Eckelmann747e4222011-05-14 23:14:50 +0200185static inline ssize_t __store_uint_attr(const char *buff, size_t count,
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000186 int min, int max,
187 void (*post_func)(struct net_device *),
Sven Eckelmann747e4222011-05-14 23:14:50 +0200188 const struct attribute *attr,
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000189 atomic_t *attr_store, struct net_device *net_dev)
190{
191 int ret;
192
Sven Eckelmann747e4222011-05-14 23:14:50 +0200193 ret = store_uint_attr(buff, count, net_dev, attr->name,
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000194 min, max, attr_store);
195 if (post_func && ret)
196 post_func(net_dev);
197
198 return ret;
199}
200
201static ssize_t show_vis_mode(struct kobject *kobj, struct attribute *attr,
202 char *buff)
203{
204 struct bat_priv *bat_priv = kobj_to_batpriv(kobj);
205 int vis_mode = atomic_read(&bat_priv->vis_mode);
206
207 return sprintf(buff, "%s\n",
208 vis_mode == VIS_TYPE_CLIENT_UPDATE ?
209 "client" : "server");
210}
211
212static ssize_t store_vis_mode(struct kobject *kobj, struct attribute *attr,
213 char *buff, size_t count)
214{
215 struct net_device *net_dev = kobj_to_netdev(kobj);
216 struct bat_priv *bat_priv = netdev_priv(net_dev);
217 unsigned long val;
218 int ret, vis_mode_tmp = -1;
219
220 ret = strict_strtoul(buff, 10, &val);
221
222 if (((count == 2) && (!ret) && (val == VIS_TYPE_CLIENT_UPDATE)) ||
223 (strncmp(buff, "client", 6) == 0) ||
224 (strncmp(buff, "off", 3) == 0))
225 vis_mode_tmp = VIS_TYPE_CLIENT_UPDATE;
226
227 if (((count == 2) && (!ret) && (val == VIS_TYPE_SERVER_SYNC)) ||
228 (strncmp(buff, "server", 6) == 0))
229 vis_mode_tmp = VIS_TYPE_SERVER_SYNC;
230
231 if (vis_mode_tmp < 0) {
232 if (buff[count - 1] == '\n')
233 buff[count - 1] = '\0';
234
235 bat_info(net_dev,
236 "Invalid parameter for 'vis mode' setting received: "
237 "%s\n", buff);
238 return -EINVAL;
239 }
240
241 if (atomic_read(&bat_priv->vis_mode) == vis_mode_tmp)
242 return count;
243
244 bat_info(net_dev, "Changing vis mode from: %s to: %s\n",
245 atomic_read(&bat_priv->vis_mode) == VIS_TYPE_CLIENT_UPDATE ?
246 "client" : "server", vis_mode_tmp == VIS_TYPE_CLIENT_UPDATE ?
247 "client" : "server");
248
249 atomic_set(&bat_priv->vis_mode, (unsigned)vis_mode_tmp);
250 return count;
251}
252
253static void post_gw_deselect(struct net_device *net_dev)
254{
255 struct bat_priv *bat_priv = netdev_priv(net_dev);
256 gw_deselect(bat_priv);
257}
258
259static ssize_t show_gw_mode(struct kobject *kobj, struct attribute *attr,
260 char *buff)
261{
262 struct bat_priv *bat_priv = kobj_to_batpriv(kobj);
263 int bytes_written;
264
265 switch (atomic_read(&bat_priv->gw_mode)) {
266 case GW_MODE_CLIENT:
267 bytes_written = sprintf(buff, "%s\n", GW_MODE_CLIENT_NAME);
268 break;
269 case GW_MODE_SERVER:
270 bytes_written = sprintf(buff, "%s\n", GW_MODE_SERVER_NAME);
271 break;
272 default:
273 bytes_written = sprintf(buff, "%s\n", GW_MODE_OFF_NAME);
274 break;
275 }
276
277 return bytes_written;
278}
279
280static ssize_t store_gw_mode(struct kobject *kobj, struct attribute *attr,
281 char *buff, size_t count)
282{
283 struct net_device *net_dev = kobj_to_netdev(kobj);
284 struct bat_priv *bat_priv = netdev_priv(net_dev);
285 char *curr_gw_mode_str;
286 int gw_mode_tmp = -1;
287
288 if (buff[count - 1] == '\n')
289 buff[count - 1] = '\0';
290
291 if (strncmp(buff, GW_MODE_OFF_NAME, strlen(GW_MODE_OFF_NAME)) == 0)
292 gw_mode_tmp = GW_MODE_OFF;
293
294 if (strncmp(buff, GW_MODE_CLIENT_NAME,
295 strlen(GW_MODE_CLIENT_NAME)) == 0)
296 gw_mode_tmp = GW_MODE_CLIENT;
297
298 if (strncmp(buff, GW_MODE_SERVER_NAME,
299 strlen(GW_MODE_SERVER_NAME)) == 0)
300 gw_mode_tmp = GW_MODE_SERVER;
301
302 if (gw_mode_tmp < 0) {
303 bat_info(net_dev,
304 "Invalid parameter for 'gw mode' setting received: "
305 "%s\n", buff);
306 return -EINVAL;
307 }
308
309 if (atomic_read(&bat_priv->gw_mode) == gw_mode_tmp)
310 return count;
311
312 switch (atomic_read(&bat_priv->gw_mode)) {
313 case GW_MODE_CLIENT:
314 curr_gw_mode_str = GW_MODE_CLIENT_NAME;
315 break;
316 case GW_MODE_SERVER:
317 curr_gw_mode_str = GW_MODE_SERVER_NAME;
318 break;
319 default:
320 curr_gw_mode_str = GW_MODE_OFF_NAME;
321 break;
322 }
323
324 bat_info(net_dev, "Changing gw mode from: %s to: %s\n",
325 curr_gw_mode_str, buff);
326
327 gw_deselect(bat_priv);
328 atomic_set(&bat_priv->gw_mode, (unsigned)gw_mode_tmp);
329 return count;
330}
331
332static ssize_t show_gw_bwidth(struct kobject *kobj, struct attribute *attr,
333 char *buff)
334{
335 struct bat_priv *bat_priv = kobj_to_batpriv(kobj);
336 int down, up;
337 int gw_bandwidth = atomic_read(&bat_priv->gw_bandwidth);
338
339 gw_bandwidth_to_kbit(gw_bandwidth, &down, &up);
340 return sprintf(buff, "%i%s/%i%s\n",
341 (down > 2048 ? down / 1024 : down),
342 (down > 2048 ? "MBit" : "KBit"),
343 (up > 2048 ? up / 1024 : up),
344 (up > 2048 ? "MBit" : "KBit"));
345}
346
347static ssize_t store_gw_bwidth(struct kobject *kobj, struct attribute *attr,
348 char *buff, size_t count)
349{
350 struct net_device *net_dev = kobj_to_netdev(kobj);
351
352 if (buff[count - 1] == '\n')
353 buff[count - 1] = '\0';
354
355 return gw_bandwidth_set(net_dev, buff, count);
356}
357
358BAT_ATTR_BOOL(aggregated_ogms, S_IRUGO | S_IWUSR, NULL);
359BAT_ATTR_BOOL(bonding, S_IRUGO | S_IWUSR, NULL);
360BAT_ATTR_BOOL(fragmentation, S_IRUGO | S_IWUSR, update_min_mtu);
361static BAT_ATTR(vis_mode, S_IRUGO | S_IWUSR, show_vis_mode, store_vis_mode);
362static BAT_ATTR(gw_mode, S_IRUGO | S_IWUSR, show_gw_mode, store_gw_mode);
363BAT_ATTR_UINT(orig_interval, S_IRUGO | S_IWUSR, 2 * JITTER, INT_MAX, NULL);
364BAT_ATTR_UINT(hop_penalty, S_IRUGO | S_IWUSR, 0, TQ_MAX_VALUE, NULL);
365BAT_ATTR_UINT(gw_sel_class, S_IRUGO | S_IWUSR, 1, TQ_MAX_VALUE,
366 post_gw_deselect);
367static BAT_ATTR(gw_bandwidth, S_IRUGO | S_IWUSR, show_gw_bwidth,
368 store_gw_bwidth);
369#ifdef CONFIG_BATMAN_ADV_DEBUG
370BAT_ATTR_UINT(log_level, S_IRUGO | S_IWUSR, 0, 3, NULL);
371#endif
372
373static struct bat_attribute *mesh_attrs[] = {
374 &bat_attr_aggregated_ogms,
375 &bat_attr_bonding,
376 &bat_attr_fragmentation,
377 &bat_attr_vis_mode,
378 &bat_attr_gw_mode,
379 &bat_attr_orig_interval,
380 &bat_attr_hop_penalty,
381 &bat_attr_gw_sel_class,
382 &bat_attr_gw_bandwidth,
383#ifdef CONFIG_BATMAN_ADV_DEBUG
384 &bat_attr_log_level,
385#endif
386 NULL,
387};
388
389int sysfs_add_meshif(struct net_device *dev)
390{
391 struct kobject *batif_kobject = &dev->dev.kobj;
392 struct bat_priv *bat_priv = netdev_priv(dev);
393 struct bat_attribute **bat_attr;
394 int err;
395
396 bat_priv->mesh_obj = kobject_create_and_add(SYSFS_IF_MESH_SUBDIR,
397 batif_kobject);
398 if (!bat_priv->mesh_obj) {
399 bat_err(dev, "Can't add sysfs directory: %s/%s\n", dev->name,
400 SYSFS_IF_MESH_SUBDIR);
401 goto out;
402 }
403
404 for (bat_attr = mesh_attrs; *bat_attr; ++bat_attr) {
405 err = sysfs_create_file(bat_priv->mesh_obj,
406 &((*bat_attr)->attr));
407 if (err) {
408 bat_err(dev, "Can't add sysfs file: %s/%s/%s\n",
409 dev->name, SYSFS_IF_MESH_SUBDIR,
410 ((*bat_attr)->attr).name);
411 goto rem_attr;
412 }
413 }
414
415 return 0;
416
417rem_attr:
418 for (bat_attr = mesh_attrs; *bat_attr; ++bat_attr)
419 sysfs_remove_file(bat_priv->mesh_obj, &((*bat_attr)->attr));
420
421 kobject_put(bat_priv->mesh_obj);
422 bat_priv->mesh_obj = NULL;
423out:
424 return -ENOMEM;
425}
426
427void sysfs_del_meshif(struct net_device *dev)
428{
429 struct bat_priv *bat_priv = netdev_priv(dev);
430 struct bat_attribute **bat_attr;
431
432 for (bat_attr = mesh_attrs; *bat_attr; ++bat_attr)
433 sysfs_remove_file(bat_priv->mesh_obj, &((*bat_attr)->attr));
434
435 kobject_put(bat_priv->mesh_obj);
436 bat_priv->mesh_obj = NULL;
437}
438
439static ssize_t show_mesh_iface(struct kobject *kobj, struct attribute *attr,
440 char *buff)
441{
442 struct net_device *net_dev = kobj_to_netdev(kobj);
Marek Lindnere6c10f42011-02-18 12:33:20 +0000443 struct hard_iface *hard_iface = hardif_get_by_netdev(net_dev);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000444 ssize_t length;
445
Marek Lindnere6c10f42011-02-18 12:33:20 +0000446 if (!hard_iface)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000447 return 0;
448
Marek Lindnere6c10f42011-02-18 12:33:20 +0000449 length = sprintf(buff, "%s\n", hard_iface->if_status == IF_NOT_IN_USE ?
450 "none" : hard_iface->soft_iface->name);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000451
Marek Lindnere6c10f42011-02-18 12:33:20 +0000452 hardif_free_ref(hard_iface);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000453
454 return length;
455}
456
457static ssize_t store_mesh_iface(struct kobject *kobj, struct attribute *attr,
458 char *buff, size_t count)
459{
460 struct net_device *net_dev = kobj_to_netdev(kobj);
Marek Lindnere6c10f42011-02-18 12:33:20 +0000461 struct hard_iface *hard_iface = hardif_get_by_netdev(net_dev);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000462 int status_tmp = -1;
Marek Lindnered75ccb2011-02-10 14:33:51 +0000463 int ret = count;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000464
Marek Lindnere6c10f42011-02-18 12:33:20 +0000465 if (!hard_iface)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000466 return count;
467
468 if (buff[count - 1] == '\n')
469 buff[count - 1] = '\0';
470
471 if (strlen(buff) >= IFNAMSIZ) {
472 pr_err("Invalid parameter for 'mesh_iface' setting received: "
473 "interface name too long '%s'\n", buff);
Marek Lindnere6c10f42011-02-18 12:33:20 +0000474 hardif_free_ref(hard_iface);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000475 return -EINVAL;
476 }
477
478 if (strncmp(buff, "none", 4) == 0)
479 status_tmp = IF_NOT_IN_USE;
480 else
481 status_tmp = IF_I_WANT_YOU;
482
Marek Lindnere6c10f42011-02-18 12:33:20 +0000483 if (hard_iface->if_status == status_tmp)
484 goto out;
485
486 if ((hard_iface->soft_iface) &&
487 (strncmp(hard_iface->soft_iface->name, buff, IFNAMSIZ) == 0))
Marek Lindnered75ccb2011-02-10 14:33:51 +0000488 goto out;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000489
Sven Eckelmann3a4375a2011-05-03 13:10:06 +0200490 if (!rtnl_trylock()) {
491 ret = -ERESTARTSYS;
Marek Lindnered75ccb2011-02-10 14:33:51 +0000492 goto out;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000493 }
494
Sven Eckelmann3a4375a2011-05-03 13:10:06 +0200495 if (status_tmp == IF_NOT_IN_USE) {
Marek Lindnere6c10f42011-02-18 12:33:20 +0000496 hardif_disable_interface(hard_iface);
Sven Eckelmann3a4375a2011-05-03 13:10:06 +0200497 goto unlock;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000498 }
499
Sven Eckelmann3a4375a2011-05-03 13:10:06 +0200500 /* if the interface already is in use */
501 if (hard_iface->if_status != IF_NOT_IN_USE)
502 hardif_disable_interface(hard_iface);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000503
Sven Eckelmann3a4375a2011-05-03 13:10:06 +0200504 ret = hardif_enable_interface(hard_iface, buff);
505
506unlock:
507 rtnl_unlock();
Marek Lindnered75ccb2011-02-10 14:33:51 +0000508out:
Marek Lindnere6c10f42011-02-18 12:33:20 +0000509 hardif_free_ref(hard_iface);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000510 return ret;
511}
512
513static ssize_t show_iface_status(struct kobject *kobj, struct attribute *attr,
514 char *buff)
515{
516 struct net_device *net_dev = kobj_to_netdev(kobj);
Marek Lindnere6c10f42011-02-18 12:33:20 +0000517 struct hard_iface *hard_iface = hardif_get_by_netdev(net_dev);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000518 ssize_t length;
519
Marek Lindnere6c10f42011-02-18 12:33:20 +0000520 if (!hard_iface)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000521 return 0;
522
Marek Lindnere6c10f42011-02-18 12:33:20 +0000523 switch (hard_iface->if_status) {
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000524 case IF_TO_BE_REMOVED:
525 length = sprintf(buff, "disabling\n");
526 break;
527 case IF_INACTIVE:
528 length = sprintf(buff, "inactive\n");
529 break;
530 case IF_ACTIVE:
531 length = sprintf(buff, "active\n");
532 break;
533 case IF_TO_BE_ACTIVATED:
534 length = sprintf(buff, "enabling\n");
535 break;
536 case IF_NOT_IN_USE:
537 default:
538 length = sprintf(buff, "not in use\n");
539 break;
540 }
541
Marek Lindnere6c10f42011-02-18 12:33:20 +0000542 hardif_free_ref(hard_iface);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000543
544 return length;
545}
546
547static BAT_ATTR(mesh_iface, S_IRUGO | S_IWUSR,
548 show_mesh_iface, store_mesh_iface);
549static BAT_ATTR(iface_status, S_IRUGO, show_iface_status, NULL);
550
551static struct bat_attribute *batman_attrs[] = {
552 &bat_attr_mesh_iface,
553 &bat_attr_iface_status,
554 NULL,
555};
556
557int sysfs_add_hardif(struct kobject **hardif_obj, struct net_device *dev)
558{
559 struct kobject *hardif_kobject = &dev->dev.kobj;
560 struct bat_attribute **bat_attr;
561 int err;
562
563 *hardif_obj = kobject_create_and_add(SYSFS_IF_BAT_SUBDIR,
564 hardif_kobject);
565
566 if (!*hardif_obj) {
567 bat_err(dev, "Can't add sysfs directory: %s/%s\n", dev->name,
568 SYSFS_IF_BAT_SUBDIR);
569 goto out;
570 }
571
572 for (bat_attr = batman_attrs; *bat_attr; ++bat_attr) {
573 err = sysfs_create_file(*hardif_obj, &((*bat_attr)->attr));
574 if (err) {
575 bat_err(dev, "Can't add sysfs file: %s/%s/%s\n",
576 dev->name, SYSFS_IF_BAT_SUBDIR,
577 ((*bat_attr)->attr).name);
578 goto rem_attr;
579 }
580 }
581
582 return 0;
583
584rem_attr:
585 for (bat_attr = batman_attrs; *bat_attr; ++bat_attr)
586 sysfs_remove_file(*hardif_obj, &((*bat_attr)->attr));
587out:
588 return -ENOMEM;
589}
590
591void sysfs_del_hardif(struct kobject **hardif_obj)
592{
593 kobject_put(*hardif_obj);
594 *hardif_obj = NULL;
595}