mirror of
https://git.proxmox.com/git/fwupd
synced 2025-08-04 11:53:05 +00:00
dfu: Use the generic fu_plugin_usb_device_added() function
This commit is contained in:
parent
b6fbf80f95
commit
13ffa3e13f
@ -117,6 +117,8 @@ typedef struct {
|
||||
G_DEFINE_TYPE_WITH_PRIVATE (DfuDevice, dfu_device, FU_TYPE_USB_DEVICE)
|
||||
#define GET_PRIVATE(o) (dfu_device_get_instance_private (o))
|
||||
|
||||
static void dfu_device_set_state (DfuDevice *device, DfuState state);
|
||||
|
||||
/**
|
||||
* dfu_device_get_transfer_size:
|
||||
* @device: a #GUsbDevice
|
||||
@ -241,24 +243,22 @@ dfu_device_parse_iface_data (DfuDevice *device, GBytes *iface_data, GError **err
|
||||
static void
|
||||
dfu_device_guess_state_from_iface (DfuDevice *device, GUsbInterface *iface)
|
||||
{
|
||||
DfuDevicePrivate *priv = GET_PRIVATE (device);
|
||||
|
||||
/* some devices use the wrong interface */
|
||||
if (dfu_device_has_quirk (device, DFU_DEVICE_QUIRK_FORCE_DFU_MODE)) {
|
||||
g_debug ("quirking device into DFU mode");
|
||||
priv->state = DFU_STATE_DFU_IDLE;
|
||||
dfu_device_set_state (device, DFU_STATE_DFU_IDLE);
|
||||
return;
|
||||
}
|
||||
|
||||
/* runtime */
|
||||
if (g_usb_interface_get_protocol (iface) == 0x01) {
|
||||
priv->state = DFU_STATE_APP_IDLE;
|
||||
dfu_device_set_state (device, DFU_STATE_APP_IDLE);
|
||||
return;
|
||||
}
|
||||
|
||||
/* DFU */
|
||||
if (g_usb_interface_get_protocol (iface) == 0x02) {
|
||||
priv->state = DFU_STATE_DFU_IDLE;
|
||||
dfu_device_set_state (device, DFU_STATE_DFU_IDLE);
|
||||
return;
|
||||
}
|
||||
g_warning ("unable to guess initial device state from interface %u",
|
||||
@ -371,7 +371,7 @@ dfu_device_add_targets (DfuDevice *device, GError **error)
|
||||
if (priv->targets->len == 0 &&
|
||||
priv->quirks & DFU_DEVICE_QUIRK_NO_DFU_RUNTIME) {
|
||||
g_debug ("no DFU runtime, so faking device");
|
||||
priv->state = DFU_STATE_APP_IDLE;
|
||||
dfu_device_set_state (device, DFU_STATE_APP_IDLE);
|
||||
priv->iface_number = 0xff;
|
||||
priv->runtime_vid = g_usb_device_get_vid (usb_device);
|
||||
priv->runtime_pid = g_usb_device_get_pid (usb_device);
|
||||
@ -461,25 +461,6 @@ dfu_device_set_timeout (DfuDevice *device, guint timeout_ms)
|
||||
priv->timeout_ms = timeout_ms;
|
||||
}
|
||||
|
||||
/**
|
||||
* dfu_device_is_runtime:
|
||||
* @device: a #GUsbDevice
|
||||
*
|
||||
* Gets the device mode.
|
||||
*
|
||||
* Return value: %TRUE if the device is in a runtime state
|
||||
**/
|
||||
gboolean
|
||||
dfu_device_is_runtime (DfuDevice *device)
|
||||
{
|
||||
DfuDevicePrivate *priv = GET_PRIVATE (device);
|
||||
g_return_val_if_fail (DFU_IS_DEVICE (device), FALSE);
|
||||
if (priv->state == DFU_STATE_APP_IDLE ||
|
||||
priv->state == DFU_STATE_APP_DETACH)
|
||||
return TRUE;
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/**
|
||||
* dfu_device_get_timeout:
|
||||
* @device: a #GUsbDevice
|
||||
@ -870,6 +851,14 @@ dfu_device_set_state (DfuDevice *device, DfuState state)
|
||||
return;
|
||||
priv->state = state;
|
||||
|
||||
/* set bootloader status */
|
||||
if (state == DFU_STATE_APP_IDLE ||
|
||||
state == DFU_STATE_APP_DETACH) {
|
||||
fu_device_remove_flag (FU_DEVICE (device), FWUPD_DEVICE_FLAG_IS_BOOTLOADER);
|
||||
} else {
|
||||
fu_device_add_flag (FU_DEVICE (device), FWUPD_DEVICE_FLAG_IS_BOOTLOADER);
|
||||
}
|
||||
|
||||
switch (state) {
|
||||
case DFU_STATE_DFU_UPLOAD_IDLE:
|
||||
fu_device_set_status (FU_DEVICE (device), FWUPD_STATUS_DEVICE_VERIFY);
|
||||
@ -1084,7 +1073,7 @@ dfu_device_detach (FuDevice *device, GError **error)
|
||||
/* already in DFU mode */
|
||||
if (!dfu_device_refresh_and_clear (self, error))
|
||||
return FALSE;
|
||||
if (!dfu_device_is_runtime (self))
|
||||
if (fu_device_has_flag (device, FWUPD_DEVICE_FLAG_IS_BOOTLOADER))
|
||||
return TRUE;
|
||||
|
||||
/* no backing USB device */
|
||||
@ -1394,7 +1383,7 @@ dfu_device_open (FuUsbDevice *device, GError **error)
|
||||
/* the device has no DFU runtime, so cheat */
|
||||
if (priv->state == DFU_STATE_APP_IDLE &&
|
||||
priv->quirks & DFU_DEVICE_QUIRK_NO_DFU_RUNTIME) {
|
||||
priv->state = DFU_STATE_APP_IDLE;
|
||||
dfu_device_set_state (self, DFU_STATE_APP_IDLE);
|
||||
priv->status = DFU_STATUS_OK;
|
||||
}
|
||||
|
||||
@ -1563,7 +1552,7 @@ dfu_device_attach (FuDevice *device, GError **error)
|
||||
/* already in runtime mode */
|
||||
if (!dfu_device_refresh_and_clear (self, error))
|
||||
return FALSE;
|
||||
if (dfu_device_is_runtime (self))
|
||||
if (!fu_device_has_flag (device, FWUPD_DEVICE_FLAG_IS_BOOTLOADER))
|
||||
return TRUE;
|
||||
|
||||
/* inform UI there's going to be a re-attach */
|
||||
@ -2113,4 +2102,5 @@ dfu_device_init (DfuDevice *device)
|
||||
priv->targets = g_ptr_array_new_with_free_func ((GDestroyNotify) g_object_unref);
|
||||
priv->timeout_ms = 1500;
|
||||
priv->transfer_size = 64;
|
||||
fu_device_add_icon (FU_DEVICE (device), "drive-harddisk-usb");
|
||||
}
|
||||
|
@ -120,7 +120,6 @@ gboolean dfu_device_clear_status (DfuDevice *device,
|
||||
GError **error);
|
||||
|
||||
guint8 dfu_device_get_interface (DfuDevice *device);
|
||||
gboolean dfu_device_is_runtime (DfuDevice *device);
|
||||
DfuState dfu_device_get_state (DfuDevice *device);
|
||||
DfuStatus dfu_device_get_status (DfuDevice *device);
|
||||
guint16 dfu_device_get_transfer_size (DfuDevice *device);
|
||||
|
@ -538,7 +538,7 @@ dfu_target_use_alt_setting (DfuTarget *target, GError **error)
|
||||
return FALSE;
|
||||
|
||||
/* use the correct setting */
|
||||
if (!dfu_device_is_runtime (priv->device)) {
|
||||
if (fu_device_has_flag (FU_DEVICE (priv->device), FWUPD_DEVICE_FLAG_IS_BOOTLOADER)) {
|
||||
if (!g_usb_device_set_interface_alt (usb_device,
|
||||
(gint) dfu_device_get_interface (priv->device),
|
||||
(gint) priv->alt_setting,
|
||||
|
@ -1191,7 +1191,7 @@ dfu_tool_read_alt (DfuToolPrivate *priv, gchar **values, GError **error)
|
||||
G_CALLBACK (fu_tool_action_changed_cb), priv);
|
||||
|
||||
/* APP -> DFU */
|
||||
if (dfu_device_is_runtime (device)) {
|
||||
if (!fu_device_has_flag (FU_DEVICE (device), FWUPD_DEVICE_FLAG_IS_BOOTLOADER)) {
|
||||
g_debug ("detaching");
|
||||
if (!fu_device_detach (FU_DEVICE (device), error))
|
||||
return FALSE;
|
||||
@ -1317,7 +1317,7 @@ dfu_tool_read (DfuToolPrivate *priv, gchar **values, GError **error)
|
||||
return FALSE;
|
||||
|
||||
/* APP -> DFU */
|
||||
if (dfu_device_is_runtime (device)) {
|
||||
if (!fu_device_has_flag (FU_DEVICE (device), FWUPD_DEVICE_FLAG_IS_BOOTLOADER)) {
|
||||
if (!fu_device_detach (FU_DEVICE (device), error))
|
||||
return FALSE;
|
||||
if (!dfu_device_wait_for_replug (device,
|
||||
@ -1556,7 +1556,7 @@ dfu_tool_write_alt (DfuToolPrivate *priv, gchar **values, GError **error)
|
||||
G_CALLBACK (fu_tool_action_changed_cb), priv);
|
||||
|
||||
/* APP -> DFU */
|
||||
if (dfu_device_is_runtime (device)) {
|
||||
if (!fu_device_has_flag (FU_DEVICE (device), FWUPD_DEVICE_FLAG_IS_BOOTLOADER)) {
|
||||
g_debug ("detaching");
|
||||
if (!fu_device_detach (FU_DEVICE (device), error))
|
||||
return FALSE;
|
||||
@ -1684,7 +1684,7 @@ dfu_tool_write (DfuToolPrivate *priv, gchar **values, GError **error)
|
||||
g_debug ("DFU: %s", str_debug);
|
||||
|
||||
/* APP -> DFU */
|
||||
if (dfu_device_is_runtime (device)) {
|
||||
if (!fu_device_has_flag (FU_DEVICE (device), FWUPD_DEVICE_FLAG_IS_BOOTLOADER)) {
|
||||
if (!fu_device_detach (FU_DEVICE (device), error))
|
||||
return FALSE;
|
||||
if (!dfu_device_wait_for_replug (device,
|
||||
@ -1846,7 +1846,7 @@ dfu_tool_list (DfuToolPrivate *priv, gchar **values, GError **error)
|
||||
}
|
||||
|
||||
/* TRANSLATORS: device mode, e.g. application runtime or DFU */
|
||||
is_runtime = dfu_device_is_runtime (device);
|
||||
is_runtime = !fu_device_has_flag (FU_DEVICE (device), FWUPD_DEVICE_FLAG_IS_BOOTLOADER);
|
||||
dfu_tool_print_indent (_("Mode"), is_runtime ? _("Runtime") : _("DFU"), 1);
|
||||
|
||||
tmp = dfu_status_to_string (dfu_device_get_status (device));
|
||||
|
@ -16,34 +16,7 @@ fu_plugin_init (FuPlugin *plugin)
|
||||
fu_plugin_set_build_hash (plugin, FU_BUILD_HASH);
|
||||
fu_plugin_add_rule (plugin, FU_PLUGIN_RULE_SUPPORTS_PROTOCOL, "org.usb.dfu");
|
||||
fu_plugin_add_rule (plugin, FU_PLUGIN_RULE_SUPPORTS_PROTOCOL, "com.st.dfuse");
|
||||
}
|
||||
|
||||
gboolean
|
||||
fu_plugin_usb_device_added (FuPlugin *plugin, FuUsbDevice *dev, GError **error)
|
||||
{
|
||||
g_autoptr(DfuDevice) device = NULL;
|
||||
g_autoptr(FuDeviceLocker) locker = NULL;
|
||||
|
||||
/* open the device */
|
||||
device = dfu_device_new (fu_usb_device_get_dev (dev));
|
||||
fu_device_set_quirks (FU_DEVICE (device), fu_plugin_get_quirks (plugin));
|
||||
dfu_device_set_usb_context (device, fu_plugin_get_usb_context (plugin));
|
||||
locker = fu_device_locker_new (device, error);
|
||||
if (locker == NULL)
|
||||
return FALSE;
|
||||
|
||||
/* ignore defective runtimes */
|
||||
if (fu_device_has_flag (FU_DEVICE (device), FWUPD_DEVICE_FLAG_ONLY_SUPPORTED)) {
|
||||
g_debug ("ignoring %s", dfu_device_get_platform_id (device));
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/* this is a guess and can be overridden in the metainfo file */
|
||||
fu_device_add_icon (device, "drive-harddisk-usb");
|
||||
|
||||
/* insert to hash */
|
||||
fu_plugin_device_add (plugin, FU_DEVICE (device));
|
||||
return TRUE;
|
||||
fu_plugin_set_device_gtype (plugin, DFU_TYPE_DEVICE);
|
||||
}
|
||||
|
||||
gboolean
|
||||
|
Loading…
Reference in New Issue
Block a user