darwin_usb.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. /*
  2. * darwin backend for libusb 1.0
  3. * Copyright (C) 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 (kIOUSBInterfaceInterfaceID300)
  28. #define usb_interface_t IOUSBInterfaceInterface300
  29. #define InterfaceInterfaceID kIOUSBInterfaceInterfaceID300
  30. #define InterfaceVersion 300
  31. #elif defined (kIOUSBInterfaceInterfaceID245)
  32. #define usb_interface_t IOUSBInterfaceInterface245
  33. #define InterfaceInterfaceID kIOUSBInterfaceInterfaceID245
  34. #define InterfaceVersion 245
  35. #elif defined (kIOUSBInterfaceInterfaceID220)
  36. #define usb_interface_t IOUSBInterfaceInterface220
  37. #define InterfaceInterfaceID kIOUSBInterfaceInterfaceID220
  38. #define InterfaceVersion 220
  39. #elif defined (kIOUSBInterfaceInterfaceID197)
  40. #define usb_interface_t IOUSBInterfaceInterface197
  41. #define InterfaceInterfaceID kIOUSBInterfaceInterfaceID197
  42. #define InterfaceVersion 197
  43. #elif defined (kIOUSBInterfaceInterfaceID190)
  44. #define usb_interface_t IOUSBInterfaceInterface190
  45. #define InterfaceInterfaceID kIOUSBInterfaceInterfaceID190
  46. #define InterfaceVersion 190
  47. #elif defined (kIOUSBInterfaceInterfaceID182)
  48. #define usb_interface_t IOUSBInterfaceInterface182
  49. #define InterfaceInterfaceID kIOUSBInterfaceInterfaceID182
  50. #define InterfaceVersion 182
  51. #else
  52. #error "IOUSBFamily is too old. Please upgrade your OS"
  53. #endif
  54. /* IOUSBDeviceInterface */
  55. #if defined (kIOUSBDeviceInterfaceID500)
  56. #define usb_device_t IOUSBDeviceInterface500
  57. #define DeviceInterfaceID kIOUSBDeviceInterfaceID500
  58. #define DeviceVersion 500
  59. #elif defined (kIOUSBDeviceInterfaceID320)
  60. #define usb_device_t IOUSBDeviceInterface320
  61. #define DeviceInterfaceID kIOUSBDeviceInterfaceID320
  62. #define DeviceVersion 320
  63. #elif defined (kIOUSBDeviceInterfaceID300)
  64. #define usb_device_t IOUSBDeviceInterface300
  65. #define DeviceInterfaceID kIOUSBDeviceInterfaceID300
  66. #define DeviceVersion 300
  67. #elif defined (kIOUSBDeviceInterfaceID245)
  68. #define usb_device_t IOUSBDeviceInterface245
  69. #define DeviceInterfaceID kIOUSBDeviceInterfaceID245
  70. #define DeviceVersion 245
  71. #elif defined (kIOUSBDeviceInterfaceID197)
  72. #define usb_device_t IOUSBDeviceInterface197
  73. #define DeviceInterfaceID kIOUSBDeviceInterfaceID197
  74. #define DeviceVersion 197
  75. #elif defined (kIOUSBDeviceInterfaceID187)
  76. #define usb_device_t IOUSBDeviceInterface187
  77. #define DeviceInterfaceID kIOUSBDeviceInterfaceID187
  78. #define DeviceVersion 187
  79. #elif defined (kIOUSBDeviceInterfaceID182)
  80. #define usb_device_t IOUSBDeviceInterface182
  81. #define DeviceInterfaceID kIOUSBDeviceInterfaceID182
  82. #define DeviceVersion 182
  83. #else
  84. #error "IOUSBFamily is too old. Please upgrade your OS"
  85. #endif
  86. #if !defined(IO_OBJECT_NULL)
  87. #define IO_OBJECT_NULL ((io_object_t) 0)
  88. #endif
  89. typedef IOCFPlugInInterface *io_cf_plugin_ref_t;
  90. typedef IONotificationPortRef io_notification_port_t;
  91. /* private structures */
  92. struct darwin_device_priv {
  93. IOUSBDeviceDescriptor dev_descriptor;
  94. UInt32 location;
  95. char sys_path[21];
  96. usb_device_t **device;
  97. int open_count;
  98. UInt8 first_config, active_config;
  99. };
  100. struct darwin_device_handle_priv {
  101. int is_open;
  102. CFRunLoopSourceRef cfSource;
  103. int fds[2];
  104. struct darwin_interface {
  105. usb_interface_t **interface;
  106. uint8_t num_endpoints;
  107. CFRunLoopSourceRef cfSource;
  108. uint64_t frames[256];
  109. uint8_t endpoint_addrs[USB_MAXENDPOINTS];
  110. } interfaces[USB_MAXINTERFACES];
  111. };
  112. struct darwin_transfer_priv {
  113. /* Isoc */
  114. IOUSBIsocFrame *isoc_framelist;
  115. int num_iso_packets;
  116. /* Control */
  117. #if !defined (LIBUSB_NO_TIMEOUT_DEVICE)
  118. IOUSBDevRequestTO req;
  119. #else
  120. IOUSBDevRequest req;
  121. #endif
  122. /* Bulk */
  123. };
  124. /* structure for signaling io completion */
  125. struct darwin_msg_async_io_complete {
  126. struct usbi_transfer *itransfer;
  127. IOReturn result;
  128. UInt32 size;
  129. };
  130. #endif