Skip to content

Commit

Permalink
Refine mapping of error codes Linux - Windows
Browse files Browse the repository at this point in the history
Signed-off-by: vadimgrn <[email protected]>
  • Loading branch information
vadimgrn committed Jul 14, 2021
1 parent ab77ab2 commit 426e319
Showing 1 changed file with 121 additions and 18 deletions.
139 changes: 121 additions & 18 deletions driver/lib/usbd_helper.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,41 +7,144 @@
* Linux error codes.
* See: include/uapi/asm-generic/errno-base.h, include/uapi/asm-generic/errno.h
*/
enum {
EPIPE_LINUX = 32,
EOVERFLOW_LINUX = 75,
EREMOTEIO_LINUX = 121
enum {
ENOENT_LNX = ENOENT,
ENXIO_LNX = ENXIO,
ENOMEM_LNX = ENOMEM,
EBUSY_LNX = EBUSY,
EXDEV_LNX = EXDEV,
ENODEV_LNX = ENODEV,
EINVAL_LNX = EINVAL,
ENOSPC_LNX = ENOSPC,
EPIPE_LNX = EPIPE,
ETIME_LNX = 62,
ENOSR_LNX = 63,
ECOMM_LNX = 70,
EPROTO_LNX = 71,
EOVERFLOW_LNX = 75,
EILSEQ_LNX = 84,
ECONNRESET_LNX = 104,
ESHUTDOWN_LNX = 108,
ETIMEDOUT_LNX = 110,
EINPROGRESS_LNX = 115,
EREMOTEIO_LNX = 121,
};

static_assert(ENOENT == 2, "assert");
static_assert(ENXIO == 6, "assert");
static_assert(ENOMEM == 12, "assert");
static_assert(EBUSY == 16, "assert");
static_assert(EXDEV == 18, "assert");
static_assert(ENODEV == 19, "assert");
static_assert(EINVAL == 22, "assert");
static_assert(ENOSPC == 28, "assert");
static_assert(EPIPE == 32, "assert");
static_assert(ETIME_LNX != ETIME, "assert");
static_assert(ENOSR_LNX != ENOSR, "assert");
//static_assert(ECOMM_LNX != ECOMM, "assert");
static_assert(EPROTO_LNX != EPROTO, "assert");
static_assert(EOVERFLOW_LNX != EOVERFLOW, "assert");
static_assert(EILSEQ_LNX != EILSEQ, "assert");
static_assert(ECONNRESET_LNX != ECONNRESET, "assert");
//static_assert(ESHUTDOWN_LNX != ESHUTDOWN, "assert");
static_assert(ETIMEDOUT_LNX != ETIMEDOUT, "assert");
static_assert(EINPROGRESS_LNX != EINPROGRESS, "assert");
//static_assert(EREMOTEIO_LNX != EREMOTEIO, "assert");

/*
* See:
* <kernel>/doc/Documentation/usb/error-codes.txt
* winddk, usb.h
*/
USBD_STATUS
to_usbd_status(int usbip_status)
{
switch (usbip_status) {
switch (abs(usbip_status)) {
case 0:
return USBD_STATUS_SUCCESS;
/* I guess it */
case -EPIPE_LINUX:
return USBD_STATUS_STALL_PID;
case -EOVERFLOW_LINUX:
return USBD_STATUS_DATA_OVERRUN;
case -EREMOTEIO_LINUX:
case EPIPE_LNX:
return USBD_STATUS_STALL_PID; /* USBD_STATUS_ENDPOINT_HALTED */
case EREMOTEIO_LNX:
return USBD_STATUS_ERROR_SHORT_TRANSFER;
default:
return USBD_STATUS_ERROR;
case ETIME_LNX:
return USBD_STATUS_DEV_NOT_RESPONDING;
case ETIMEDOUT_LNX:
return USBD_STATUS_TIMEOUT;
case ENOENT_LNX:
case ECONNRESET_LNX:
return USBD_STATUS_CANCELED;
case EINPROGRESS_LNX:
return USBD_STATUS_PENDING;
case EOVERFLOW_LNX:
return USBD_STATUS_BABBLE_DETECTED;
case ENODEV_LNX:
case ESHUTDOWN_LNX:
return USBD_STATUS_DEVICE_GONE;
case EILSEQ_LNX:
return USBD_STATUS_CRC;
case ECOMM_LNX:
return USBD_STATUS_DATA_OVERRUN;
case ENOSR_LNX:
return USBD_STATUS_DATA_UNDERRUN;
case ENOMEM_LNX:
return USBD_STATUS_INSUFFICIENT_RESOURCES;
case EPROTO_LNX:
return USBD_STATUS_BTSTUFF; /* USBD_STATUS_INTERNAL_HC_ERROR */
case ENOSPC_LNX:
return USBD_STATUS_NO_BANDWIDTH;
case EXDEV_LNX:
return USBD_STATUS_ISOCH_REQUEST_FAILED;
case ENXIO_LNX:
return USBD_STATUS_INTERNAL_HC_ERROR;
}

return USBD_STATUS_INVALID_PARAMETER;
}

/*
* See:
* winddk, usb.h
* <kernel>/doc/Documentation/usb/error-codes.txt
*/
int
to_usbip_status(USBD_STATUS status)
{
switch (status) {
case 0:
case USBD_STATUS_SUCCESS:
return 0;
case USBD_STATUS_STALL_PID:
return -EPIPE;
default:
return -1;
case USBD_STATUS_ENDPOINT_HALTED:
return -EPIPE_LNX;
case USBD_STATUS_ERROR_SHORT_TRANSFER:
return -EREMOTEIO_LNX;
case USBD_STATUS_TIMEOUT:
return -ETIMEDOUT_LNX; /* ETIME */
case USBD_STATUS_CANCELED:
return -ECONNRESET_LNX; /* ENOENT */
case USBD_STATUS_PENDING:
return -EINPROGRESS_LNX;
case USBD_STATUS_BABBLE_DETECTED:
return -EOVERFLOW_LNX;
case USBD_STATUS_DEVICE_GONE:
return -ENODEV_LNX;
case USBD_STATUS_CRC:
return -EILSEQ_LNX;
case USBD_STATUS_DATA_OVERRUN:
return -ECOMM_LNX;
case USBD_STATUS_DATA_UNDERRUN:
return -ENOSR_LNX;
case USBD_STATUS_INSUFFICIENT_RESOURCES:
return -ENOMEM_LNX;
case USBD_STATUS_BTSTUFF:
case USBD_STATUS_INTERNAL_HC_ERROR:
case USBD_STATUS_HUB_INTERNAL_ERROR:
case USBD_STATUS_DEV_NOT_RESPONDING:
return -EPROTO_LNX;
case USBD_STATUS_ERROR_BUSY:
return -EBUSY_LNX;
}

return status < 0 ? -EINVAL_LNX : 0; /* see USBD_ERROR */
}

/*
Expand All @@ -56,7 +159,7 @@ enum {
ULONG
to_usbd_flags(int flags)
{
ULONG usbd_flags = 0;
ULONG usbd_flags = 0;

if (flags & URB_SHORT_NOT_OK)
usbd_flags |= USBD_SHORT_TRANSFER_OK;
Expand Down

0 comments on commit 426e319

Please sign in to comment.