summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRichard Hughes <richard@hughsie.com>2017-08-02 20:12:52 +0100
committerRichard Hughes <richard@hughsie.com>2017-08-02 20:12:52 +0100
commitf20246caa90e5279cfae8bf7f30ac69ce1edad80 (patch)
treeb88569d336a737270fd1e8c2bf1f83916e5af59b
parent770039b300bc9f8f9ce377e90cb9c60a616a28a4 (diff)
downloadcolord-f20246caa90e5279cfae8bf7f30ac69ce1edad80.tar.gz
huey: Get the device status before trying to unlock
This means in the future we can check the model.
-rw-r--r--src/sensors/huey/huey-device.c39
-rw-r--r--src/sensors/huey/huey-device.h3
2 files changed, 42 insertions, 0 deletions
diff --git a/src/sensors/huey/huey-device.c b/src/sensors/huey/huey-device.c
index d485d95..7b34204 100644
--- a/src/sensors/huey/huey-device.c
+++ b/src/sensors/huey/huey-device.c
@@ -142,6 +142,38 @@ huey_device_send_data (GUsbDevice *device,
return FALSE;
}
+gchar *
+huey_device_get_status (GUsbDevice *device, GError **error)
+{
+ guint8 request[8];
+ guint8 reply[8];
+ gboolean ret;
+ gsize reply_read;
+ g_autoptr(GError) error_local = NULL;
+
+ g_return_val_if_fail (G_USB_IS_DEVICE (device), NULL);
+ g_return_val_if_fail (error == NULL || *error == NULL, NULL);
+
+ memset (request, 0x00, sizeof(request));
+ memset (reply, 0x00, sizeof(reply));
+ request[0] = HUEY_CMD_GET_STATUS;
+ ret = huey_device_send_data (device,
+ request, 8,
+ reply, 8,
+ &reply_read,
+ &error_local);
+ if (!ret) {
+ if (!g_error_matches (error_local, G_IO_ERROR, G_IO_ERROR_NOT_INITIALIZED)) {
+ g_propagate_error (error, error_local);
+ error_local = NULL;
+ return NULL;
+ }
+ }
+
+ /* for error the string is also set */
+ return g_strndup ((gchar *) reply + 2, 6);
+}
+
gboolean
huey_device_unlock (GUsbDevice *device, GError **error)
{
@@ -149,10 +181,17 @@ huey_device_unlock (GUsbDevice *device, GError **error)
guint8 reply[8];
gboolean ret;
gsize reply_read;
+ g_autofree gchar *status = NULL;
g_return_val_if_fail (G_USB_IS_DEVICE (device), FALSE);
g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
+ /* get initial status */
+ status = huey_device_get_status (device, error);
+ if (status == NULL)
+ return FALSE;
+ g_debug ("status is: %s", status);
+
/* embedded devices on Lenovo machines use a different unlock code */
if (g_usb_device_get_vid (device) == 0x0765 &&
(g_usb_device_get_pid (device) == 0x5001 ||
diff --git a/src/sensors/huey/huey-device.h b/src/sensors/huey/huey-device.h
index 6f90d89..20c698d 100644
--- a/src/sensors/huey/huey-device.h
+++ b/src/sensors/huey/huey-device.h
@@ -43,6 +43,9 @@ gboolean huey_device_set_leds (GUsbDevice *device,
gchar *huey_device_get_serial_number (GUsbDevice *device,
GError **error)
G_GNUC_WARN_UNUSED_RESULT;
+gchar *huey_device_get_status (GUsbDevice *device,
+ GError **error)
+ G_GNUC_WARN_UNUSED_RESULT;
gchar *huey_device_get_unlock_string (GUsbDevice *device,
GError **error)
G_GNUC_WARN_UNUSED_RESULT;