Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(251)

Unified Diff: src/libusb-glue.c

Issue 2345493002: Uprev libmtp to 1.1.12 (Closed) Base URL: https://chromium.googlesource.com/chromium/deps/libmtp@master
Patch Set: Re-upload cl Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/libopenusb1-glue.c ('k') | src/libusb1-glue.c » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/libusb-glue.c
diff --git a/src/libusb-glue.c b/src/libusb-glue.c
index 7c23f14a104b7639aecfadf2d3f6065d83f88c96..bdf41b4089e6f353e615281097497d078d143230 100644
--- a/src/libusb-glue.c
+++ b/src/libusb-glue.c
@@ -676,18 +676,9 @@ LIBMTP_error_number_t LIBMTP_Detect_Raw_Devices(LIBMTP_raw_device_t ** devices,
}
}
if (!device_known) {
- // 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.)
- */
+ device_unknown(i,
+ dev->libusb_device->descriptor.idVendor,
+ dev->libusb_device->descriptor.idProduct);
}
// Save the location on the bus
retdevs[i].bus_location = dev->bus_location;
@@ -821,6 +812,7 @@ 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,
@@ -831,9 +823,25 @@ 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);
@@ -852,16 +860,21 @@ ptp_read_func (
expect_terminator_byte = 1;
}
}
- 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));
+ 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;
LIBMTP_USB_DEBUG("Reading in 0x%04lx bytes\n", toread);
@@ -891,7 +904,7 @@ ptp_read_func (
result--;
}
- int putfunc_ret = handler->putfunc(NULL, handler->priv, result, bytes, &written);
+ int putfunc_ret = handler->putfunc(NULL, handler->priv, result, bytes);
if (putfunc_ret != PTP_RC_OK)
return putfunc_ret;
@@ -1064,8 +1077,7 @@ memory_getfunc(PTPParams* params, void* private,
static uint16_t
memory_putfunc(PTPParams* params, void* private,
- unsigned long sendlen, unsigned char *data,
- unsigned long *putlen
+ unsigned long sendlen, unsigned char *data
) {
PTPMemHandlerPrivate* priv = (PTPMemHandlerPrivate*)private;
@@ -1075,7 +1087,6 @@ memory_putfunc(PTPParams* params, void* private,
}
memcpy (priv->data + priv->curoff, data, sendlen);
priv->curoff += sendlen;
- *putlen = sendlen;
return PTP_RC_OK;
}
@@ -1137,7 +1148,7 @@ ptp_exit_recv_memory_handler (PTPDataHandler *handler,
/* send / receive functions */
uint16_t
-ptp_usb_sendreq (PTPParams* params, PTPContainer* req)
+ptp_usb_sendreq (PTPParams* params, PTPContainer* req, int dataphase)
{
uint16_t ret;
PTPUSBBulkContainer usbreq;
@@ -1147,7 +1158,7 @@ ptp_usb_sendreq (PTPParams* params, PTPContainer* req)
char txt[256];
- (void) ptp_render_opcode (params, req->Code, sizeof(txt), txt);
+ (void) ptp_render_ofc (params, req->Code, sizeof(txt), txt);
LIBMTP_USB_DEBUG("REQUEST: 0x%04x, %s\n", req->Code, txt);
/* build appropriate USB container */
@@ -1186,13 +1197,13 @@ ptp_usb_sendreq (PTPParams* params, PTPContainer* req)
uint16_t
ptp_usb_senddata (PTPParams* params, PTPContainer* ptp,
- unsigned long size, PTPDataHandler *handler
+ uint64_t size, PTPDataHandler *handler
) {
uint16_t ret;
int wlen, datawlen;
unsigned long written;
PTPUSBBulkContainer usbdata;
- uint32_t bytes_left_to_transfer;
+ uint64_t bytes_left_to_transfer;
PTPDataHandler memhandler;
@@ -1254,6 +1265,10 @@ 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) {
@@ -1267,7 +1282,7 @@ static uint16_t ptp_usb_getpacket(PTPParams *params,
return PTP_RC_OK;
}
ptp_init_recv_memory_handler (&memhandler);
- ret = ptp_read_func(PTP_USB_BULK_HS_MAX_PACKET_LEN_READ, &memhandler, params->data, rlen, 0);
+ ret = ptp_read_func(packet_size, &memhandler, params->data, rlen, 0);
ptp_exit_recv_memory_handler (&memhandler, &x, rlen);
if (x) {
memcpy (packet, x, *rlen);
@@ -1281,7 +1296,6 @@ 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;
@@ -1323,12 +1337,11 @@ ptp_usb_getdata (PTPParams* params, PTPContainer* ptp, PTPDataHandler *handler)
break;
}
}
- if (usbdata.length == 0xffffffffU) {
+ if (rlen == ptp_usb->inep_maxpacket) {
/* Copy first part of data to 'data' */
putfunc_ret =
handler->putfunc(
- params, handler->priv, rlen - PTP_USB_BULK_HDR_LEN, usbdata.payload.data,
- &written
+ params, handler->priv, rlen - PTP_USB_BULK_HDR_LEN, usbdata.payload.data
);
if (putfunc_ret != PTP_RC_OK)
return putfunc_ret;
@@ -1339,7 +1352,7 @@ ptp_usb_getdata (PTPParams* params, PTPContainer* ptp, PTPDataHandler *handler)
uint16_t xret;
xret = ptp_read_func(
- PTP_USB_BULK_HS_MAX_PACKET_LEN_READ,
+ 0x20000000,
handler,
params->data,
&readdata,
@@ -1347,7 +1360,7 @@ ptp_usb_getdata (PTPParams* params, PTPContainer* ptp, PTPDataHandler *handler)
);
if (xret != PTP_RC_OK)
return xret;
- if (readdata < PTP_USB_BULK_HS_MAX_PACKET_LEN_READ)
+ if (readdata < 0x20000000)
break;
}
return PTP_RC_OK;
@@ -1398,14 +1411,13 @@ 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,
- &written
+ usbdata.payload.data
);
if (putfunc_ret != PTP_RC_OK)
return putfunc_ret;
if (FLAG_NO_ZERO_READS(ptp_usb) &&
- len+PTP_USB_BULK_HDR_LEN == PTP_USB_BULK_HS_MAX_PACKET_LEN_READ) {
+ len+PTP_USB_BULK_HDR_LEN == ptp_usb->inep_maxpacket) {
LIBMTP_USB_DEBUG("Reading in extra terminating byte\n");
@@ -1419,8 +1431,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 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) {
+ 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) {
int zeroresult = 0;
char zerobyte = 0;
@@ -1606,6 +1618,17 @@ 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;
@@ -1818,11 +1841,14 @@ 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);
}
« no previous file with comments | « src/libopenusb1-glue.c ('k') | src/libusb1-glue.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698