Home | History | Annotate | Download | only in src
      1 /**
      2  * \file libusb-glue.h
      3  * Low-level USB interface glue towards libusb.
      4  *
      5  * Copyright (C) 2005-2007 Richard A. Low <richard (at) wentnet.com>
      6  * Copyright (C) 2005-2007 Linus Walleij <triad (at) df.lth.se>
      7  * Copyright (C) 2006-2007 Marcus Meissner
      8  * Copyright (C) 2007 Ted Bullock
      9  * Copyright (C) 2008 Chris Bagwell <chris (at) cnpbagwell.com>
     10  *
     11  * This library is free software; you can redistribute it and/or
     12  * modify it under the terms of the GNU Lesser General Public
     13  * License as published by the Free Software Foundation; either
     14  * version 2 of the License, or (at your option) any later version.
     15  *
     16  * This library is distributed in the hope that it will be useful,
     17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
     18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
     19  * Lesser General Public License for more details.
     20  *
     21  * You should have received a copy of the GNU Lesser General Public
     22  * License along with this library; if not, write to the
     23  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
     24  * Boston, MA 02111-1307, USA.
     25  *
     26  * Created by Richard Low on 24/12/2005.
     27  * Modified by Linus Walleij
     28  *
     29  */
     30 #ifndef LIBUSB_GLUE_H
     31 #define LIBUSB_GLUE_H
     32 
     33 #include "ptp.h"
     34 #include <usb.h>
     35 #include "libmtp.h"
     36 #include "device-flags.h"
     37 
     38 /* Make functions available for C++ */
     39 #ifdef __cplusplus
     40 extern "C" {
     41 #endif /* __cplusplus */
     42 
     43 #define USB_BULK_READ usb_bulk_read
     44 #define USB_BULK_WRITE usb_bulk_write
     45 
     46 /**
     47  * Internal USB struct.
     48  */
     49 typedef struct _PTP_USB PTP_USB;
     50 struct _PTP_USB {
     51   PTPParams *params;
     52   usb_dev_handle* handle;
     53   uint8_t interface;
     54   int inep;
     55   int inep_maxpacket;
     56   int outep;
     57   int outep_maxpacket;
     58   int intep;
     59   int timeout;
     60   /** File transfer callbacks and counters */
     61   int callback_active;
     62   uint64_t current_transfer_total;
     63   uint64_t current_transfer_complete;
     64   LIBMTP_progressfunc_t current_transfer_callback;
     65   void const * current_transfer_callback_data;
     66   /** Any special device flags, only used internally */
     67   LIBMTP_raw_device_t rawdevice;
     68 };
     69 
     70 int open_device (int busn, int devn, short force, PTP_USB *ptp_usb, PTPParams *params, struct usb_device **dev);
     71 void dump_usbinfo(PTP_USB *ptp_usb);
     72 const char *get_playlist_extension(PTP_USB *ptp_usb);
     73 void close_device(PTP_USB *ptp_usb, PTPParams *params);
     74 LIBMTP_error_number_t configure_usb_device(LIBMTP_raw_device_t *device,
     75 					   PTPParams *params,
     76 					   void **usbinfo);
     77 void set_usb_device_timeout(PTP_USB *ptp_usb, int timeout);
     78 void get_usb_device_timeout(PTP_USB *ptp_usb, int *timeout);
     79 
     80 /* Flag check macros */
     81 #define FLAG_BROKEN_MTPGETOBJPROPLIST_ALL(a) \
     82   ((a)->rawdevice.device_entry.device_flags & DEVICE_FLAG_BROKEN_MTPGETOBJPROPLIST_ALL)
     83 #define FLAG_UNLOAD_DRIVER(a) \
     84   ((a)->rawdevice.device_entry.device_flags & DEVICE_FLAG_UNLOAD_DRIVER)
     85 #define FLAG_BROKEN_MTPGETOBJPROPLIST(a) \
     86   ((a)->rawdevice.device_entry.device_flags & DEVICE_FLAG_BROKEN_MTPGETOBJPROPLIST)
     87 #define FLAG_NO_ZERO_READS(a) \
     88   ((a)->rawdevice.device_entry.device_flags & DEVICE_FLAG_NO_ZERO_READS)
     89 #define FLAG_IRIVER_OGG_ALZHEIMER(a) \
     90   ((a)->rawdevice.device_entry.device_flags & DEVICE_FLAG_IRIVER_OGG_ALZHEIMER)
     91 #define FLAG_ONLY_7BIT_FILENAMES(a) \
     92   ((a)->rawdevice.device_entry.device_flags & DEVICE_FLAG_ONLY_7BIT_FILENAMES)
     93 #define FLAG_NO_RELEASE_INTERFACE(a) \
     94   ((a)->rawdevice.device_entry.device_flags & DEVICE_FLAG_NO_RELEASE_INTERFACE)
     95 #define FLAG_IGNORE_HEADER_ERRORS(a) \
     96   ((a)->rawdevice.device_entry.device_flags & DEVICE_FLAG_IGNORE_HEADER_ERRORS)
     97 #define FLAG_BROKEN_SET_OBJECT_PROPLIST(a) \
     98   ((a)->rawdevice.device_entry.device_flags & DEVICE_FLAG_BROKEN_SET_OBJECT_PROPLIST)
     99 #define FLAG_OGG_IS_UNKNOWN(a) \
    100   ((a)->rawdevice.device_entry.device_flags & DEVICE_FLAG_OGG_IS_UNKNOWN)
    101 #define FLAG_BROKEN_SET_SAMPLE_DIMENSIONS(a) \
    102   ((a)->rawdevice.device_entry.device_flags & DEVICE_FLAG_BROKEN_SET_SAMPLE_DIMENSIONS)
    103 #define FLAG_ALWAYS_PROBE_DESCRIPTOR(a) \
    104   ((a)->rawdevice.device_entry.device_flags & DEVICE_FLAG_ALWAYS_PROBE_DESCRIPTOR)
    105 #define FLAG_PLAYLIST_SPL_V1(a) \
    106   ((a)->rawdevice.device_entry.device_flags & DEVICE_FLAG_PLAYLIST_SPL_V1)
    107 #define FLAG_PLAYLIST_SPL_V2(a) \
    108   ((a)->rawdevice.device_entry.device_flags & DEVICE_FLAG_PLAYLIST_SPL_V2)
    109 #define FLAG_PLAYLIST_SPL(a) \
    110   ((a)->rawdevice.device_entry.device_flags & (DEVICE_FLAG_PLAYLIST_SPL_V1 | DEVICE_FLAG_PLAYLIST_SPL_V2))
    111 #define FLAG_CANNOT_HANDLE_DATEMODIFIED(a) \
    112   ((a)->rawdevice.device_entry.device_flags & DEVICE_FLAG_CANNOT_HANDLE_DATEMODIFIED)
    113 #define FLAG_BROKEN_SEND_OBJECT_PROPLIST(a) \
    114   ((a)->rawdevice.device_entry.device_flags & DEVICE_FLAG_BROKEN_SEND_OBJECT_PROPLIST)
    115 #define FLAG_BROKEN_BATTERY_LEVEL(a) \
    116   ((a)->rawdevice.device_entry.device_flags & DEVICE_FLAG_BROKEN_BATTERY_LEVEL)
    117 #define FLAG_FLAC_IS_UNKNOWN(a) \
    118   ((a)->rawdevice.device_entry.device_flags & DEVICE_FLAG_FLAC_IS_UNKNOWN)
    119 
    120 /* connect_first_device return codes */
    121 #define PTP_CD_RC_CONNECTED	0
    122 #define PTP_CD_RC_NO_DEVICES	1
    123 #define PTP_CD_RC_ERROR_CONNECTING	2
    124 
    125 #ifdef __cplusplus
    126 }
    127 #endif /* __cplusplus */
    128 
    129 #endif //  LIBUSB-GLUE_H
    130