genesys: usbhub: Add has-public-key private flag

The Genesys Logic USB Hub does have support for public-key.

This adds the private flag has-public-key, and sets that flag for the HP
USB Hubs only. Also, this authenticates during setup only if that flag
is set.
This commit is contained in:
Gaël PORTAY 2022-03-19 18:01:42 +01:00 committed by Richard Hughes
parent ac760f7a2d
commit d056b382dd
2 changed files with 40 additions and 21 deletions

View File

@ -23,6 +23,14 @@
* Device has a MStar scaler attached via I2C.
*/
#define FU_GENESYS_USBHUB_FLAG_HAS_MSTAR_SCALER (1 << 0)
/**
* FU_GENESYS_USBHUB_FLAG_HAS_PUBLIC_KEY:
*
* Device has a public-key appended to firmware.
*
* Since 1.7.7
*/
#define FU_GENESYS_USBHUB_FLAG_HAS_PUBLIC_KEY (1 << 1)
#define GENESYS_USBHUB_STATIC_TOOL_DESC_IDX_USB_3_0 0x84
#define GENESYS_USBHUB_DYNAMIC_TOOL_DESC_IDX_USB_3_0 0x85
@ -616,8 +624,10 @@ static gboolean
fu_genesys_usbhub_device_detach(FuDevice *device, FuProgress *progress, GError **error)
{
FuGenesysUsbhubDevice *self = FU_GENESYS_USBHUB_DEVICE(device);
if (!fu_genesys_usbhub_device_authenticate(self, error))
return FALSE;
if (fu_device_has_private_flag(device, FU_GENESYS_USBHUB_FLAG_HAS_PUBLIC_KEY)) {
if (!fu_genesys_usbhub_device_authenticate(self, error))
return FALSE;
}
if (!fu_genesys_usbhub_device_set_isp_mode(self, ISP_ENTER, error))
return FALSE;
@ -695,7 +705,6 @@ fu_genesys_usbhub_device_setup(FuDevice *device, GError **error)
g_autoptr(GError) error_local = NULL;
g_autoptr(GBytes) blob = NULL;
g_autofree guint8 *buf = NULL;
g_autofree gchar *guid = NULL;
/* FuUsbDevice->setup */
if (!FU_DEVICE_CLASS(fu_genesys_usbhub_device_parent_class)->setup(device, error)) {
@ -815,8 +824,10 @@ fu_genesys_usbhub_device_setup(FuDevice *device, GError **error)
}
}
if (!fu_genesys_usbhub_device_authenticate(self, error))
return FALSE;
if (fu_device_has_private_flag(device, FU_GENESYS_USBHUB_FLAG_HAS_PUBLIC_KEY)) {
if (!fu_genesys_usbhub_device_authenticate(self, error))
return FALSE;
}
if (!fu_genesys_usbhub_device_set_isp_mode(self, ISP_ENTER, error))
return FALSE;
self->cfi_device = fu_genesys_usbhub_device_cfi_setup(self, error);
@ -927,19 +938,24 @@ fu_genesys_usbhub_device_setup(FuDevice *device, GError **error)
self->write_recovery_bank = address == self->fw_bank_addr[1];
}
/* get public key */
if (!fu_memcpy_safe(self->public_key,
sizeof(self->public_key),
0, /* dst */
g_bytes_get_data(blob, NULL),
g_bytes_get_size(blob),
self->fw_data_total_count, /* src */
sizeof(self->public_key),
error))
return FALSE;
guid =
fwupd_guid_hash_data(self->public_key, sizeof(self->public_key), FWUPD_GUID_FLAG_NONE);
fu_device_add_instance_strup(device, "PUBKEY", guid);
/* has public key */
if (fu_device_has_private_flag(device, FU_GENESYS_USBHUB_FLAG_HAS_PUBLIC_KEY)) {
g_autofree gchar *guid = NULL;
if (!fu_memcpy_safe(self->public_key,
sizeof(self->public_key),
0, /* dst */
g_bytes_get_data(blob, NULL),
g_bytes_get_size(blob),
self->fw_data_total_count, /* src */
sizeof(self->public_key),
error))
return FALSE;
guid = fwupd_guid_hash_data(self->public_key,
sizeof(self->public_key),
FWUPD_GUID_FLAG_NONE);
fu_device_add_instance_strup(device, "PUBKEY", guid);
}
fu_device_build_instance_id(device, NULL, "USB", "VID", "PID", "PUBKEY", NULL);
/* have MStar scaler */
@ -1379,6 +1395,9 @@ fu_genesys_usbhub_device_init(FuGenesysUsbhubDevice *self)
fu_device_register_private_flag(FU_DEVICE(self),
FU_GENESYS_USBHUB_FLAG_HAS_MSTAR_SCALER,
"has-mstar-scaler");
fu_device_register_private_flag(FU_DEVICE(self),
FU_GENESYS_USBHUB_FLAG_HAS_PUBLIC_KEY,
"has-public-key");
self->vcs.req_switch = GENESYS_USBHUB_GL_HUB_SWITCH;
self->vcs.req_read = GENESYS_USBHUB_GL_HUB_READ;
self->vcs.req_write = GENESYS_USBHUB_GL_HUB_WRITE;

View File

@ -4,7 +4,7 @@
[USB\VID_03F0&PID_0610]
Plugin = genesys
Name = HP USB-C Controller
Flags = dual-image
Flags = dual-image,has-public-key
GenesysUsbhubSwitchRequest = 0xA1
GenesysUsbhubReadRequest = 0xA2
GenesysUsbhubWriteRequest = 0xA3
@ -12,7 +12,7 @@ GenesysUsbhubWriteRequest = 0xA3
[USB\VID_03F0&PID_0610&PUBKEY_AB859399-95B8-5817-B521-9AD8CC7F5BD6]
Plugin = genesys
Name = HP M24fd USB-C Controller
Flags = dual-image,has-mstar-scaler
Flags = dual-image,has-public-key,has-mstar-scaler
GenesysUsbhubSwitchRequest = 0xA1
GenesysUsbhubReadRequest = 0xA2
GenesysUsbhubWriteRequest = 0xA3
@ -20,7 +20,7 @@ GenesysUsbhubWriteRequest = 0xA3
[USB\VID_03F0&PID_0610&PUBKEY_6BE97D77-C2BA-5AA2-B7DF-B9B318BEC2B5]
Plugin = genesys
Name = HP M27fd USB-C Controller
Flags = dual-image,has-mstar-scaler
Flags = dual-image,has-public-key,has-mstar-scaler
GenesysUsbhubSwitchRequest = 0xA1
GenesysUsbhubReadRequest = 0xA2
GenesysUsbhubWriteRequest = 0xA3