aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarc Schink <jaylink-dev@marcschink.de>2016-10-17 11:22:13 +0200
committerMarc Schink <jaylink-dev@marcschink.de>2016-10-29 10:55:37 +0200
commit564df3739b1ea4c56d38ec867c49aee76372ec75 (patch)
tree3ee03099408790838cc6fc2e2212131b90379857
parent13ff1d93e0100b56a028107ba420d0210f7c8430 (diff)
Use JAYLINK_ERR_IO
Signed-off-by: Marc Schink <jaylink-dev@marcschink.de>
-rw-r--r--libjaylink/device.c12
-rw-r--r--libjaylink/discovery.c7
-rw-r--r--libjaylink/emucom.c2
-rw-r--r--libjaylink/fileio.c4
-rw-r--r--libjaylink/jtag.c3
-rw-r--r--libjaylink/swd.c1
-rw-r--r--libjaylink/swo.c4
-rw-r--r--libjaylink/target.c8
-rw-r--r--libjaylink/transport.c28
9 files changed, 65 insertions, 4 deletions
diff --git a/libjaylink/device.c b/libjaylink/device.c
index fa10d0f..1b2a75e 100644
--- a/libjaylink/device.c
+++ b/libjaylink/device.c
@@ -359,6 +359,7 @@ static void free_device_handle(struct jaylink_device_handle *devh)
* @retval JAYLINK_ERR_ARG Invalid arguments.
* @retval JAYLINK_ERR_TIMEOUT A timeout occurred.
* @retval JAYLINK_ERR_MALLOC Memory allocation error.
+ * @retval JAYLINK_ERR_IO Input/output error.
* @retval JAYLINK_ERR Other error conditions.
*
* @since 0.1.0
@@ -451,6 +452,7 @@ JAYLINK_API struct jaylink_device *jaylink_get_device(
* @retval JAYLINK_ERR_ARG Invalid arguments.
* @retval JAYLINK_ERR_TIMEOUT A timeout occurred.
* @retval JAYLINK_ERR_MALLOC Memory allocation error.
+ * @retval JAYLINK_ERR_IO Input/output error.
* @retval JAYLINK_ERR Other error conditions.
*
* @since 0.1.0
@@ -551,6 +553,7 @@ JAYLINK_API int jaylink_get_firmware_version(
* @retval JAYLINK_OK Success.
* @retval JAYLINK_ERR_ARG Invalid arguments.
* @retval JAYLINK_ERR_TIMEOUT A timeout occurred.
+ * @retval JAYLINK_ERR_IO Input/output error.
* @retval JAYLINK_ERR Other error conditions.
*
* @since 0.1.0
@@ -628,6 +631,7 @@ JAYLINK_API int jaylink_get_hardware_info(struct jaylink_device_handle *devh,
* @retval JAYLINK_OK Success.
* @retval JAYLINK_ERR_ARG Invalid arguments.
* @retval JAYLINK_ERR_TIMEOUT A timeout occurred.
+ * @retval JAYLINK_ERR_IO Input/output error.
* @retval JAYLINK_ERR Other error conditions.
*
* @since 0.1.0
@@ -690,6 +694,7 @@ JAYLINK_API int jaylink_get_hardware_version(
* @retval JAYLINK_OK Success.
* @retval JAYLINK_ERR_ARG Invalid arguments.
* @retval JAYLINK_ERR_TIMEOUT A timeout occurred.
+ * @retval JAYLINK_ERR_IO Input/output error.
* @retval JAYLINK_ERR Other error conditions.
*
* @since 0.1.0
@@ -761,6 +766,7 @@ JAYLINK_API int jaylink_get_hardware_status(struct jaylink_device_handle *devh,
* @retval JAYLINK_OK Success.
* @retval JAYLINK_ERR_ARG Invalid arguments.
* @retval JAYLINK_ERR_TIMEOUT A timeout occurred.
+ * @retval JAYLINK_ERR_IO Input/output error.
* @retval JAYLINK_ERR Other error conditions.
*
* @see jaylink_get_extended_caps()
@@ -828,6 +834,7 @@ JAYLINK_API int jaylink_get_caps(struct jaylink_device_handle *devh,
* @retval JAYLINK_OK Success.
* @retval JAYLINK_ERR_ARG Invalid arguments.
* @retval JAYLINK_ERR_TIMEOUT A timeout occurred.
+ * @retval JAYLINK_ERR_IO Input/output error.
* @retval JAYLINK_ERR Other error conditions.
*
* @see jaylink_get_caps()
@@ -888,6 +895,7 @@ JAYLINK_API int jaylink_get_extended_caps(struct jaylink_device_handle *devh,
* @retval JAYLINK_OK Success.
* @retval JAYLINK_ERR_ARG Invalid arguments.
* @retval JAYLINK_ERR_TIMEOUT A timeout occurred.
+ * @retval JAYLINK_ERR_IO Input/output error.
* @retval JAYLINK_ERR Other error conditions.
*
* @since 0.1.0
@@ -949,6 +957,7 @@ JAYLINK_API int jaylink_get_free_memory(struct jaylink_device_handle *devh,
* @retval JAYLINK_OK Success.
* @retval JAYLINK_ERR_ARG Invalid arguments.
* @retval JAYLINK_ERR_TIMEOUT A timeout occurred.
+ * @retval JAYLINK_ERR_IO Input/output error.
* @retval JAYLINK_ERR Other error conditions.
*
* @since 0.1.0
@@ -1008,6 +1017,7 @@ JAYLINK_API int jaylink_read_raw_config(struct jaylink_device_handle *devh,
* @retval JAYLINK_OK Success.
* @retval JAYLINK_ERR_ARG Invalid arguments.
* @retval JAYLINK_ERR_TIMEOUT A timeout occurred.
+ * @retval JAYLINK_ERR_IO Input/output error.
* @retval JAYLINK_ERR Other error conditions.
*
* @since 0.1.0
@@ -1180,6 +1190,7 @@ static bool _inet_pton(const char *str, struct in_addr *in)
* @retval JAYLINK_ERR_ARG Invalid arguments.
* @retval JAYLINK_ERR_TIMEOUT A timeout occurred.
* @retval JAYLINK_ERR_PROTO Protocol violation.
+ * @retval JAYLINK_ERR_IO Input/output error.
* @retval JAYLINK_ERR Other error conditions.
*
* @see jaylink_unregister()
@@ -1320,6 +1331,7 @@ JAYLINK_API int jaylink_register(struct jaylink_device_handle *devh,
* @retval JAYLINK_ERR_ARG Invalid arguments.
* @retval JAYLINK_ERR_TIMEOUT A timeout occurred.
* @retval JAYLINK_ERR_PROTO Protocol violation.
+ * @retval JAYLINK_ERR_IO Input/output error.
* @retval JAYLINK_ERR Other error conditions.
*
* @see jaylink_register()
diff --git a/libjaylink/discovery.c b/libjaylink/discovery.c
index fa72da4..aa294d6 100644
--- a/libjaylink/discovery.c
+++ b/libjaylink/discovery.c
@@ -248,7 +248,11 @@ static int discovery_usb_scan(struct jaylink_context *ctx)
ret = libusb_get_device_list(ctx->usb_ctx, &devs);
- if (ret < 0) {
+ if (ret == LIBUSB_ERROR_IO) {
+ log_err(ctx, "Failed to retrieve device list: input/output "
+ "error.");
+ return JAYLINK_ERR_IO;
+ } else if (ret < 0) {
log_err(ctx, "Failed to retrieve device list: %s.",
libusb_error_name(ret));
return JAYLINK_ERR;
@@ -303,6 +307,7 @@ static void clear_discovery_list(struct jaylink_context *ctx)
*
* @retval JAYLINK_OK Success.
* @retval JAYLINK_ERR_ARG Invalid arguments.
+ * @retval JAYLINK_ERR_IO Input/output error.
* @retval JAYLINK_ERR Other error conditions.
*
* @see jaylink_get_devices()
diff --git a/libjaylink/emucom.c b/libjaylink/emucom.c
index bf09030..057113b 100644
--- a/libjaylink/emucom.c
+++ b/libjaylink/emucom.c
@@ -78,6 +78,7 @@
* @retval JAYLINK_ERR_ARG Invalid arguments.
* @retval JAYLINK_ERR_TIMEOUT A timeout occurred.
* @retval JAYLINK_ERR_PROTO Protocol violation.
+ * @retval JAYLINK_ERR_IO Input/output error.
* @retval JAYLINK_ERR_DEV Unspecified device error.
* @retval JAYLINK_ERR_DEV_NOT_SUPPORTED Channel is not supported by the
* device.
@@ -193,6 +194,7 @@ JAYLINK_API int jaylink_emucom_read(struct jaylink_device_handle *devh,
* @retval JAYLINK_ERR_ARG Invalid arguments.
* @retval JAYLINK_ERR_TIMEOUT A timeout occurred.
* @retval JAYLINK_ERR_PROTO Protocol violation.
+ * @retval JAYLINK_ERR_IO Input/output error.
* @retval JAYLINK_ERR_DEV Unspecified device error.
* @retval JAYLINK_ERR_DEV_NOT_SUPPORTED Channel is not supported by the
* device.
diff --git a/libjaylink/fileio.c b/libjaylink/fileio.c
index 53664b0..1908803 100644
--- a/libjaylink/fileio.c
+++ b/libjaylink/fileio.c
@@ -69,6 +69,7 @@
* @retval JAYLINK_OK Success.
* @retval JAYLINK_ERR_ARG Invalid arguments.
* @retval JAYLINK_ERR_TIMEOUT A timeout occurred.
+ * @retval JAYLINK_ERR_IO Input/output error.
* @retval JAYLINK_ERR_DEV Unspecified device error, or the file was not found.
* @retval JAYLINK_ERR Other error conditions.
*
@@ -203,6 +204,7 @@ JAYLINK_API int jaylink_file_read(struct jaylink_device_handle *devh,
* @retval JAYLINK_OK Success.
* @retval JAYLINK_ERR_ARG Invalid arguments.
* @retval JAYLINK_ERR_TIMEOUT A timeout occurred.
+ * @retval JAYLINK_ERR_IO Input/output error.
* @retval JAYLINK_ERR_DEV Unspecified device error, or the file was not found.
* @retval JAYLINK_ERR Other error conditions.
*
@@ -328,6 +330,7 @@ JAYLINK_API int jaylink_file_write(struct jaylink_device_handle *devh,
* @retval JAYLINK_OK Success.
* @retval JAYLINK_ERR_ARG Invalid arguments.
* @retval JAYLINK_ERR_TIMEOUT A timeout occurred.
+ * @retval JAYLINK_ERR_IO Input/output error.
* @retval JAYLINK_ERR_DEV Unspecified device error, or the file was not found.
* @retval JAYLINK_ERR Other error conditions.
*
@@ -419,6 +422,7 @@ JAYLINK_API int jaylink_file_get_size(struct jaylink_device_handle *devh,
* @retval JAYLINK_OK Success.
* @retval JAYLINK_ERR_ARG Invalid arguments.
* @retval JAYLINK_ERR_TIMEOUT A timeout occurred.
+ * @retval JAYLINK_ERR_IO Input/output error.
* @retval JAYLINK_ERR_DEV Unspecified device error, or the file was not found.
* @retval JAYLINK_ERR Other error conditions.
*
diff --git a/libjaylink/jtag.c b/libjaylink/jtag.c
index 9c76058..7fab4df 100644
--- a/libjaylink/jtag.c
+++ b/libjaylink/jtag.c
@@ -61,6 +61,7 @@
* @retval JAYLINK_OK Success.
* @retval JAYLINK_ERR_ARG Invalid arguments.
* @retval JAYLINK_ERR_TIMEOUT A timeout occurred.
+ * @retval JAYLINK_ERR_IO Input/output error.
* @retval JAYLINK_ERR_DEV Unspecified device error.
* @retval JAYLINK_ERR_DEV_NO_MEMORY Not enough memory on the device to perform
* the operation.
@@ -177,6 +178,7 @@ JAYLINK_API int jaylink_jtag_io(struct jaylink_device_handle *devh,
* @retval JAYLINK_OK Success.
* @retval JAYLINK_ERR_ARG Invalid arguments.
* @retval JAYLINK_ERR_TIMEOUT A timeout occurred.
+ * @retval JAYLINK_ERR_IO Input/output error.
* @retval JAYLINK_ERR Other error conditions.
*
* @since 0.1.0
@@ -220,6 +222,7 @@ JAYLINK_API int jaylink_jtag_clear_trst(struct jaylink_device_handle *devh)
* @retval JAYLINK_OK Success.
* @retval JAYLINK_ERR_ARG Invalid arguments.
* @retval JAYLINK_ERR_TIMEOUT A timeout occurred.
+ * @retval JAYLINK_ERR_IO Input/output error.
* @retval JAYLINK_ERR Other error conditions.
*
* @since 0.1.0
diff --git a/libjaylink/swd.c b/libjaylink/swd.c
index 2662d35..2dcf16d 100644
--- a/libjaylink/swd.c
+++ b/libjaylink/swd.c
@@ -57,6 +57,7 @@
* @retval JAYLINK_OK Success.
* @retval JAYLINK_ERR_ARG Invalid arguments.
* @retval JAYLINK_ERR_TIMEOUT A timeout occurred.
+ * @retval JAYLINK_ERR_IO Input/output error.
* @retval JAYLINK_ERR_DEV Unspecified device error.
* @retval JAYLINK_ERR_DEV_NO_MEMORY Not enough memory on the device to perform
* the operation.
diff --git a/libjaylink/swo.c b/libjaylink/swo.c
index 32fe80f..79d08d9 100644
--- a/libjaylink/swo.c
+++ b/libjaylink/swo.c
@@ -57,6 +57,7 @@
* @retval JAYLINK_OK Success.
* @retval JAYLINK_ERR_ARG Invalid arguments.
* @retval JAYLINK_ERR_TIMEOUT A timeout occurred.
+ * @retval JAYLINK_ERR_IO Input/output error.
* @retval JAYLINK_ERR_DEV Unspecified device error.
* @retval JAYLINK_ERR Other error conditions.
*
@@ -142,6 +143,7 @@ JAYLINK_API int jaylink_swo_start(struct jaylink_device_handle *devh,
* @retval JAYLINK_OK Success.
* @retval JAYLINK_ERR_ARG Invalid arguments.
* @retval JAYLINK_ERR_TIMEOUT A timeout occurred.
+ * @retval JAYLINK_ERR_IO Input/output error.
* @retval JAYLINK_ERR_DEV Unspecified device error.
* @retval JAYLINK_ERR Other error conditions.
*
@@ -215,6 +217,7 @@ JAYLINK_API int jaylink_swo_stop(struct jaylink_device_handle *devh)
* @retval JAYLINK_ERR_ARG Invalid arguments.
* @retval JAYLINK_ERR_TIMEOUT A timeout occurred.
* @retval JAYLINK_ERR_PROTO Protocol violation.
+ * @retval JAYLINK_ERR_IO Input/output error.
* @retval JAYLINK_ERR_DEV Unspecified device error.
* @retval JAYLINK_ERR Other error conditions.
*
@@ -331,6 +334,7 @@ JAYLINK_API int jaylink_swo_read(struct jaylink_device_handle *devh,
* @retval JAYLINK_ERR_ARG Invalid arguments.
* @retval JAYLINK_ERR_TIMEOUT A timeout occurred.
* @retval JAYLINK_ERR_PROTO Protocol violation.
+ * @retval JAYLINK_ERR_IO Input/output error.
* @retval JAYLINK_ERR_DEV Unspecified device error.
* @retval JAYLINK_ERR Other error conditions.
*
diff --git a/libjaylink/target.c b/libjaylink/target.c
index 0260ccf..923e3ad 100644
--- a/libjaylink/target.c
+++ b/libjaylink/target.c
@@ -53,6 +53,7 @@
* @retval JAYLINK_OK Success.
* @retval JAYLINK_ERR_ARG Invalid arguments.
* @retval JAYLINK_ERR_TIMEOUT A timeout occurred.
+ * @retval JAYLINK_ERR_IO Input/output error.
* @retval JAYLINK_ERR Other error conditions.
*
* @see jaylink_get_speeds()
@@ -117,6 +118,7 @@ JAYLINK_API int jaylink_set_speed(struct jaylink_device_handle *devh,
* @retval JAYLINK_ERR_ARG Invalid arguments.
* @retval JAYLINK_ERR_TIMEOUT A timeout occurred.
* @retval JAYLINK_ERR_PROTO Protocol violation.
+ * @retval JAYLINK_ERR_IO Input/output error.
* @retval JAYLINK_ERR Other error conditions.
*
* @see jaylink_select_interface()
@@ -191,6 +193,7 @@ JAYLINK_API int jaylink_get_speeds(struct jaylink_device_handle *devh,
* @retval JAYLINK_OK Success.
* @retval JAYLINK_ERR_ARG Invalid arguments.
* @retval JAYLINK_ERR_TIMEOUT A timeout occurred.
+ * @retval JAYLINK_ERR_IO Input/output error.
* @retval JAYLINK_ERR Other error conditions.
*
* @see jaylink_get_available_interfaces()
@@ -271,6 +274,7 @@ JAYLINK_API int jaylink_select_interface(struct jaylink_device_handle *devh,
* @retval JAYLINK_OK Success.
* @retval JAYLINK_ERR_ARG Invalid arguments.
* @retval JAYLINK_ERR_TIMEOUT A timeout occurred.
+ * @retval JAYLINK_ERR_IO Input/output error.
* @retval JAYLINK_ERR Other error conditions.
*
* @see jaylink_select_interface()
@@ -336,6 +340,7 @@ JAYLINK_API int jaylink_get_available_interfaces(
* @retval JAYLINK_OK Success.
* @retval JAYLINK_ERR_ARG Invalid arguments.
* @retval JAYLINK_ERR_TIMEOUT A timeout occurred.
+ * @retval JAYLINK_ERR_IO Input/output error.
* @retval JAYLINK_ERR Other error conditions.
*
* @see jaylink_select_interface()
@@ -394,6 +399,7 @@ JAYLINK_API int jaylink_get_selected_interface(
* @retval JAYLINK_OK Success.
* @retval JAYLINK_ERR_ARG Invalid arguments.
* @retval JAYLINK_ERR_TIMEOUT A timeout occurred.
+ * @retval JAYLINK_ERR_IO Input/output error.
* @retval JAYLINK_ERR Other error conditions.
*
* @since 0.1.0
@@ -437,6 +443,7 @@ JAYLINK_API int jaylink_clear_reset(struct jaylink_device_handle *devh)
* @retval JAYLINK_OK Success.
* @retval JAYLINK_ERR_ARG Invalid arguments.
* @retval JAYLINK_ERR_TIMEOUT A timeout occurred.
+ * @retval JAYLINK_ERR_IO Input/output error.
* @retval JAYLINK_ERR Other error conditions.
*
* @since 0.1.0
@@ -488,6 +495,7 @@ JAYLINK_API int jaylink_set_reset(struct jaylink_device_handle *devh)
* @retval JAYLINK_OK Success.
* @retval JAYLINK_ERR_ARG Invalid arguments.
* @retval JAYLINK_ERR_TIMEOUT A timeout occurred.
+ * @retval JAYLINK_ERR_IO Input/output error.
* @retval JAYLINK_ERR Other error conditions.
*
* @since 0.1.0
diff --git a/libjaylink/transport.c b/libjaylink/transport.c
index fe0d5ba..a82b83d 100644
--- a/libjaylink/transport.c
+++ b/libjaylink/transport.c
@@ -65,7 +65,11 @@ static int initialize_handle(struct jaylink_device_handle *devh)
*/
ret = libusb_get_active_config_descriptor(devh->dev->usb_dev, &config);
- if (ret != LIBUSB_SUCCESS) {
+ if (ret == LIBUSB_ERROR_IO) {
+ log_err(ctx, "Failed to get configuration descriptor: "
+ "input/output error.");
+ return JAYLINK_ERR_IO;
+ } else if (ret != LIBUSB_SUCCESS) {
log_err(ctx, "Failed to get configuration descriptor: %s.",
libusb_error_name(ret));
return JAYLINK_ERR;
@@ -160,6 +164,7 @@ static void cleanup_handle(struct jaylink_device_handle *devh)
* @param[in,out] devh Device handle.
*
* @retval JAYLINK_OK Success.
+ * @retval JAYLINK_ERR_IO Input/output error.
* @retval JAYLINK_ERR Other error conditions.
*/
JAYLINK_PRIV int transport_open(struct jaylink_device_handle *devh)
@@ -185,7 +190,11 @@ JAYLINK_PRIV int transport_open(struct jaylink_device_handle *devh)
ret = libusb_open(dev->usb_dev, &usb_devh);
- if (ret != LIBUSB_SUCCESS) {
+ if (ret == LIBUSB_ERROR_IO) {
+ log_err(ctx, "Failed to open device: input/output error.");
+ cleanup_handle(devh);
+ return JAYLINK_ERR_IO;
+ } else if (ret != LIBUSB_SUCCESS) {
log_err(ctx, "Failed to open device: %s.",
libusb_error_name(ret));
cleanup_handle(devh);
@@ -194,7 +203,10 @@ JAYLINK_PRIV int transport_open(struct jaylink_device_handle *devh)
ret = libusb_claim_interface(usb_devh, devh->interface_number);
- if (ret != LIBUSB_SUCCESS) {
+ if (ret == LIBUSB_ERROR_IO) {
+ log_err(ctx, "Failed to claim interface: input/output error.");
+ return JAYLINK_ERR_IO;
+ } else if (ret != LIBUSB_SUCCESS) {
log_err(ctx, "Failed to claim interface: %s.",
libusb_error_name(ret));
cleanup_handle(devh);
@@ -443,6 +455,10 @@ static int usb_send(struct jaylink_device_handle *devh, const uint8_t *buffer,
log_warn(ctx, "Sending data to device timed out, "
"retrying.");
tries--;
+ } else if (ret == LIBUSB_ERROR_IO) {
+ log_err(ctx, "Failed to send data to device: "
+ "input/output error.");
+ return JAYLINK_ERR_IO;
} else {
log_err(ctx, "Failed to send data to device: %s.",
libusb_error_name(ret));
@@ -483,6 +499,7 @@ static int usb_send(struct jaylink_device_handle *devh, const uint8_t *buffer,
* @retval JAYLINK_OK Success.
* @retval JAYLINK_ERR_ARG Invalid arguments.
* @retval JAYLINK_ERR_TIMEOUT A timeout occurred.
+ * @retval JAYLINK_ERR_IO Input/output error.
* @retval JAYLINK_ERR Other error conditions.
*/
JAYLINK_PRIV int transport_write(struct jaylink_device_handle *devh,
@@ -593,6 +610,10 @@ static int usb_recv(struct jaylink_device_handle *devh, uint8_t *buffer,
"retrying.");
tries--;
continue;
+ } else if (ret == LIBUSB_ERROR_IO) {
+ log_err(ctx, "Failed to receive data from device: "
+ "input/output error.");
+ return JAYLINK_ERR_IO;
} else if (ret != LIBUSB_SUCCESS) {
log_err(ctx, "Failed to receive data from device: %s.",
libusb_error_name(ret));
@@ -629,6 +650,7 @@ static int usb_recv(struct jaylink_device_handle *devh, uint8_t *buffer,
* @retval JAYLINK_OK Success.
* @retval JAYLINK_ERR_ARG Invalid arguments.
* @retval JAYLINK_ERR_TIMEOUT A timeout occurred.
+ * @retval JAYLINK_ERR_IO Input/output error.
* @retval JAYLINK_ERR Other error conditions.
*/
JAYLINK_PRIV int transport_read(struct jaylink_device_handle *devh,