usb: add visual logging system to usb storage code for debugging
What changed, and why it matters
This commit adds extra on-screen logging and debugging messages for the USB storage feature. It does not change how the device protects keys or data, and it does not fix or introduce a security vulnerability. The new logging is disabled by default.
No security action required. If enabling USB_VISUAL_LOG in production, review whether verbose error strings derived from USB host stack values could leak sensitive path or timing information via the screen.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The patch introduces a visual logging macro system (USB_LOGI/USB_LOGE/USB_MESSAGE_ACTIVITY) in main/usbhmsc/usbhmsc.c/h. USB_VISUAL_LOG is hard-coded to false, so the screen-display path is compiled out at runtime. Existing JADE_LOGE/JADE_LOGI calls remain, and error handling around msc_host_install, msc_host_uninstall, and usb_host_uninstall is unchanged except for wrapping install in an explicit JADE_ASSERT. No bounds, type, or control-flow security changes are evident.
Changed components
main/usbhmsc/usbhmsc.cmain/usbhmsc/usbhmsc.hInspect captured patch +43 / −4
diff --git a/main/usbhmsc/usbhmsc.c b/main/usbhmsc/usbhmsc.c
index 15883fb..18d21bb 100644
--- a/main/usbhmsc/usbhmsc.c
+++ b/main/usbhmsc/usbhmsc.c
@@ -152,7 +152,14 @@ static void usbstorage_task(void* ignore)
.callback = msc_event_cb,
};
- JADE_ERROR_CHECK(msc_host_install(&msc_config));
+ {
+ USB_LOGI(500, "msc_host_install..");
+ const esp_err_t err = msc_host_install(&msc_config);
+ if (err != ESP_OK) {
+ USB_LOGE(5000, "msc_host_install failed %d", err);
+ }
+ JADE_ASSERT(err == ESP_OK);
+ }
bool done = false;
@@ -193,11 +200,12 @@ static void usbstorage_task(void* ignore)
done = !usbstorage_is_enabled;
break;
} else if (!ebt && requires_host_uninstall && !usb_device_installed) {
+ USB_LOGI(500, "msc_host_uninstall..");
esp_err_t err = msc_host_uninstall();
if (err == ESP_OK) {
requires_host_uninstall = false;
} else {
- JADE_LOGE("msc_host_uninstall failed %d", err);
+ USB_LOGE(5000, "msc_host_uninstall failed %d", err);
}
}
}
@@ -207,9 +215,10 @@ static void usbstorage_task(void* ignore)
// This may fail if the user removes the device at the right time
if (requires_host_uninstall) {
+ USB_LOGI(500, "msc_host_uninstall..");
const esp_err_t err = msc_host_uninstall();
if (err != ESP_OK) {
- JADE_LOGE("msc_host_uninstall failed %d", err);
+ USB_LOGE(5000, "msc_host_uninstall failed %d", err);
}
}
@@ -218,9 +227,10 @@ static void usbstorage_task(void* ignore)
vTaskDelete(aux_task);
vEventGroupDelete(usb_flags);
+ USB_LOGI(500, "usb_host_uninstall..");
const esp_err_t err = usb_host_uninstall();
if (err != ESP_OK) {
- JADE_LOGE("usb_host_uninstall failed %d", err);
+ USB_LOGE(5000, "usb_host_uninstall failed %d", err);
}
xSemaphoreGive(main_task_semaphore);
diff --git a/main/usbhmsc/usbhmsc.h b/main/usbhmsc/usbhmsc.h
index f9790b7..8f89285 100644
--- a/main/usbhmsc/usbhmsc.h
+++ b/main/usbhmsc/usbhmsc.h
@@ -7,6 +7,35 @@
#define USBSTORAGE_MOUNT_POINT "/usb"
+#define USB_VISUAL_LOG false
+#define USB_VISUAL_LOG_LEVEL ESP_LOG_INFO
+#define USB_MESSAGE_ACTIVITY(delay, msg) \
+ do { \
+ if (USB_VISUAL_LOG) { \
+ const char* message[] = { msg }; \
+ display_message_activity(message, 1); \
+ vTaskDelay(delay / portTICK_PERIOD_MS); \
+ } \
+ } while (false)
+#define USB_LOGE(delay, fmt, ...) \
+ do { \
+ JADE_LOGE(fmt, ##__VA_ARGS__); \
+ if (USB_VISUAL_LOG && USB_VISUAL_LOG_LEVEL >= ESP_LOG_ERROR) { \
+ char msg[128]; \
+ snprintf(msg, sizeof(msg), fmt, ##__VA_ARGS__); \
+ USB_MESSAGE_ACTIVITY(delay, msg); \
+ } \
+ } while (false)
+#define USB_LOGI(delay, fmt, ...) \
+ do { \
+ JADE_LOGI(fmt, ##__VA_ARGS__); \
+ if (USB_VISUAL_LOG && USB_VISUAL_LOG_LEVEL >= ESP_LOG_INFO) { \
+ char msg[128]; \
+ snprintf(msg, sizeof(msg), fmt, ##__VA_ARGS__); \
+ USB_MESSAGE_ACTIVITY(delay, msg); \
+ } \
+ } while (false)
+
typedef enum {
USBSTORAGE_EVENT_DETECTED,
USBSTORAGE_EVENT_EJECTED,
Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.