Added functionality for getting error strings from codes

This commit is contained in:
2020-01-12 16:13:15 -05:00
parent afe7b1bbd6
commit 41d3ae8550
3 changed files with 47 additions and 6 deletions

View File

@@ -46,4 +46,6 @@ int ctrl_transfer(struct pwned_device *dev,
int reset(struct pwned_device *dev);
int serial_descriptor(struct pwned_device *dev, unsigned char *serial_buf, int len);
const char *usb_error_name(int ret);
#endif //CHECKM8_TOOL_LIBUSB_HELPERS_H

View File

@@ -29,7 +29,7 @@ int dfu_send_data(struct pwned_device *dev, unsigned char *data, long data_len,
if(ret > 0) checkm8_debug_indent("\ttransferred %i bytes\n", ret);
else
{
checkm8_debug_indent("\trequest failed with error code %i\n", ret);
checkm8_debug_indent("\trequest failed with error code %i (%s)\n", ret, usb_error_name(ret));
return CHECKM8_FAIL_XFER;
}
index += amount;
@@ -75,7 +75,7 @@ struct dev_cmd_resp *command(struct pwned_device *dev,
if(ret >= 0) checkm8_debug_indent("\ttransferred %i bytes\n", ret);
else
{
checkm8_debug_indent("\trequest failed with error code %i\n", ret);
checkm8_debug_indent("\trequest failed with error code %i (%s)\n", ret, usb_error_name(ret));
cmd_resp->ret = ret;
return cmd_resp;
}
@@ -84,7 +84,7 @@ struct dev_cmd_resp *command(struct pwned_device *dev,
if(ret >= 0) checkm8_debug_indent("\ttransferred %i bytes\n", ret);
else
{
checkm8_debug_indent("\trequest failed with error code %i\n", ret);
checkm8_debug_indent("\trequest failed with error code %i (%s)\n", ret, usb_error_name(ret));
cmd_resp->ret = ret;
return cmd_resp;
}
@@ -93,7 +93,7 @@ struct dev_cmd_resp *command(struct pwned_device *dev,
if(ret >= 0) checkm8_debug_indent("\ttransferred %i bytes\n", ret);
else
{
checkm8_debug_indent("\trequest failed with error code %i\n", ret);
checkm8_debug_indent("\trequest failed with error code %i (%s)\n", ret, usb_error_name(ret));
cmd_resp->ret = ret;
return cmd_resp;
}
@@ -114,7 +114,7 @@ struct dev_cmd_resp *command(struct pwned_device *dev,
if(ret >= 0) checkm8_debug_indent("\tfinal request transferred %i bytes\n", ret);
else
{
checkm8_debug_indent("\tfinal request failed with error code %i\n", ret);
checkm8_debug_indent("\tfinal request failed with error code %i (%s)\n", ret, usb_error_name(ret));
cmd_resp->ret = ret;
return cmd_resp;
}
@@ -128,7 +128,7 @@ struct dev_cmd_resp *command(struct pwned_device *dev,
if(ret >= 0) checkm8_debug_indent("\tfinal request transferred %i bytes\n", ret);
else
{
checkm8_debug_indent("\tfinal request failed with error code %i\n", ret);
checkm8_debug_indent("\tfinal request failed with error code %i (%s)\n", ret, usb_error_name(ret));
cmd_resp->ret = ret;
return cmd_resp;
}

View File

@@ -247,6 +247,7 @@ int is_device_session_open(struct pwned_device *dev)
}
#ifdef WITH_ARDUINO
void ard_read(struct pwned_device *dev, unsigned char *target, int nbytes)
{
int index = 0, amount;
@@ -257,6 +258,7 @@ void ard_read(struct pwned_device *dev, unsigned char *target, int nbytes)
else index += amount;
}
}
#endif
@@ -650,3 +652,40 @@ int serial_descriptor(struct pwned_device *dev, unsigned char *serial_buf, int l
return CHECKM8_SUCCESS;
#endif
}
const char *usb_error_name(int code)
{
#ifdef WITH_ARDUINO
switch(code)
{
case CHECKM8_SUCCESS:
return "CHECKM8_SUCCESS";
case CHECKM8_FAIL_INVARGS:
return "CHECKM8_FAIL_INVARGS";
case CHECKM8_FAIL_NODEV:
return "CHECKM8_FAIL_NODEV";
case CHECKM8_FAIL_NOEXP:
return "CHECKM8_FAIL_NOEXP";
case CHECKM8_FAIL_NOTDONE:
return "CHECKM8_FAIL_NOTDONE";
case CHECKM8_FAIL_XFER:
return "CHECKM8_FAIL_XFER";
case CHECKM8_FAIL_NOINST:
return "CHECKM8_FAIL_NOINST";
case CHECKM8_FAIL_PROT:
return "CHECKM8_FAIL_PROT";
default:
return "UNKNOWN";
}
#else
return libusb_error_name(code);
#endif
}