From 1259027ebc65982afc6b073a5822458d09c0a97b Mon Sep 17 00:00:00 2001 From: PaulStoffregen Date: Sun, 10 Sep 2017 01:53:50 -0700 Subject: [PATCH] Disallow claim of USBDriver with non-NULL device, even if on available_drivers list --- USBHost_t36.h | 5 ++++- enumeration.cpp | 3 +++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/USBHost_t36.h b/USBHost_t36.h index 51957bf..bb8365e 100644 --- a/USBHost_t36.h +++ b/USBHost_t36.h @@ -372,7 +372,10 @@ protected: // The device this object instance is bound to. In words, this // is the specific device this driver is using. When not bound - // to any device, this must be NULL. + // to any device, this must be NULL. Drivers may set this to + // any non-NULL value if they are in a state where they do not + // wish to claim any device or interface (eg, if getting data + // from the HID parser). Device_t *device; friend class USBHost; diff --git a/enumeration.cpp b/enumeration.cpp index 5539e2b..f75f538 100644 --- a/enumeration.cpp +++ b/enumeration.cpp @@ -292,6 +292,7 @@ void USBHost::claim_drivers(Device_t *dev) // first check if any driver wishes to claim the entire device for (driver=available_drivers; driver != NULL; driver = driver->next) { + if (driver->device != NULL) continue; if (driver->claim(dev, 0, enumbuf + 9, enumlen - 9)) { if (prev) { prev->next = driver->next; @@ -329,6 +330,7 @@ void USBHost::claim_drivers(Device_t *dev) // found an interface, ask available drivers if they want it prev = NULL; for (driver=available_drivers; driver != NULL; driver = driver->next) { + if (driver->device != NULL) continue; // TODO: should parse ahead and give claim() // an accurate length. (end - p) is the rest // of ALL descriptors, likely more interfaces @@ -402,6 +404,7 @@ void USBHost::disconnect_Device(Device_t *dev) for (USBDriver *p = dev->drivers; p; ) { println("disconnect driver ", (uint32_t)p, HEX); p->disconnect(); + p->device = NULL; USBDriver *next = p->next; p->next = available_drivers; available_drivers = p;