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

Side by Side Diff: src/libopenusb1-glue.c

Issue 2364793002: Revert "Uprev libmtp to 1.1.12" (Closed) Base URL: https://chromium.googlesource.com/chromium/deps/libmtp@master
Patch Set: Created 4 years, 2 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 unified diff | Download patch
« no previous file with comments | « src/libmtp.h.in ('k') | src/libusb-glue.c » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * \file libusb1-glue.c 2 * \file libusb1-glue.c
3 * Low-level USB interface glue towards libusb. 3 * Low-level USB interface glue towards libusb.
4 * 4 *
5 * Copyright (C) 2005-2007 Richard A. Low <richard@wentnet.com> 5 * Copyright (C) 2005-2007 Richard A. Low <richard@wentnet.com>
6 * Copyright (C) 2005-2012 Linus Walleij <triad@df.lth.se> 6 * Copyright (C) 2005-2012 Linus Walleij <triad@df.lth.se>
7 * Copyright (C) 2006-2011 Marcus Meissner 7 * Copyright (C) 2006-2011 Marcus Meissner
8 * Copyright (C) 2007 Ted Bullock 8 * Copyright (C) 2007 Ted Bullock
9 * Copyright (C) 2008 Chris Bagwell <chris@cnpbagwell.com> 9 * Copyright (C) 2008 Chris Bagwell <chris@cnpbagwell.com>
10 * 10 *
(...skipping 643 matching lines...) Expand 10 before | Expand all | Expand 10 after
654 LIBMTP_ERROR("Device %d (VID=%04x and PID=%04x) is a %s %s.\n", 654 LIBMTP_ERROR("Device %d (VID=%04x and PID=%04x) is a %s %s.\n",
655 i, 655 i,
656 desc.idVendor, 656 desc.idVendor,
657 desc.idProduct, 657 desc.idProduct,
658 mtp_device_table[j].vendor, 658 mtp_device_table[j].vendor,
659 mtp_device_table[j].product); 659 mtp_device_table[j].product);
660 break; 660 break;
661 } 661 }
662 } 662 }
663 if (!device_known) { 663 if (!device_known) {
664 device_unknown(i, desc.idVendor, desc.idProduct); 664 // This device is unknown to the developers
665 LIBMTP_ERROR("Device %d (VID=%04x and PID=%04x) is UNKNOWN.\n",
666 i,
667 desc.idVendor,
668 desc.idProduct);
669 LIBMTP_ERROR("Please report this VID/PID and the device model to the libmtp development team\n");
670 /*
671 * Trying to get iManufacturer or iProduct from the device at this
672 * point would require opening a device handle, that we don't want
673 * to do right now. (Takes time for no good enough reason.)
674 */
665 } 675 }
666 // Save the location on the bus 676 // Save the location on the bus
667 retdevs[i].bus_location = 0; 677 retdevs[i].bus_location = 0;
668 retdevs[i].devnum = openusb_get_devid(libmtp_openusb_handle, &dev->devic e); 678 retdevs[i].devnum = openusb_get_devid(libmtp_openusb_handle, &dev->devic e);
669 i++; 679 i++;
670 dev = dev->next; 680 dev = dev->next;
671 } 681 }
672 *devices = retdevs; 682 *devices = retdevs;
673 *numdevs = i; 683 *numdevs = i;
674 free_mtpdevice_list(devlist); 684 free_mtpdevice_list(devlist);
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
786 int readzero 796 int readzero
787 ) { 797 ) {
788 PTP_USB *ptp_usb = (PTP_USB *) data; 798 PTP_USB *ptp_usb = (PTP_USB *) data;
789 unsigned long toread = 0; 799 unsigned long toread = 0;
790 int ret = 0; 800 int ret = 0;
791 int xread; 801 int xread;
792 unsigned long curread = 0; 802 unsigned long curread = 0;
793 unsigned long written; 803 unsigned long written;
794 unsigned char *bytes; 804 unsigned char *bytes;
795 int expect_terminator_byte = 0; 805 int expect_terminator_byte = 0;
796 unsigned long usb_inep_maxpacket_size;
797 unsigned long context_block_size_1;
798 unsigned long context_block_size_2;
799 uint16_t ptp_dev_vendor_id = ptp_usb->rawdevice.device_entry.vendor_id;
800 806
801 //"iRiver" device special handling
802 if (ptp_dev_vendor_id == 0x4102 || ptp_dev_vendor_id == 0x1006) {
803 usb_inep_maxpacket_size = ptp_usb->inep_maxpacket;
804 if (usb_inep_maxpacket_size == 0x400) {
805 context_block_size_1 = CONTEXT_BLOCK_SIZE_1 - 0x200;
806 context_block_size_2 = CONTEXT_BLOCK_SIZE_2 + 0x200;
807 }
808 else {
809 context_block_size_1 = CONTEXT_BLOCK_SIZE_1;
810 context_block_size_2 = CONTEXT_BLOCK_SIZE_2;
811 }
812 }
813 struct openusb_bulk_request bulk; 807 struct openusb_bulk_request bulk;
814 // This is the largest block we'll need to read in. 808 // This is the largest block we'll need to read in.
815 bytes = malloc(CONTEXT_BLOCK_SIZE); 809 bytes = malloc(CONTEXT_BLOCK_SIZE);
816 while (curread < size) { 810 while (curread < size) {
817 811
818 LIBMTP_USB_DEBUG("Remaining size to read: 0x%04lx bytes\n", size - curre ad); 812 LIBMTP_USB_DEBUG("Remaining size to read: 0x%04lx bytes\n", size - curre ad);
819 813
820 // check equal to condition here 814 // check equal to condition here
821 if (size - curread < CONTEXT_BLOCK_SIZE) { 815 if (size - curread < CONTEXT_BLOCK_SIZE) {
822 // this is the last packet 816 // this is the last packet
823 toread = size - curread; 817 toread = size - curread;
824 // this is equivalent to zero read for these devices 818 // this is equivalent to zero read for these devices
825 if (readzero && FLAG_NO_ZERO_READS(ptp_usb) && toread % 64 == 0) { 819 if (readzero && FLAG_NO_ZERO_READS(ptp_usb) && toread % 64 == 0) {
826 toread += 1; 820 toread += 1;
827 expect_terminator_byte = 1; 821 expect_terminator_byte = 1;
828 } 822 }
829 } else if (ptp_dev_vendor_id == 0x4102 || ptp_dev_vendor_id == 0x1006) { 823 } else if (curread == 0)
830 » » //"iRiver" device special handling 824 // we are first packet, but not last packet
831 » » if (curread == 0) 825 toread = CONTEXT_BLOCK_SIZE_1;
832 » » » // we are first packet, but not last packet 826 else if (toread == CONTEXT_BLOCK_SIZE_1)
833 » » » toread = context_block_size_1; 827 toread = CONTEXT_BLOCK_SIZE_2;
834 » » else if (toread == context_block_size_1) 828 else if (toread == CONTEXT_BLOCK_SIZE_2)
835 » » » toread = context_block_size_2; 829 toread = CONTEXT_BLOCK_SIZE_1;
836 » » else if (toread == context_block_size_2) 830 else
837 » » » toread = context_block_size_1; 831 LIBMTP_INFO("unexpected toread size 0x%04x, 0x%04x remaining bytes\n ",
838 » » else 832 (unsigned int) toread, (unsigned int) (size - curread));
839 » » » LIBMTP_INFO("unexpected toread size 0x%04x, 0x%04x remai ning bytes\n",
840 » » » » (unsigned int) toread, (unsigned int) (size - curread));
841 » }
842 » else
843 » » toread = CONTEXT_BLOCK_SIZE;
844 833
845 LIBMTP_USB_DEBUG("Reading in 0x%04lx bytes\n", toread); 834 LIBMTP_USB_DEBUG("Reading in 0x%04lx bytes\n", toread);
846 835
847 /* 836 /*
848 ret = USB_BULK_READ(ptp_usb->handle, 837 ret = USB_BULK_READ(ptp_usb->handle,
849 ptp_usb->inep, 838 ptp_usb->inep,
850 bytes, 839 bytes,
851 toread, 840 toread,
852 &xread, 841 &xread,
853 ptp_usb->timeout); 842 ptp_usb->timeout);
(...skipping 16 matching lines...) Expand all
870 else 859 else
871 LIBMTP_USB_DATA(bytes, xread, 16); 860 LIBMTP_USB_DATA(bytes, xread, 16);
872 861
873 // want to discard extra byte 862 // want to discard extra byte
874 if (expect_terminator_byte && xread == toread) { 863 if (expect_terminator_byte && xread == toread) {
875 LIBMTP_USB_DEBUG("<==USB IN\nDiscarding extra byte\n"); 864 LIBMTP_USB_DEBUG("<==USB IN\nDiscarding extra byte\n");
876 865
877 xread--; 866 xread--;
878 } 867 }
879 868
880 int putfunc_ret = handler->putfunc(NULL, handler->priv, xread, bytes); 869 int putfunc_ret = handler->putfunc(NULL, handler->priv, xread, bytes, &w ritten);
881 LIBMTP_USB_DEBUG("handler->putfunc ret = 0x%x\n", putfunc_ret); 870 LIBMTP_USB_DEBUG("handler->putfunc ret = 0x%x\n", putfunc_ret);
882 if (putfunc_ret != PTP_RC_OK) 871 if (putfunc_ret != PTP_RC_OK)
883 return putfunc_ret; 872 return putfunc_ret;
884 873
885 ptp_usb->current_transfer_complete += xread; 874 ptp_usb->current_transfer_complete += xread;
886 curread += xread; 875 curread += xread;
887 876
888 // Increase counters, call callback 877 // Increase counters, call callback
889 if (ptp_usb->callback_active) { 878 if (ptp_usb->callback_active) {
890 if (ptp_usb->current_transfer_complete >= ptp_usb->current_transfer_ total) { 879 if (ptp_usb->current_transfer_complete >= ptp_usb->current_transfer_ total) {
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after
1078 if (priv->curoff + tocopy > priv->size) 1067 if (priv->curoff + tocopy > priv->size)
1079 tocopy = priv->size - priv->curoff; 1068 tocopy = priv->size - priv->curoff;
1080 memcpy(data, priv->data + priv->curoff, tocopy); 1069 memcpy(data, priv->data + priv->curoff, tocopy);
1081 priv->curoff += tocopy; 1070 priv->curoff += tocopy;
1082 *gotlen = tocopy; 1071 *gotlen = tocopy;
1083 return PTP_RC_OK; 1072 return PTP_RC_OK;
1084 } 1073 }
1085 1074
1086 static uint16_t 1075 static uint16_t
1087 memory_putfunc(PTPParams* params, void* private, 1076 memory_putfunc(PTPParams* params, void* private,
1088 unsigned long sendlen, unsigned char *data 1077 unsigned long sendlen, unsigned char *data,
1078 unsigned long *putlen
1089 ) { 1079 ) {
1090 PTPMemHandlerPrivate* priv = (PTPMemHandlerPrivate*) private; 1080 PTPMemHandlerPrivate* priv = (PTPMemHandlerPrivate*) private;
1091 1081
1092 if (priv->curoff + sendlen > priv->size) { 1082 if (priv->curoff + sendlen > priv->size) {
1093 priv->data = realloc(priv->data, priv->curoff + sendlen); 1083 priv->data = realloc(priv->data, priv->curoff + sendlen);
1094 priv->size = priv->curoff + sendlen; 1084 priv->size = priv->curoff + sendlen;
1095 } 1085 }
1096 memcpy(priv->data + priv->curoff, data, sendlen); 1086 memcpy(priv->data + priv->curoff, data, sendlen);
1097 priv->curoff += sendlen; 1087 priv->curoff += sendlen;
1088 *putlen = sendlen;
1098 return PTP_RC_OK; 1089 return PTP_RC_OK;
1099 } 1090 }
1100 1091
1101 /* init private struct for receiving data. */ 1092 /* init private struct for receiving data. */
1102 static uint16_t 1093 static uint16_t
1103 ptp_init_recv_memory_handler(PTPDataHandler *handler) { 1094 ptp_init_recv_memory_handler(PTPDataHandler *handler) {
1104 PTPMemHandlerPrivate* priv; 1095 PTPMemHandlerPrivate* priv;
1105 priv = malloc(sizeof (PTPMemHandlerPrivate)); 1096 priv = malloc(sizeof (PTPMemHandlerPrivate));
1106 handler->priv = priv; 1097 handler->priv = priv;
1107 handler->getfunc = memory_getfunc; 1098 handler->getfunc = memory_getfunc;
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
1150 PTPMemHandlerPrivate* priv = (PTPMemHandlerPrivate*) handler->priv; 1141 PTPMemHandlerPrivate* priv = (PTPMemHandlerPrivate*) handler->priv;
1151 *data = priv->data; 1142 *data = priv->data;
1152 *size = priv->size; 1143 *size = priv->size;
1153 free(priv); 1144 free(priv);
1154 return PTP_RC_OK; 1145 return PTP_RC_OK;
1155 } 1146 }
1156 1147
1157 /* send / receive functions */ 1148 /* send / receive functions */
1158 1149
1159 uint16_t 1150 uint16_t
1160 ptp_usb_sendreq(PTPParams* params, PTPContainer* req, int dataphase) { 1151 ptp_usb_sendreq(PTPParams* params, PTPContainer* req) {
1161 uint16_t ret; 1152 uint16_t ret;
1162 PTPUSBBulkContainer usbreq; 1153 PTPUSBBulkContainer usbreq;
1163 PTPDataHandler memhandler; 1154 PTPDataHandler memhandler;
1164 unsigned long written = 0; 1155 unsigned long written = 0;
1165 unsigned long towrite; 1156 unsigned long towrite;
1166 1157
1167 char txt[256]; 1158 char txt[256];
1168 1159
1169 (void) ptp_render_ofc(params, req->Code, sizeof (txt), txt); 1160 (void) ptp_render_opcode(params, req->Code, sizeof (txt), txt);
1170 LIBMTP_USB_DEBUG("REQUEST: 0x%04x, %s\n", req->Code, txt); 1161 LIBMTP_USB_DEBUG("REQUEST: 0x%04x, %s\n", req->Code, txt);
1171 1162
1172 /* build appropriate USB container */ 1163 /* build appropriate USB container */
1173 usbreq.length = htod32(PTP_USB_BULK_REQ_LEN - 1164 usbreq.length = htod32(PTP_USB_BULK_REQ_LEN -
1174 (sizeof (uint32_t)*(5 - req->Nparam))); 1165 (sizeof (uint32_t)*(5 - req->Nparam)));
1175 usbreq.type = htod16(PTP_USB_CONTAINER_COMMAND); 1166 usbreq.type = htod16(PTP_USB_CONTAINER_COMMAND);
1176 usbreq.code = htod16(req->Code); 1167 usbreq.code = htod16(req->Code);
1177 usbreq.trans_id = htod32(req->Transaction_ID); 1168 usbreq.trans_id = htod32(req->Transaction_ID);
1178 usbreq.payload.params.param1 = htod32(req->Param1); 1169 usbreq.payload.params.param1 = htod32(req->Param1);
1179 usbreq.payload.params.param2 = htod32(req->Param2); 1170 usbreq.payload.params.param2 = htod32(req->Param2);
(...skipping 18 matching lines...) Expand all
1198 "PTP: request code 0x%04x sending req wrote only %ld bytes inste ad of %d", 1189 "PTP: request code 0x%04x sending req wrote only %ld bytes inste ad of %d",
1199 req->Code, written, towrite 1190 req->Code, written, towrite
1200 ); 1191 );
1201 ret = PTP_ERROR_IO; 1192 ret = PTP_ERROR_IO;
1202 } 1193 }
1203 return ret; 1194 return ret;
1204 } 1195 }
1205 1196
1206 uint16_t 1197 uint16_t
1207 ptp_usb_senddata(PTPParams* params, PTPContainer* ptp, 1198 ptp_usb_senddata(PTPParams* params, PTPContainer* ptp,
1208 uint64_t size, PTPDataHandler *handler 1199 unsigned long size, PTPDataHandler *handler
1209 ) { 1200 ) {
1210 uint16_t ret; 1201 uint16_t ret;
1211 int wlen, datawlen; 1202 int wlen, datawlen;
1212 unsigned long written; 1203 unsigned long written;
1213 PTPUSBBulkContainer usbdata; 1204 PTPUSBBulkContainer usbdata;
1214 uint64_t bytes_left_to_transfer; 1205 uint32_t bytes_left_to_transfer;
1215 PTPDataHandler memhandler; 1206 PTPDataHandler memhandler;
1216 1207
1217 LIBMTP_USB_DEBUG("SEND DATA PHASE\n"); 1208 LIBMTP_USB_DEBUG("SEND DATA PHASE\n");
1218 1209
1219 /* build appropriate USB container */ 1210 /* build appropriate USB container */
1220 usbdata.length = htod32(PTP_USB_BULK_HDR_LEN + size); 1211 usbdata.length = htod32(PTP_USB_BULK_HDR_LEN + size);
1221 usbdata.type = htod16(PTP_USB_CONTAINER_DATA); 1212 usbdata.type = htod16(PTP_USB_CONTAINER_DATA);
1222 usbdata.code = htod16(ptp->Code); 1213 usbdata.code = htod16(ptp->Code);
1223 usbdata.trans_id = htod32(ptp->Transaction_ID); 1214 usbdata.trans_id = htod32(ptp->Transaction_ID);
1224 1215
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
1268 if (ret != PTP_RC_OK && ret != PTP_ERROR_CANCEL) 1259 if (ret != PTP_RC_OK && ret != PTP_ERROR_CANCEL)
1269 ret = PTP_ERROR_IO; 1260 ret = PTP_ERROR_IO;
1270 return ret; 1261 return ret;
1271 } 1262 }
1272 1263
1273 static uint16_t ptp_usb_getpacket(PTPParams *params, 1264 static uint16_t ptp_usb_getpacket(PTPParams *params,
1274 PTPUSBBulkContainer *packet, unsigned long *rlen) { 1265 PTPUSBBulkContainer *packet, unsigned long *rlen) {
1275 PTPDataHandler memhandler; 1266 PTPDataHandler memhandler;
1276 uint16_t ret; 1267 uint16_t ret;
1277 unsigned char *x = NULL; 1268 unsigned char *x = NULL;
1278 unsigned long packet_size;
1279 PTP_USB *ptp_usb = (PTP_USB *) params->data;
1280
1281 packet_size = ptp_usb->inep_maxpacket;
1282 1269
1283 /* read the header and potentially the first data */ 1270 /* read the header and potentially the first data */
1284 if (params->response_packet_size > 0) { 1271 if (params->response_packet_size > 0) {
1285 /* If there is a buffered packet, just use it. */ 1272 /* If there is a buffered packet, just use it. */
1286 memcpy(packet, params->response_packet, params->response_packet_size); 1273 memcpy(packet, params->response_packet, params->response_packet_size);
1287 *rlen = params->response_packet_size; 1274 *rlen = params->response_packet_size;
1288 free(params->response_packet); 1275 free(params->response_packet);
1289 params->response_packet = NULL; 1276 params->response_packet = NULL;
1290 params->response_packet_size = 0; 1277 params->response_packet_size = 0;
1291 /* Here this signifies a "virtual read" */ 1278 /* Here this signifies a "virtual read" */
1292 return PTP_RC_OK; 1279 return PTP_RC_OK;
1293 } 1280 }
1294 ptp_init_recv_memory_handler(&memhandler); 1281 ptp_init_recv_memory_handler(&memhandler);
1295 ret = ptp_read_func(packet_size, &memhandler, params->data, rlen, 0); 1282 ret = ptp_read_func(PTP_USB_BULK_HS_MAX_PACKET_LEN_READ, &memhandler, params ->data, rlen, 0);
1296 ptp_exit_recv_memory_handler(&memhandler, &x, rlen); 1283 ptp_exit_recv_memory_handler(&memhandler, &x, rlen);
1297 if (x) { 1284 if (x) {
1298 memcpy(packet, x, *rlen); 1285 memcpy(packet, x, *rlen);
1299 free(x); 1286 free(x);
1300 } 1287 }
1301 return ret; 1288 return ret;
1302 } 1289 }
1303 1290
1304 uint16_t 1291 uint16_t
1305 ptp_usb_getdata(PTPParams* params, PTPContainer* ptp, PTPDataHandler *handler) { 1292 ptp_usb_getdata(PTPParams* params, PTPContainer* ptp, PTPDataHandler *handler) {
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
1342 // getting data. It appears Windows ignores the contents of this 1329 // getting data. It appears Windows ignores the contents of this
1343 // field entirely. 1330 // field entirely.
1344 if (ret < PTP_RC_Undefined || ret > PTP_RC_SpecificationOfDestin ationUnsupported) { 1331 if (ret < PTP_RC_Undefined || ret > PTP_RC_SpecificationOfDestin ationUnsupported) {
1345 libusb_glue_debug(params, "ptp2/ptp_usb_getdata: detected a broken " 1332 libusb_glue_debug(params, "ptp2/ptp_usb_getdata: detected a broken "
1346 "PTP header, code field insane."); 1333 "PTP header, code field insane.");
1347 ret = PTP_ERROR_IO; 1334 ret = PTP_ERROR_IO;
1348 } 1335 }
1349 break; 1336 break;
1350 } 1337 }
1351 } 1338 }
1352 if (rlen == ptp_usb->inep_maxpacket) { 1339 if (usbdata.length == 0xffffffffU) {
1353 /* Copy first part of data to 'data' */ 1340 /* Copy first part of data to 'data' */
1354 putfunc_ret = 1341 putfunc_ret =
1355 handler->putfunc( 1342 handler->putfunc(
1356 params, handler->priv, rlen - PTP_USB_BULK_HDR_LEN, usbdata. payload.data 1343 params, handler->priv, rlen - PTP_USB_BULK_HDR_LEN, usbdata. payload.data,
1344 &written
1357 ); 1345 );
1358 if (putfunc_ret != PTP_RC_OK) 1346 if (putfunc_ret != PTP_RC_OK)
1359 return putfunc_ret; 1347 return putfunc_ret;
1360 1348
1361 /* stuff data directly to passed data handler */ 1349 /* stuff data directly to passed data handler */
1362 while (1) { 1350 while (1) {
1363 unsigned long readdata; 1351 unsigned long readdata;
1364 uint16_t xret; 1352 uint16_t xret;
1365 1353
1366 xret = ptp_read_func( 1354 xret = ptp_read_func(
1367 0x20000000, 1355 PTP_USB_BULK_HS_MAX_PACKET_LEN_READ,
1368 handler, 1356 handler,
1369 params->data, 1357 params->data,
1370 &readdata, 1358 &readdata,
1371 0 1359 0
1372 ); 1360 );
1373 if (xret != PTP_RC_OK) 1361 if (xret != PTP_RC_OK)
1374 return xret; 1362 return xret;
1375 if (readdata < 0x20000000) 1363 if (readdata < PTP_USB_BULK_HS_MAX_PACKET_LEN_READ)
1376 break; 1364 break;
1377 } 1365 }
1378 return PTP_RC_OK; 1366 return PTP_RC_OK;
1379 } 1367 }
1380 if (rlen > dtoh32(usbdata.length)) { 1368 if (rlen > dtoh32(usbdata.length)) {
1381 /* 1369 /*
1382 * Buffer the surplus response packet if it is >= 1370 * Buffer the surplus response packet if it is >=
1383 * PTP_USB_BULK_HDR_LEN 1371 * PTP_USB_BULK_HDR_LEN
1384 * (i.e. it is probably an entire package) 1372 * (i.e. it is probably an entire package)
1385 * else discard it as erroneous surplus data. 1373 * else discard it as erroneous surplus data.
(...skipping 30 matching lines...) Expand all
1416 len = dtoh32(usbdata.length) - PTP_USB_BULK_HDR_LEN; 1404 len = dtoh32(usbdata.length) - PTP_USB_BULK_HDR_LEN;
1417 1405
1418 /* autodetect split header/data MTP devices */ 1406 /* autodetect split header/data MTP devices */
1419 if (dtoh32(usbdata.length) > 12 && (rlen == 12)) 1407 if (dtoh32(usbdata.length) > 12 && (rlen == 12))
1420 params->split_header_data = 1; 1408 params->split_header_data = 1;
1421 1409
1422 /* Copy first part of data to 'data' */ 1410 /* Copy first part of data to 'data' */
1423 putfunc_ret = 1411 putfunc_ret =
1424 handler->putfunc( 1412 handler->putfunc(
1425 params, handler->priv, rlen - PTP_USB_BULK_HDR_LEN, 1413 params, handler->priv, rlen - PTP_USB_BULK_HDR_LEN,
1426 usbdata.payload.data 1414 usbdata.payload.data,
1415 &written
1427 ); 1416 );
1428 if (putfunc_ret != PTP_RC_OK) 1417 if (putfunc_ret != PTP_RC_OK)
1429 return putfunc_ret; 1418 return putfunc_ret;
1430 1419
1431 if (FLAG_NO_ZERO_READS(ptp_usb) && 1420 if (FLAG_NO_ZERO_READS(ptp_usb) &&
1432 len + PTP_USB_BULK_HDR_LEN == ptp_usb->inep_maxpacket) { 1421 len + PTP_USB_BULK_HDR_LEN == PTP_USB_BULK_HS_MAX_PACKET_LEN_REA D) {
1433 1422
1434 LIBMTP_USB_DEBUG("Reading in extra terminating byte\n"); 1423 LIBMTP_USB_DEBUG("Reading in extra terminating byte\n");
1435 1424
1436 // need to read in extra byte and discard it 1425 // need to read in extra byte and discard it
1437 int result = 0, xread; 1426 int result = 0, xread;
1438 unsigned char byte = 0; 1427 unsigned char byte = 0;
1439 1428
1440 /* 1429 /*
1441 result = USB_BULK_READ(ptp_usb->handle, 1430 result = USB_BULK_READ(ptp_usb->handle,
1442 ptp_usb->inep, 1431 ptp_usb->inep,
1443 &byte, 1432 &byte,
1444 1, 1433 1,
1445 &xread, 1434 &xread,
1446 ptp_usb->timeout); 1435 ptp_usb->timeout);
1447 */ 1436 */
1448 1437
1449 bulk.payload = &byte; 1438 bulk.payload = &byte;
1450 bulk.length = 1; 1439 bulk.length = 1;
1451 bulk.timeout = ptp_usb->timeout; 1440 bulk.timeout = ptp_usb->timeout;
1452 bulk.flags = 0; 1441 bulk.flags = 0;
1453 bulk.next = NULL; 1442 bulk.next = NULL;
1454 result = openusb_bulk_xfer(*ptp_usb->handle, ptp_usb->interface, ptp _usb->inep, &bulk); 1443 result = openusb_bulk_xfer(*ptp_usb->handle, ptp_usb->interface, ptp _usb->inep, &bulk);
1455 xread = bulk.result.transferred_bytes; 1444 xread = bulk.result.transferred_bytes;
1456 1445
1457 if (result != 1) 1446 if (result != 1)
1458 LIBMTP_INFO("Could not read in extra byte for %d bytes long file , return value 0x%04x\n", ptp_usb->inep_maxpacket, result); 1447 LIBMTP_INFO("Could not read in extra byte for PTP_USB_BULK_HS_MA X_PACKET_LEN_READ long file, return value 0x%04x\n", result);
1459 } else if (len + PTP_USB_BULK_HDR_LEN == ptp_usb->inep_maxpacket && para ms->split_header_data == 0) { 1448 } else if (len + PTP_USB_BULK_HDR_LEN == PTP_USB_BULK_HS_MAX_PACKET_LEN_ READ && params->split_header_data == 0) {
1460 int zeroresult = 0, xread; 1449 int zeroresult = 0, xread;
1461 unsigned char zerobyte = 0; 1450 unsigned char zerobyte = 0;
1462 1451
1463 LIBMTP_INFO("Reading in zero packet after header\n"); 1452 LIBMTP_INFO("Reading in zero packet after header\n");
1464 /* 1453 /*
1465 zeroresult = USB_BULK_READ(ptp_usb->handle, 1454 zeroresult = USB_BULK_READ(ptp_usb->handle,
1466 ptp_usb->inep, 1455 ptp_usb->inep,
1467 &zerobyte, 1456 &zerobyte,
1468 0, 1457 0,
1469 &xread, 1458 &xread,
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after
1685 return ptp_usb_event(params, event, PTP_EVENT_CHECK_FAST); 1674 return ptp_usb_event(params, event, PTP_EVENT_CHECK_FAST);
1686 } 1675 }
1687 1676
1688 uint16_t 1677 uint16_t
1689 ptp_usb_event_wait(PTPParams* params, PTPContainer* event) { 1678 ptp_usb_event_wait(PTPParams* params, PTPContainer* event) {
1690 1679
1691 return ptp_usb_event(params, event, PTP_EVENT_CHECK); 1680 return ptp_usb_event(params, event, PTP_EVENT_CHECK);
1692 } 1681 }
1693 1682
1694 uint16_t 1683 uint16_t
1695 ptp_usb_event_async (PTPParams* params, PTPEventCbFn cb, void *user_data) {
1696 /* Unsupported */
1697 return PTP_ERROR_CANCEL;
1698 }
1699
1700 int LIBMTP_Handle_Events_Timeout_Completed(struct timeval *tv, int *completed) {
1701 /* Unsupported */
1702 return -12;
1703 }
1704
1705 uint16_t
1706 ptp_usb_control_cancel_request(PTPParams *params, uint32_t transactionid) { 1684 ptp_usb_control_cancel_request(PTPParams *params, uint32_t transactionid) {
1707 PTP_USB *ptp_usb = (PTP_USB *) (params->data); 1685 PTP_USB *ptp_usb = (PTP_USB *) (params->data);
1708 int ret; 1686 int ret;
1709 unsigned char buffer[6]; 1687 unsigned char buffer[6];
1710 1688
1711 htod16a(&buffer[0], PTP_EC_CancelTransaction); 1689 htod16a(&buffer[0], PTP_EC_CancelTransaction);
1712 htod32a(&buffer[2], transactionid); 1690 htod32a(&buffer[2], transactionid);
1713 /* 1691 /*
1714 ret = libusb_control_transfer(ptp_usb->handle, 1692 ret = libusb_control_transfer(ptp_usb->handle,
1715 LIBUSB_REQUEST_TYPE_CLASS | LIBUSB_RECIPIENT_I NTERFACE, 1693 LIBUSB_REQUEST_TYPE_CLASS | LIBUSB_RECIPIENT_I NTERFACE,
(...skipping 526 matching lines...) Expand 10 before | Expand all | Expand 10 after
2242 ctrl.timeout = ptp_usb->timeout; 2220 ctrl.timeout = ptp_usb->timeout;
2243 ctrl.next = NULL; 2221 ctrl.next = NULL;
2244 ctrl.setup.bRequest = USB_REQ_GET_STATUS; 2222 ctrl.setup.bRequest = USB_REQ_GET_STATUS;
2245 ctrl.setup.bmRequestType = USB_ENDPOINT_IN | USB_RECIP_ENDPOINT; 2223 ctrl.setup.bmRequestType = USB_ENDPOINT_IN | USB_RECIP_ENDPOINT;
2246 ctrl.setup.wIndex = ep; 2224 ctrl.setup.wIndex = ep;
2247 ctrl.setup.wValue = USB_FEATURE_HALT; 2225 ctrl.setup.wValue = USB_FEATURE_HALT;
2248 openusb_ctrl_xfer(*ptp_usb->handle, ptp_usb->interface, ep, &ctrl); 2226 openusb_ctrl_xfer(*ptp_usb->handle, ptp_usb->interface, ep, &ctrl);
2249 return ctrl.result.status; 2227 return ctrl.result.status;
2250 2228
2251 } 2229 }
OLDNEW
« no previous file with comments | « src/libmtp.h.in ('k') | src/libusb-glue.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698