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