Exemplo n.º 1
0
static char *
get_driver_name (GUdevDevice *device)
{
    GUdevDevice *parent = NULL;
    const char *driver, *subsys;
    char *ret = NULL;

    driver = g_udev_device_get_driver (device);
    if (!driver) {
        parent = g_udev_device_get_parent (device);
        if (parent)
            driver = g_udev_device_get_driver (parent);

        /* Check for bluetooth; it's driver is a bunch of levels up so we
         * just check for the subsystem of the parent being bluetooth.
         */
        if (!driver && parent) {
            subsys = g_udev_device_get_subsystem (parent);
            if (subsys && !strcmp (subsys, "bluetooth"))
                driver = "bluetooth";
        }
    }

    if (driver)
        ret = g_strdup (driver);
    if (parent)
        g_object_unref (parent);

    return ret;
}
Exemplo n.º 2
0
static gboolean
dev_get_attrs (GUdevDevice *udev_device,
               const char **out_ifname,
               const char **out_path,
               char **out_driver)
{
    GUdevDevice *parent = NULL;
    const char *ifname, *driver, *path;

    g_return_val_if_fail (udev_device != NULL, FALSE);
    g_return_val_if_fail (out_ifname != NULL, FALSE);
    g_return_val_if_fail (out_path != NULL, FALSE);
    g_return_val_if_fail (out_driver != NULL, FALSE);

    ifname = g_udev_device_get_name (udev_device);
    if (!ifname) {
        nm_log_dbg (LOGD_HW, "failed to get device's interface");
        return FALSE;
    }

    path = g_udev_device_get_sysfs_path (udev_device);
    if (!path) {
        nm_log_warn (LOGD_HW, "couldn't determine device path; ignoring...");
        return FALSE;
    }

    driver = g_udev_device_get_driver (udev_device);
    if (!driver) {
        /* Try the parent */
        parent = g_udev_device_get_parent (udev_device);
        if (parent) {
            driver = g_udev_device_get_driver (parent);
            g_object_unref (parent);
        }
    }

    *out_ifname = ifname;
    *out_path = path;
    *out_driver = g_strdup (driver);

    return TRUE;
}
Exemplo n.º 3
0
static gboolean device_is_acm(GUdevDevice * device)
{
	GUdevDevice *parent;
	parent = g_udev_device_get_parent(device);
	if (parent) {
		/* Serial driver */
		if (g_strcmp0(g_udev_device_get_driver(parent), "cdc_acm") == 0) {
			g_object_unref(parent);
			return TRUE;
		}
		g_object_unref(parent);
	}
	return FALSE;
}
Exemplo n.º 4
0
const char *
nmp_utils_udev_get_driver (GUdevDevice *device)
{
	GUdevDevice *parent = NULL, *grandparent = NULL;
	const char *driver, *subsys;

	driver = g_udev_device_get_driver (device);
	if (driver)
		goto out;

	/* Try the parent */
	parent = g_udev_device_get_parent (device);
	if (parent) {
		driver = g_udev_device_get_driver (parent);
		if (!driver) {
			/* Try the grandparent if it's an ibmebus device or if the
			 * subsys is NULL which usually indicates some sort of
			 * platform device like a 'gadget' net interface.
			 */
			subsys = g_udev_device_get_subsystem (parent);
			if (   (g_strcmp0 (subsys, "ibmebus") == 0)
			    || (subsys == NULL)) {
				grandparent = g_udev_device_get_parent (parent);
				if (grandparent)
					driver = g_udev_device_get_driver (grandparent);
			}
		}
	}
	g_clear_object (&parent);
	g_clear_object (&grandparent);

out:
	/* Intern the string so we don't have to worry about memory
	 * management in NMPlatformLink. */
	return g_intern_string (driver);
}
Exemplo n.º 5
0
static void dump_device_and_parent(GUdevDevice * device, guint indent)
{
	const gchar *const *list;
	const gchar *const *iter;
	GUdevDevice *parent;
	char propstr[500];
	guint32 namelen = 0, i;

	println(indent, "------------------------------------------------------");
	println(indent, "%-20s %s", _("Name:"), g_udev_device_get_name(device));
	println(indent, "%-20s %s", _("Type:"), g_udev_device_get_devtype(device));
	println(indent, "%-20s %s", _("Subsystem:"), g_udev_device_get_subsystem(device));
	println(indent, "%-20s %s", _("Number:"), g_udev_device_get_number(device));
	println(indent, "%-20s %s", _("Path:"), g_udev_device_get_sysfs_path(device));
	println(indent, "%-20s %s", _("Driver:"), g_udev_device_get_driver(device));
	println(indent, "%-20s %lld", _("Sequential Number:"), (long long int)g_udev_device_get_seqnum(device));
	println(indent, "%-20s %s", _("Device File:"), g_udev_device_get_device_file(device));

	println(indent, " ");
	println(indent, _("Properties:"));

	/* Get longest property name length for alignment */
	list = g_udev_device_get_property_keys(device);
	for (iter = list; iter && *iter; iter++) {
		if (strlen(*iter) > namelen)
			namelen = strlen(*iter);
	}
	namelen++;

	for (iter = list; iter && *iter; iter++) {
		strcpy(propstr, *iter);
		strcat(propstr, ":");
		for (i = 0; i < namelen - strlen(*iter); i++)
			strcat(propstr, " ");
		strcat(propstr, g_udev_device_get_property(device, *iter));
		println(indent + 2, "%s", propstr);
	}

	println(indent, " ");

	parent = g_udev_device_get_parent(device);
	if (parent) {
		dump_device_and_parent(parent, indent + 4);
		g_object_unref(parent);
	}
}
Exemplo n.º 6
0
static void
fu_plugin_thunderbolt_power_get_path (FuPlugin *plugin)
{
	FuPluginData *data = fu_plugin_get_data (plugin);
	g_autoptr(GList) devices = NULL;
	const gchar *basepath;
	const gchar *driver;

	/* in case driver went away */
	if (data->force_path != NULL) {
		g_free (data->force_path);
		data->force_path = NULL;
	}

	devices = g_udev_client_query_by_subsystem (data->udev, "wmi");
	for (GList* l = devices; l != NULL; l = l->next) {
		g_autofree gchar *built_path = NULL;
		GUdevDevice *device = l->data;

		/* only supports intel-wmi-thunderbolt for now */
		driver = g_udev_device_get_driver (device);
		if (g_strcmp0 (driver, "intel-wmi-thunderbolt") != 0)
			continue;

		/* check for the attribute to be loaded */
		basepath = g_udev_device_get_sysfs_path (device);
		if (basepath == NULL)
			continue;
		built_path = g_build_path ("/", basepath,
					   "force_power", NULL);
		if (g_file_test (built_path, G_FILE_TEST_IS_REGULAR)) {
			data->force_path = g_steal_pointer (&built_path);
			g_debug ("Detected force power support at %s",
				 data->force_path);
			break;
		}
	}
	g_list_foreach (devices, (GFunc) g_object_unref, NULL);
}
Exemplo n.º 7
0
/**
 * pk_device_rebind:
 **/
static gboolean
pk_device_rebind (GUdevClient *client, const gchar *path, GError **error)
{
	GUdevDevice *device;
	gint busnum;
	gint devnum;
	gboolean ret = FALSE;
	const gchar *driver;
	const gchar *subsystem;
	gchar *bus_id = NULL;
	GError *error_local = NULL;

	/* get device */
	device = g_udev_client_query_by_sysfs_path (client, path);
	if (device == NULL) {
		/* TRANSLATORS: the device could not be found in sysfs */
		*error = g_error_new (1, 0, "%s: %s\n", _("Device could not be found"), path);
		goto out;
	}

	/* get properties about the device */
	driver = g_udev_device_get_driver (device);
	subsystem = g_udev_device_get_subsystem (device);
	busnum = g_udev_device_get_sysfs_attr_as_int (device, "busnum");
	devnum = g_udev_device_get_sysfs_attr_as_int (device, "devnum");

	/* debug */
	if (verbose) {
		g_debug ("DEVICE: driver:%s, subsystem:%s, busnum:%i, devnum:%i",
			 driver, subsystem, busnum, devnum);
	}

	/* form the bus id as recognised by the kernel */
	bus_id = g_path_get_basename (path);

	/* FIXME: sometimes the busnum is incorrect */
	if (bus_id == NULL)
		bus_id = g_strdup_printf ("%i-%i", busnum, devnum);

	/* unbind device */
	ret = pk_device_unbind (path, bus_id, &error_local);
	if (!ret) {
		/* TRANSLATORS: we failed to release the current driver */
		*error = g_error_new (1, 0, "%s: %s", _("Failed to unregister driver"), error_local->message);
		g_error_free (error_local);
		goto out;
	}

	/* bind device */
	ret = pk_device_bind (bus_id, subsystem, driver, &error_local);
	if (!ret) {
		/* TRANSLATORS: we failed to bind the old driver */
		*error = g_error_new (1, 0, "%s: %s", _("Failed to register driver"), error_local->message);
		g_error_free (error_local);
		goto out;
	}
out:
	g_free (bus_id);
	if (device != NULL)
		g_object_unref (device);
	return ret;
}