int udev_builtin_hwdb_lookup(struct udev_device *dev,
                             const char *prefix, const char *modalias,
                             const char *filter, bool test) {
        struct udev_list_entry *list;
        struct udev_list_entry *entry;
        int n = 0;

        if (!hwdb)
                return -ENOENT;

        if (prefix) {
                _cleanup_free_ const char *lookup;

                lookup = strjoin(prefix, modalias, NULL);
                if (!lookup)
                        return -ENOMEM;
                list = udev_hwdb_get_properties_list_entry(hwdb, lookup, 0);
        } else
                list = udev_hwdb_get_properties_list_entry(hwdb, modalias, 0);

        udev_list_entry_foreach(entry, list) {
                if (filter && fnmatch(filter, udev_list_entry_get_name(entry), FNM_NOESCAPE) != 0)
                        continue;

                if (udev_builtin_add_property(dev, test,
                                              udev_list_entry_get_name(entry),
                                              udev_list_entry_get_value(entry)) < 0)
                        return -ENOMEM;
                n++;
        }
        return n;
}
Exemple #2
0
char *batocomp(const bdaddr_t *ba)
{
	struct udev *udev;
	struct udev_hwdb *hwdb;
	struct udev_list_entry *head, *entry;
	char modalias[11], *comp = NULL;

	sprintf(modalias, "OUI:%2.2X%2.2X%2.2X", ba->b[5], ba->b[4], ba->b[3]);

	udev = udev_new();
	if (!udev)
		return NULL;

	hwdb = udev_hwdb_new(udev);
	if (!hwdb)
		goto done;

	head = udev_hwdb_get_properties_list_entry(hwdb, modalias, 0);

	udev_list_entry_foreach(entry, head) {
		const char *name = udev_list_entry_get_name(entry);

		if (name && !strcmp(name, "ID_OUI_FROM_DATABASE")) {
			comp = strdup(udev_list_entry_get_value(entry));
			break;
		}
	}

	hwdb = udev_hwdb_unref(hwdb);

done:
	udev = udev_unref(udev);

	return comp;
}
/**
 * gnome_pnp_ids_get_pnp_id:
 * @pnp_ids: a #GnomePnpIds object
 * @pnp_id: the PNP ID to look for
 *
 * Find the full manufacturer name for the given PNP ID.
 *
 * Returns: (transfer full): a new string representing the manufacturer name,
 * or %NULL when not found.
 */
gchar *
gnome_pnp_ids_get_pnp_id (GnomePnpIds *pnp_ids, const gchar *pnp_id)
{
#ifdef HAVE_UDEV
        GnomePnpIdsPrivate *priv = pnp_ids->priv;
        struct udev_list_entry *list_entry, *l;
        char *modalias;
        char *ret = NULL;

        modalias = g_strdup_printf ("acpi:%s:", pnp_id);
        list_entry = udev_hwdb_get_properties_list_entry(priv->hwdb, modalias, 0);
        g_free (modalias);
        if (list_entry == NULL)
                return ret;

        /* Try to get the model specific string */
        l = udev_list_entry_get_by_name (list_entry, "ID_MODEL_FROM_DATABASE");
        if (l == NULL)
                l = udev_list_entry_get_by_name (list_entry, "ID_VENDOR_FROM_DATABASE");

        if (l == NULL)
                return ret;

        ret = g_strdup (udev_list_entry_get_value (l));

        return ret;
#else
        return g_strdup ("Undefined");
#endif
}
Exemple #4
0
static const char *hwdb_get(const char *modalias, const char *key)
{
	struct udev_list_entry *entry;

	udev_list_entry_foreach(entry, udev_hwdb_get_properties_list_entry(hwdb, modalias, 0))
		if (strcmp(udev_list_entry_get_name(entry), key) == 0)
			return udev_list_entry_get_value(entry);

	return NULL;
}