Skip to content

Commit

Permalink
Addresses issue Nuand#408 for macOS. Under macOS, when libusb_cancel_…
Browse files Browse the repository at this point in the history
…transfer

is called on one transfer, all transfers on the same endpoint are
cancelled. Calling libusb_cancel_transfer on additional transfers on the
same endpoint _may_ result in macOS returning kIOReturnAborted. The net
result is the bladeRF can no longer be communicated with.

The fix to this is to only call libusb_cancel_transfer once in
cancel_all_transfers and set the appropriate state for all transfers.
Refer to libusb_cancel_transfer documentation for more details.
  • Loading branch information
jcmartin committed May 18, 2023
1 parent 368f0ac commit 25e3954
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions host/libraries/libbladeRF/src/backend/usb/libusb.c
Original file line number Diff line number Diff line change
Expand Up @@ -1003,6 +1003,29 @@ static inline void cancel_all_transfers(struct bladerf_stream *stream)
int status;
struct lusb_stream_data *stream_data = stream->backend_data;

#ifdef __APPLE__
/* For macOS and iOS, canceling one transfer will cause all transfers
* on the same endpoint to be cancelled.
*/
bool have_cancelled = false;

for (i = 0; i < stream_data->num_transfers; i++) {
if (stream_data->transfer_status[i] == TRANSFER_IN_FLIGHT) {
if (!have_cancelled) {
status = libusb_cancel_transfer(stream_data->transfers[i]);
if (status < 0 && status != LIBUSB_ERROR_NOT_FOUND) {
log_error("Error canceling transfer (%d): %s\n",
status, libusb_error_name(status));
} else {
stream_data->transfer_status[i] = TRANSFER_CANCEL_PENDING;
}
have_cancelled = true;
} else {
stream_data->transfer_status[i] = TRANSFER_CANCEL_PENDING;
}
}
}
#else
for (i = 0; i < stream_data->num_transfers; i++) {
if (stream_data->transfer_status[i] == TRANSFER_IN_FLIGHT) {
status = libusb_cancel_transfer(stream_data->transfers[i]);
Expand All @@ -1014,6 +1037,7 @@ static inline void cancel_all_transfers(struct bladerf_stream *stream)
}
}
}
#endif
}

static inline size_t transfer_idx(struct lusb_stream_data *stream_data,
Expand Down

0 comments on commit 25e3954

Please sign in to comment.