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