aboutsummaryrefslogtreecommitdiff
path: root/elksmart-comm.c
diff options
context:
space:
mode:
Diffstat (limited to 'elksmart-comm.c')
-rw-r--r--elksmart-comm.c35
1 files changed, 23 insertions, 12 deletions
diff --git a/elksmart-comm.c b/elksmart-comm.c
index 3aeec34..8d2a146 100644
--- a/elksmart-comm.c
+++ b/elksmart-comm.c
@@ -251,6 +251,8 @@ enum {
// 0x184 (EKX5S-T, international edition)
USB_PRODUCT_SMTCTL_SMART_EKX4S = 0x0195,
USB_PRODUCT_SMTCTL_SMART_EKX5S_T = 0x0184,
+ // 0x132 (EKX5S-T, to be reverse-engineered)
+ USB_PRODUCT_SMTCTL_SMART_EKX5S_T_2025 = 0x0132,
// There should only ever be one interface.
USB_INTERFACE = 0,
@@ -277,7 +279,8 @@ init_device_from_desc(struct libusb_config_descriptor *desc, struct error **e)
return error_set(e, "unexpected alternate setting count");
const struct libusb_interface_descriptor *asd = desc->interface->altsetting;
- if (asd->bInterfaceClass != LIBUSB_CLASS_COMM)
+ if (asd->bInterfaceClass != LIBUSB_CLASS_COMM &&
+ asd->bInterfaceClass != LIBUSB_CLASS_VENDOR_SPEC /* 045c:0132 */)
return error_set(e, "unexpected USB interface class");
if (asd->bNumEndpoints != 2)
return error_set(e, "unexpected endpoint count");
@@ -306,20 +309,25 @@ init_device_from_desc(struct libusb_config_descriptor *desc, struct error **e)
static bool
init_device(libusb_device_handle *device, struct error **e)
{
- struct libusb_config_descriptor *desc = NULL;
- int result =
- libusb_get_active_config_descriptor(libusb_get_device(device), &desc);
- if (result)
+ int result = libusb_kernel_driver_active(device, USB_INTERFACE);
+ if (result == 1) {
+ // macOS for some reason claims the interface and we need to detach it
+ // before the following call to libusb_get_active_config_descriptor().
+ if ((result = libusb_detach_kernel_driver(device, USB_INTERFACE)))
+ return error_set(e, "cannot detach kernel driver: %s",
+ libusb_strerror(result));
+
+ print_debug("detached the kernel driver");
+ } else if (result) {
return error_set(e, "%s", libusb_strerror(result));
+ }
- bool ok = true;
- if ((result = libusb_kernel_driver_active(device, USB_INTERFACE)) == 1)
- ok = error_set(e, "device is claimed by a kernel driver");
- else if (result)
- ok = error_set(e, "%s", libusb_strerror(result));
- else
- ok = init_device_from_desc(desc, e);
+ struct libusb_config_descriptor *desc = NULL;
+ if ((result = libusb_get_active_config_descriptor(
+ libusb_get_device(device), &desc)))
+ return error_set(e, "%s", libusb_strerror(result));
+ bool ok = init_device_from_desc(desc, e);
libusb_free_config_descriptor(desc);
return ok;
}
@@ -642,6 +650,9 @@ main(int argc, char *argv[])
if (!device && !result)
device = find_device(
USB_VENDOR_SMTCTL, USB_PRODUCT_SMTCTL_SMART_EKX5S_T, &result);
+ if (!device && !result)
+ device = find_device(
+ USB_VENDOR_SMTCTL, USB_PRODUCT_SMTCTL_SMART_EKX5S_T_2025, &result);
if (result)
exit_fatal("couldn't open device: %s", libusb_strerror(result));