Index: src/libusb-glue.c |
diff --git a/src/libusb-glue.c b/src/libusb-glue.c |
index bdf41b4089e6f353e615281097497d078d143230..7c23f14a104b7639aecfadf2d3f6065d83f88c96 100644 |
--- a/src/libusb-glue.c |
+++ b/src/libusb-glue.c |
@@ -676,9 +676,18 @@ LIBMTP_error_number_t LIBMTP_Detect_Raw_Devices(LIBMTP_raw_device_t ** devices, |
} |
} |
if (!device_known) { |
- device_unknown(i, |
- dev->libusb_device->descriptor.idVendor, |
- dev->libusb_device->descriptor.idProduct); |
+ // This device is unknown to the developers |
+ LIBMTP_ERROR("Device %d (VID=%04x and PID=%04x) is UNKNOWN.\n", |
+ i, |
+ dev->libusb_device->descriptor.idVendor, |
+ dev->libusb_device->descriptor.idProduct); |
+ LIBMTP_ERROR("Please report this VID/PID and the device model to the " |
+ "libmtp development team\n"); |
+ /* |
+ * Trying to get iManufacturer or iProduct from the device at this |
+ * point would require opening a device handle, that we don't want |
+ * to do right now. (Takes time for no good enough reason.) |
+ */ |
} |
// Save the location on the bus |
retdevs[i].bus_location = dev->bus_location; |
@@ -812,7 +821,6 @@ libusb_glue_error (PTPParams *params, const char *format, ...) |
#define CONTEXT_BLOCK_SIZE_1 0x3e00 |
#define CONTEXT_BLOCK_SIZE_2 0x200 |
#define CONTEXT_BLOCK_SIZE CONTEXT_BLOCK_SIZE_1+CONTEXT_BLOCK_SIZE_2 |
- |
static short |
ptp_read_func ( |
unsigned long size, PTPDataHandler *handler,void *data, |
@@ -823,25 +831,9 @@ ptp_read_func ( |
unsigned long toread = 0; |
int result = 0; |
unsigned long curread = 0; |
+ unsigned long written; |
unsigned char *bytes; |
int expect_terminator_byte = 0; |
- unsigned long usb_inep_maxpacket_size; |
- unsigned long context_block_size_1; |
- unsigned long context_block_size_2; |
- uint16_t ptp_dev_vendor_id = ptp_usb->rawdevice.device_entry.vendor_id; |
- |
- //"iRiver" device special handling |
- if (ptp_dev_vendor_id == 0x4102 || ptp_dev_vendor_id == 0x1006) { |
- usb_inep_maxpacket_size = ptp_usb->inep_maxpacket; |
- if (usb_inep_maxpacket_size == 0x400) { |
- context_block_size_1 = CONTEXT_BLOCK_SIZE_1 - 0x200; |
- context_block_size_2 = CONTEXT_BLOCK_SIZE_2 + 0x200; |
- } |
- else { |
- context_block_size_1 = CONTEXT_BLOCK_SIZE_1; |
- context_block_size_2 = CONTEXT_BLOCK_SIZE_2; |
- } |
- } |
// This is the largest block we'll need to read in. |
bytes = malloc(CONTEXT_BLOCK_SIZE); |
@@ -860,21 +852,16 @@ ptp_read_func ( |
expect_terminator_byte = 1; |
} |
} |
- else if (ptp_dev_vendor_id == 0x4102 || ptp_dev_vendor_id == 0x1006) { |
- //"iRiver" device special handling |
- if (curread == 0) |
- // we are first packet, but not last packet |
- toread = context_block_size_1; |
- else if (toread == context_block_size_1) |
- toread = context_block_size_2; |
- else if (toread == context_block_size_2) |
- toread = context_block_size_1; |
- else |
- LIBMTP_INFO("unexpected toread size 0x%04x, 0x%04x remaining bytes\n", |
- (unsigned int) toread, (unsigned int) (size-curread)); |
- |
- } else |
- toread = CONTEXT_BLOCK_SIZE; |
+ else if (curread == 0) |
+ // we are first packet, but not last packet |
+ toread = CONTEXT_BLOCK_SIZE_1; |
+ else if (toread == CONTEXT_BLOCK_SIZE_1) |
+ toread = CONTEXT_BLOCK_SIZE_2; |
+ else if (toread == CONTEXT_BLOCK_SIZE_2) |
+ toread = CONTEXT_BLOCK_SIZE_1; |
+ else |
+ LIBMTP_INFO("unexpected toread size 0x%04x, 0x%04x remaining bytes\n", |
+ (unsigned int) toread, (unsigned int) (size-curread)); |
LIBMTP_USB_DEBUG("Reading in 0x%04lx bytes\n", toread); |
@@ -904,7 +891,7 @@ ptp_read_func ( |
result--; |
} |
- int putfunc_ret = handler->putfunc(NULL, handler->priv, result, bytes); |
+ int putfunc_ret = handler->putfunc(NULL, handler->priv, result, bytes, &written); |
if (putfunc_ret != PTP_RC_OK) |
return putfunc_ret; |
@@ -1077,7 +1064,8 @@ memory_getfunc(PTPParams* params, void* private, |
static uint16_t |
memory_putfunc(PTPParams* params, void* private, |
- unsigned long sendlen, unsigned char *data |
+ unsigned long sendlen, unsigned char *data, |
+ unsigned long *putlen |
) { |
PTPMemHandlerPrivate* priv = (PTPMemHandlerPrivate*)private; |
@@ -1087,6 +1075,7 @@ memory_putfunc(PTPParams* params, void* private, |
} |
memcpy (priv->data + priv->curoff, data, sendlen); |
priv->curoff += sendlen; |
+ *putlen = sendlen; |
return PTP_RC_OK; |
} |
@@ -1148,7 +1137,7 @@ ptp_exit_recv_memory_handler (PTPDataHandler *handler, |
/* send / receive functions */ |
uint16_t |
-ptp_usb_sendreq (PTPParams* params, PTPContainer* req, int dataphase) |
+ptp_usb_sendreq (PTPParams* params, PTPContainer* req) |
{ |
uint16_t ret; |
PTPUSBBulkContainer usbreq; |
@@ -1158,7 +1147,7 @@ ptp_usb_sendreq (PTPParams* params, PTPContainer* req, int dataphase) |
char txt[256]; |
- (void) ptp_render_ofc (params, req->Code, sizeof(txt), txt); |
+ (void) ptp_render_opcode (params, req->Code, sizeof(txt), txt); |
LIBMTP_USB_DEBUG("REQUEST: 0x%04x, %s\n", req->Code, txt); |
/* build appropriate USB container */ |
@@ -1197,13 +1186,13 @@ ptp_usb_sendreq (PTPParams* params, PTPContainer* req, int dataphase) |
uint16_t |
ptp_usb_senddata (PTPParams* params, PTPContainer* ptp, |
- uint64_t size, PTPDataHandler *handler |
+ unsigned long size, PTPDataHandler *handler |
) { |
uint16_t ret; |
int wlen, datawlen; |
unsigned long written; |
PTPUSBBulkContainer usbdata; |
- uint64_t bytes_left_to_transfer; |
+ uint32_t bytes_left_to_transfer; |
PTPDataHandler memhandler; |
@@ -1265,10 +1254,6 @@ static uint16_t ptp_usb_getpacket(PTPParams *params, |
PTPDataHandler memhandler; |
uint16_t ret; |
unsigned char *x = NULL; |
- unsigned long packet_size; |
- PTP_USB *ptp_usb = (PTP_USB *) params->data; |
- |
- packet_size = ptp_usb->inep_maxpacket; |
/* read the header and potentially the first data */ |
if (params->response_packet_size > 0) { |
@@ -1282,7 +1267,7 @@ static uint16_t ptp_usb_getpacket(PTPParams *params, |
return PTP_RC_OK; |
} |
ptp_init_recv_memory_handler (&memhandler); |
- ret = ptp_read_func(packet_size, &memhandler, params->data, rlen, 0); |
+ ret = ptp_read_func(PTP_USB_BULK_HS_MAX_PACKET_LEN_READ, &memhandler, params->data, rlen, 0); |
ptp_exit_recv_memory_handler (&memhandler, &x, rlen); |
if (x) { |
memcpy (packet, x, *rlen); |
@@ -1296,6 +1281,7 @@ ptp_usb_getdata (PTPParams* params, PTPContainer* ptp, PTPDataHandler *handler) |
{ |
uint16_t ret; |
PTPUSBBulkContainer usbdata; |
+ unsigned long written; |
PTP_USB *ptp_usb = (PTP_USB *) params->data; |
int putfunc_ret; |
@@ -1337,11 +1323,12 @@ ptp_usb_getdata (PTPParams* params, PTPContainer* ptp, PTPDataHandler *handler) |
break; |
} |
} |
- if (rlen == ptp_usb->inep_maxpacket) { |
+ if (usbdata.length == 0xffffffffU) { |
/* Copy first part of data to 'data' */ |
putfunc_ret = |
handler->putfunc( |
- params, handler->priv, rlen - PTP_USB_BULK_HDR_LEN, usbdata.payload.data |
+ params, handler->priv, rlen - PTP_USB_BULK_HDR_LEN, usbdata.payload.data, |
+ &written |
); |
if (putfunc_ret != PTP_RC_OK) |
return putfunc_ret; |
@@ -1352,7 +1339,7 @@ ptp_usb_getdata (PTPParams* params, PTPContainer* ptp, PTPDataHandler *handler) |
uint16_t xret; |
xret = ptp_read_func( |
- 0x20000000, |
+ PTP_USB_BULK_HS_MAX_PACKET_LEN_READ, |
handler, |
params->data, |
&readdata, |
@@ -1360,7 +1347,7 @@ ptp_usb_getdata (PTPParams* params, PTPContainer* ptp, PTPDataHandler *handler) |
); |
if (xret != PTP_RC_OK) |
return xret; |
- if (readdata < 0x20000000) |
+ if (readdata < PTP_USB_BULK_HS_MAX_PACKET_LEN_READ) |
break; |
} |
return PTP_RC_OK; |
@@ -1411,13 +1398,14 @@ ptp_usb_getdata (PTPParams* params, PTPContainer* ptp, PTPDataHandler *handler) |
putfunc_ret = |
handler->putfunc( |
params, handler->priv, rlen - PTP_USB_BULK_HDR_LEN, |
- usbdata.payload.data |
+ usbdata.payload.data, |
+ &written |
); |
if (putfunc_ret != PTP_RC_OK) |
return putfunc_ret; |
if (FLAG_NO_ZERO_READS(ptp_usb) && |
- len+PTP_USB_BULK_HDR_LEN == ptp_usb->inep_maxpacket) { |
+ len+PTP_USB_BULK_HDR_LEN == PTP_USB_BULK_HS_MAX_PACKET_LEN_READ) { |
LIBMTP_USB_DEBUG("Reading in extra terminating byte\n"); |
@@ -1431,8 +1419,8 @@ ptp_usb_getdata (PTPParams* params, PTPContainer* ptp, PTPDataHandler *handler) |
ptp_usb->timeout); |
if (result != 1) |
- LIBMTP_INFO("Could not read in extra byte for %d bytes long file, return value 0x%04x\n", ptp_usb->inep_maxpacket, result); |
- } else if (len+PTP_USB_BULK_HDR_LEN == ptp_usb->inep_maxpacket && params->split_header_data == 0) { |
+ LIBMTP_INFO("Could not read in extra byte for PTP_USB_BULK_HS_MAX_PACKET_LEN_READ long file, return value 0x%04x\n", result); |
+ } else if (len+PTP_USB_BULK_HDR_LEN == PTP_USB_BULK_HS_MAX_PACKET_LEN_READ && params->split_header_data == 0) { |
int zeroresult = 0; |
char zerobyte = 0; |
@@ -1618,17 +1606,6 @@ ptp_usb_event_wait (PTPParams* params, PTPContainer* event) { |
} |
uint16_t |
-ptp_usb_event_async (PTPParams* params, PTPEventCbFn cb, void *user_data) { |
- /* Unsupported */ |
- return PTP_ERROR_CANCEL; |
-} |
- |
-int LIBMTP_Handle_Events_Timeout_Completed(struct timeval *tv, int *completed) { |
- /* Unsupported */ |
- return -12; |
-} |
- |
-uint16_t |
ptp_usb_control_cancel_request (PTPParams *params, uint32_t transactionid) { |
PTP_USB *ptp_usb = (PTP_USB *)(params->data); |
int ret; |
@@ -1841,14 +1818,11 @@ static void close_usb(PTP_USB* ptp_usb) |
* STALL is persistant or not). |
*/ |
clear_stall(ptp_usb); |
-#if 0 |
- // causes troubles due to a kernel bug in 3.x kernels before/around 3.8 |
// Clear halts on any endpoints |
clear_halt(ptp_usb); |
// Added to clear some stuff on the OUT endpoint |
// TODO: is this good on the Mac too? |
// HINT: some devices may need that you comment these two out too. |
-#endif |
usb_resetep(ptp_usb->handle, ptp_usb->outep); |
usb_release_interface(ptp_usb->handle, (int) ptp_usb->interface); |
} |