37 struct net_device *net_dev = batadv_kobj_to_netdev(obj);
38 return netdev_priv(net_dev);
41 #define BATADV_UEV_TYPE_VAR "BATTYPE="
42 #define BATADV_UEV_ACTION_VAR "BATACTION="
43 #define BATADV_UEV_DATA_VAR "BATDATA="
45 static char *batadv_uev_action_str[] = {
51 static char *batadv_uev_type_str[] = {
56 #define BATADV_ATTR(_name, _mode, _show, _store) \
57 struct batadv_attribute batadv_attr_##_name = { \
58 .attr = {.name = __stringify(_name), \
64 #define BATADV_ATTR_SIF_STORE_BOOL(_name, _post_func) \
65 ssize_t batadv_store_##_name(struct kobject *kobj, \
66 struct attribute *attr, char *buff, \
69 struct net_device *net_dev = batadv_kobj_to_netdev(kobj); \
70 struct batadv_priv *bat_priv = netdev_priv(net_dev); \
71 return __batadv_store_bool_attr(buff, count, _post_func, attr, \
72 &bat_priv->_name, net_dev); \
75 #define BATADV_ATTR_SIF_SHOW_BOOL(_name) \
76 ssize_t batadv_show_##_name(struct kobject *kobj, \
77 struct attribute *attr, char *buff) \
79 struct batadv_priv *bat_priv = batadv_kobj_to_batpriv(kobj); \
80 return sprintf(buff, "%s\n", \
81 atomic_read(&bat_priv->_name) == 0 ? \
82 "disabled" : "enabled"); \
88 #define BATADV_ATTR_SIF_BOOL(_name, _mode, _post_func) \
89 static BATADV_ATTR_SIF_STORE_BOOL(_name, _post_func) \
90 static BATADV_ATTR_SIF_SHOW_BOOL(_name) \
91 static BATADV_ATTR(_name, _mode, batadv_show_##_name, \
95 #define BATADV_ATTR_SIF_STORE_UINT(_name, _min, _max, _post_func) \
96 ssize_t batadv_store_##_name(struct kobject *kobj, \
97 struct attribute *attr, char *buff, \
100 struct net_device *net_dev = batadv_kobj_to_netdev(kobj); \
101 struct batadv_priv *bat_priv = netdev_priv(net_dev); \
102 return __batadv_store_uint_attr(buff, count, _min, _max, \
104 &bat_priv->_name, net_dev); \
107 #define BATADV_ATTR_SIF_SHOW_UINT(_name) \
108 ssize_t batadv_show_##_name(struct kobject *kobj, \
109 struct attribute *attr, char *buff) \
111 struct batadv_priv *bat_priv = batadv_kobj_to_batpriv(kobj); \
112 return sprintf(buff, "%i\n", atomic_read(&bat_priv->_name)); \
118 #define BATADV_ATTR_SIF_UINT(_name, _mode, _min, _max, _post_func) \
119 static BATADV_ATTR_SIF_STORE_UINT(_name, _min, _max, _post_func)\
120 static BATADV_ATTR_SIF_SHOW_UINT(_name) \
121 static BATADV_ATTR(_name, _mode, batadv_show_##_name, \
122 batadv_store_##_name)
125 #define BATADV_ATTR_HIF_STORE_UINT(_name, _min, _max, _post_func) \
126 ssize_t batadv_store_##_name(struct kobject *kobj, \
127 struct attribute *attr, char *buff, \
130 struct net_device *net_dev = batadv_kobj_to_netdev(kobj); \
131 struct batadv_hard_iface *hard_iface; \
134 hard_iface = batadv_hardif_get_by_netdev(net_dev); \
138 length = __batadv_store_uint_attr(buff, count, _min, _max, \
140 &hard_iface->_name, net_dev); \
142 batadv_hardif_free_ref(hard_iface); \
146 #define BATADV_ATTR_HIF_SHOW_UINT(_name) \
147 ssize_t batadv_show_##_name(struct kobject *kobj, \
148 struct attribute *attr, char *buff) \
150 struct net_device *net_dev = batadv_kobj_to_netdev(kobj); \
151 struct batadv_hard_iface *hard_iface; \
154 hard_iface = batadv_hardif_get_by_netdev(net_dev); \
158 length = sprintf(buff, "%i\n", atomic_read(&hard_iface->_name));\
160 batadv_hardif_free_ref(hard_iface); \
167 #define BATADV_ATTR_HIF_UINT(_name, _mode, _min, _max, _post_func) \
168 static BATADV_ATTR_HIF_STORE_UINT(_name, _min, _max, _post_func)\
169 static BATADV_ATTR_HIF_SHOW_UINT(_name) \
170 static BATADV_ATTR(_name, _mode, batadv_show_##_name, \
171 batadv_store_##_name)
174 static int batadv_store_bool_attr(
char *buff,
size_t count,
180 if (buff[count - 1] ==
'\n')
181 buff[count - 1] =
'\0';
183 if ((
strncmp(buff,
"1", 2) == 0) ||
184 (
strncmp(buff,
"enable", 7) == 0) ||
185 (
strncmp(buff,
"enabled", 8) == 0))
188 if ((
strncmp(buff,
"0", 2) == 0) ||
189 (
strncmp(buff,
"disable", 8) == 0) ||
190 (
strncmp(buff,
"disabled", 9) == 0))
194 batadv_info(net_dev,
"%s: Invalid parameter received: %s\n",
202 batadv_info(net_dev,
"%s: Changing from: %s to: %s\n", attr_name,
204 enabled == 1 ?
"enabled" :
"disabled");
211 __batadv_store_bool_attr(
char *buff,
size_t count,
218 ret = batadv_store_bool_attr(buff, count, net_dev, attr->
name,
220 if (post_func && ret)
226 static int batadv_store_uint_attr(
const char *buff,
size_t count,
229 unsigned int min,
unsigned int max,
232 unsigned long uint_val;
235 ret = kstrtoul(buff, 10, &uint_val);
237 batadv_info(net_dev,
"%s: Invalid parameter received: %s\n",
242 if (uint_val < min) {
243 batadv_info(net_dev,
"%s: Value is too small: %lu min: %u\n",
244 attr_name, uint_val, min);
248 if (uint_val > max) {
249 batadv_info(net_dev,
"%s: Value is too big: %lu max: %u\n",
250 attr_name, uint_val, max);
257 batadv_info(net_dev,
"%s: Changing from: %i to: %lu\n",
265 __batadv_store_uint_attr(
const char *buff,
size_t count,
273 ret = batadv_store_uint_attr(buff, count, net_dev, attr->
name, min, max,
275 if (post_func && ret)
284 struct batadv_priv *bat_priv = batadv_kobj_to_batpriv(kobj);
293 return sprintf(buff,
"%s\n", mode);
300 struct net_device *net_dev = batadv_kobj_to_netdev(kobj);
301 struct batadv_priv *bat_priv = netdev_priv(net_dev);
303 int ret, vis_mode_tmp = -1;
304 const char *old_mode, *new_mode;
306 ret = kstrtoul(buff, 10, &val);
308 if (((count == 2) && (!ret) &&
310 (
strncmp(buff,
"client", 6) == 0) ||
311 (
strncmp(buff,
"off", 3) == 0))
314 if (((count == 2) && (!ret) &&
316 (
strncmp(buff,
"server", 6) == 0))
319 if (vis_mode_tmp < 0) {
320 if (buff[count - 1] ==
'\n')
321 buff[count - 1] =
'\0';
324 "Invalid parameter for 'vis mode' setting received: %s\n",
342 batadv_info(net_dev,
"Changing vis mode from: %s to: %s\n", old_mode,
352 struct batadv_priv *bat_priv = batadv_kobj_to_batpriv(kobj);
356 static void batadv_post_gw_deselect(
struct net_device *net_dev)
358 struct batadv_priv *bat_priv = netdev_priv(net_dev);
365 struct batadv_priv *bat_priv = batadv_kobj_to_batpriv(kobj);
370 bytes_written =
sprintf(buff,
"%s\n",
374 bytes_written =
sprintf(buff,
"%s\n",
378 bytes_written =
sprintf(buff,
"%s\n",
383 return bytes_written;
390 struct net_device *net_dev = batadv_kobj_to_netdev(kobj);
391 struct batadv_priv *bat_priv = netdev_priv(net_dev);
392 char *curr_gw_mode_str;
393 int gw_mode_tmp = -1;
395 if (buff[count - 1] ==
'\n')
396 buff[count - 1] =
'\0';
410 if (gw_mode_tmp < 0) {
412 "Invalid parameter for 'gw mode' setting received: %s\n",
432 batadv_info(net_dev,
"Changing gw mode from: %s to: %s\n",
433 curr_gw_mode_str, buff);
443 struct batadv_priv *bat_priv = batadv_kobj_to_batpriv(kobj);
448 return sprintf(buff,
"%i%s/%i%s\n",
449 (down > 2048 ? down / 1024 : down),
450 (down > 2048 ?
"MBit" :
"KBit"),
451 (up > 2048 ? up / 1024 : up),
452 (up > 2048 ?
"MBit" :
"KBit"));
459 struct net_device *net_dev = batadv_kobj_to_netdev(kobj);
461 if (buff[count - 1] ==
'\n')
462 buff[count - 1] =
'\0';
469 #ifdef CONFIG_BATMAN_ADV_BLA
475 batadv_store_vis_mode);
478 batadv_store_gw_mode);
484 batadv_post_gw_deselect);
486 batadv_store_gw_bwidth);
487 #ifdef CONFIG_BATMAN_ADV_DEBUG
492 &batadv_attr_aggregated_ogms,
493 &batadv_attr_bonding,
494 #ifdef CONFIG_BATMAN_ADV_BLA
495 &batadv_attr_bridge_loop_avoidance,
497 &batadv_attr_fragmentation,
498 &batadv_attr_ap_isolation,
499 &batadv_attr_vis_mode,
500 &batadv_attr_routing_algo,
501 &batadv_attr_gw_mode,
502 &batadv_attr_orig_interval,
503 &batadv_attr_hop_penalty,
504 &batadv_attr_gw_sel_class,
505 &batadv_attr_gw_bandwidth,
506 #ifdef CONFIG_BATMAN_ADV_DEBUG
507 &batadv_attr_log_level,
514 struct kobject *batif_kobject = &dev->
dev.kobj;
527 for (bat_attr = batadv_mesh_attrs; *bat_attr; ++bat_attr) {
529 &((*bat_attr)->attr));
531 batadv_err(dev,
"Can't add sysfs file: %s/%s/%s\n",
533 ((*bat_attr)->attr).name);
541 for (bat_attr = batadv_mesh_attrs; *bat_attr; ++bat_attr)
555 for (bat_attr = batadv_mesh_attrs; *bat_attr; ++bat_attr)
565 struct net_device *net_dev = batadv_kobj_to_netdev(kobj);
579 length =
sprintf(buff,
"%s\n", ifname);
581 batadv_hardif_free_ref(hard_iface);
590 struct net_device *net_dev = batadv_kobj_to_netdev(kobj);
599 if (buff[count - 1] ==
'\n')
600 buff[count - 1] =
'\0';
603 pr_err(
"Invalid parameter for 'mesh_iface' setting received: interface name too long '%s'\n",
605 batadv_hardif_free_ref(hard_iface);
609 if (
strncmp(buff,
"none", 4) == 0)
640 batadv_hardif_free_ref(hard_iface);
647 struct net_device *net_dev = batadv_kobj_to_netdev(kobj);
657 length =
sprintf(buff,
"disabling\n");
660 length =
sprintf(buff,
"inactive\n");
663 length =
sprintf(buff,
"active\n");
666 length =
sprintf(buff,
"enabling\n");
670 length =
sprintf(buff,
"not in use\n");
674 batadv_hardif_free_ref(hard_iface);
680 batadv_store_mesh_iface);
684 &batadv_attr_mesh_iface,
685 &batadv_attr_iface_status,
691 struct kobject *hardif_kobject = &dev->
dev.kobj;
704 for (bat_attr = batadv_batman_attrs; *bat_attr; ++bat_attr) {
707 batadv_err(dev,
"Can't add sysfs file: %s/%s/%s\n",
709 ((*bat_attr)->attr).name);
717 for (bat_attr = batadv_batman_attrs; *bat_attr; ++bat_attr)
737 primary_if = batadv_primary_if_get_selected(bat_priv);
744 strlen(batadv_uev_type_str[type]) + 1,
750 batadv_uev_type_str[type]);
753 strlen(batadv_uev_action_str[action]) + 1,
759 batadv_uev_action_str[action]);
773 kfree(uevent_env[0]);
774 kfree(uevent_env[1]);
775 kfree(uevent_env[2]);
778 batadv_hardif_free_ref(primary_if);
782 "Impossible to send uevent for (%s,%s,%s) event (err: %d)\n",
783 batadv_uev_type_str[type],
784 batadv_uev_action_str[action],