コード例 #1
0
ファイル: ethtool.c プロジェクト: mtomaschewski/wicked
static inline void
ni_ethtool_init(ni_ethtool_t *ethtool)
{
	if (ethtool)  {
		unsigned int flag;

		/* initially, everything is supported */
		for (flag = 0; flag < NI_ETHTOOL_SUPPORT_MAX; ++flag)
			ni_bitfield_setbit(&ethtool->supported, flag);
	}
}
コード例 #2
0
ファイル: ethtool.c プロジェクト: openSUSE/wicked
/*
 * get/set ethtool.eee
 */
static dbus_bool_t
ni_objectmodel_ethtool_eee_adv_into_dict(ni_dbus_variant_t *dict,
		const char *entry, const ni_bitfield_t *bitfield)
{
	ni_bitfield_t tmpfield = NI_BITFIELD_INIT;
	ni_dbus_variant_t *array;
	unsigned int bit, bits;
	char *hexstr = NULL;
	const char *name;

	if (!dict || !ni_bitfield_isset(bitfield))
		return FALSE;

	if (!(array = ni_dbus_dict_add(dict, entry)))
		return FALSE;

	ni_dbus_variant_init_string_array(array);

	/* known modes by name */
	bits = ni_bitfield_bits(bitfield);
	for (bit = 0; bit < bits; ++bit) {
		if (!ni_bitfield_testbit(bitfield, bit))
			continue;

		if (!(name = ni_ethtool_link_adv_speed_name(bit)))
			ni_bitfield_setbit(&tmpfield, bit);
		else
		if (!ni_dbus_variant_append_string_array(array, name))
			ni_bitfield_setbit(&tmpfield, bit);
	}

	/* unknown modes as hex */
	if (ni_bitfield_isset(&tmpfield)) {
		if (ni_bitfield_format(&tmpfield, &hexstr, TRUE) && hexstr)
			ni_dbus_variant_append_string_array(array, hexstr);
		ni_string_free(&hexstr);
	}

	ni_bitfield_destroy(&tmpfield);
	return TRUE;
}
コード例 #3
0
ファイル: ethtool.c プロジェクト: openSUSE/wicked
static inline ni_bool_t
set_ethtool_link_advertise(const char *value, ni_bitfield_t *bitfield)
{
	ni_string_array_t tmp = NI_STRING_ARRAY_INIT;
	unsigned int i, bit;
	ni_bool_t ret = FALSE;

	if (ni_string_split(&tmp, value, ",", 0)) {
		ret = tmp.count > 0;

		for (i = 0; i < tmp.count; ++i) {
			value = tmp.data[i];
			if (ni_ethtool_link_adv_type(value, &bit))
				ni_bitfield_setbit(bitfield, bit);
			else
			if (!(ret = ni_bitfield_parse(bitfield, value, 0)))
				break;
		}
	}
	ni_string_array_destroy(&tmp);
	return ret;
}
コード例 #4
0
ファイル: ethtool.c プロジェクト: openSUSE/wicked
static dbus_bool_t
ni_objectmodel_ethtool_link_adv_bitfield_from_array(const ni_dbus_variant_t *array,
		ni_bitfield_t *bitfield, ni_bool_t (*name_to_bit)(const char *, unsigned int *))
{
	const char *value;
	unsigned int bit;
	size_t len, pos;

	if (!ni_dbus_variant_is_string_array(array))
		return FALSE;

	if ((len = array->array.len) > ni_ethtool_link_mode_nbits())
		len = ni_ethtool_link_mode_nbits();

	for (pos = 0; pos < len; ++pos) {
		value = array->string_array_value[pos];
		if (name_to_bit(value, &bit))
			ni_bitfield_setbit(bitfield, bit);
		else
			ni_bitfield_parse(bitfield, value, 0);
	}
	return TRUE;
}