darwin_usb.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. /*
  2. * darwin backend for libusbx 1.0
  3. * Copyright © 2008-2013 Nathan Hjelm <hjelmn@users.sourceforge.net>
  4. *
  5. * This library is free software; you can redistribute it and/or
  6. * modify it under the terms of the GNU Lesser General Public
  7. * License as published by the Free Software Foundation; either
  8. * version 2.1 of the License, or (at your option) any later version.
  9. *
  10. * This library is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13. * Lesser General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU Lesser General Public
  16. * License along with this library; if not, write to the Free Software
  17. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  18. */
  19. #if !defined(LIBUSB_DARWIN_H)
  20. #define LIBUSB_DARWIN_H
  21. #include "libusbi.h"
  22. #include <IOKit/IOTypes.h>
  23. #include <IOKit/IOCFBundle.h>
  24. #include <IOKit/usb/IOUSBLib.h>
  25. #include <IOKit/IOCFPlugIn.h>
  26. /* IOUSBInterfaceInferface */
  27. #if defined (kIOUSBInterfaceInterfaceID550)
  28. #define usb_interface_t IOUSBInterfaceInterface550
  29. #define InterfaceInterfaceID kIOUSBInterfaceInterfaceID550
  30. #define InterfaceVersion 550
  31. #elif defined (kIOUSBInterfaceInterfaceID500)
  32. #define usb_interface_t IOUSBInterfaceInterface500
  33. #define InterfaceInterfaceID kIOUSBInterfaceInterfaceID500
  34. #define InterfaceVersion 500
  35. #elif defined (kIOUSBInterfaceInterfaceID300)
  36. #define usb_interface_t IOUSBInterfaceInterface300
  37. #define InterfaceInterfaceID kIOUSBInterfaceInterfaceID300
  38. #define InterfaceVersion 300
  39. #elif defined (kIOUSBInterfaceInterfaceID245)
  40. #define usb_interface_t IOUSBInterfaceInterface245
  41. #define InterfaceInterfaceID kIOUSBInterfaceInterfaceID245
  42. #define InterfaceVersion 245
  43. #elif defined (kIOUSBInterfaceInterfaceID220)
  44. #define usb_interface_t IOUSBInterfaceInterface220
  45. #define InterfaceInterfaceID kIOUSBInterfaceInterfaceID220
  46. #define InterfaceVersion 220
  47. #else
  48. #error "IOUSBFamily is too old. Please upgrade your OS"
  49. #endif
  50. /* IOUSBDeviceInterface */
  51. #if defined (kIOUSBDeviceInterfaceID500)
  52. #define usb_device_t IOUSBDeviceInterface500
  53. #define DeviceInterfaceID kIOUSBDeviceInterfaceID500
  54. #define DeviceVersion 500
  55. #elif defined (kIOUSBDeviceInterfaceID320)
  56. #define usb_device_t IOUSBDeviceInterface320
  57. #define DeviceInterfaceID kIOUSBDeviceInterfaceID320
  58. #define DeviceVersion 320
  59. #elif defined (kIOUSBDeviceInterfaceID300)
  60. #define usb_device_t IOUSBDeviceInterface300
  61. #define DeviceInterfaceID kIOUSBDeviceInterfaceID300
  62. #define DeviceVersion 300
  63. #elif defined (kIOUSBDeviceInterfaceID245)
  64. #define usb_device_t IOUSBDeviceInterface245
  65. #define DeviceInterfaceID kIOUSBDeviceInterfaceID245
  66. #define DeviceVersion 245
  67. #elif defined (kIOUSBDeviceInterfaceID220)
  68. #define usb_device_t IOUSBDeviceInterface197
  69. #define DeviceInterfaceID kIOUSBDeviceInterfaceID197
  70. #define DeviceVersion 197
  71. #else
  72. #error "IOUSBFamily is too old. Please upgrade your OS"
  73. #endif
  74. #if !defined(IO_OBJECT_NULL)
  75. #define IO_OBJECT_NULL ((io_object_t) 0)
  76. #endif
  77. typedef IOCFPlugInInterface *io_cf_plugin_ref_t;
  78. typedef IONotificationPortRef io_notification_port_t;
  79. /* private structures */
  80. struct darwin_cached_device {
  81. struct list_head list;
  82. IOUSBDeviceDescriptor dev_descriptor;
  83. UInt32 location;
  84. UInt64 parent_session;
  85. UInt64 session;
  86. UInt16 address;
  87. char sys_path[21];
  88. usb_device_t **device;
  89. int open_count;
  90. UInt8 first_config, active_config, port;
  91. int can_enumerate;
  92. int refcount;
  93. };
  94. struct darwin_device_priv {
  95. struct darwin_cached_device *dev;
  96. };
  97. struct darwin_device_handle_priv {
  98. int is_open;
  99. CFRunLoopSourceRef cfSource;
  100. int fds[2];
  101. struct darwin_interface {
  102. usb_interface_t **interface;
  103. uint8_t num_endpoints;
  104. CFRunLoopSourceRef cfSource;
  105. uint64_t frames[256];
  106. uint8_t endpoint_addrs[USB_MAXENDPOINTS];
  107. } interfaces[USB_MAXINTERFACES];
  108. };
  109. struct darwin_transfer_priv {
  110. /* Isoc */
  111. IOUSBIsocFrame *isoc_framelist;
  112. int num_iso_packets;
  113. /* Control */
  114. IOUSBDevRequestTO req;
  115. /* Bulk */
  116. };
  117. /* structure for signaling io completion */
  118. struct darwin_msg_async_io_complete {
  119. struct usbi_transfer *itransfer;
  120. IOReturn result;
  121. UInt32 size;
  122. };
  123. #endif