From dfcc2c99272c87b1928e794fddc05fac46cf9412 Mon Sep 17 00:00:00 2001 From: Dmitry Isaenko Date: Sat, 9 May 2020 18:03:25 +0300 Subject: [PATCH] A bit more renames and debug things --- .../nsusbloader/Utilities/NxdtUsbAbi1.java | 22 ++++++++++++------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/src/main/java/nsusbloader/Utilities/NxdtUsbAbi1.java b/src/main/java/nsusbloader/Utilities/NxdtUsbAbi1.java index 8a9c0a4..682c94e 100644 --- a/src/main/java/nsusbloader/Utilities/NxdtUsbAbi1.java +++ b/src/main/java/nsusbloader/Utilities/NxdtUsbAbi1.java @@ -22,6 +22,7 @@ import javafx.concurrent.Task; import nsusbloader.COM.USB.UsbErrorCodes; import nsusbloader.ModelControllers.LogPrinter; import nsusbloader.NSLDataTypes.EMsgType; +import nsusbloader.RainbowHexDump; import org.usb4java.DeviceHandle; import org.usb4java.LibUsb; @@ -67,7 +68,7 @@ class NxdtUsbAbi1 { 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; - private static final byte[] USBSTATUS_MALFORMED_CMD = { 0x4e, 0x58, 0x44, 0x54, + private static final byte[] USBSTATUS_MALFORMED_REQUEST = { 0x4e, 0x58, 0x44, 0x54, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; @@ -99,9 +100,12 @@ class NxdtUsbAbi1 { try { byte[] directive; int command; - while (true){ - directive = readUsbCmd(); + while (true){ + directive = readUsbDirective(); + + RainbowHexDump.hexDumpUTF8(directive); + if (isInvalidDirective(directive)) continue; @@ -122,7 +126,7 @@ class NxdtUsbAbi1 { } } } - catch (InterruptedException ioe){ + catch (InterruptedException ie){ logPrinter.print("Execution interrupted", EMsgType.INFO); } catch (Exception e){ @@ -135,12 +139,12 @@ class NxdtUsbAbi1 { private boolean isInvalidDirective(byte[] message) throws Exception{ if (! Arrays.equals(Arrays.copyOfRange(message, 0,4), MAGIC_NXDT)){ writeUsb(USBSTATUS_INVALID_MAGIC); - logPrinter.print("Invalid magic command", EMsgType.INFO); + logPrinter.print("Invalid 'MAGIC'", EMsgType.INFO); return true; } if (message.length != NXDT_COMMAND_SIZE){ - writeUsb(USBSTATUS_MALFORMED_CMD); - logPrinter.print("Invalid command size. Expected size is 4096 while received is "+message.length, EMsgType.INFO); + writeUsb(USBSTATUS_MALFORMED_REQUEST); + logPrinter.print("Invalid directive size. Expected size is 4096 while received is "+message.length, EMsgType.INFO); return true; } return false; @@ -213,6 +217,8 @@ class NxdtUsbAbi1 { } private void createPath(String path) throws Exception{ + // QA NOTE: Clarify if exception is even possible on RO FS. + File resultingFile = new File(path); File folderForTheFile = resultingFile.getParentFile(); folderForTheFile.mkdirs(); @@ -283,7 +289,7 @@ class NxdtUsbAbi1 { * @return byte array if data read successful * 'null' if read failed * */ - private byte[] readUsbCmd() throws Exception{ + private byte[] readUsbDirective() throws Exception{ ByteBuffer readBuffer = ByteBuffer.allocateDirect(NXDT_COMMAND_SIZE); // We can limit it to 32 bytes, but there is a non-zero chance to got OVERFLOW from libusb. IntBuffer readBufTransferred = IntBuffer.allocate(1);