]> asedeno.scripts.mit.edu Git - linux.git/commitdiff
usbip: tools: add more error codes for usbip request/reply messages
authorShuah Khan <shuahkh@osg.samsung.com>
Wed, 7 Mar 2018 20:42:24 +0000 (13:42 -0700)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 9 Mar 2018 17:17:08 +0000 (09:17 -0800)
Currently ST_OK and ST_NA are the only values defined to communicate
status of a request from a client. Add more error codes to clearly
indicate what failed. For example, when client sends request to import
a device that isn't export-able, server can send a specific error code
to the client.

Existing defines are moved to a common header in libsrc to be included
in the libusbip_la-usbip_common.o to be used by all the usbip tools.
Supporting interface to print error strings is added to the common lib.

Signed-off-by: Shuah Khan <shuahkh@osg.samsung.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
tools/usb/usbip/libsrc/usbip_common.c
tools/usb/usbip/libsrc/usbip_common.h
tools/usb/usbip/src/usbip_network.h

index 001bb8e8f66894f694d71e04c7391e05c59e7502..bb424638d75b0e639020a765192bea2020dd369c 100644 (file)
@@ -66,6 +66,29 @@ const char *usbip_speed_string(int num)
        return "Unknown Speed";
 }
 
+struct op_common_status_string {
+       int num;
+       char *desc;
+};
+
+static struct op_common_status_string op_common_status_strings[] = {
+       { ST_OK,        "Request Completed Successfully" },
+       { ST_NA,        "Request Failed" },
+       { ST_DEV_BUSY,  "Device busy (exported)" },
+       { ST_DEV_ERR,   "Device in error state" },
+       { ST_NODEV,     "Device not found" },
+       { ST_ERROR,     "Unexpected response" },
+       { 0, NULL}
+};
+
+const char *usbip_op_common_status_string(int status)
+{
+       for (int i = 0; op_common_status_strings[i].desc != NULL; i++)
+               if (op_common_status_strings[i].num == status)
+                       return op_common_status_strings[i].desc;
+
+       return "Unknown Op Common Status";
+}
 
 #define DBG_UDEV_INTEGER(name)\
        dbg("%-20s = %x", to_string(name), (int) udev->name)
index e45ec9d2fdbc57081ffd24c96ff2f416a9f429ed..73a367a7fa10cb191af3f41e71178c021ccd7d31 100644 (file)
 #define SYSFS_PATH_MAX         256
 #define SYSFS_BUS_ID_SIZE      32
 
+/* Defines for op_code status in server/client op_common PDUs */
+#define ST_OK  0x00
+#define ST_NA  0x01
+       /* Device requested for import is not available */
+#define ST_DEV_BUSY    0x02
+       /* Device requested for import is in error state */
+#define ST_DEV_ERR     0x03
+#define ST_NODEV       0x04
+#define ST_ERROR       0x05
+
 extern int usbip_use_syslog;
 extern int usbip_use_stderr;
 extern int usbip_use_debug ;
@@ -130,6 +140,7 @@ int read_usb_interface(struct usbip_usb_device *udev, int i,
 
 const char *usbip_speed_string(int num);
 const char *usbip_status_string(int32_t status);
+const char *usbip_op_common_status_string(int status);
 
 int usbip_names_init(char *);
 void usbip_names_free(void);
index 7032687621d3b503edb38f6ad69926631633c7b4..b6a2f9be888c65aedad87cd8f7306ced35307b71 100644 (file)
@@ -27,9 +27,7 @@ struct op_common {
 #define OP_REPLY       (0x00 << 8)
        uint16_t code;
 
-       /* add more error code */
-#define ST_OK  0x00
-#define ST_NA  0x01
+       /* status codes defined in usbip_common.h */
        uint32_t status; /* op_code status (for reply) */
 
 } __attribute__((packed));