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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « src/libopenusb1-glue.c ('k') | src/libusb1-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 libusb-glue.c 2 * \file libusb-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-2007 Marcus Meissner 7 * Copyright (C) 2006-2007 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 658 matching lines...) Expand 10 before | Expand all | Expand 10 after
669 LIBMTP_ERROR("Device %d (VID=%04x and PID=%04x) is a %s %s.\n", 669 LIBMTP_ERROR("Device %d (VID=%04x and PID=%04x) is a %s %s.\n",
670 i, 670 i,
671 dev->libusb_device->descriptor.idVendor, 671 dev->libusb_device->descriptor.idVendor,
672 dev->libusb_device->descriptor.idProduct, 672 dev->libusb_device->descriptor.idProduct,
673 mtp_device_table[j].vendor, 673 mtp_device_table[j].vendor,
674 mtp_device_table[j].product); 674 mtp_device_table[j].product);
675 break; 675 break;
676 } 676 }
677 } 677 }
678 if (!device_known) { 678 if (!device_known) {
679 // This device is unknown to the developers 679 device_unknown(i,
680 LIBMTP_ERROR("Device %d (VID=%04x and PID=%04x) is UNKNOWN.\n", 680 dev->libusb_device->descriptor.idVendor,
681 » i, 681 dev->libusb_device->descriptor.idProduct);
682 » dev->libusb_device->descriptor.idVendor,
683 » dev->libusb_device->descriptor.idProduct);
684 LIBMTP_ERROR("Please report this VID/PID and the device model to the "
685 » "libmtp development team\n");
686 /*
687 * Trying to get iManufacturer or iProduct from the device at this
688 * point would require opening a device handle, that we don't want
689 * to do right now. (Takes time for no good enough reason.)
690 */
691 } 682 }
692 // Save the location on the bus 683 // Save the location on the bus
693 retdevs[i].bus_location = dev->bus_location; 684 retdevs[i].bus_location = dev->bus_location;
694 retdevs[i].devnum = dev->libusb_device->devnum; 685 retdevs[i].devnum = dev->libusb_device->devnum;
695 i++; 686 i++;
696 dev = dev->next; 687 dev = dev->next;
697 } 688 }
698 *devices = retdevs; 689 *devices = retdevs;
699 *numdevs = i; 690 *numdevs = i;
700 free_mtpdevice_list(devlist); 691 free_mtpdevice_list(devlist);
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
814 * 5. Send remaining bytes. If this happens to be exactly sizeof(endpoint) 805 * 5. Send remaining bytes. If this happens to be exactly sizeof(endpoint)
815 * then also send a zero-length package. 806 * then also send a zero-length package.
816 * 807 *
817 * Further there is some special quirks to handle zero reads from the 808 * Further there is some special quirks to handle zero reads from the
818 * device, since some devices can't do them at all due to shortcomings 809 * device, since some devices can't do them at all due to shortcomings
819 * of the USB slave controller in the device. 810 * of the USB slave controller in the device.
820 */ 811 */
821 #define CONTEXT_BLOCK_SIZE_1 0x3e00 812 #define CONTEXT_BLOCK_SIZE_1 0x3e00
822 #define CONTEXT_BLOCK_SIZE_2 0x200 813 #define CONTEXT_BLOCK_SIZE_2 0x200
823 #define CONTEXT_BLOCK_SIZE CONTEXT_BLOCK_SIZE_1+CONTEXT_BLOCK_SIZE_2 814 #define CONTEXT_BLOCK_SIZE CONTEXT_BLOCK_SIZE_1+CONTEXT_BLOCK_SIZE_2
815
824 static short 816 static short
825 ptp_read_func ( 817 ptp_read_func (
826 unsigned long size, PTPDataHandler *handler,void *data, 818 unsigned long size, PTPDataHandler *handler,void *data,
827 unsigned long *readbytes, 819 unsigned long *readbytes,
828 int readzero 820 int readzero
829 ) { 821 ) {
830 PTP_USB *ptp_usb = (PTP_USB *)data; 822 PTP_USB *ptp_usb = (PTP_USB *)data;
831 unsigned long toread = 0; 823 unsigned long toread = 0;
832 int result = 0; 824 int result = 0;
833 unsigned long curread = 0; 825 unsigned long curread = 0;
834 unsigned long written;
835 unsigned char *bytes; 826 unsigned char *bytes;
836 int expect_terminator_byte = 0; 827 int expect_terminator_byte = 0;
828 unsigned long usb_inep_maxpacket_size;
829 unsigned long context_block_size_1;
830 unsigned long context_block_size_2;
831 uint16_t ptp_dev_vendor_id = ptp_usb->rawdevice.device_entry.vendor_id;
832
833 //"iRiver" device special handling
834 if (ptp_dev_vendor_id == 0x4102 || ptp_dev_vendor_id == 0x1006) {
835 usb_inep_maxpacket_size = ptp_usb->inep_maxpacket;
836 if (usb_inep_maxpacket_size == 0x400) {
837 context_block_size_1 = CONTEXT_BLOCK_SIZE_1 - 0x200;
838 context_block_size_2 = CONTEXT_BLOCK_SIZE_2 + 0x200;
839 }
840 else {
841 context_block_size_1 = CONTEXT_BLOCK_SIZE_1;
842 context_block_size_2 = CONTEXT_BLOCK_SIZE_2;
843 }
844 }
837 845
838 // This is the largest block we'll need to read in. 846 // This is the largest block we'll need to read in.
839 bytes = malloc(CONTEXT_BLOCK_SIZE); 847 bytes = malloc(CONTEXT_BLOCK_SIZE);
840 while (curread < size) { 848 while (curread < size) {
841 849
842 LIBMTP_USB_DEBUG("Remaining size to read: 0x%04lx bytes\n", size - curread); 850 LIBMTP_USB_DEBUG("Remaining size to read: 0x%04lx bytes\n", size - curread);
843 851
844 // check equal to condition here 852 // check equal to condition here
845 if (size - curread < CONTEXT_BLOCK_SIZE) 853 if (size - curread < CONTEXT_BLOCK_SIZE)
846 { 854 {
847 // this is the last packet 855 // this is the last packet
848 toread = size - curread; 856 toread = size - curread;
849 // this is equivalent to zero read for these devices 857 // this is equivalent to zero read for these devices
850 if (readzero && FLAG_NO_ZERO_READS(ptp_usb) && toread % 64 == 0) { 858 if (readzero && FLAG_NO_ZERO_READS(ptp_usb) && toread % 64 == 0) {
851 toread += 1; 859 toread += 1;
852 expect_terminator_byte = 1; 860 expect_terminator_byte = 1;
853 } 861 }
854 } 862 }
855 else if (curread == 0) 863 else if (ptp_dev_vendor_id == 0x4102 || ptp_dev_vendor_id == 0x1006) {
856 // we are first packet, but not last packet 864 » //"iRiver" device special handling
857 toread = CONTEXT_BLOCK_SIZE_1; 865 » if (curread == 0)
858 else if (toread == CONTEXT_BLOCK_SIZE_1) 866 » » // we are first packet, but not last packet
859 toread = CONTEXT_BLOCK_SIZE_2; 867 » » toread = context_block_size_1;
860 else if (toread == CONTEXT_BLOCK_SIZE_2) 868 » else if (toread == context_block_size_1)
861 toread = CONTEXT_BLOCK_SIZE_1; 869 » » toread = context_block_size_2;
862 else 870 » else if (toread == context_block_size_2)
863 LIBMTP_INFO("unexpected toread size 0x%04x, 0x%04x remaining bytes\n", 871 » » toread = context_block_size_1;
864 » (unsigned int) toread, (unsigned int) (size-curread)); 872 » else
873 » » LIBMTP_INFO("unexpected toread size 0x%04x, 0x%04x remaining bytes\n",
874 » » » » (unsigned int) toread, (unsigned int) (size-curr ead));
875
876 } else
877 » toread = CONTEXT_BLOCK_SIZE;
865 878
866 LIBMTP_USB_DEBUG("Reading in 0x%04lx bytes\n", toread); 879 LIBMTP_USB_DEBUG("Reading in 0x%04lx bytes\n", toread);
867 880
868 result = USB_BULK_READ(ptp_usb->handle, 881 result = USB_BULK_READ(ptp_usb->handle,
869 ptp_usb->inep, 882 ptp_usb->inep,
870 (char*) bytes, 883 (char*) bytes,
871 toread, 884 toread,
872 ptp_usb->timeout); 885 ptp_usb->timeout);
873 886
874 LIBMTP_USB_DEBUG("Result of read: 0x%04x\n", result); 887 LIBMTP_USB_DEBUG("Result of read: 0x%04x\n", result);
875 888
876 if (result < 0) { 889 if (result < 0) {
877 return PTP_ERROR_IO; 890 return PTP_ERROR_IO;
878 } 891 }
879 892
880 LIBMTP_USB_DEBUG("<==USB IN\n"); 893 LIBMTP_USB_DEBUG("<==USB IN\n");
881 if (result == 0) 894 if (result == 0)
882 LIBMTP_USB_DEBUG("Zero Read\n"); 895 LIBMTP_USB_DEBUG("Zero Read\n");
883 else 896 else
884 LIBMTP_USB_DATA(bytes, result, 16); 897 LIBMTP_USB_DATA(bytes, result, 16);
885 898
886 // want to discard extra byte 899 // want to discard extra byte
887 if (expect_terminator_byte && result == toread) 900 if (expect_terminator_byte && result == toread)
888 { 901 {
889 LIBMTP_USB_DEBUG("<==USB IN\nDiscarding extra byte\n"); 902 LIBMTP_USB_DEBUG("<==USB IN\nDiscarding extra byte\n");
890 903
891 result--; 904 result--;
892 } 905 }
893 906
894 int putfunc_ret = handler->putfunc(NULL, handler->priv, result, bytes, &writ ten); 907 int putfunc_ret = handler->putfunc(NULL, handler->priv, result, bytes);
895 if (putfunc_ret != PTP_RC_OK) 908 if (putfunc_ret != PTP_RC_OK)
896 return putfunc_ret; 909 return putfunc_ret;
897 910
898 ptp_usb->current_transfer_complete += result; 911 ptp_usb->current_transfer_complete += result;
899 curread += result; 912 curread += result;
900 913
901 // Increase counters, call callback 914 // Increase counters, call callback
902 if (ptp_usb->callback_active) { 915 if (ptp_usb->callback_active) {
903 if (ptp_usb->current_transfer_complete >= ptp_usb->current_transfer_total) { 916 if (ptp_usb->current_transfer_complete >= ptp_usb->current_transfer_total) {
904 // send last update and disable callback. 917 // send last update and disable callback.
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
1057 if (priv->curoff + tocopy > priv->size) 1070 if (priv->curoff + tocopy > priv->size)
1058 tocopy = priv->size - priv->curoff; 1071 tocopy = priv->size - priv->curoff;
1059 memcpy (data, priv->data + priv->curoff, tocopy); 1072 memcpy (data, priv->data + priv->curoff, tocopy);
1060 priv->curoff += tocopy; 1073 priv->curoff += tocopy;
1061 *gotlen = tocopy; 1074 *gotlen = tocopy;
1062 return PTP_RC_OK; 1075 return PTP_RC_OK;
1063 } 1076 }
1064 1077
1065 static uint16_t 1078 static uint16_t
1066 memory_putfunc(PTPParams* params, void* private, 1079 memory_putfunc(PTPParams* params, void* private,
1067 » unsigned long sendlen, unsigned char *data, 1080 » unsigned long sendlen, unsigned char *data
1068 » unsigned long *putlen
1069 ) { 1081 ) {
1070 PTPMemHandlerPrivate* priv = (PTPMemHandlerPrivate*)private; 1082 PTPMemHandlerPrivate* priv = (PTPMemHandlerPrivate*)private;
1071 1083
1072 if (priv->curoff + sendlen > priv->size) { 1084 if (priv->curoff + sendlen > priv->size) {
1073 priv->data = realloc (priv->data, priv->curoff+sendlen); 1085 priv->data = realloc (priv->data, priv->curoff+sendlen);
1074 priv->size = priv->curoff + sendlen; 1086 priv->size = priv->curoff + sendlen;
1075 } 1087 }
1076 memcpy (priv->data + priv->curoff, data, sendlen); 1088 memcpy (priv->data + priv->curoff, data, sendlen);
1077 priv->curoff += sendlen; 1089 priv->curoff += sendlen;
1078 *putlen = sendlen;
1079 return PTP_RC_OK; 1090 return PTP_RC_OK;
1080 } 1091 }
1081 1092
1082 /* init private struct for receiving data. */ 1093 /* init private struct for receiving data. */
1083 static uint16_t 1094 static uint16_t
1084 ptp_init_recv_memory_handler(PTPDataHandler *handler) { 1095 ptp_init_recv_memory_handler(PTPDataHandler *handler) {
1085 PTPMemHandlerPrivate* priv; 1096 PTPMemHandlerPrivate* priv;
1086 priv = malloc (sizeof(PTPMemHandlerPrivate)); 1097 priv = malloc (sizeof(PTPMemHandlerPrivate));
1087 handler->priv = priv; 1098 handler->priv = priv;
1088 handler->getfunc = memory_getfunc; 1099 handler->getfunc = memory_getfunc;
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
1130 PTPMemHandlerPrivate* priv = (PTPMemHandlerPrivate*)handler->priv; 1141 PTPMemHandlerPrivate* priv = (PTPMemHandlerPrivate*)handler->priv;
1131 *data = priv->data; 1142 *data = priv->data;
1132 *size = priv->size; 1143 *size = priv->size;
1133 free (priv); 1144 free (priv);
1134 return PTP_RC_OK; 1145 return PTP_RC_OK;
1135 } 1146 }
1136 1147
1137 /* send / receive functions */ 1148 /* send / receive functions */
1138 1149
1139 uint16_t 1150 uint16_t
1140 ptp_usb_sendreq (PTPParams* params, PTPContainer* req) 1151 ptp_usb_sendreq (PTPParams* params, PTPContainer* req, int dataphase)
1141 { 1152 {
1142 uint16_t ret; 1153 uint16_t ret;
1143 PTPUSBBulkContainer usbreq; 1154 PTPUSBBulkContainer usbreq;
1144 PTPDataHandler memhandler; 1155 PTPDataHandler memhandler;
1145 unsigned long written = 0; 1156 unsigned long written = 0;
1146 unsigned long towrite; 1157 unsigned long towrite;
1147 1158
1148 char txt[256]; 1159 char txt[256];
1149 1160
1150 » (void) ptp_render_opcode (params, req->Code, sizeof(txt), txt); 1161 » (void) ptp_render_ofc (params, req->Code, sizeof(txt), txt);
1151 LIBMTP_USB_DEBUG("REQUEST: 0x%04x, %s\n", req->Code, txt); 1162 LIBMTP_USB_DEBUG("REQUEST: 0x%04x, %s\n", req->Code, txt);
1152 1163
1153 /* build appropriate USB container */ 1164 /* build appropriate USB container */
1154 usbreq.length=htod32(PTP_USB_BULK_REQ_LEN- 1165 usbreq.length=htod32(PTP_USB_BULK_REQ_LEN-
1155 (sizeof(uint32_t)*(5-req->Nparam))); 1166 (sizeof(uint32_t)*(5-req->Nparam)));
1156 usbreq.type=htod16(PTP_USB_CONTAINER_COMMAND); 1167 usbreq.type=htod16(PTP_USB_CONTAINER_COMMAND);
1157 usbreq.code=htod16(req->Code); 1168 usbreq.code=htod16(req->Code);
1158 usbreq.trans_id=htod32(req->Transaction_ID); 1169 usbreq.trans_id=htod32(req->Transaction_ID);
1159 usbreq.payload.params.param1=htod32(req->Param1); 1170 usbreq.payload.params.param1=htod32(req->Param1);
1160 usbreq.payload.params.param2=htod32(req->Param2); 1171 usbreq.payload.params.param2=htod32(req->Param2);
(...skipping 18 matching lines...) Expand all
1179 "PTP: request code 0x%04x sending req wrote only %ld byt es instead of %d", 1190 "PTP: request code 0x%04x sending req wrote only %ld byt es instead of %d",
1180 req->Code, written, towrite 1191 req->Code, written, towrite
1181 ); 1192 );
1182 ret = PTP_ERROR_IO; 1193 ret = PTP_ERROR_IO;
1183 } 1194 }
1184 return ret; 1195 return ret;
1185 } 1196 }
1186 1197
1187 uint16_t 1198 uint16_t
1188 ptp_usb_senddata (PTPParams* params, PTPContainer* ptp, 1199 ptp_usb_senddata (PTPParams* params, PTPContainer* ptp,
1189 » » unsigned long size, PTPDataHandler *handler 1200 » » uint64_t size, PTPDataHandler *handler
1190 ) { 1201 ) {
1191 uint16_t ret; 1202 uint16_t ret;
1192 int wlen, datawlen; 1203 int wlen, datawlen;
1193 unsigned long written; 1204 unsigned long written;
1194 PTPUSBBulkContainer usbdata; 1205 PTPUSBBulkContainer usbdata;
1195 » uint32_t bytes_left_to_transfer; 1206 » uint64_t bytes_left_to_transfer;
1196 PTPDataHandler memhandler; 1207 PTPDataHandler memhandler;
1197 1208
1198 1209
1199 LIBMTP_USB_DEBUG("SEND DATA PHASE\n"); 1210 LIBMTP_USB_DEBUG("SEND DATA PHASE\n");
1200 1211
1201 /* build appropriate USB container */ 1212 /* build appropriate USB container */
1202 usbdata.length = htod32(PTP_USB_BULK_HDR_LEN+size); 1213 usbdata.length = htod32(PTP_USB_BULK_HDR_LEN+size);
1203 usbdata.type = htod16(PTP_USB_CONTAINER_DATA); 1214 usbdata.type = htod16(PTP_USB_CONTAINER_DATA);
1204 usbdata.code = htod16(ptp->Code); 1215 usbdata.code = htod16(ptp->Code);
1205 usbdata.trans_id= htod32(ptp->Transaction_ID); 1216 usbdata.trans_id= htod32(ptp->Transaction_ID);
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
1247 ret = PTP_ERROR_IO; 1258 ret = PTP_ERROR_IO;
1248 return ret; 1259 return ret;
1249 } 1260 }
1250 1261
1251 static uint16_t ptp_usb_getpacket(PTPParams *params, 1262 static uint16_t ptp_usb_getpacket(PTPParams *params,
1252 PTPUSBBulkContainer *packet, unsigned long *rlen) 1263 PTPUSBBulkContainer *packet, unsigned long *rlen)
1253 { 1264 {
1254 PTPDataHandler memhandler; 1265 PTPDataHandler memhandler;
1255 uint16_t ret; 1266 uint16_t ret;
1256 unsigned char *x = NULL; 1267 unsigned char *x = NULL;
1268 unsigned long packet_size;
1269 PTP_USB *ptp_usb = (PTP_USB *) params->data;
1270
1271 packet_size = ptp_usb->inep_maxpacket;
1257 1272
1258 /* read the header and potentially the first data */ 1273 /* read the header and potentially the first data */
1259 if (params->response_packet_size > 0) { 1274 if (params->response_packet_size > 0) {
1260 /* If there is a buffered packet, just use it. */ 1275 /* If there is a buffered packet, just use it. */
1261 memcpy(packet, params->response_packet, params->response_packet_ size); 1276 memcpy(packet, params->response_packet, params->response_packet_ size);
1262 *rlen = params->response_packet_size; 1277 *rlen = params->response_packet_size;
1263 free(params->response_packet); 1278 free(params->response_packet);
1264 params->response_packet = NULL; 1279 params->response_packet = NULL;
1265 params->response_packet_size = 0; 1280 params->response_packet_size = 0;
1266 /* Here this signifies a "virtual read" */ 1281 /* Here this signifies a "virtual read" */
1267 return PTP_RC_OK; 1282 return PTP_RC_OK;
1268 } 1283 }
1269 ptp_init_recv_memory_handler (&memhandler); 1284 ptp_init_recv_memory_handler (&memhandler);
1270 » ret = ptp_read_func(PTP_USB_BULK_HS_MAX_PACKET_LEN_READ, &memhandler, pa rams->data, rlen, 0); 1285 » ret = ptp_read_func(packet_size, &memhandler, params->data, rlen, 0);
1271 ptp_exit_recv_memory_handler (&memhandler, &x, rlen); 1286 ptp_exit_recv_memory_handler (&memhandler, &x, rlen);
1272 if (x) { 1287 if (x) {
1273 memcpy (packet, x, *rlen); 1288 memcpy (packet, x, *rlen);
1274 free (x); 1289 free (x);
1275 } 1290 }
1276 return ret; 1291 return ret;
1277 } 1292 }
1278 1293
1279 uint16_t 1294 uint16_t
1280 ptp_usb_getdata (PTPParams* params, PTPContainer* ptp, PTPDataHandler *handler) 1295 ptp_usb_getdata (PTPParams* params, PTPContainer* ptp, PTPDataHandler *handler)
1281 { 1296 {
1282 uint16_t ret; 1297 uint16_t ret;
1283 PTPUSBBulkContainer usbdata; 1298 PTPUSBBulkContainer usbdata;
1284 unsigned long written;
1285 PTP_USB *ptp_usb = (PTP_USB *) params->data; 1299 PTP_USB *ptp_usb = (PTP_USB *) params->data;
1286 int putfunc_ret; 1300 int putfunc_ret;
1287 1301
1288 LIBMTP_USB_DEBUG("GET DATA PHASE\n"); 1302 LIBMTP_USB_DEBUG("GET DATA PHASE\n");
1289 1303
1290 memset(&usbdata,0,sizeof(usbdata)); 1304 memset(&usbdata,0,sizeof(usbdata));
1291 do { 1305 do {
1292 unsigned long len, rlen; 1306 unsigned long len, rlen;
1293 1307
1294 ret = ptp_usb_getpacket(params, &usbdata, &rlen); 1308 ret = ptp_usb_getpacket(params, &usbdata, &rlen);
(...skipping 21 matching lines...) Expand all
1316 // getting data. It appears Windows ignores the contents of this 1330 // getting data. It appears Windows ignores the contents of this
1317 // field entirely. 1331 // field entirely.
1318 if (ret < PTP_RC_Undefined || ret > PTP_RC_Speci ficationOfDestinationUnsupported) { 1332 if (ret < PTP_RC_Undefined || ret > PTP_RC_Speci ficationOfDestinationUnsupported) {
1319 libusb_glue_debug (params, "ptp2/ptp_usb _getdata: detected a broken " 1333 libusb_glue_debug (params, "ptp2/ptp_usb _getdata: detected a broken "
1320 "PTP header, code field insan e."); 1334 "PTP header, code field insan e.");
1321 ret = PTP_ERROR_IO; 1335 ret = PTP_ERROR_IO;
1322 } 1336 }
1323 break; 1337 break;
1324 } 1338 }
1325 } 1339 }
1326 » » if (usbdata.length == 0xffffffffU) { 1340 » » if (rlen == ptp_usb->inep_maxpacket) {
1327 /* Copy first part of data to 'data' */ 1341 /* Copy first part of data to 'data' */
1328 putfunc_ret = 1342 putfunc_ret =
1329 handler->putfunc( 1343 handler->putfunc(
1330 » » » » params, handler->priv, rlen - PTP_USB_BULK_ HDR_LEN, usbdata.payload.data, 1344 » » » » params, handler->priv, rlen - PTP_USB_BULK_ HDR_LEN, usbdata.payload.data
1331 » » » » &written
1332 ); 1345 );
1333 if (putfunc_ret != PTP_RC_OK) 1346 if (putfunc_ret != PTP_RC_OK)
1334 return putfunc_ret; 1347 return putfunc_ret;
1335 1348
1336 /* stuff data directly to passed data handler */ 1349 /* stuff data directly to passed data handler */
1337 while (1) { 1350 while (1) {
1338 unsigned long readdata; 1351 unsigned long readdata;
1339 uint16_t xret; 1352 uint16_t xret;
1340 1353
1341 xret = ptp_read_func( 1354 xret = ptp_read_func(
1342 » » » » » PTP_USB_BULK_HS_MAX_PACKET_LEN_READ, 1355 » » » » » 0x20000000,
1343 handler, 1356 handler,
1344 params->data, 1357 params->data,
1345 &readdata, 1358 &readdata,
1346 0 1359 0
1347 ); 1360 );
1348 if (xret != PTP_RC_OK) 1361 if (xret != PTP_RC_OK)
1349 return xret; 1362 return xret;
1350 » » if (readdata < PTP_USB_BULK_HS_MAX_PACKET_LEN_READ) 1363 » » if (readdata < 0x20000000)
1351 break; 1364 break;
1352 } 1365 }
1353 return PTP_RC_OK; 1366 return PTP_RC_OK;
1354 } 1367 }
1355 if (rlen > dtoh32(usbdata.length)) { 1368 if (rlen > dtoh32(usbdata.length)) {
1356 /* 1369 /*
1357 * Buffer the surplus response packet if it is >= 1370 * Buffer the surplus response packet if it is >=
1358 * PTP_USB_BULK_HDR_LEN 1371 * PTP_USB_BULK_HDR_LEN
1359 * (i.e. it is probably an entire package) 1372 * (i.e. it is probably an entire package)
1360 * else discard it as erroneous surplus data. 1373 * else discard it as erroneous surplus data.
(...skipping 30 matching lines...) Expand all
1391 len=dtoh32(usbdata.length)-PTP_USB_BULK_HDR_LEN; 1404 len=dtoh32(usbdata.length)-PTP_USB_BULK_HDR_LEN;
1392 1405
1393 /* autodetect split header/data MTP devices */ 1406 /* autodetect split header/data MTP devices */
1394 if (dtoh32(usbdata.length) > 12 && (rlen==12)) 1407 if (dtoh32(usbdata.length) > 12 && (rlen==12))
1395 params->split_header_data = 1; 1408 params->split_header_data = 1;
1396 1409
1397 /* Copy first part of data to 'data' */ 1410 /* Copy first part of data to 'data' */
1398 putfunc_ret = 1411 putfunc_ret =
1399 handler->putfunc( 1412 handler->putfunc(
1400 params, handler->priv, rlen - PTP_USB_BULK_HD R_LEN, 1413 params, handler->priv, rlen - PTP_USB_BULK_HD R_LEN,
1401 » » » » usbdata.payload.data, 1414 » » » » usbdata.payload.data
1402 » » » » &written
1403 ); 1415 );
1404 if (putfunc_ret != PTP_RC_OK) 1416 if (putfunc_ret != PTP_RC_OK)
1405 return putfunc_ret; 1417 return putfunc_ret;
1406 1418
1407 if (FLAG_NO_ZERO_READS(ptp_usb) && 1419 if (FLAG_NO_ZERO_READS(ptp_usb) &&
1408 » » len+PTP_USB_BULK_HDR_LEN == PTP_USB_BULK_HS_MAX_PACKET_LEN_R EAD) { 1420 » » len+PTP_USB_BULK_HDR_LEN == ptp_usb->inep_maxpacket) {
1409 1421
1410 LIBMTP_USB_DEBUG("Reading in extra terminating byte\n"); 1422 LIBMTP_USB_DEBUG("Reading in extra terminating byte\n");
1411 1423
1412 // need to read in extra byte and discard it 1424 // need to read in extra byte and discard it
1413 int result = 0; 1425 int result = 0;
1414 char byte = 0; 1426 char byte = 0;
1415 result = USB_BULK_READ(ptp_usb->handle, 1427 result = USB_BULK_READ(ptp_usb->handle,
1416 ptp_usb->inep, 1428 ptp_usb->inep,
1417 &byte, 1429 &byte,
1418 1, 1430 1,
1419 ptp_usb->timeout); 1431 ptp_usb->timeout);
1420 1432
1421 if (result != 1) 1433 if (result != 1)
1422 » » LIBMTP_INFO("Could not read in extra byte for PTP_USB_BULK_H S_MAX_PACKET_LEN_READ long file, return value 0x%04x\n", result); 1434 » » LIBMTP_INFO("Could not read in extra byte for %d bytes long file, return value 0x%04x\n", ptp_usb->inep_maxpacket, result);
1423 » » } else if (len+PTP_USB_BULK_HDR_LEN == PTP_USB_BULK_HS_MAX_PACKE T_LEN_READ && params->split_header_data == 0) { 1435 » » } else if (len+PTP_USB_BULK_HDR_LEN == ptp_usb->inep_maxpacket & & params->split_header_data == 0) {
1424 int zeroresult = 0; 1436 int zeroresult = 0;
1425 char zerobyte = 0; 1437 char zerobyte = 0;
1426 1438
1427 1439
1428 LIBMTP_INFO("Reading in zero packet after header\n"); 1440 LIBMTP_INFO("Reading in zero packet after header\n");
1429 1441
1430 zeroresult = USB_BULK_READ(ptp_usb->handle, 1442 zeroresult = USB_BULK_READ(ptp_usb->handle,
1431 ptp_usb->inep, 1443 ptp_usb->inep,
1432 &zerobyte, 1444 &zerobyte,
1433 0, 1445 0,
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after
1599 return ptp_usb_event (params, event, PTP_EVENT_CHECK_FAST); 1611 return ptp_usb_event (params, event, PTP_EVENT_CHECK_FAST);
1600 } 1612 }
1601 1613
1602 uint16_t 1614 uint16_t
1603 ptp_usb_event_wait (PTPParams* params, PTPContainer* event) { 1615 ptp_usb_event_wait (PTPParams* params, PTPContainer* event) {
1604 1616
1605 return ptp_usb_event (params, event, PTP_EVENT_CHECK); 1617 return ptp_usb_event (params, event, PTP_EVENT_CHECK);
1606 } 1618 }
1607 1619
1608 uint16_t 1620 uint16_t
1621 ptp_usb_event_async (PTPParams* params, PTPEventCbFn cb, void *user_data) {
1622 /* Unsupported */
1623 return PTP_ERROR_CANCEL;
1624 }
1625
1626 int LIBMTP_Handle_Events_Timeout_Completed(struct timeval *tv, int *completed) {
1627 /* Unsupported */
1628 return -12;
1629 }
1630
1631 uint16_t
1609 ptp_usb_control_cancel_request (PTPParams *params, uint32_t transactionid) { 1632 ptp_usb_control_cancel_request (PTPParams *params, uint32_t transactionid) {
1610 PTP_USB *ptp_usb = (PTP_USB *)(params->data); 1633 PTP_USB *ptp_usb = (PTP_USB *)(params->data);
1611 int ret; 1634 int ret;
1612 unsigned char buffer[6]; 1635 unsigned char buffer[6];
1613 1636
1614 htod16a(&buffer[0],PTP_EC_CancelTransaction); 1637 htod16a(&buffer[0],PTP_EC_CancelTransaction);
1615 htod32a(&buffer[2],transactionid); 1638 htod32a(&buffer[2],transactionid);
1616 ret = usb_control_msg(ptp_usb->handle, 1639 ret = usb_control_msg(ptp_usb->handle,
1617 USB_TYPE_CLASS | USB_RECIP_INTERFACE, 1640 USB_TYPE_CLASS | USB_RECIP_INTERFACE,
1618 0x64, 0x0000, 0x0000, 1641 0x64, 0x0000, 0x0000,
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after
1811 * Clear any stalled endpoints 1834 * Clear any stalled endpoints
1812 * On misbehaving devices designed for Windows/Mac, quote from: 1835 * On misbehaving devices designed for Windows/Mac, quote from:
1813 * http://www2.one-eyed-alien.net/~mdharm/linux-usb/target_offenses.txt 1836 * http://www2.one-eyed-alien.net/~mdharm/linux-usb/target_offenses.txt
1814 * Device does Bad Things(tm) when it gets a GET_STATUS after CLEAR_HALT 1837 * Device does Bad Things(tm) when it gets a GET_STATUS after CLEAR_HALT
1815 * (...) Windows, when clearing a stall, only sends the CLEAR_HALT command, 1838 * (...) Windows, when clearing a stall, only sends the CLEAR_HALT command,
1816 * and presumes that the stall has cleared. Some devices actually choke 1839 * and presumes that the stall has cleared. Some devices actually choke
1817 * if the CLEAR_HALT is followed by a GET_STATUS (used to determine if the 1840 * if the CLEAR_HALT is followed by a GET_STATUS (used to determine if the
1818 * STALL is persistant or not). 1841 * STALL is persistant or not).
1819 */ 1842 */
1820 clear_stall(ptp_usb); 1843 clear_stall(ptp_usb);
1844 #if 0
1845 // causes troubles due to a kernel bug in 3.x kernels before/around 3.8
1821 // Clear halts on any endpoints 1846 // Clear halts on any endpoints
1822 clear_halt(ptp_usb); 1847 clear_halt(ptp_usb);
1823 // Added to clear some stuff on the OUT endpoint 1848 // Added to clear some stuff on the OUT endpoint
1824 // TODO: is this good on the Mac too? 1849 // TODO: is this good on the Mac too?
1825 // HINT: some devices may need that you comment these two out too. 1850 // HINT: some devices may need that you comment these two out too.
1851 #endif
1826 usb_resetep(ptp_usb->handle, ptp_usb->outep); 1852 usb_resetep(ptp_usb->handle, ptp_usb->outep);
1827 usb_release_interface(ptp_usb->handle, (int) ptp_usb->interface); 1853 usb_release_interface(ptp_usb->handle, (int) ptp_usb->interface);
1828 } 1854 }
1829 if (FLAG_FORCE_RESET_ON_CLOSE(ptp_usb)) { 1855 if (FLAG_FORCE_RESET_ON_CLOSE(ptp_usb)) {
1830 /* 1856 /*
1831 * Some devices really love to get reset after being 1857 * Some devices really love to get reset after being
1832 * disconnected. Again, since Windows never disconnects 1858 * disconnected. Again, since Windows never disconnects
1833 * a device closing behaviour is seldom or never exercised 1859 * a device closing behaviour is seldom or never exercised
1834 * on devices when engineered and often error prone. 1860 * on devices when engineered and often error prone.
1835 * Reset may help some. 1861 * Reset may help some.
(...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after
2108 { 2134 {
2109 return (usb_control_msg(ptp_usb->handle, 2135 return (usb_control_msg(ptp_usb->handle,
2110 USB_DP_DTH|USB_RECIP_ENDPOINT, 2136 USB_DP_DTH|USB_RECIP_ENDPOINT,
2111 USB_REQ_GET_STATUS, 2137 USB_REQ_GET_STATUS,
2112 USB_FEATURE_HALT, 2138 USB_FEATURE_HALT,
2113 ep, 2139 ep,
2114 (char *) status, 2140 (char *) status,
2115 2, 2141 2,
2116 ptp_usb->timeout)); 2142 ptp_usb->timeout));
2117 } 2143 }
OLDNEW
« 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