|
Packit Service |
b0a153 |
/*
|
|
Packit Service |
b0a153 |
* darwin backend for libusb 1.0
|
|
Packit Service |
b0a153 |
* Copyright © 2008-2019 Nathan Hjelm <hjelmn@users.sourceforge.net>
|
|
Packit Service |
b0a153 |
* Copyright © 2019 Google LLC. All rights reserved.
|
|
Packit Service |
b0a153 |
*
|
|
Packit Service |
b0a153 |
* This library is free software; you can redistribute it and/or
|
|
Packit Service |
b0a153 |
* modify it under the terms of the GNU Lesser General Public
|
|
Packit Service |
b0a153 |
* License as published by the Free Software Foundation; either
|
|
Packit Service |
b0a153 |
* version 2.1 of the License, or (at your option) any later version.
|
|
Packit Service |
b0a153 |
*
|
|
Packit Service |
b0a153 |
* This library is distributed in the hope that it will be useful,
|
|
Packit Service |
b0a153 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit Service |
b0a153 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
Packit Service |
b0a153 |
* Lesser General Public License for more details.
|
|
Packit Service |
b0a153 |
*
|
|
Packit Service |
b0a153 |
* You should have received a copy of the GNU Lesser General Public
|
|
Packit Service |
b0a153 |
* License along with this library; if not, write to the Free Software
|
|
Packit Service |
b0a153 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
Packit Service |
b0a153 |
*/
|
|
Packit Service |
b0a153 |
|
|
Packit Service |
b0a153 |
#if !defined(LIBUSB_DARWIN_H)
|
|
Packit Service |
b0a153 |
#define LIBUSB_DARWIN_H
|
|
Packit Service |
b0a153 |
|
|
Packit Service |
b0a153 |
#include <stdbool.h>
|
|
Packit Service |
b0a153 |
|
|
Packit Service |
b0a153 |
#include "libusbi.h"
|
|
Packit Service |
b0a153 |
|
|
Packit Service |
b0a153 |
#include <IOKit/IOTypes.h>
|
|
Packit Service |
b0a153 |
#include <IOKit/IOCFBundle.h>
|
|
Packit Service |
b0a153 |
#include <IOKit/usb/IOUSBLib.h>
|
|
Packit Service |
b0a153 |
#include <IOKit/IOCFPlugIn.h>
|
|
Packit Service |
b0a153 |
|
|
Packit Service |
b0a153 |
/* IOUSBInterfaceInferface */
|
|
Packit Service |
b0a153 |
|
|
Packit Service |
b0a153 |
/* New in OS 10.12.0. */
|
|
Packit Service |
b0a153 |
#if defined (kIOUSBInterfaceInterfaceID800) && (MAC_OS_X_VERSION_MIN_REQUIRED >= 101200)
|
|
Packit Service |
b0a153 |
|
|
Packit Service |
b0a153 |
#define usb_interface_t IOUSBInterfaceInterface800
|
|
Packit Service |
b0a153 |
#define InterfaceInterfaceID kIOUSBInterfaceInterfaceID800
|
|
Packit Service |
b0a153 |
#define InterfaceVersion 800
|
|
Packit Service |
b0a153 |
|
|
Packit Service |
b0a153 |
/* New in OS 10.10.0. */
|
|
Packit Service |
b0a153 |
#elif defined (kIOUSBInterfaceInterfaceID700) && (MAC_OS_X_VERSION_MIN_REQUIRED >= 101000)
|
|
Packit Service |
b0a153 |
|
|
Packit Service |
b0a153 |
#define usb_interface_t IOUSBInterfaceInterface700
|
|
Packit Service |
b0a153 |
#define InterfaceInterfaceID kIOUSBInterfaceInterfaceID700
|
|
Packit Service |
b0a153 |
#define InterfaceVersion 700
|
|
Packit Service |
b0a153 |
|
|
Packit Service |
b0a153 |
/* New in OS 10.9.0. */
|
|
Packit Service |
b0a153 |
#elif defined (kIOUSBInterfaceInterfaceID650) && (MAC_OS_X_VERSION_MIN_REQUIRED >= 1090)
|
|
Packit Service |
b0a153 |
|
|
Packit Service |
b0a153 |
#define usb_interface_t IOUSBInterfaceInterface650
|
|
Packit Service |
b0a153 |
#define InterfaceInterfaceID kIOUSBInterfaceInterfaceID650
|
|
Packit Service |
b0a153 |
#define InterfaceVersion 650
|
|
Packit Service |
b0a153 |
|
|
Packit Service |
b0a153 |
/* New in OS 10.8.2 but can't test deployment target to that granularity, so round up. */
|
|
Packit Service |
b0a153 |
#elif defined (kIOUSBInterfaceInterfaceID550) && (MAC_OS_X_VERSION_MIN_REQUIRED >= 1090)
|
|
Packit Service |
b0a153 |
|
|
Packit Service |
b0a153 |
#define usb_interface_t IOUSBInterfaceInterface550
|
|
Packit Service |
b0a153 |
#define InterfaceInterfaceID kIOUSBInterfaceInterfaceID550
|
|
Packit Service |
b0a153 |
#define InterfaceVersion 550
|
|
Packit Service |
b0a153 |
|
|
Packit Service |
b0a153 |
/* New in OS 10.7.3 but can't test deployment target to that granularity, so round up. */
|
|
Packit Service |
b0a153 |
#elif defined (kIOUSBInterfaceInterfaceID500) && (MAC_OS_X_VERSION_MIN_REQUIRED >= 1080)
|
|
Packit Service |
b0a153 |
|
|
Packit Service |
b0a153 |
#define usb_interface_t IOUSBInterfaceInterface500
|
|
Packit Service |
b0a153 |
#define InterfaceInterfaceID kIOUSBInterfaceInterfaceID500
|
|
Packit Service |
b0a153 |
#define InterfaceVersion 500
|
|
Packit Service |
b0a153 |
|
|
Packit Service |
b0a153 |
/* New in OS 10.5.0. */
|
|
Packit Service |
b0a153 |
#elif defined (kIOUSBInterfaceInterfaceID300) && (MAC_OS_X_VERSION_MIN_REQUIRED >= 1050)
|
|
Packit Service |
b0a153 |
|
|
Packit Service |
b0a153 |
#define usb_interface_t IOUSBInterfaceInterface300
|
|
Packit Service |
b0a153 |
#define InterfaceInterfaceID kIOUSBInterfaceInterfaceID300
|
|
Packit Service |
b0a153 |
#define InterfaceVersion 300
|
|
Packit Service |
b0a153 |
|
|
Packit Service |
b0a153 |
/* New in OS 10.4.5 (or 10.4.6?) but can't test deployment target to that granularity, so round up. */
|
|
Packit Service |
b0a153 |
#elif defined (kIOUSBInterfaceInterfaceID245) && (MAC_OS_X_VERSION_MIN_REQUIRED >= 1050)
|
|
Packit Service |
b0a153 |
|
|
Packit Service |
b0a153 |
#define usb_interface_t IOUSBInterfaceInterface245
|
|
Packit Service |
b0a153 |
#define InterfaceInterfaceID kIOUSBInterfaceInterfaceID245
|
|
Packit Service |
b0a153 |
#define InterfaceVersion 245
|
|
Packit Service |
b0a153 |
|
|
Packit Service |
b0a153 |
/* New in OS 10.4.0. */
|
|
Packit Service |
b0a153 |
#elif defined (kIOUSBInterfaceInterfaceID220) && (MAC_OS_X_VERSION_MIN_REQUIRED >= 1040)
|
|
Packit Service |
b0a153 |
|
|
Packit Service |
b0a153 |
#define usb_interface_t IOUSBInterfaceInterface220
|
|
Packit Service |
b0a153 |
#define InterfaceInterfaceID kIOUSBInterfaceInterfaceID220
|
|
Packit Service |
b0a153 |
#define InterfaceVersion 220
|
|
Packit Service |
b0a153 |
|
|
Packit Service |
b0a153 |
#else
|
|
Packit Service |
b0a153 |
|
|
Packit Service |
b0a153 |
#error "IOUSBFamily is too old. Please upgrade your SDK and/or deployment target"
|
|
Packit Service |
b0a153 |
|
|
Packit Service |
b0a153 |
#endif
|
|
Packit Service |
b0a153 |
|
|
Packit Service |
b0a153 |
/* IOUSBDeviceInterface */
|
|
Packit Service |
b0a153 |
|
|
Packit Service |
b0a153 |
/* New in OS 10.9.0. */
|
|
Packit Service |
b0a153 |
#if defined (kIOUSBDeviceInterfaceID650) && (MAC_OS_X_VERSION_MIN_REQUIRED >= 1090)
|
|
Packit Service |
b0a153 |
|
|
Packit Service |
b0a153 |
#define usb_device_t IOUSBDeviceInterface650
|
|
Packit Service |
b0a153 |
#define DeviceInterfaceID kIOUSBDeviceInterfaceID650
|
|
Packit Service |
b0a153 |
#define DeviceVersion 650
|
|
Packit Service |
b0a153 |
|
|
Packit Service |
b0a153 |
/* New in OS 10.7.3 but can't test deployment target to that granularity, so round up. */
|
|
Packit Service |
b0a153 |
#elif defined (kIOUSBDeviceInterfaceID500) && (MAC_OS_X_VERSION_MIN_REQUIRED >= 1080)
|
|
Packit Service |
b0a153 |
|
|
Packit Service |
b0a153 |
#define usb_device_t IOUSBDeviceInterface500
|
|
Packit Service |
b0a153 |
#define DeviceInterfaceID kIOUSBDeviceInterfaceID500
|
|
Packit Service |
b0a153 |
#define DeviceVersion 500
|
|
Packit Service |
b0a153 |
|
|
Packit Service |
b0a153 |
/* New in OS 10.5.4 but can't test deployment target to that granularity, so round up. */
|
|
Packit Service |
b0a153 |
#elif defined (kIOUSBDeviceInterfaceID320) && (MAC_OS_X_VERSION_MIN_REQUIRED >= 1060)
|
|
Packit Service |
b0a153 |
|
|
Packit Service |
b0a153 |
#define usb_device_t IOUSBDeviceInterface320
|
|
Packit Service |
b0a153 |
#define DeviceInterfaceID kIOUSBDeviceInterfaceID320
|
|
Packit Service |
b0a153 |
#define DeviceVersion 320
|
|
Packit Service |
b0a153 |
|
|
Packit Service |
b0a153 |
/* New in OS 10.5.0. */
|
|
Packit Service |
b0a153 |
#elif defined (kIOUSBDeviceInterfaceID300) && (MAC_OS_X_VERSION_MIN_REQUIRED >= 1050)
|
|
Packit Service |
b0a153 |
|
|
Packit Service |
b0a153 |
#define usb_device_t IOUSBDeviceInterface300
|
|
Packit Service |
b0a153 |
#define DeviceInterfaceID kIOUSBDeviceInterfaceID300
|
|
Packit Service |
b0a153 |
#define DeviceVersion 300
|
|
Packit Service |
b0a153 |
|
|
Packit Service |
b0a153 |
/* New in OS 10.4.5 (or 10.4.6?) but can't test deployment target to that granularity, so round up. */
|
|
Packit Service |
b0a153 |
#elif defined (kIOUSBDeviceInterfaceID245) && (MAC_OS_X_VERSION_MIN_REQUIRED >= 1050)
|
|
Packit Service |
b0a153 |
|
|
Packit Service |
b0a153 |
#define usb_device_t IOUSBDeviceInterface245
|
|
Packit Service |
b0a153 |
#define DeviceInterfaceID kIOUSBDeviceInterfaceID245
|
|
Packit Service |
b0a153 |
#define DeviceVersion 245
|
|
Packit Service |
b0a153 |
|
|
Packit Service |
b0a153 |
/* New in OS 10.2.3 but can't test deployment target to that granularity, so round up. */
|
|
Packit Service |
b0a153 |
#elif defined (kIOUSBDeviceInterfaceID197) && (MAC_OS_X_VERSION_MIN_REQUIRED >= 1030)
|
|
Packit Service |
b0a153 |
|
|
Packit Service |
b0a153 |
#define usb_device_t IOUSBDeviceInterface197
|
|
Packit Service |
b0a153 |
#define DeviceInterfaceID kIOUSBDeviceInterfaceID197
|
|
Packit Service |
b0a153 |
#define DeviceVersion 197
|
|
Packit Service |
b0a153 |
|
|
Packit Service |
b0a153 |
#else
|
|
Packit Service |
b0a153 |
|
|
Packit Service |
b0a153 |
#error "IOUSBFamily is too old. Please upgrade your SDK and/or deployment target"
|
|
Packit Service |
b0a153 |
|
|
Packit Service |
b0a153 |
#endif
|
|
Packit Service |
b0a153 |
|
|
Packit Service |
b0a153 |
#if !defined(IO_OBJECT_NULL)
|
|
Packit Service |
b0a153 |
#define IO_OBJECT_NULL ((io_object_t) 0)
|
|
Packit Service |
b0a153 |
#endif
|
|
Packit Service |
b0a153 |
|
|
Packit Service |
b0a153 |
typedef IOCFPlugInInterface *io_cf_plugin_ref_t;
|
|
Packit Service |
b0a153 |
typedef IONotificationPortRef io_notification_port_t;
|
|
Packit Service |
b0a153 |
|
|
Packit Service |
b0a153 |
/* private structures */
|
|
Packit Service |
b0a153 |
struct darwin_cached_device {
|
|
Packit Service |
b0a153 |
struct list_head list;
|
|
Packit Service |
b0a153 |
IOUSBDeviceDescriptor dev_descriptor;
|
|
Packit Service |
b0a153 |
UInt32 location;
|
|
Packit Service |
b0a153 |
UInt64 parent_session;
|
|
Packit Service |
b0a153 |
UInt64 session;
|
|
Packit Service |
b0a153 |
USBDeviceAddress address;
|
|
Packit Service |
b0a153 |
char sys_path[21];
|
|
Packit Service |
b0a153 |
usb_device_t **device;
|
|
Packit Service |
b0a153 |
int open_count;
|
|
Packit Service |
b0a153 |
UInt8 first_config, active_config, port;
|
|
Packit Service |
b0a153 |
int can_enumerate;
|
|
Packit Service |
b0a153 |
int refcount;
|
|
Packit Service |
b0a153 |
bool in_reenumerate;
|
|
Packit Service |
b0a153 |
};
|
|
Packit Service |
b0a153 |
|
|
Packit Service |
b0a153 |
struct darwin_device_priv {
|
|
Packit Service |
b0a153 |
struct darwin_cached_device *dev;
|
|
Packit Service |
b0a153 |
};
|
|
Packit Service |
b0a153 |
|
|
Packit Service |
b0a153 |
struct darwin_device_handle_priv {
|
|
Packit Service |
b0a153 |
bool is_open;
|
|
Packit Service |
b0a153 |
CFRunLoopSourceRef cfSource;
|
|
Packit Service |
b0a153 |
|
|
Packit Service |
b0a153 |
struct darwin_interface {
|
|
Packit Service |
b0a153 |
usb_interface_t **interface;
|
|
Packit Service |
b0a153 |
uint8_t num_endpoints;
|
|
Packit Service |
b0a153 |
CFRunLoopSourceRef cfSource;
|
|
Packit Service |
b0a153 |
uint64_t frames[256];
|
|
Packit Service |
b0a153 |
uint8_t endpoint_addrs[USB_MAXENDPOINTS];
|
|
Packit Service |
b0a153 |
} interfaces[USB_MAXINTERFACES];
|
|
Packit Service |
b0a153 |
};
|
|
Packit Service |
b0a153 |
|
|
Packit Service |
b0a153 |
struct darwin_transfer_priv {
|
|
Packit Service |
b0a153 |
/* Isoc */
|
|
Packit Service |
b0a153 |
IOUSBIsocFrame *isoc_framelist;
|
|
Packit Service |
b0a153 |
int num_iso_packets;
|
|
Packit Service |
b0a153 |
|
|
Packit Service |
b0a153 |
/* Control */
|
|
Packit Service |
b0a153 |
IOUSBDevRequestTO req;
|
|
Packit Service |
b0a153 |
|
|
Packit Service |
b0a153 |
/* Bulk */
|
|
Packit Service |
b0a153 |
|
|
Packit Service |
b0a153 |
/* Completion status */
|
|
Packit Service |
b0a153 |
IOReturn result;
|
|
Packit Service |
b0a153 |
UInt32 size;
|
|
Packit Service |
b0a153 |
};
|
|
Packit Service |
b0a153 |
|
|
Packit Service |
b0a153 |
#endif
|