<commit_before>/*
 *  libusb-glue.c
 *
 *  Created by <NAME> on 24/12/2005. (as mtp-utils.c)
 *  Modified by <NAME> 2006-03-06
 *  (Notice that Anglo-Saxons use little-endian dates and Swedes use big-endian dates.)
 *
 * This file adds some utils (many copied from ptpcam.c from libptp2) to
 * use MTP devices. Include mtp-utils.h to use any of the ptp/mtp functions.
 *
 */
#include "ptp.h"
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <getopt.h>
#include <unistd.h>
#include <sys/types.h>
#include <utime.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <sys/mman.h>
#include <usb.h>

#include "libmtp.h"
#include "libusb-glue.h"
#include "util.h"

/* OUR APPLICATION USB URB (2MB) ;) */
#define PTPCAM_USB_URB		2097152

/* this must not be too short - the original 4000 was not long
   enough for big file transfers. I imagine the player spends a 
   bit of time gearing up to receiving lots of data. This also makes
   connecting/disconnecting more reliable */
#define USB_TIMEOUT		10000
#define USB_CAPTURE_TIMEOUT	20000

/* USB control message data phase direction */
#ifndef USB_DP_HTD
#define USB_DP_HTD		(0x00 << 7)	/* host to device */
#endif
#ifndef USB_DP_DTH
#define USB_DP_DTH		(0x01 << 7)	/* device to host */
#endif

/* USB Feature selector HALT */
#ifndef USB_FEATURE_HALT
#define USB_FEATURE_HALT	0x00
#endif

/*
 * MTP device list, trying real bad to get all devices into
 * this list by stealing from everyone I know.
 */
static const LIBMTP_device_entry_t mtp_device_table[] = {
  /* Creative devices */
  { "Creative Zen Vision", 0x041e, 0x411f },
  { "Creative Portable Media Center", 0x041e, 0x4123 },
  { "Creative Zen Xtra (MTP mode)", 0x041e, 0x4128 },
  { "Second generation Dell DJ", 0x041e, 0x412f },
  { "Creative Zen Micro (MTP mode)", 0x041e, 0x4130 },
  { "Creative Zen Touch (MTP mode)", 0x041e, 0x4131 },
  { "Dell Pocket DJ (MTP mode)", 0x041e, 0x4132 },
  { "Creative Zen Sleek (MTP mode)", 0x041e, 0x4137 },
  { "Creative Zen MicroPhoto", 0x041e, 0x413c },
  { "Creative Zen Sleek Photo", 0x041e, 0x413d },
  { "Creative Zen Vision:M", 0x041e, 0x413e },
  /* From libgphoto2 */
  { "Samsung:YH-820", 0x04e8, 0x502e },
  /* Contributed by <EMAIL> */
  { "Samsung YH-925", 0x04e8, 0x502f },
  /* Contributed by anonymous person on SourceForge */
  { "Samsung YP-T7J", 0x04e8, 0x5047 },
  /* From a rouge .INF file */
  { "Samsung YH-999 Portable Media Center", 0x04e8, 0x5a0f },
  { "Intel Bandon Portable Media Center", 0x045e, 0x00c9 },
  { "iRiver Portable Media Center", 0x1006, 0x4002 },
  { "iRiver Portable Media Center", 0x1006, 0x4003 },
  /* From <NAME> */
  { "JVC Alneo XA-HD500", 0x04f1, 0x6105 },
  /* From libgphoto2 source */
  { "Philipps HDD6320", 0x0471, 0x01eb },
  { "Philipps HDD6320 2", 0x0471, 0x014b },
  /* Anonymous SourceForge user */
  { "Philipps HDD1630/17", 0x0471, 0x014c },
  /* Reported by <EMAIL> */
  { "SanDisk Sansa c150", 0x0781, 0x7410 },
  /* From libgphoto2 source */
  { "SanDisk Sansa e200", 0x0781, 0x7420 },
  /* Reported by <EMAIL> */
  { "SanDisk Sansa e260", 0x0781, 0x7420 },
  /* From libgphoto2 source */
  { "iRiver T10", 0x4102, 0x1113 },
  { "iRiver T20 FM", 0x4102, 0x1114 },
  { "iRiver U10", 0x4102, 0x1116 },
  { "iRiver T10", 0x4102, 0x1117 },
  { "iRiver T20", 0x4102, 0x1118 },
  { "iRiver T30", 0x4102, 0x1119 },
  { "iRiver H10", 0x4102, 0x2102 },
  { "<NAME>", 0x413c, 0x4500 },
  { "Toshiba Gigabeat MEGF-40", 0x0930, 0x0009 },
  { "Toshiba Gigabeat", 0x0930, 0x000c }
};
static const int mtp_device_table_size = sizeof(mtp_device_table) / sizeof(LIBMTP_device_entry_t);

int ptpcam_usb_timeout = USB_TIMEOUT;

// Local functions
static struct usb_bus* init_usb();
static struct usb_device *probe_usb_bus_for_mtp_devices(void);
static void close_usb(PTP_USB* ptp_usb, uint8_t interfaceNumber);
static struct usb_device* find_device (int busn, int devicen, short force);
static void find_endpoints(struct usb_device *dev, int* inep, int* inep_maxpacket, int* outep, int* outep_maxpacket, int* intep);
static void clear_stall(PTP_USB* ptp_usb);
static int init_ptp_usb (PTPParams* params, PTP_USB* ptp_usb, struct usb_device* dev);
static short ptp_write_func (unsigned char *bytes, unsigned int size, void *data);
static short ptp_read_func (unsigned char *bytes, unsigned int size, void *data, unsigned int *readbytes);
static short ptp_check_int (unsigned char *bytes, unsigned int size, void *data, unsigned int *rlen);
static int usb_clear_stall_feature(PTP_USB* ptp_usb, int ep);<commit_msg>One more device ID<commit_after>/*
 *  libusb-glue.c
 *
 *  Created by <NAME> on 24/12/2005. (as mtp-utils.c)
 *  Modified by <NAME> 2006-03-06
 *  (Notice that Anglo-Saxons use little-endian dates and Swedes use big-endian dates.)
 *
 * This file adds some utils (many copied from ptpcam.c from libptp2) to
 * use MTP devices. Include mtp-utils.h to use any of the ptp/mtp functions.
 *
 */
#include "ptp.h"
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <getopt.h>
#include <unistd.h>
#include <sys/types.h>
#include <utime.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <sys/mman.h>
#include <usb.h>

#include "libmtp.h"
#include "libusb-glue.h"
#include "util.h"

/* OUR APPLICATION USB URB (2MB) ;) */
#define PTPCAM_USB_URB		2097152

/* this must not be too short - the original 4000 was not long
   enough for big file transfers. I imagine the player spends a 
   bit of time gearing up to receiving lots of data. This also makes
   connecting/disconnecting more reliable */
#define USB_TIMEOUT		10000
#define USB_CAPTURE_TIMEOUT	20000

/* USB control message data phase direction */
#ifndef USB_DP_HTD
#define USB_DP_HTD		(0x00 << 7)	/* host to device */
#endif
#ifndef USB_DP_DTH
#define USB_DP_DTH		(0x01 << 7)	/* device to host */
#endif

/* USB Feature selector HALT */
#ifndef USB_FEATURE_HALT
#define USB_FEATURE_HALT	0x00
#endif

/*
 * MTP device list, trying real bad to get all devices into
 * this list by stealing from everyone I know.
 */
static const LIBMTP_device_entry_t mtp_device_table[] = {
  /* Creative devices */
  { "Creative Zen Vision", 0x041e, 0x411f },
  { "Creative Portable Media Center", 0x041e, 0x4123 },
  { "Creative Zen Xtra (MTP mode)", 0x041e, 0x4128 },
  { "Second generation Dell DJ", 0x041e, 0x412f },
  { "Creative Zen Micro (MTP mode)", 0x041e, 0x4130 },
  { "Creative Zen Touch (MTP mode)", 0x041e, 0x4131 },
  { "Dell Pocket DJ (MTP mode)", 0x041e, 0x4132 },
  { "Creative Zen Sleek (MTP mode)", 0x041e, 0x4137 },
  { "Creative Zen MicroPhoto", 0x041e, 0x413c },
  { "Creative Zen Sleek Photo", 0x041e, 0x413d },
  { "Creative Zen Vision:M", 0x041e, 0x413e },
  /* From libgphoto2 */
  { "Samsung:YH-820", 0x04e8, 0x502e },
  /* Contributed by <EMAIL> */
  { "Samsung YH-925", 0x04e8, 0x502f },
  /* Contributed by anonymous person on SourceForge */
  { "Samsung YP-T7J", 0x04e8, 0x5047 },
  /* From a rouge .INF file */
  { "Samsung YH-999 Portable Media Center", 0x04e8, 0x5a0f },
  { "Intel Bandon Portable Media Center", 0x045e, 0x00c9 },
  { "iRiver Portable Media Center", 0x1006, 0x4002 },
  { "iRiver Portable Media Center", 0x1006, 0x4003 },
  /* From <NAME> */
  { "JVC Alneo XA-HD500", 0x04f1, 0x6105 },
  /* From libgphoto2 source */
  { "Philipps HDD6320", 0x0471, 0x01eb },
  { "Philipps HDD6320 2", 0x0471, 0x014b },
  /* Anonymous SourceForge user */
  { "Philipps HDD1630/17", 0x0471, 0x014c },
  /* Reported by <EMAIL> */
  { "SanDisk Sansa c150", 0x0781, 0x7410 },
  /* From libgphoto2 source */
  { "SanDisk Sansa e200", 0x0781, 0x7420 },
  /* Reported by <EMAIL> */
  { "SanDisk Sansa e260", 0x0781, 0x7420 },
  /* From libgphoto2 source */
  { "iRiver T10", 0x4102, 0x1113 },
  { "iRiver T20 FM", 0x4102, 0x1114 },
  { "iRiver U10", 0x4102, 0x1116 },
  { "iRiver T10", 0x4102, 0x1117 },
  { "iRiver T20", 0x4102, 0x1118 },
  { "iRiver T30", 0x4102, 0x1119 },
  /* Reported by <NAME> */
  { "iRiver H10", 0x4102, 0x2101 },
  { "iRiver H10", 0x4102, 0x2102 },
  { "<NAME>", 0x413c, 0x4500 },
  { "Toshiba Gigabeat MEGF-40", 0x0930, 0x0009 },
  { "Toshiba Gigabeat", 0x0930, 0x000c }
};
static const int mtp_device_table_size = sizeof(mtp_device_table) / sizeof(LIBMTP_device_entry_t);

int ptpcam_usb_timeout = USB_TIMEOUT;

// Local functions
static struct usb_bus* init_usb();
static struct usb_device *probe_usb_bus_for_mtp_devices(void);
static void close_usb(PTP_USB* ptp_usb, uint8_t interfaceNumber);
static struct usb_device* find_device (int busn, int devicen, short force);
static void find_endpoints(struct usb_device *dev, int* inep, int* inep_maxpacket, int* outep, int* outep_maxpacket, int* intep);
static void clear_stall(PTP_USB* ptp_usb);
static int init_ptp_usb (PTPParams* params, PTP_USB* ptp_usb, struct usb_device* dev);
static short ptp_write_func (unsigned char *bytes, unsigned int size, void *data);
static short ptp_read_func (unsigned char *bytes, unsigned int size, void *data, unsigned int *readbytes);
static short ptp_check_int (unsigned char *bytes, unsigned int size, void *data, unsigned int *rlen);
static int usb_clear_stall_feature(PTP_USB* ptp_usb, int ep);
{'fraction_non_alphanumeric': 0.12961345271893426, 'fraction_numerical': 0.09412535488097838, 'mean_word_length': 4.165820642978003, 'pattern_counts': {'":': 0, '<': 50, '<?xml version=': 0, '>': 42, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6841476', 'n_tokens_mistral': 4207, 'n_tokens_neox': 3623, 'n_words': 1045}