~ubuntu-branches/ubuntu/saucy/libgphoto2/saucy-proposed

« back to all changes in this revision

Viewing changes to .pc/kFreeBSD-ENODATA.patch/libgphoto2_port/libusb1/libusb1.c

  • Committer: Package Import Robot
  • Author(s): Martin Pitt
  • Date: 2013-07-31 07:00:09 UTC
  • mfrom: (1.4.4)
  • Revision ID: package-import@ubuntu.com-20130731070009-enrbvg3hry64cxl1
Tags: 2.5.2-0ubuntu1
* New upstream release.
* Drop 01-increase_max_entries.patch, 02-libusbx_no_debug.patch,
  03-libusbx-fixes.patch: fixed upstream.
* Add libxml2-dev build dependency for new optional features.
* ABI changes: libgphoto2-2 → libgphoto2-6,
  libgphoto2-port0 → libgphoto2-port10
* debian/libgphoto2-dev-doc.install: Adjust to changed HTML API doc folder
  name.
* debian/libgphoto2-port10.install: Adjust for changed libgphoto-port ABI.

Show diffs side-by-side

added added

removed removed

Lines of Context:
71
71
 
72
72
        int detached;
73
73
 
 
74
        time_t                          devslastchecked;
 
75
        int                             nrofdevs;
 
76
        struct libusb_device_descriptor *descs;
 
77
        libusb_device                   **devs;
74
78
};
75
79
 
76
80
GPPortType
79
83
        return (GP_PORT_USB);
80
84
}
81
85
 
82
 
static time_t gp_devslastchecked = 0;
83
 
static int gp_nrofdevs = 0;
84
 
static struct libusb_device_descriptor  *gp_descs;
85
 
static libusb_device                    **gp_devs;
86
86
 
87
87
static ssize_t
88
 
load_devicelist (libusb_context *ctx) {
 
88
load_devicelist (GPPortPrivateLibrary *pl) {
89
89
        time_t  xtime;
90
90
 
91
91
        time(&xtime);
92
 
        if (xtime != gp_devslastchecked) {
93
 
                if (gp_nrofdevs)
94
 
                        libusb_free_device_list (gp_devs, 1);
95
 
                free (gp_descs);
96
 
                gp_nrofdevs = 0;
97
 
                gp_devs = NULL;
98
 
                gp_descs = NULL;
 
92
        if (xtime != pl->devslastchecked) {
 
93
                if (pl->nrofdevs)
 
94
                        libusb_free_device_list (pl->devs, 1);
 
95
                free (pl->descs);
 
96
                pl->nrofdevs = 0;
 
97
                pl->devs = NULL;
 
98
                pl->descs = NULL;
99
99
        }
100
 
        if (!gp_nrofdevs) {
 
100
        if (!pl->nrofdevs) {
101
101
                int     i;
102
102
 
103
 
                gp_nrofdevs = libusb_get_device_list (ctx, &gp_devs);
104
 
                gp_descs = malloc (sizeof(gp_descs[0])*gp_nrofdevs);
105
 
                for (i=0;i<gp_nrofdevs;i++) {
 
103
                pl->nrofdevs = libusb_get_device_list (pl->ctx, &pl->devs);
 
104
                pl->descs = malloc (sizeof(pl->descs[0])*pl->nrofdevs);
 
105
                for (i=0;i<pl->nrofdevs;i++) {
106
106
                        int ret;
107
 
                        ret = libusb_get_device_descriptor(gp_devs[i], &gp_descs[i]);
 
107
                        ret = libusb_get_device_descriptor(pl->devs[i], &pl->descs[i]);
108
108
                        if (ret)
109
109
                                gp_log (GP_LOG_ERROR, "libusb1", "libusb_get_device_descriptor(%d) returned %d", i, ret);
110
110
                }
111
111
        }
112
 
        time (&gp_devslastchecked);
113
 
        return gp_nrofdevs;
 
112
        time (&pl->devslastchecked);
 
113
        return pl->nrofdevs;
114
114
}
115
115
 
116
116
int
119
119
        GPPortInfo      info;
120
120
        int             nrofdevices = 0;
121
121
        int             d, i, i1, i2, unknownint;
 
122
        libusb_context  *ctx;
 
123
        libusb_device   **devs = NULL;
 
124
        int             nrofdevs = 0;
 
125
        struct libusb_device_descriptor *descs;
122
126
 
123
127
        /* generic matcher. This will catch passed XXX,YYY entries for instance. */
124
 
        info.type = GP_PORT_USB;
125
 
        strcpy (info.name, "");
126
 
        strcpy (info.path, "^usb:");
 
128
        gp_port_info_new (&info);
 
129
        gp_port_info_set_type (info, GP_PORT_USB);
 
130
        gp_port_info_set_name (info, "");
 
131
        gp_port_info_set_path (info, "^usb:");
127
132
        CHECK (gp_port_info_list_append (list, info));
128
133
 
129
 
        libusb_init (NULL);
130
 
        gp_nrofdevs = load_devicelist (NULL);
 
134
        if (libusb_init (&ctx) != 0) {
 
135
                gp_log (GP_LOG_ERROR, "libusb1", "libusb_init failed.");
 
136
                return GP_ERROR_IO;
 
137
        }
 
138
        nrofdevs = libusb_get_device_list (ctx, &devs);
 
139
        descs = malloc (sizeof(descs[0])*nrofdevs);
 
140
        for (i=0;i<nrofdevs;i++) {
 
141
                int ret;
 
142
                ret = libusb_get_device_descriptor(devs[i], &descs[i]);
 
143
                if (ret)
 
144
                        gp_log (GP_LOG_ERROR, "libusb1", "libusb_get_device_descriptor(%d) returned %d", i, ret);
 
145
        }
131
146
 
132
 
        for (d = 0; d < gp_nrofdevs; d++) {
 
147
        for (d = 0; d < nrofdevs; d++) {
133
148
                /* Devices which are definitely not cameras. */
134
 
                if (    (gp_descs[d].bDeviceClass == LIBUSB_CLASS_HUB)          ||
135
 
                        (gp_descs[d].bDeviceClass == LIBUSB_CLASS_HID)          ||
136
 
                        (gp_descs[d].bDeviceClass == LIBUSB_CLASS_PRINTER)      ||
137
 
                        (gp_descs[d].bDeviceClass == LIBUSB_CLASS_COMM) ||
138
 
                        (gp_descs[d].bDeviceClass == 0xe0)      /* wireless / bluetooth */
 
149
                if (    (descs[d].bDeviceClass == LIBUSB_CLASS_HUB)             ||
 
150
                        (descs[d].bDeviceClass == LIBUSB_CLASS_HID)             ||
 
151
                        (descs[d].bDeviceClass == LIBUSB_CLASS_PRINTER) ||
 
152
                        (descs[d].bDeviceClass == LIBUSB_CLASS_COMM)    ||
 
153
                        (descs[d].bDeviceClass == 0xe0) /* wireless / bluetooth */
139
154
                )
140
155
                        continue;
141
156
                /* excepts HUBs, usually the interfaces have the classes, not
142
157
                 * the device */
143
158
                unknownint = 0;
144
 
                for (i = 0; i < gp_descs[d].bNumConfigurations; i++) {
 
159
                for (i = 0; i < descs[d].bNumConfigurations; i++) {
145
160
                        struct libusb_config_descriptor *config;
146
161
                        int ret;
147
162
 
148
 
                        ret = libusb_get_config_descriptor (gp_devs[d], i, &config);
 
163
                        ret = libusb_get_config_descriptor (devs[d], i, &config);
149
164
                        if (ret) {
150
165
                                unknownint++;
151
166
                                continue;
185
200
        /* Redo the same bus/device walk, but now add the ports with usb:x,y notation,
186
201
         * so we can address all USB devices.
187
202
         */
188
 
        for (d = 0; d < gp_nrofdevs; d++) {
 
203
        for (d = 0; d < nrofdevs; d++) {
 
204
                char path[200];
 
205
 
189
206
                /* Devices which are definitely not cameras. */
190
 
                if (    (gp_descs[d].bDeviceClass == LIBUSB_CLASS_HUB)          ||
191
 
                        (gp_descs[d].bDeviceClass == LIBUSB_CLASS_HID)          ||
192
 
                        (gp_descs[d].bDeviceClass == LIBUSB_CLASS_PRINTER)      ||
193
 
                        (gp_descs[d].bDeviceClass == LIBUSB_CLASS_COMM)
 
207
                if (    (descs[d].bDeviceClass == LIBUSB_CLASS_HUB)             ||
 
208
                        (descs[d].bDeviceClass == LIBUSB_CLASS_HID)             ||
 
209
                        (descs[d].bDeviceClass == LIBUSB_CLASS_PRINTER) ||
 
210
                        (descs[d].bDeviceClass == LIBUSB_CLASS_COMM)
194
211
                )
195
212
                        continue;
196
213
                /* excepts HUBs, usually the interfaces have the classes, not
197
214
                 * the device */
198
215
                unknownint = 0;
199
 
                for (i = 0; i < gp_descs[d].bNumConfigurations; i++) {
 
216
                for (i = 0; i < descs[d].bNumConfigurations; i++) {
200
217
                        struct libusb_config_descriptor *config;
201
218
                        int ret;
202
219
 
203
 
                        ret = libusb_get_config_descriptor (gp_devs[d], i, &config);
 
220
                        ret = libusb_get_config_descriptor (devs[d], i, &config);
204
221
                        if (ret) {
205
222
                                gp_log (GP_LOG_ERROR, "libusb1", "libusb_get_config_descriptor(%d) returned %d", d, ret);
206
223
                                unknownint++;
223
240
                /* Note: We do not skip USB storage. Some devices can support both,
224
241
                 * and the Ricoh erronously reports it.
225
242
                 */ 
226
 
                info.type = GP_PORT_USB;
227
 
                strcpy (info.name, "Universal Serial Bus");
228
 
                snprintf (info.path,sizeof(info.path), "usb:%03d,%03d",
229
 
                        libusb_get_bus_number (gp_devs[d]),
230
 
                        libusb_get_device_address (gp_devs[d])
 
243
                gp_port_info_new (&info);
 
244
                gp_port_info_set_type (info, GP_PORT_USB);
 
245
                gp_port_info_set_name (info, "Universal Serial Bus");
 
246
                snprintf (path,sizeof(path), "usb:%03d,%03d",
 
247
                        libusb_get_bus_number (devs[d]),
 
248
                        libusb_get_device_address (devs[d])
231
249
                );
 
250
                gp_port_info_set_path (info, path);
232
251
                CHECK (gp_port_info_list_append (list, info));
233
252
        }
234
253
        /* This will only be added if no other device was ever added.
235
254
         * Users doing "usb:" usage will enter the regular expression matcher case. */
236
255
        if (nrofdevices == 0) {
237
 
                info.type = GP_PORT_USB;
238
 
                strcpy (info.name, "Universal Serial Bus");
239
 
                strcpy (info.path, "usb:");
 
256
                gp_port_info_new (&info);
 
257
                gp_port_info_set_type (info, GP_PORT_USB);
 
258
                gp_port_info_set_name (info, "Universal Serial Bus");
 
259
                gp_port_info_set_path (info, "usb:");
240
260
                CHECK (gp_port_info_list_append (list, info));
241
261
        }
242
 
        libusb_exit (NULL);
 
262
        libusb_exit (ctx); /* should free all stuff above */
243
263
        return (GP_OK);
244
264
}
245
265
 
252
272
 
253
273
        port->pl->config = port->pl->interface = port->pl->altsetting = -1;
254
274
 
255
 
        libusb_init (&port->pl->ctx);
 
275
        if (libusb_init (&port->pl->ctx) != 0) {
 
276
                gp_log (GP_LOG_ERROR, "libusb1", "libusb_init failed.");
 
277
                free (port->pl);
 
278
                port->pl = NULL;
 
279
                return GP_ERROR_IO;
 
280
        }
 
281
#if 0
256
282
        libusb_set_debug (port->pl->ctx, 255);
257
 
 
258
 
#if 0
259
 
        usb_init ();
260
 
        usb_find_busses ();
261
 
        usb_find_devices ();
262
283
#endif
263
 
 
264
 
        return (GP_OK);
 
284
        return GP_OK;
265
285
}
266
286
 
267
287
static int
268
288
gp_port_usb_exit (GPPort *port)
269
289
{
270
290
        if (port->pl) {
 
291
                free (port->pl->descs);
271
292
                libusb_exit (port->pl->ctx);
272
293
                free (port->pl);
273
294
                port->pl = NULL;
274
295
        }
275
 
        if (gp_devs) libusb_free_device_list (gp_devs, 1);
276
 
        free (gp_descs);
277
296
        return (GP_OK);
278
297
}
279
298
 
 
299
static int gp_port_usb_find_path_lib(GPPort *port);
280
300
static int
281
301
gp_port_usb_open (GPPort *port)
282
302
{
283
303
        int ret;
284
304
 
285
305
        gp_log (GP_LOG_DEBUG,"libusb1","gp_port_usb_open()");
286
 
        if (!port || !port->pl->d)
 
306
        if (!port)
287
307
                return GP_ERROR_BAD_PARAMETERS;
288
308
 
 
309
        if (!port->pl->d) {
 
310
                gp_port_usb_find_path_lib(port);
 
311
                if (!port->pl->d)
 
312
                        return GP_ERROR_BAD_PARAMETERS;
 
313
        }
 
314
 
289
315
        ret = libusb_open (port->pl->d, &port->pl->dh);
290
316
        if (ret) {
291
317
                gp_log (GP_LOG_ERROR, "libusb1", "libusb_open returned %d", ret);
428
454
{
429
455
        int ret, curread;
430
456
 
431
 
        if (!port || !port->pl->dh)
 
457
        if (!port || !port->pl->dh) {
 
458
                gp_log (GP_LOG_ERROR, "libusb1", "gp_port_usb_read: bad parameters");
432
459
                return GP_ERROR_BAD_PARAMETERS;
 
460
        }
433
461
 
 
462
        gp_log (GP_LOG_DEBUG, "libusb1", "reading with timeout %d", port->timeout);
434
463
        ret = libusb_bulk_transfer (port->pl->dh, port->settings.usb.inep,
435
464
                             (unsigned char*)bytes, size, &curread, port->timeout);
 
465
        gp_log (GP_LOG_DEBUG, "libusb1", "ret = %d", ret);
436
466
        if (ret < 0)
437
467
                return GP_ERROR_IO_READ;
438
468
 
440
470
}
441
471
 
442
472
static int
 
473
gp_port_usb_reset(GPPort *port)
 
474
{
 
475
        int ret, curread;
 
476
 
 
477
        if (!port || !port->pl->dh) {
 
478
                gp_log (GP_LOG_ERROR, "libusb1", "gp_port_usb_reset: bad parameters");
 
479
                return GP_ERROR_BAD_PARAMETERS;
 
480
        }
 
481
 
 
482
        gp_log (GP_LOG_DEBUG, "libusb1", "reseting");
 
483
        ret = libusb_reset_device (port->pl->dh);
 
484
        gp_log (GP_LOG_DEBUG, "libusb1", "ret = %d", ret);
 
485
        if (ret < 0)
 
486
                return GP_ERROR_IO_READ;
 
487
        return GP_OK;
 
488
}
 
489
 
 
490
static int
443
491
gp_port_usb_check_int (GPPort *port, char *bytes, int size, int timeout)
444
492
{
445
493
        int ret, curread;
558
606
        if (!port)
559
607
                return GP_ERROR_BAD_PARAMETERS;
560
608
 
561
 
        gp_log (GP_LOG_DEBUG, "libusb1", "gp_port_usb_update(old int=%d, conf=%d, alt=%d), (new int=%d, conf=%d, alt=%d)",
 
609
        gp_log (GP_LOG_DEBUG, "libusb1", "gp_port_usb_update(old int=%d, conf=%d, alt=%d) port %s, (new int=%d, conf=%d, alt=%d) port %s",
562
610
                port->settings.usb.interface,
563
611
                port->settings.usb.config,
564
612
                port->settings.usb.altsetting,
 
613
                port->settings.usb.port,
565
614
                port->settings_pending.usb.interface,
566
615
                port->settings_pending.usb.config,
567
 
                port->settings_pending.usb.altsetting
 
616
                port->settings_pending.usb.altsetting,
 
617
                port->settings_pending.usb.port
568
618
        );
569
619
 
570
 
/* do not set it here, otherwise stv680 doesnt work 
 
620
/* do not overwrite it ... we need to set it.
571
621
        if (port->pl->interface == -1) port->pl->interface = port->settings.usb.interface;
572
622
        if (port->pl->config == -1) port->pl->config = port->settings.usb.config;
573
623
        if (port->pl->altsetting == -1) port->pl->altsetting = port->settings.usb.altsetting;
740
790
}
741
791
 
742
792
static int
 
793
gp_port_usb_find_path_lib(GPPort *port)
 
794
{
 
795
        char *s;
 
796
        int d, busnr = 0, devnr = 0;
 
797
        GPPortPrivateLibrary *pl = port->pl;
 
798
 
 
799
        if (!port)
 
800
                return (GP_ERROR_BAD_PARAMETERS);
 
801
 
 
802
        s = strchr (port->settings.usb.port,':');
 
803
        if (s && (s[1] != '\0')) { /* usb:%d,%d */
 
804
                if (sscanf (s+1, "%d,%d", &busnr, &devnr) != 2)
 
805
                        return GP_ERROR_BAD_PARAMETERS;
 
806
        } else {
 
807
                return GP_ERROR_BAD_PARAMETERS;
 
808
        }
 
809
 
 
810
        pl->nrofdevs = load_devicelist (port->pl);
 
811
 
 
812
        for (d = 0; d < pl->nrofdevs; d++) {
 
813
                struct libusb_config_descriptor *confdesc;
 
814
                int ret;
 
815
                int config = -1, interface = -1, altsetting = -1;
 
816
 
 
817
                if (busnr != libusb_get_bus_number (pl->devs[d]))
 
818
                        continue;
 
819
                if (devnr != libusb_get_device_address (pl->devs[d]))
 
820
                        continue;
 
821
 
 
822
                port->pl->d = pl->devs[d];
 
823
 
 
824
                gp_log (GP_LOG_VERBOSE, "libusb1", "Found path %s", port->settings.usb.port); 
 
825
 
 
826
                /* Use the first config, interface and altsetting we find */
 
827
                gp_port_usb_find_first_altsetting(pl->devs[d], &config, &interface, &altsetting);
 
828
 
 
829
                ret = libusb_get_config_descriptor (pl->devs[d], config, &confdesc);
 
830
                if (ret)
 
831
                        continue;
 
832
 
 
833
                /* Set the defaults */
 
834
                port->settings.usb.config = confdesc->bConfigurationValue;
 
835
                port->settings.usb.interface = confdesc->interface[interface].altsetting[altsetting].bInterfaceNumber;
 
836
                port->settings.usb.altsetting = confdesc->interface[interface].altsetting[altsetting].bAlternateSetting;
 
837
 
 
838
                port->settings.usb.inep  = gp_port_usb_find_ep(pl->devs[d], config, interface, altsetting, LIBUSB_ENDPOINT_IN, LIBUSB_TRANSFER_TYPE_BULK);
 
839
                port->settings.usb.outep = gp_port_usb_find_ep(pl->devs[d], config, interface, altsetting, LIBUSB_ENDPOINT_OUT, LIBUSB_TRANSFER_TYPE_BULK);
 
840
                port->settings.usb.intep = gp_port_usb_find_ep(pl->devs[d], config, interface, altsetting, LIBUSB_ENDPOINT_IN, LIBUSB_TRANSFER_TYPE_INTERRUPT);
 
841
 
 
842
                port->settings.usb.maxpacketsize = libusb_get_max_packet_size (pl->devs[d], port->settings.usb.inep);
 
843
                gp_log (GP_LOG_VERBOSE, "libusb1",
 
844
                        "Detected defaults: config %d, "
 
845
                        "interface %d, altsetting %d, "
 
846
                        "inep %02x, outep %02x, intep %02x, "
 
847
                        "class %02x, subclass %02x",
 
848
                        port->settings.usb.config,
 
849
                        port->settings.usb.interface,
 
850
                        port->settings.usb.altsetting,
 
851
                        port->settings.usb.inep,
 
852
                        port->settings.usb.outep,
 
853
                        port->settings.usb.intep,
 
854
                        confdesc->interface[interface].altsetting[altsetting].bInterfaceClass,
 
855
                        confdesc->interface[interface].altsetting[altsetting].bInterfaceSubClass
 
856
                        );
 
857
                libusb_free_config_descriptor (confdesc);
 
858
                return GP_OK;
 
859
        }
 
860
#if 0
 
861
        gp_port_set_error (port, _("Could not find USB device "
 
862
                "(vendor 0x%x, product 0x%x). Make sure this device "
 
863
                "is connected to the computer."), idvendor, idproduct);
 
864
#endif
 
865
        return GP_ERROR_IO_USB_FIND;
 
866
}
 
867
static int
743
868
gp_port_usb_find_device_lib(GPPort *port, int idvendor, int idproduct)
744
869
{
745
870
        char *s;
746
871
        int d, busnr = 0, devnr = 0;
 
872
        GPPortPrivateLibrary *pl = port->pl;
747
873
 
748
874
        if (!port)
749
875
                return (GP_ERROR_BAD_PARAMETERS);
767
893
                return GP_ERROR_BAD_PARAMETERS;
768
894
        }
769
895
 
770
 
        gp_nrofdevs = load_devicelist (port->pl->ctx);
 
896
        pl->nrofdevs = load_devicelist (port->pl);
771
897
 
772
 
        for (d = 0; d < gp_nrofdevs; d++) {
 
898
        for (d = 0; d < pl->nrofdevs; d++) {
773
899
                struct libusb_config_descriptor *confdesc;
774
900
                int ret;
775
901
                int config = -1, interface = -1, altsetting = -1;
776
902
 
777
 
                if ((gp_descs[d].idVendor != idvendor) ||
778
 
                    (gp_descs[d].idProduct != idproduct))
779
 
                        continue;
780
 
 
781
 
                if (busnr && (busnr != libusb_get_bus_number (gp_devs[d])))
782
 
                        continue;
783
 
                if (devnr && (devnr != libusb_get_device_address (gp_devs[d])))
784
 
                        continue;
785
 
 
786
 
                port->pl->d = gp_devs[d];
 
903
                if ((pl->descs[d].idVendor != idvendor) ||
 
904
                    (pl->descs[d].idProduct != idproduct))
 
905
                        continue;
 
906
 
 
907
                if (busnr && (busnr != libusb_get_bus_number (pl->devs[d])))
 
908
                        continue;
 
909
                if (devnr && (devnr != libusb_get_device_address (pl->devs[d])))
 
910
                        continue;
 
911
 
 
912
                port->pl->d = pl->devs[d];
787
913
 
788
914
                gp_log (GP_LOG_VERBOSE, "libusb1",
789
915
                        "Looking for USB device "
791
917
                        idvendor, idproduct);
792
918
 
793
919
                /* Use the first config, interface and altsetting we find */
794
 
                gp_port_usb_find_first_altsetting(gp_devs[d], &config, &interface, &altsetting);
 
920
                gp_port_usb_find_first_altsetting(pl->devs[d], &config, &interface, &altsetting);
795
921
 
796
 
                ret = libusb_get_config_descriptor (gp_devs[d], config, &confdesc);
 
922
                ret = libusb_get_config_descriptor (pl->devs[d], config, &confdesc);
797
923
                if (ret)
798
924
                        continue;
799
925
 
810
936
                port->settings.usb.interface = confdesc->interface[interface].altsetting[altsetting].bInterfaceNumber;
811
937
                port->settings.usb.altsetting = confdesc->interface[interface].altsetting[altsetting].bAlternateSetting;
812
938
 
813
 
                port->settings.usb.inep  = gp_port_usb_find_ep(gp_devs[d], config, interface, altsetting, LIBUSB_ENDPOINT_IN, LIBUSB_TRANSFER_TYPE_BULK);
814
 
                port->settings.usb.outep = gp_port_usb_find_ep(gp_devs[d], config, interface, altsetting, LIBUSB_ENDPOINT_OUT, LIBUSB_TRANSFER_TYPE_BULK);
815
 
                port->settings.usb.intep = gp_port_usb_find_ep(gp_devs[d], config, interface, altsetting, LIBUSB_ENDPOINT_IN, LIBUSB_TRANSFER_TYPE_INTERRUPT);
 
939
                port->settings.usb.inep  = gp_port_usb_find_ep(pl->devs[d], config, interface, altsetting, LIBUSB_ENDPOINT_IN, LIBUSB_TRANSFER_TYPE_BULK);
 
940
                port->settings.usb.outep = gp_port_usb_find_ep(pl->devs[d], config, interface, altsetting, LIBUSB_ENDPOINT_OUT, LIBUSB_TRANSFER_TYPE_BULK);
 
941
                port->settings.usb.intep = gp_port_usb_find_ep(pl->devs[d], config, interface, altsetting, LIBUSB_ENDPOINT_IN, LIBUSB_TRANSFER_TYPE_INTERRUPT);
816
942
 
817
 
                port->settings.usb.maxpacketsize = libusb_get_max_packet_size (gp_devs[d], port->settings.usb.inep);
 
943
                port->settings.usb.maxpacketsize = libusb_get_max_packet_size (pl->devs[d], port->settings.usb.inep);
818
944
                gp_log (GP_LOG_VERBOSE, "libusb1",
819
945
                        "Detected defaults: config %d, "
820
946
                        "interface %d, altsetting %d, "
998
1124
        if (class == 666) /* Special hack for MTP devices with MS OS descriptors. */
999
1125
                return gp_port_usb_match_mtp_device (dev, configno, interfaceno, altsettingno);
1000
1126
 
 
1127
        ret = libusb_get_device_descriptor(dev, &desc);
 
1128
 
1001
1129
        if (desc.bDeviceClass == class &&
1002
1130
            (subclass == -1 ||
1003
1131
             desc.bDeviceSubClass == subclass) &&
1005
1133
             desc.bDeviceProtocol == protocol))
1006
1134
                return 1;
1007
1135
 
1008
 
        ret = libusb_get_device_descriptor(dev, &desc);
1009
1136
 
1010
1137
        for (i = 0; i < desc.bNumConfigurations; i++) {
1011
1138
                struct libusb_config_descriptor *config;
1045
1172
{
1046
1173
        char *s;
1047
1174
        int d, busnr = 0, devnr = 0;
 
1175
        GPPortPrivateLibrary *pl = port->pl;
1048
1176
 
1049
1177
        if (!port)
1050
1178
                return (GP_ERROR_BAD_PARAMETERS);
1065
1193
        if (!class)
1066
1194
                return GP_ERROR_BAD_PARAMETERS;
1067
1195
 
1068
 
        gp_nrofdevs = load_devicelist (port->pl->ctx);
1069
 
        for (d = 0; d < gp_nrofdevs; d++) {
 
1196
        pl->nrofdevs = load_devicelist (port->pl);
 
1197
        for (d = 0; d < pl->nrofdevs; d++) {
1070
1198
                struct libusb_config_descriptor *confdesc;
1071
1199
                int i, ret, config = -1, interface = -1, altsetting = -1;
1072
1200
 
1073
 
                if (busnr && (busnr != libusb_get_bus_number (gp_devs[d])))
 
1201
                if (busnr && (busnr != libusb_get_bus_number (pl->devs[d])))
1074
1202
                        continue;
1075
 
                if (devnr && (devnr != libusb_get_device_address (gp_devs[d])))
 
1203
                if (devnr && (devnr != libusb_get_device_address (pl->devs[d])))
1076
1204
                        continue;
1077
1205
 
1078
1206
                gp_log (GP_LOG_VERBOSE, "gphoto2-port-usb",
1080
1208
                        "(class 0x%x, subclass, 0x%x, protocol 0x%x)...", 
1081
1209
                        class, subclass, protocol);
1082
1210
 
1083
 
                ret = gp_port_usb_match_device_by_class(gp_devs[d], class, subclass, protocol, &config, &interface, &altsetting);
 
1211
                ret = gp_port_usb_match_device_by_class(pl->devs[d], class, subclass, protocol, &config, &interface, &altsetting);
1084
1212
                if (!ret)
1085
1213
                        continue;
1086
1214
 
1087
 
                port->pl->d = gp_devs[d];
 
1215
                port->pl->d = pl->devs[d];
1088
1216
                gp_log (GP_LOG_VERBOSE, "libusb1",
1089
1217
                        "Found USB class device "
1090
1218
                        "(class 0x%x, subclass, 0x%x, protocol 0x%x)", 
1091
1219
                        class, subclass, protocol);
1092
1220
 
1093
 
                ret = libusb_get_config_descriptor (gp_devs[d], config, &confdesc);
 
1221
                ret = libusb_get_config_descriptor (pl->devs[d], config, &confdesc);
1094
1222
                if (ret) continue;
1095
1223
 
1096
1224
                /* Set the defaults */
1098
1226
                port->settings.usb.interface = confdesc->interface[interface].altsetting[altsetting].bInterfaceNumber;
1099
1227
                port->settings.usb.altsetting = confdesc->interface[interface].altsetting[altsetting].bAlternateSetting;
1100
1228
 
1101
 
                port->settings.usb.inep  = gp_port_usb_find_ep(gp_devs[d], config, interface, altsetting, LIBUSB_ENDPOINT_IN, LIBUSB_TRANSFER_TYPE_BULK);
1102
 
                port->settings.usb.outep = gp_port_usb_find_ep(gp_devs[d], config, interface, altsetting, LIBUSB_ENDPOINT_OUT, LIBUSB_TRANSFER_TYPE_BULK);
1103
 
                port->settings.usb.intep = gp_port_usb_find_ep(gp_devs[d], config, interface, altsetting, LIBUSB_ENDPOINT_IN, LIBUSB_TRANSFER_TYPE_INTERRUPT);
 
1229
                port->settings.usb.inep  = gp_port_usb_find_ep(pl->devs[d], config, interface, altsetting, LIBUSB_ENDPOINT_IN, LIBUSB_TRANSFER_TYPE_BULK);
 
1230
                port->settings.usb.outep = gp_port_usb_find_ep(pl->devs[d], config, interface, altsetting, LIBUSB_ENDPOINT_OUT, LIBUSB_TRANSFER_TYPE_BULK);
 
1231
                port->settings.usb.intep = gp_port_usb_find_ep(pl->devs[d], config, interface, altsetting, LIBUSB_ENDPOINT_IN, LIBUSB_TRANSFER_TYPE_INTERRUPT);
1104
1232
                port->settings.usb.maxpacketsize = 0;
1105
1233
                gp_log (GP_LOG_DEBUG, "libusb1", "inep to look for is %02x", port->settings.usb.inep);
1106
1234
                for (i=0;i<confdesc->interface[interface].altsetting[altsetting].bNumEndpoints;i++) {
1117
1245
                        port->settings.usb.config,
1118
1246
                        port->settings.usb.interface,
1119
1247
                        port->settings.usb.altsetting,
1120
 
                        gp_descs[d].idVendor,
1121
 
                        gp_descs[d].idProduct,
 
1248
                        pl->descs[d].idVendor,
 
1249
                        pl->descs[d].idProduct,
1122
1250
                        port->settings.usb.inep,
1123
1251
                        port->settings.usb.outep,
1124
1252
                        port->settings.usb.intep
1149
1277
        ops->open   = gp_port_usb_open;
1150
1278
        ops->close  = gp_port_usb_close;
1151
1279
        ops->read   = gp_port_usb_read;
 
1280
        ops->reset  = gp_port_usb_reset;
1152
1281
        ops->write  = gp_port_usb_write;
1153
1282
        ops->check_int = gp_port_usb_check_int;
1154
1283
        ops->update = gp_port_usb_update;