Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

usbip: tools: add more error codes for usbip request/reply messages

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>

authored by

Shuah Khan and committed by
Greg Kroah-Hartman
f6bcbf2e 8fe8f582

+35 -3
+23
tools/usb/usbip/libsrc/usbip_common.c
··· 66 66 return "Unknown Speed"; 67 67 } 68 68 69 + struct op_common_status_string { 70 + int num; 71 + char *desc; 72 + }; 73 + 74 + static struct op_common_status_string op_common_status_strings[] = { 75 + { ST_OK, "Request Completed Successfully" }, 76 + { ST_NA, "Request Failed" }, 77 + { ST_DEV_BUSY, "Device busy (exported)" }, 78 + { ST_DEV_ERR, "Device in error state" }, 79 + { ST_NODEV, "Device not found" }, 80 + { ST_ERROR, "Unexpected response" }, 81 + { 0, NULL} 82 + }; 83 + 84 + const char *usbip_op_common_status_string(int status) 85 + { 86 + for (int i = 0; op_common_status_strings[i].desc != NULL; i++) 87 + if (op_common_status_strings[i].num == status) 88 + return op_common_status_strings[i].desc; 89 + 90 + return "Unknown Op Common Status"; 91 + } 69 92 70 93 #define DBG_UDEV_INTEGER(name)\ 71 94 dbg("%-20s = %x", to_string(name), (int) udev->name)
+11
tools/usb/usbip/libsrc/usbip_common.h
··· 43 43 #define SYSFS_PATH_MAX 256 44 44 #define SYSFS_BUS_ID_SIZE 32 45 45 46 + /* Defines for op_code status in server/client op_common PDUs */ 47 + #define ST_OK 0x00 48 + #define ST_NA 0x01 49 + /* Device requested for import is not available */ 50 + #define ST_DEV_BUSY 0x02 51 + /* Device requested for import is in error state */ 52 + #define ST_DEV_ERR 0x03 53 + #define ST_NODEV 0x04 54 + #define ST_ERROR 0x05 55 + 46 56 extern int usbip_use_syslog; 47 57 extern int usbip_use_stderr; 48 58 extern int usbip_use_debug ; ··· 140 130 141 131 const char *usbip_speed_string(int num); 142 132 const char *usbip_status_string(int32_t status); 133 + const char *usbip_op_common_status_string(int status); 143 134 144 135 int usbip_names_init(char *); 145 136 void usbip_names_free(void);
+1 -3
tools/usb/usbip/src/usbip_network.h
··· 27 27 #define OP_REPLY (0x00 << 8) 28 28 uint16_t code; 29 29 30 - /* add more error code */ 31 - #define ST_OK 0x00 32 - #define ST_NA 0x01 30 + /* status codes defined in usbip_common.h */ 33 31 uint32_t status; /* op_code status (for reply) */ 34 32 35 33 } __attribute__((packed));