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-2012 Marcus Meissner | 7 * Copyright (C) 2006-2012 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 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
77 }; | 77 }; |
78 typedef struct mtpdevice_list_struct mtpdevice_list_t; | 78 typedef struct mtpdevice_list_struct mtpdevice_list_t; |
79 | 79 |
80 static const LIBMTP_device_entry_t mtp_device_table[] = { | 80 static const LIBMTP_device_entry_t mtp_device_table[] = { |
81 /* We include an .h file which is shared between us and libgphoto2 */ | 81 /* We include an .h file which is shared between us and libgphoto2 */ |
82 #include "music-players.h" | 82 #include "music-players.h" |
83 }; | 83 }; |
84 static const int mtp_device_table_size = sizeof(mtp_device_table) / sizeof(LIBMT
P_device_entry_t); | 84 static const int mtp_device_table_size = sizeof(mtp_device_table) / sizeof(LIBMT
P_device_entry_t); |
85 | 85 |
86 // Local functions | 86 // Local functions |
87 static void init_usb(); | 87 static LIBMTP_error_number_t init_usb(); |
88 static void close_usb(PTP_USB* ptp_usb); | 88 static void close_usb(PTP_USB* ptp_usb); |
89 static int find_interface_and_endpoints(libusb_device *dev, | 89 static int find_interface_and_endpoints(libusb_device *dev, |
90 uint8_t *interface, | 90 uint8_t *interface, |
91 int* inep, | 91 int* inep, |
92 int* inep_maxpacket, | 92 int* inep_maxpacket, |
93 int* outep, | 93 int* outep, |
94 int* outep_maxpacket, | 94 int* outep_maxpacket, |
95 int* intep); | 95 int* intep); |
96 static void clear_stall(PTP_USB* ptp_usb); | 96 static void clear_stall(PTP_USB* ptp_usb); |
97 static int init_ptp_usb (PTPParams* params, PTP_USB* ptp_usb, libusb_device* dev
); | 97 static int init_ptp_usb (PTPParams* params, PTP_USB* ptp_usb, libusb_device* dev
); |
(...skipping 20 matching lines...) Expand all Loading... |
118 * value means failure. | 118 * value means failure. |
119 */ | 119 */ |
120 int LIBMTP_Get_Supported_Devices_List(LIBMTP_device_entry_t ** const devices, in
t * const numdevs) | 120 int LIBMTP_Get_Supported_Devices_List(LIBMTP_device_entry_t ** const devices, in
t * const numdevs) |
121 { | 121 { |
122 *devices = (LIBMTP_device_entry_t *) &mtp_device_table; | 122 *devices = (LIBMTP_device_entry_t *) &mtp_device_table; |
123 *numdevs = mtp_device_table_size; | 123 *numdevs = mtp_device_table_size; |
124 return 0; | 124 return 0; |
125 } | 125 } |
126 | 126 |
127 | 127 |
128 static void init_usb() | 128 static LIBMTP_error_number_t init_usb() |
129 { | 129 { |
130 /* | 130 /* |
131 * Some additional libusb debugging please. | 131 * Some additional libusb debugging please. |
132 * We use the same level debug between MTP and USB. | 132 * We use the same level debug between MTP and USB. |
133 */ | 133 */ |
134 libusb_init(NULL); | 134 if (libusb_init(NULL) < 0) { |
| 135 LIBMTP_ERROR("Libusb1 init failed\n"); |
| 136 return LIBMTP_ERROR_USB_LAYER; |
| 137 } |
135 | 138 |
136 if ((LIBMTP_debug & LIBMTP_DEBUG_USB) != 0) | 139 if ((LIBMTP_debug & LIBMTP_DEBUG_USB) != 0) |
137 libusb_set_debug(NULL,9); | 140 libusb_set_debug(NULL,9); |
| 141 return LIBMTP_ERROR_NONE; |
138 } | 142 } |
139 | 143 |
140 /** | 144 /** |
141 * Small recursive function to append a new usb_device to the linked list of | 145 * Small recursive function to append a new usb_device to the linked list of |
142 * USB MTP devices | 146 * USB MTP devices |
143 * @param devlist dynamic linked list of pointers to usb devices with MTP | 147 * @param devlist dynamic linked list of pointers to usb devices with MTP |
144 * properties, to be extended with new device. | 148 * properties, to be extended with new device. |
145 * @param newdevice the new device to add. | 149 * @param newdevice the new device to add. |
146 * @param bus_location bus for this device. | 150 * @param bus_location bus for this device. |
147 * @return an extended array or NULL on failure. | 151 * @return an extended array or NULL on failure. |
(...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
471 * to the list). | 475 * to the list). |
472 * @return LIBMTP_ERROR_NONE implies that devices have been found, scan the list | 476 * @return LIBMTP_ERROR_NONE implies that devices have been found, scan the list |
473 * appropriately. LIBMTP_ERROR_NO_DEVICE_ATTACHED implies that no | 477 * appropriately. LIBMTP_ERROR_NO_DEVICE_ATTACHED implies that no |
474 * devices have been found. | 478 * devices have been found. |
475 */ | 479 */ |
476 static LIBMTP_error_number_t get_mtp_usb_device_list(mtpdevice_list_t ** mtp_dev
ice_list) | 480 static LIBMTP_error_number_t get_mtp_usb_device_list(mtpdevice_list_t ** mtp_dev
ice_list) |
477 { | 481 { |
478 ssize_t nrofdevs; | 482 ssize_t nrofdevs; |
479 libusb_device **devs = NULL; | 483 libusb_device **devs = NULL; |
480 int ret, i; | 484 int ret, i; |
| 485 LIBMTP_error_number_t init_usb_ret; |
481 | 486 |
482 init_usb(); | 487 init_usb_ret = init_usb(); |
| 488 if (init_usb_ret != LIBMTP_ERROR_NONE) |
| 489 return init_usb_ret; |
483 | 490 |
484 nrofdevs = libusb_get_device_list (NULL, &devs); | 491 nrofdevs = libusb_get_device_list (NULL, &devs); |
485 for (i = 0; i < nrofdevs ; i++) { | 492 for (i = 0; i < nrofdevs ; i++) { |
486 libusb_device *dev = devs[i]; | 493 libusb_device *dev = devs[i]; |
487 struct libusb_device_descriptor desc; | 494 struct libusb_device_descriptor desc; |
488 | 495 |
489 ret = libusb_get_device_descriptor(dev, &desc); | 496 ret = libusb_get_device_descriptor(dev, &desc); |
490 if (ret != LIBUSB_SUCCESS) continue; | 497 if (ret != LIBUSB_SUCCESS) continue; |
491 | 498 |
492 if (desc.bDeviceClass != LIBUSB_CLASS_HUB) { | 499 if (desc.bDeviceClass != LIBUSB_CLASS_HUB) { |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
544 * | 551 * |
545 * @param busno the bus number of the device to check | 552 * @param busno the bus number of the device to check |
546 * @param deviceno the device number of the device to check | 553 * @param deviceno the device number of the device to check |
547 * @return 1 if the device is MTP else 0 | 554 * @return 1 if the device is MTP else 0 |
548 */ | 555 */ |
549 int LIBMTP_Check_Specific_Device(int busno, int devno) | 556 int LIBMTP_Check_Specific_Device(int busno, int devno) |
550 { | 557 { |
551 ssize_t nrofdevs; | 558 ssize_t nrofdevs; |
552 libusb_device **devs = NULL; | 559 libusb_device **devs = NULL; |
553 int i; | 560 int i; |
| 561 LIBMTP_error_number_t init_usb_ret; |
554 | 562 |
555 init_usb(); | 563 init_usb_ret = init_usb(); |
| 564 if (init_usb_ret != LIBMTP_ERROR_NONE) |
| 565 return 0; |
556 | 566 |
557 nrofdevs = libusb_get_device_list (NULL, &devs); | 567 nrofdevs = libusb_get_device_list (NULL, &devs); |
558 for (i = 0; i < nrofdevs ; i++ ) { | 568 for (i = 0; i < nrofdevs ; i++ ) { |
559 | 569 |
560 if (libusb_get_bus_number(devs[i]) != busno) | 570 if (libusb_get_bus_number(devs[i]) != busno) |
561 continue; | 571 continue; |
562 if (libusb_get_device_address(devs[i]) != devno) | 572 if (libusb_get_device_address(devs[i]) != devno) |
563 continue; | 573 continue; |
564 | 574 |
565 if (probe_device_descriptor(devs[i], NULL)) | 575 if (probe_device_descriptor(devs[i], NULL)) |
(...skipping 1331 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1897 PTPParams *params, | 1907 PTPParams *params, |
1898 void **usbinfo) | 1908 void **usbinfo) |
1899 { | 1909 { |
1900 PTP_USB *ptp_usb; | 1910 PTP_USB *ptp_usb; |
1901 libusb_device *ldevice; | 1911 libusb_device *ldevice; |
1902 uint16_t ret = 0; | 1912 uint16_t ret = 0; |
1903 int err, found = 0, i; | 1913 int err, found = 0, i; |
1904 ssize_t nrofdevs; | 1914 ssize_t nrofdevs; |
1905 libusb_device **devs = NULL; | 1915 libusb_device **devs = NULL; |
1906 struct libusb_device_descriptor desc; | 1916 struct libusb_device_descriptor desc; |
| 1917 LIBMTP_error_number_t init_usb_ret; |
1907 | 1918 |
1908 /* See if we can find this raw device again... */ | 1919 /* See if we can find this raw device again... */ |
1909 init_usb(); | 1920 init_usb_ret = init_usb(); |
| 1921 if (init_usb_ret != LIBMTP_ERROR_NONE) |
| 1922 return init_usb_ret; |
1910 | 1923 |
1911 nrofdevs = libusb_get_device_list (NULL, &devs); | 1924 nrofdevs = libusb_get_device_list (NULL, &devs); |
1912 for (i = 0; i < nrofdevs ; i++) { | 1925 for (i = 0; i < nrofdevs ; i++) { |
1913 if (libusb_get_bus_number (devs[i]) != device->bus_location) | 1926 if (libusb_get_bus_number (devs[i]) != device->bus_location) |
1914 continue; | 1927 continue; |
1915 if (libusb_get_device_address (devs[i]) != device->devnum) | 1928 if (libusb_get_device_address (devs[i]) != device->devnum) |
1916 continue; | 1929 continue; |
1917 | 1930 |
1918 ret = libusb_get_device_descriptor (devs[i], &desc); | 1931 ret = libusb_get_device_descriptor (devs[i], &desc); |
1919 if (ret != LIBUSB_SUCCESS) continue; | 1932 if (ret != LIBUSB_SUCCESS) continue; |
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2069 { | 2082 { |
2070 return libusb_control_transfer(ptp_usb->handle, | 2083 return libusb_control_transfer(ptp_usb->handle, |
2071 LIBUSB_ENDPOINT_IN|LIBUSB_RECIPIENT_ENDPOINT, | 2084 LIBUSB_ENDPOINT_IN|LIBUSB_RECIPIENT_ENDPOINT, |
2072 LIBUSB_REQUEST_GET_STATUS, | 2085 LIBUSB_REQUEST_GET_STATUS, |
2073 USB_FEATURE_HALT, | 2086 USB_FEATURE_HALT, |
2074 ep, | 2087 ep, |
2075 (unsigned char *) status, | 2088 (unsigned char *) status, |
2076 2, | 2089 2, |
2077 ptp_usb->timeout); | 2090 ptp_usb->timeout); |
2078 } | 2091 } |
OLD | NEW |