From 1b166a5b0573c8c0b1fd7d74c5f2737ca2b26ec4 Mon Sep 17 00:00:00 2001 From: Martin Ling Date: Thu, 15 Sep 2022 15:22:41 +0100 Subject: [PATCH] Pad the last data in a transmission to the next 512 byte boundary. --- host/libhackrf/src/hackrf.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/host/libhackrf/src/hackrf.c b/host/libhackrf/src/hackrf.c index 40545cde..31fcb6de 100644 --- a/host/libhackrf/src/hackrf.c +++ b/host/libhackrf/src/hackrf.c @@ -374,10 +374,17 @@ static int prepare_transfers( // Now everything is ready, go ahead and submit the ready transfers. for (transfer_index = 0; transfer_index < ready_transfers; transfer_index++) { - device->transfers[transfer_index]->endpoint = endpoint_address; - device->transfers[transfer_index]->callback = callback; + struct libusb_transfer* transfer = device->transfers[transfer_index]; + transfer->endpoint = endpoint_address; + transfer->callback = callback; - error = libusb_submit_transfer(device->transfers[transfer_index]); + // Pad the size of a short transfer to the next 512-byte boundary. + if (endpoint_address == TX_ENDPOINT_ADDRESS) { + while (transfer->length % 512 != 0) + transfer->buffer[transfer->length++] = 0; + } + + error = libusb_submit_transfer(transfer); if (error != 0) { last_libusb_error = error; return HACKRF_ERROR_LIBUSB; @@ -1805,6 +1812,10 @@ hackrf_libusb_transfer_callback(struct libusb_transfer* usb_transfer) if ((resubmit = device->transfers_setup)) { if (usb_transfer->endpoint == TX_ENDPOINT_ADDRESS) { usb_transfer->length = transfer.valid_length; + // Pad to the next 512-byte boundary. + uint8_t* buffer = usb_transfer->buffer; + while (usb_transfer->length % 512 != 0) + buffer[usb_transfer->length++] = 0; } result = libusb_submit_transfer(usb_transfer); }