IOS/USB: Use LibusbUtils::ErrorWrap and LIBUSB_SUCCESS
This commit is contained in:
parent
5d301cc206
commit
83afaba785
|
@ -141,15 +141,15 @@ bool LibusbDevice::Attach()
|
||||||
{
|
{
|
||||||
NOTICE_LOG_FMT(IOS_USB, "[{:04x}:{:04x}] Opening device", m_vid, m_pid);
|
NOTICE_LOG_FMT(IOS_USB, "[{:04x}:{:04x}] Opening device", m_vid, m_pid);
|
||||||
const int ret = libusb_open(m_device, &m_handle);
|
const int ret = libusb_open(m_device, &m_handle);
|
||||||
if (ret != 0)
|
if (ret != LIBUSB_SUCCESS)
|
||||||
{
|
{
|
||||||
ERROR_LOG_FMT(IOS_USB, "[{:04x}:{:04x}] Failed to open: {}", m_vid, m_pid,
|
ERROR_LOG_FMT(IOS_USB, "[{:04x}:{:04x}] Failed to open: {}", m_vid, m_pid,
|
||||||
libusb_error_name(ret));
|
LibusbUtils::ErrorWrap(ret));
|
||||||
m_handle = nullptr;
|
m_handle = nullptr;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (ClaimAllInterfaces(DEFAULT_CONFIG_NUM) < 0)
|
if (ClaimAllInterfaces(DEFAULT_CONFIG_NUM) < LIBUSB_SUCCESS)
|
||||||
return false;
|
return false;
|
||||||
m_device_attached = true;
|
m_device_attached = true;
|
||||||
return true;
|
return true;
|
||||||
|
@ -161,7 +161,7 @@ bool LibusbDevice::AttachAndChangeInterface(const u8 interface)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (interface != m_active_interface)
|
if (interface != m_active_interface)
|
||||||
return ChangeInterface(interface) == 0;
|
return ChangeInterface(interface) == LIBUSB_SUCCESS;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -182,7 +182,7 @@ int LibusbDevice::ChangeInterface(const u8 interface)
|
||||||
INFO_LOG_FMT(IOS_USB, "[{:04x}:{:04x} {}] Changing interface to {}", m_vid, m_pid,
|
INFO_LOG_FMT(IOS_USB, "[{:04x}:{:04x} {}] Changing interface to {}", m_vid, m_pid,
|
||||||
m_active_interface, interface);
|
m_active_interface, interface);
|
||||||
m_active_interface = interface;
|
m_active_interface = interface;
|
||||||
return 0;
|
return LIBUSB_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
int LibusbDevice::SetAltSetting(const u8 alt_setting)
|
int LibusbDevice::SetAltSetting(const u8 alt_setting)
|
||||||
|
@ -216,15 +216,15 @@ int LibusbDevice::SubmitTransfer(std::unique_ptr<CtrlMessage> cmd)
|
||||||
if (static_cast<u8>(cmd->index) != m_active_interface)
|
if (static_cast<u8>(cmd->index) != m_active_interface)
|
||||||
{
|
{
|
||||||
const int ret = ChangeInterface(static_cast<u8>(cmd->index));
|
const int ret = ChangeInterface(static_cast<u8>(cmd->index));
|
||||||
if (ret < 0)
|
if (ret < LIBUSB_SUCCESS)
|
||||||
{
|
{
|
||||||
ERROR_LOG_FMT(IOS_USB, "[{:04x}:{:04x} {}] Failed to change interface to {}: {}", m_vid,
|
ERROR_LOG_FMT(IOS_USB, "[{:04x}:{:04x} {}] Failed to change interface to {}: {}", m_vid,
|
||||||
m_pid, m_active_interface, cmd->index, libusb_error_name(ret));
|
m_pid, m_active_interface, cmd->index, LibusbUtils::ErrorWrap(ret));
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
const int ret = SetAltSetting(static_cast<u8>(cmd->value));
|
const int ret = SetAltSetting(static_cast<u8>(cmd->value));
|
||||||
if (ret == 0)
|
if (ret == LIBUSB_SUCCESS)
|
||||||
m_ios.EnqueueIPCReply(cmd->ios_request, cmd->length);
|
m_ios.EnqueueIPCReply(cmd->ios_request, cmd->length);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
@ -234,7 +234,7 @@ int LibusbDevice::SubmitTransfer(std::unique_ptr<CtrlMessage> cmd)
|
||||||
m_vid, m_pid, m_active_interface, cmd->index, cmd->value);
|
m_vid, m_pid, m_active_interface, cmd->index, cmd->value);
|
||||||
ReleaseAllInterfacesForCurrentConfig();
|
ReleaseAllInterfacesForCurrentConfig();
|
||||||
const int ret = libusb_set_configuration(m_handle, cmd->value);
|
const int ret = libusb_set_configuration(m_handle, cmd->value);
|
||||||
if (ret == 0)
|
if (ret == LIBUSB_SUCCESS)
|
||||||
{
|
{
|
||||||
ClaimAllInterfaces(cmd->value);
|
ClaimAllInterfaces(cmd->value);
|
||||||
m_ios.EnqueueIPCReply(cmd->ios_request, cmd->length);
|
m_ios.EnqueueIPCReply(cmd->ios_request, cmd->length);
|
||||||
|
@ -376,7 +376,7 @@ void LibusbDevice::TransferEndpoint::HandleTransfer(libusb_transfer* transfer,
|
||||||
const std::unique_ptr<u8[]> buffer(transfer->buffer);
|
const std::unique_ptr<u8[]> buffer(transfer->buffer);
|
||||||
const auto& cmd = *iterator->second.get();
|
const auto& cmd = *iterator->second.get();
|
||||||
const auto* device = static_cast<LibusbDevice*>(transfer->user_data);
|
const auto* device = static_cast<LibusbDevice*>(transfer->user_data);
|
||||||
s32 return_value = 0;
|
s32 return_value = LIBUSB_SUCCESS;
|
||||||
switch (transfer->status)
|
switch (transfer->status)
|
||||||
{
|
{
|
||||||
case LIBUSB_TRANSFER_COMPLETED:
|
case LIBUSB_TRANSFER_COMPLETED:
|
||||||
|
@ -425,7 +425,7 @@ static int DoForEachInterface(const Configs& configs, u8 config_num, Function ac
|
||||||
for (u8 i = 0; i < configs[config_num]->bNumInterfaces; ++i)
|
for (u8 i = 0; i < configs[config_num]->bNumInterfaces; ++i)
|
||||||
{
|
{
|
||||||
ret = action(i);
|
ret = action(i);
|
||||||
if (ret < 0)
|
if (ret < LIBUSB_SUCCESS)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
|
@ -435,15 +435,16 @@ int LibusbDevice::ClaimAllInterfaces(u8 config_num) const
|
||||||
{
|
{
|
||||||
const int ret = DoForEachInterface(m_config_descriptors, config_num, [this](u8 i) {
|
const int ret = DoForEachInterface(m_config_descriptors, config_num, [this](u8 i) {
|
||||||
const int ret2 = libusb_detach_kernel_driver(m_handle, i);
|
const int ret2 = libusb_detach_kernel_driver(m_handle, i);
|
||||||
if (ret2 < 0 && ret2 != LIBUSB_ERROR_NOT_FOUND && ret2 != LIBUSB_ERROR_NOT_SUPPORTED)
|
if (ret2 < LIBUSB_SUCCESS && ret2 != LIBUSB_ERROR_NOT_FOUND &&
|
||||||
|
ret2 != LIBUSB_ERROR_NOT_SUPPORTED)
|
||||||
{
|
{
|
||||||
ERROR_LOG_FMT(IOS_USB, "[{:04x}:{:04x}] Failed to detach kernel driver: {}", m_vid, m_pid,
|
ERROR_LOG_FMT(IOS_USB, "[{:04x}:{:04x}] Failed to detach kernel driver: {}", m_vid, m_pid,
|
||||||
libusb_error_name(ret2));
|
LibusbUtils::ErrorWrap(ret2));
|
||||||
return ret2;
|
return ret2;
|
||||||
}
|
}
|
||||||
return libusb_claim_interface(m_handle, i);
|
return libusb_claim_interface(m_handle, i);
|
||||||
});
|
});
|
||||||
if (ret < 0)
|
if (ret < LIBUSB_SUCCESS)
|
||||||
{
|
{
|
||||||
ERROR_LOG_FMT(IOS_USB, "[{:04x}:{:04x}] Failed to claim all interfaces (configuration {})",
|
ERROR_LOG_FMT(IOS_USB, "[{:04x}:{:04x}] Failed to claim all interfaces (configuration {})",
|
||||||
m_vid, m_pid, config_num);
|
m_vid, m_pid, config_num);
|
||||||
|
@ -456,7 +457,7 @@ int LibusbDevice::ReleaseAllInterfaces(u8 config_num) const
|
||||||
const int ret = DoForEachInterface(m_config_descriptors, config_num, [this](u8 i) {
|
const int ret = DoForEachInterface(m_config_descriptors, config_num, [this](u8 i) {
|
||||||
return libusb_release_interface(m_handle, i);
|
return libusb_release_interface(m_handle, i);
|
||||||
});
|
});
|
||||||
if (ret < 0 && ret != LIBUSB_ERROR_NO_DEVICE && ret != LIBUSB_ERROR_NOT_FOUND)
|
if (ret < LIBUSB_SUCCESS && ret != LIBUSB_ERROR_NO_DEVICE && ret != LIBUSB_ERROR_NOT_FOUND)
|
||||||
{
|
{
|
||||||
ERROR_LOG_FMT(IOS_USB, "[{:04x}:{:04x}] Failed to release all interfaces (configuration {})",
|
ERROR_LOG_FMT(IOS_USB, "[{:04x}:{:04x}] Failed to release all interfaces (configuration {})",
|
||||||
m_vid, m_pid, config_num);
|
m_vid, m_pid, config_num);
|
||||||
|
@ -468,7 +469,7 @@ int LibusbDevice::ReleaseAllInterfacesForCurrentConfig() const
|
||||||
{
|
{
|
||||||
int config_num;
|
int config_num;
|
||||||
const int get_config_ret = libusb_get_configuration(m_handle, &config_num);
|
const int get_config_ret = libusb_get_configuration(m_handle, &config_num);
|
||||||
if (get_config_ret < 0)
|
if (get_config_ret < LIBUSB_SUCCESS)
|
||||||
return get_config_ret;
|
return get_config_ret;
|
||||||
return ReleaseAllInterfaces(config_num);
|
return ReleaseAllInterfaces(config_num);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue