~ubuntu-branches/ubuntu/precise/libmtp/precise-proposed

« back to all changes in this revision

Viewing changes to src/libusb-glue.c

  • Committer: Bazaar Package Importer
  • Author(s): Alessio Treglia
  • Date: 2010-05-25 08:22:17 UTC
  • mto: (0.2.1 upstream) (16.1.8 sid)
  • mto: This revision was merged to the branch mainline in revision 28.
  • Revision ID: james.westby@ubuntu.com-20100525082217-3jpyw97sxwiewb6r
Tags: upstream-1.0.3
ImportĀ upstreamĀ versionĀ 1.0.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
148
148
  /* Workaround a libusb 0.1 bug : bus location is not initialised */
149
149
  busses = usb_get_busses();
150
150
  for (bus = busses; bus != NULL; bus = bus->next) {
151
 
    bus->location = strtoul(bus->dirname, NULL, 10);
 
151
    if (!bus->location)
 
152
      bus->location = strtoul(bus->dirname, NULL, 10);
152
153
  }
153
154
  return (busses);
154
155
}
176
177
  new_list_entry->libusb_device = newdevice;
177
178
  new_list_entry->bus_location = bus_location;
178
179
  new_list_entry->next = NULL;
179
 
  
 
180
 
180
181
  if (devlist == NULL) {
181
182
    return new_list_entry;
182
183
  } else {
192
193
/**
193
194
 * Small recursive function to free dynamic memory allocated to the linked list
194
195
 * of USB MTP devices
195
 
 * @param devlist dynamic linked list of pointers to usb devices with MTP 
 
196
 * @param devlist dynamic linked list of pointers to usb devices with MTP
196
197
 * properties.
197
198
 * @return nothing
198
199
 */
228
229
  unsigned char buf[1024], cmd;
229
230
  int i;
230
231
  int ret;
231
 
  
232
 
  /* Don't examine hubs (no point in that) */
233
 
  if (dev->descriptor.bDeviceClass == USB_CLASS_HUB) {
 
232
 
 
233
  /*
 
234
   * Don't examine hubs or HID devices, no point in that.
 
235
   * (Some Kensington mice really don't like this.)
 
236
   */
 
237
  if (dev->descriptor.bDeviceClass == USB_CLASS_HUB ||
 
238
      dev->descriptor.bDeviceClass == USB_CLASS_HID) {
234
239
    return 0;
235
240
  }
236
 
  
 
241
 
237
242
  /* Attempt to open Device on this port */
238
243
  devh = usb_open(dev);
239
244
  if (devh == NULL) {
666
671
 
667
672
static void
668
673
libusb_glue_debug (PTPParams *params, const char *format, ...)
669
 
{  
 
674
{
670
675
        va_list args;
671
676
 
672
677
        va_start (args, format);
679
684
                fflush (stderr);
680
685
        }
681
686
        va_end (args);
682
 
}  
 
687
}
683
688
 
684
689
static void
685
690
libusb_glue_error (PTPParams *params, const char *format, ...)
1091
1096
        usbdata.type    = htod16(PTP_USB_CONTAINER_DATA);
1092
1097
        usbdata.code    = htod16(ptp->Code);
1093
1098
        usbdata.trans_id= htod32(ptp->Transaction_ID);
1094
 
  
 
1099
 
1095
1100
        ((PTP_USB*)params->data)->current_transfer_complete = 0;
1096
1101
        ((PTP_USB*)params->data)->current_transfer_total = size+PTP_USB_BULK_HDR_LEN;
1097
1102
 
1103
1108
                /* For all camera devices. */
1104
1109
                datawlen = (size<PTP_USB_BULK_PAYLOAD_LEN_WRITE)?size:PTP_USB_BULK_PAYLOAD_LEN_WRITE;
1105
1110
                wlen = PTP_USB_BULK_HDR_LEN + datawlen;
1106
 
    
 
1111
 
1107
1112
                ret = handler->getfunc(params, handler->priv, datawlen, usbdata.payload.data, &gotlen);
1108
1113
                if (ret != PTP_RC_OK)
1109
1114
                        return ret;
1171
1176
        PTPUSBBulkContainer usbdata;
1172
1177
        unsigned long   written;
1173
1178
        PTP_USB *ptp_usb = (PTP_USB *) params->data;
1174
 
 
 
1179
        int putfunc_ret;
1175
1180
 
1176
1181
        LIBMTP_USB_DEBUG("GET DATA PHASE\n");
1177
1182
 
1212
1217
                        }
1213
1218
                }
1214
1219
                if (usbdata.length == 0xffffffffU) {
1215
 
                        /* Copy first part of data to 'data' */
1216
 
      int putfunc_ret = 
1217
 
                        handler->putfunc(
1218
 
                                params, handler->priv, rlen - PTP_USB_BULK_HDR_LEN, usbdata.payload.data,
1219
 
                                &written
1220
 
                        );
1221
 
      if (putfunc_ret != PTP_RC_OK)
1222
 
        return putfunc_ret;
1223
 
                        /* stuff data directly to passed data handler */
1224
 
                        while (1) {
1225
 
                                unsigned long readdata;
1226
 
                                uint16_t xret;
1227
 
 
1228
 
                                xret = ptp_read_func(
1229
 
                                        PTP_USB_BULK_HS_MAX_PACKET_LEN_READ,
1230
 
                                        handler,
1231
 
                                        params->data,
1232
 
                                        &readdata,
1233
 
                                        0
1234
 
                                );
1235
 
                                if (xret != PTP_RC_OK)
1236
 
                                        return xret;
1237
 
                                if (readdata < PTP_USB_BULK_HS_MAX_PACKET_LEN_READ)
1238
 
                                        break;
1239
 
                        }
1240
 
                        return PTP_RC_OK;
 
1220
                  /* Copy first part of data to 'data' */
 
1221
                  putfunc_ret =
 
1222
                    handler->putfunc(
 
1223
                                     params, handler->priv, rlen - PTP_USB_BULK_HDR_LEN, usbdata.payload.data,
 
1224
                                     &written
 
1225
                                     );
 
1226
                  if (putfunc_ret != PTP_RC_OK)
 
1227
                    return putfunc_ret;
 
1228
 
 
1229
                  /* stuff data directly to passed data handler */
 
1230
                  while (1) {
 
1231
                    unsigned long readdata;
 
1232
                    uint16_t xret;
 
1233
 
 
1234
                    xret = ptp_read_func(
 
1235
                                         PTP_USB_BULK_HS_MAX_PACKET_LEN_READ,
 
1236
                                         handler,
 
1237
                                         params->data,
 
1238
                                         &readdata,
 
1239
                                         0
 
1240
                                         );
 
1241
                    if (xret != PTP_RC_OK)
 
1242
                      return xret;
 
1243
                    if (readdata < PTP_USB_BULK_HS_MAX_PACKET_LEN_READ)
 
1244
                      break;
 
1245
                  }
 
1246
                  return PTP_RC_OK;
1241
1247
                }
1242
1248
                if (rlen > dtoh32(usbdata.length)) {
1243
1249
                        /*
1282
1288
                        params->split_header_data = 1;
1283
1289
 
1284
1290
                /* Copy first part of data to 'data' */
1285
 
    int putfunc_ret = 
1286
 
                handler->putfunc(
1287
 
                        params, handler->priv, rlen - PTP_USB_BULK_HDR_LEN, usbdata.payload.data,
1288
 
                        &written
1289
 
                );
1290
 
    if (putfunc_ret != PTP_RC_OK)
1291
 
      return putfunc_ret;
 
1291
                putfunc_ret =
 
1292
                  handler->putfunc(
 
1293
                                   params, handler->priv, rlen - PTP_USB_BULK_HDR_LEN,
 
1294
                                   usbdata.payload.data,
 
1295
                                   &written
 
1296
                                   );
 
1297
                if (putfunc_ret != PTP_RC_OK)
 
1298
                  return putfunc_ret;
1292
1299
 
1293
1300
                if (FLAG_NO_ZERO_READS(ptp_usb) &&
1294
1301
                    len+PTP_USB_BULK_HDR_LEN == PTP_USB_BULK_HS_MAX_PACKET_LEN_READ) {
1309
1316
 
1310
1317
                  LIBMTP_INFO("Reading in zero packet after header\n");
1311
1318
 
1312
 
          zeroresult = USB_BULK_READ(ptp_usb->handle, ptp_usb->inep, &zerobyte, 0, ptp_usb->timeout);
 
1319
                  zeroresult = USB_BULK_READ(ptp_usb->handle, ptp_usb->inep, &zerobyte, 0, ptp_usb->timeout);
1313
1320
 
1314
1321
                  if (zeroresult != 0)
1315
1322
                    LIBMTP_INFO("LIBMTP panic: unable to read in zero packet, response 0x%04x", zeroresult);
1548
1555
    // if it isn't explicitly set
1549
1556
    // See above, same issue with pthreads means that if this fails it is not
1550
1557
    // fatal
 
1558
    // However, this causes problems on Macs so disable here
 
1559
    #ifndef __APPLE__
1551
1560
    usbresult = usb_set_altinterface(device_handle, 0);
1552
1561
    if (usbresult)
1553
1562
      fprintf(stderr, "ignoring usb_claim_interface = %d", usbresult);
 
1563
    #endif
1554
1564
 
1555
1565
    if (FLAG_SWITCH_MODE_BLACKBERRY(ptp_usb)) {
1556
1566
      int ret;