Esempio n. 1
0
int sysfs_add_hardif(struct kobject **hardif_obj, struct net_device *dev)
{
    struct kobject *hardif_kobject = &dev->dev.kobj;
    struct bat_attribute **bat_attr;
    int err;

    *hardif_obj = kobject_create_and_add(SYSFS_IF_BAT_SUBDIR,
                                         hardif_kobject);

    if (!*hardif_obj) {
        bat_err(dev, "Can't add sysfs directory: %s/%s\n", dev->name,
                SYSFS_IF_BAT_SUBDIR);
        goto out;
    }

    for (bat_attr = batman_attrs; *bat_attr; ++bat_attr) {
        err = sysfs_create_file(*hardif_obj, &((*bat_attr)->attr));
        if (err) {
            bat_err(dev, "Can't add sysfs file: %s/%s/%s\n",
                    dev->name, SYSFS_IF_BAT_SUBDIR,
                    ((*bat_attr)->attr).name);
            goto rem_attr;
        }
    }

    return 0;

rem_attr:
    for (bat_attr = batman_attrs; *bat_attr; ++bat_attr)
        sysfs_remove_file(*hardif_obj, &((*bat_attr)->attr));
out:
    return -ENOMEM;
}
static bool parse_gw_bandwidth(struct net_device *net_dev, char *buff,
			       long *up, long *down)
{
	int ret, multi = 1;
	char *slash_ptr, *tmp_ptr;

	slash_ptr = strchr(buff, '/');
	if (slash_ptr)
		*slash_ptr = 0;

	if (strlen(buff) > 4) {
		tmp_ptr = buff + strlen(buff) - 4;

		if (strnicmp(tmp_ptr, "mbit", 4) == 0)
			multi = 1024;

		if ((strnicmp(tmp_ptr, "kbit", 4) == 0) ||
			(multi > 1))
			*tmp_ptr = '\0';
	}

	ret = strict_strtoul(buff, 10, down);
	if (ret) {
		bat_err(net_dev,
			"Download speed of gateway mode invalid: %s\n",
			buff);
		return false;
	}

	*down *= multi;

	/* we also got some upload info */
	if (slash_ptr) {
		multi = 1;

		if (strlen(slash_ptr + 1) > 4) {
			tmp_ptr = slash_ptr + 1 - 4 + strlen(slash_ptr + 1);

			if (strnicmp(tmp_ptr, "mbit", 4) == 0)
				multi = 1024;

			if ((strnicmp(tmp_ptr, "kbit", 4) == 0) ||
				(multi > 1))
				*tmp_ptr = '\0';
		}

		ret = strict_strtoul(slash_ptr + 1, 10, up);
		if (ret) {
			bat_err(net_dev,
				"Upload speed of gateway mode invalid: "
				"%s\n", slash_ptr + 1);
			return false;
		}

		*up *= multi;
	}

	return true;
}
Esempio n. 3
0
int sysfs_add_meshif(struct net_device *dev)
{
	struct kobject *batif_kobject = &dev->dev.kobj;
	struct bat_priv *bat_priv = netdev_priv(dev);
	struct bat_attribute **bat_attr;
	int err;

	atomic_set(&bat_priv->aggregation_enabled, 1);
	atomic_set(&bat_priv->bonding_enabled, 0);
	atomic_set(&bat_priv->vis_mode, VIS_TYPE_CLIENT_UPDATE);
	atomic_set(&bat_priv->orig_interval, 1000);
	atomic_set(&bat_priv->log_level, 0);

	bat_priv->primary_if = NULL;
	bat_priv->num_ifaces = 0;

	bat_priv->mesh_obj = kobject_create_and_add(SYSFS_IF_MESH_SUBDIR,
						    batif_kobject);
	if (!bat_priv->mesh_obj) {
		bat_err(dev, "Can't add sysfs directory: %s/%s\n", dev->name,
			SYSFS_IF_MESH_SUBDIR);
		goto out;
	}

	for (bat_attr = mesh_attrs; *bat_attr; ++bat_attr) {
		err = sysfs_create_file(bat_priv->mesh_obj,
					&((*bat_attr)->attr));
		if (err) {
			bat_err(dev, "Can't add sysfs file: %s/%s/%s\n",
				dev->name, SYSFS_IF_MESH_SUBDIR,
				((*bat_attr)->attr).name);
			goto rem_attr;
		}
	}

	return 0;

rem_attr:
	for (bat_attr = mesh_attrs; *bat_attr; ++bat_attr)
		sysfs_remove_file(bat_priv->mesh_obj, &((*bat_attr)->attr));

	kobject_put(bat_priv->mesh_obj);
	bat_priv->mesh_obj = NULL;
out:
	return -ENOMEM;
}
Esempio n. 4
0
int sysfs_add_meshif(struct net_device *dev)
{
    struct kobject *batif_kobject = &dev->dev.kobj;
    struct bat_priv *bat_priv = netdev_priv(dev);
    struct bat_attribute **bat_attr;
    int err;

    bat_priv->mesh_obj = kobject_create_and_add(SYSFS_IF_MESH_SUBDIR,
                         batif_kobject);
    if (!bat_priv->mesh_obj) {
        bat_err(dev, "Can't add sysfs directory: %s/%s\n", dev->name,
                SYSFS_IF_MESH_SUBDIR);
        goto out;
    }

    for (bat_attr = mesh_attrs; *bat_attr; ++bat_attr) {
        err = sysfs_create_file(bat_priv->mesh_obj,
                                &((*bat_attr)->attr));
        if (err) {
            bat_err(dev, "Can't add sysfs file: %s/%s/%s\n",
                    dev->name, SYSFS_IF_MESH_SUBDIR,
                    ((*bat_attr)->attr).name);
            goto rem_attr;
        }
    }

    return 0;

rem_attr:
    for (bat_attr = mesh_attrs; *bat_attr; ++bat_attr)
        sysfs_remove_file(bat_priv->mesh_obj, &((*bat_attr)->attr));

    kobject_put(bat_priv->mesh_obj);
    bat_priv->mesh_obj = NULL;
out:
    return -ENOMEM;
}
Esempio n. 5
0
int debugfs_add_meshif(struct net_device *dev)
{
	struct bat_priv *bat_priv = netdev_priv(dev);
	struct bat_debuginfo **bat_debug;
	struct dentry *file;

	if (!bat_debugfs)
		goto out;

	bat_priv->debug_dir = debugfs_create_dir(dev->name, bat_debugfs);
	if (!bat_priv->debug_dir)
		goto out;

	bat_socket_setup(bat_priv);
	debug_log_setup(bat_priv);

	for (bat_debug = mesh_debuginfos; *bat_debug; ++bat_debug) {
		file = debugfs_create_file(((*bat_debug)->attr).name,
					  S_IFREG | ((*bat_debug)->attr).mode,
					  bat_priv->debug_dir,
					  dev, &(*bat_debug)->fops);
		if (!file) {
			bat_err(dev, "Can't add debugfs file: %s/%s\n",
				dev->name, ((*bat_debug)->attr).name);
			goto rem_attr;
		}
	}

	return 0;
rem_attr:
	debugfs_remove_recursive(bat_priv->debug_dir);
	bat_priv->debug_dir = NULL;
out:
#ifdef CONFIG_DEBUG_FS
	return -ENOMEM;
#else
	return 0;
#endif /* CONFIG_DEBUG_FS */
}
Esempio n. 6
0
static ssize_t store_bond(struct kobject *kobj, struct attribute *attr,
			  char *buff, size_t count)
{
	struct device *dev = to_dev(kobj->parent);
	struct net_device *net_dev = to_net_dev(dev);
	struct bat_priv *bat_priv = netdev_priv(net_dev);
	int bonding_enabled_tmp = -1;

	if (((count == 2) && (buff[0] == '1')) ||
	    (strncmp(buff, "enable", 6) == 0))
		bonding_enabled_tmp = 1;

	if (((count == 2) && (buff[0] == '0')) ||
	    (strncmp(buff, "disable", 7) == 0))
		bonding_enabled_tmp = 0;

	if (bonding_enabled_tmp < 0) {
		if (buff[count - 1] == '\n')
			buff[count - 1] = '\0';

		bat_err(net_dev,
			"Invalid parameter for 'bonding' setting received: "
			"%s\n", buff);
		return -EINVAL;
	}

	if (atomic_read(&bat_priv->bonding_enabled) == bonding_enabled_tmp)
		return count;

	bat_info(net_dev, "Changing bonding from: %s to: %s\n",
		 atomic_read(&bat_priv->bonding_enabled) == 1 ?
		 "enabled" : "disabled",
		 bonding_enabled_tmp == 1 ? "enabled" : "disabled");

	atomic_set(&bat_priv->bonding_enabled, (unsigned)bonding_enabled_tmp);
	return count;
}