Пример #1
0
/*
 * main netdev ethtool struct get/set helpers
 */
void
ni_ethtool_free(ni_ethtool_t *ethtool)
{
	if (ethtool) {
		ni_bitfield_destroy(&ethtool->supported);
		ni_ethtool_driver_info_free(ethtool->driver_info);
		ni_ethtool_priv_flags_free(ethtool->priv_flags);
		free(ethtool);
	}
}
Пример #2
0
/*
 * 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
static dbus_bool_t
ni_objectmodel_ethtool_link_adv_into_dict(ni_dbus_variant_t *dict,
		const char *name, const ni_bitfield_t *bitfield)
{
	ni_bitfield_t tmpfield = NI_BITFIELD_INIT;
	ni_dbus_variant_t *child;

	if (!dict || ni_string_empty(name) || !ni_bitfield_bits(bitfield))
		return FALSE;

	if (!(child = ni_dbus_dict_add(dict, name)))
		return FALSE;

	ni_dbus_variant_init_dict(child);
	ni_bitfield_set_data(&tmpfield, ni_bitfield_get_data(bitfield), ni_bitfield_bytes(bitfield));
	ni_objectmodel_ethtool_link_adv_autoneg_into_dict(child, &tmpfield);
	ni_objectmodel_ethtool_link_adv_ports_into_dict(child, &tmpfield);
	ni_objectmodel_ethtool_link_adv_speed_into_dict(child, &tmpfield);
	ni_objectmodel_ethtool_link_adv_pause_into_dict(child, &tmpfield);
	ni_objectmodel_ethtool_link_adv_fec_modes_into_dict(child, &tmpfield);
	ni_objectmodel_ethtool_link_adv_unknown_into_dict(child, &tmpfield);
	ni_bitfield_destroy(&tmpfield);
	return TRUE;
}