2
0

SDL_hidapi.c 36 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018
  1. /*
  2. Simple DirectMedia Layer
  3. Copyright (C) 1997-2021 Sam Lantinga <[email protected]>
  4. This software is provided 'as-is', without any express or implied
  5. warranty. In no event will the authors be held liable for any damages
  6. arising from the use of this software.
  7. Permission is granted to anyone to use this software for any purpose,
  8. including commercial applications, and to alter it and redistribute it
  9. freely, subject to the following restrictions:
  10. 1. The origin of this software must not be misrepresented; you must not
  11. claim that you wrote the original software. If you use this software
  12. in a product, an acknowledgment in the product documentation would be
  13. appreciated but is not required.
  14. 2. Altered source versions must be plainly marked as such, and must not be
  15. misrepresented as being the original software.
  16. 3. This notice may not be removed or altered from any source distribution.
  17. */
  18. /* Original hybrid wrapper for Linux by Valve Software. Their original notes:
  19. *
  20. * The libusb version doesn't support Bluetooth, but not all Linux
  21. * distributions allow access to /dev/hidraw*
  22. *
  23. * This merges the two, at a small performance cost, until distributions
  24. * have granted access to /dev/hidraw*
  25. */
  26. #include "../SDL_internal.h"
  27. #include "SDL_loadso.h"
  28. #include "SDL_hidapi.h"
  29. #ifdef SDL_JOYSTICK_HIDAPI
  30. /* Platform HIDAPI Implementation */
  31. #define hid_device_ PLATFORM_hid_device_
  32. #define hid_device PLATFORM_hid_device
  33. #define hid_device_info PLATFORM_hid_device_info
  34. #define hid_init PLATFORM_hid_init
  35. #define hid_exit PLATFORM_hid_exit
  36. #define hid_enumerate PLATFORM_hid_enumerate
  37. #define hid_free_enumeration PLATFORM_hid_free_enumeration
  38. #define hid_open PLATFORM_hid_open
  39. #define hid_open_path PLATFORM_hid_open_path
  40. #define hid_write PLATFORM_hid_write
  41. #define hid_read_timeout PLATFORM_hid_read_timeout
  42. #define hid_read PLATFORM_hid_read
  43. #define hid_set_nonblocking PLATFORM_hid_set_nonblocking
  44. #define hid_send_feature_report PLATFORM_hid_send_feature_report
  45. #define hid_get_feature_report PLATFORM_hid_get_feature_report
  46. #define hid_close PLATFORM_hid_close
  47. #define hid_get_manufacturer_string PLATFORM_hid_get_manufacturer_string
  48. #define hid_get_product_string PLATFORM_hid_get_product_string
  49. #define hid_get_serial_number_string PLATFORM_hid_get_serial_number_string
  50. #define hid_get_indexed_string PLATFORM_hid_get_indexed_string
  51. #define hid_error PLATFORM_hid_error
  52. #define new_hid_device PLATFORM_new_hid_device
  53. #define free_hid_device PLATFORM_free_hid_device
  54. #define input_report PLATFORM_input_report
  55. #define return_data PLATFORM_return_data
  56. #define make_path PLATFORM_make_path
  57. #define read_thread PLATFORM_read_thread
  58. #undef HIDAPI_H__
  59. #if __LINUX__
  60. #include "../../core/linux/SDL_udev.h"
  61. #if SDL_USE_LIBUDEV
  62. static const SDL_UDEV_Symbols *udev_ctx = NULL;
  63. #define udev_device_get_sysattr_value udev_ctx->udev_device_get_sysattr_value
  64. #define udev_new udev_ctx->udev_new
  65. #define udev_unref udev_ctx->udev_unref
  66. #define udev_device_new_from_devnum udev_ctx->udev_device_new_from_devnum
  67. #define udev_device_get_parent_with_subsystem_devtype udev_ctx->udev_device_get_parent_with_subsystem_devtype
  68. #define udev_device_unref udev_ctx->udev_device_unref
  69. #define udev_enumerate_new udev_ctx->udev_enumerate_new
  70. #define udev_enumerate_add_match_subsystem udev_ctx->udev_enumerate_add_match_subsystem
  71. #define udev_enumerate_scan_devices udev_ctx->udev_enumerate_scan_devices
  72. #define udev_enumerate_get_list_entry udev_ctx->udev_enumerate_get_list_entry
  73. #define udev_list_entry_get_name udev_ctx->udev_list_entry_get_name
  74. #define udev_device_new_from_syspath udev_ctx->udev_device_new_from_syspath
  75. #define udev_device_get_devnode udev_ctx->udev_device_get_devnode
  76. #define udev_list_entry_get_next udev_ctx->udev_list_entry_get_next
  77. #define udev_enumerate_unref udev_ctx->udev_enumerate_unref
  78. #include "linux/hid.c"
  79. #define HAVE_PLATFORM_BACKEND 1
  80. #endif /* SDL_USE_LIBUDEV */
  81. #elif __MACOSX__
  82. #include "mac/hid.c"
  83. #define HAVE_PLATFORM_BACKEND 1
  84. #define udev_ctx 1
  85. #elif __WINDOWS__
  86. #include "windows/hid.c"
  87. #define HAVE_PLATFORM_BACKEND 1
  88. #define udev_ctx 1
  89. #endif
  90. #undef hid_device_
  91. #undef hid_device
  92. #undef hid_device_info
  93. #undef hid_init
  94. #undef hid_exit
  95. #undef hid_enumerate
  96. #undef hid_free_enumeration
  97. #undef hid_open
  98. #undef hid_open_path
  99. #undef hid_write
  100. #undef hid_read_timeout
  101. #undef hid_read
  102. #undef hid_set_nonblocking
  103. #undef hid_send_feature_report
  104. #undef hid_get_feature_report
  105. #undef hid_close
  106. #undef hid_get_manufacturer_string
  107. #undef hid_get_product_string
  108. #undef hid_get_serial_number_string
  109. #undef hid_get_indexed_string
  110. #undef hid_error
  111. #undef new_hid_device
  112. #undef free_hid_device
  113. #undef input_report
  114. #undef return_data
  115. #undef make_path
  116. #undef read_thread
  117. #ifdef SDL_JOYSTICK_HIDAPI_STEAMXBOX
  118. #define HAVE_DRIVER_BACKEND 1
  119. #endif
  120. #ifdef HAVE_DRIVER_BACKEND
  121. /* DRIVER HIDAPI Implementation */
  122. #define hid_device_ DRIVER_hid_device_
  123. #define hid_device DRIVER_hid_device
  124. #define hid_device_info DRIVER_hid_device_info
  125. #define hid_init DRIVER_hid_init
  126. #define hid_exit DRIVER_hid_exit
  127. #define hid_enumerate DRIVER_hid_enumerate
  128. #define hid_free_enumeration DRIVER_hid_free_enumeration
  129. #define hid_open DRIVER_hid_open
  130. #define hid_open_path DRIVER_hid_open_path
  131. #define hid_write DRIVER_hid_write
  132. #define hid_read_timeout DRIVER_hid_read_timeout
  133. #define hid_read DRIVER_hid_read
  134. #define hid_set_nonblocking DRIVER_hid_set_nonblocking
  135. #define hid_send_feature_report DRIVER_hid_send_feature_report
  136. #define hid_get_feature_report DRIVER_hid_get_feature_report
  137. #define hid_close DRIVER_hid_close
  138. #define hid_get_manufacturer_string DRIVER_hid_get_manufacturer_string
  139. #define hid_get_product_string DRIVER_hid_get_product_string
  140. #define hid_get_serial_number_string DRIVER_hid_get_serial_number_string
  141. #define hid_get_indexed_string DRIVER_hid_get_indexed_string
  142. #define hid_error DRIVER_hid_error
  143. #ifdef SDL_JOYSTICK_HIDAPI_STEAMXBOX
  144. #undef HIDAPI_H__
  145. #include "steamxbox/hid.c"
  146. #else
  147. #error Need a driver hid.c for this platform!
  148. #endif
  149. #undef hid_device_
  150. #undef hid_device
  151. #undef hid_device_info
  152. #undef hid_init
  153. #undef hid_exit
  154. #undef hid_enumerate
  155. #undef hid_free_enumeration
  156. #undef hid_open
  157. #undef hid_open_path
  158. #undef hid_write
  159. #undef hid_read_timeout
  160. #undef hid_read
  161. #undef hid_set_nonblocking
  162. #undef hid_send_feature_report
  163. #undef hid_get_feature_report
  164. #undef hid_close
  165. #undef hid_get_manufacturer_string
  166. #undef hid_get_product_string
  167. #undef hid_get_serial_number_string
  168. #undef hid_get_indexed_string
  169. #undef hid_error
  170. #endif /* HAVE_DRIVER_BACKEND */
  171. #ifdef SDL_LIBUSB_DYNAMIC
  172. /* libusb HIDAPI Implementation */
  173. /* Include this now, for our dynamically-loaded libusb context */
  174. #include <libusb.h>
  175. static struct
  176. {
  177. void* libhandle;
  178. int (*init)(libusb_context **ctx);
  179. void (*exit)(libusb_context *ctx);
  180. ssize_t (*get_device_list)(libusb_context *ctx, libusb_device ***list);
  181. void (*free_device_list)(libusb_device **list, int unref_devices);
  182. int (*get_device_descriptor)(libusb_device *dev, struct libusb_device_descriptor *desc);
  183. int (*get_active_config_descriptor)(libusb_device *dev, struct libusb_config_descriptor **config);
  184. int (*get_config_descriptor)(
  185. libusb_device *dev,
  186. uint8_t config_index,
  187. struct libusb_config_descriptor **config
  188. );
  189. void (*free_config_descriptor)(struct libusb_config_descriptor *config);
  190. uint8_t (*get_bus_number)(libusb_device *dev);
  191. uint8_t (*get_device_address)(libusb_device *dev);
  192. int (*open)(libusb_device *dev, libusb_device_handle **dev_handle);
  193. void (*close)(libusb_device_handle *dev_handle);
  194. int (*claim_interface)(libusb_device_handle *dev_handle, int interface_number);
  195. int (*release_interface)(libusb_device_handle *dev_handle, int interface_number);
  196. int (*kernel_driver_active)(libusb_device_handle *dev_handle, int interface_number);
  197. int (*detach_kernel_driver)(libusb_device_handle *dev_handle, int interface_number);
  198. int (*attach_kernel_driver)(libusb_device_handle *dev_handle, int interface_number);
  199. int (*set_interface_alt_setting)(libusb_device_handle *dev, int interface_number, int alternate_setting);
  200. struct libusb_transfer * (*alloc_transfer)(int iso_packets);
  201. int (*submit_transfer)(struct libusb_transfer *transfer);
  202. int (*cancel_transfer)(struct libusb_transfer *transfer);
  203. void (*free_transfer)(struct libusb_transfer *transfer);
  204. int (*control_transfer)(
  205. libusb_device_handle *dev_handle,
  206. uint8_t request_type,
  207. uint8_t bRequest,
  208. uint16_t wValue,
  209. uint16_t wIndex,
  210. unsigned char *data,
  211. uint16_t wLength,
  212. unsigned int timeout
  213. );
  214. int (*interrupt_transfer)(
  215. libusb_device_handle *dev_handle,
  216. unsigned char endpoint,
  217. unsigned char *data,
  218. int length,
  219. int *actual_length,
  220. unsigned int timeout
  221. );
  222. int (*handle_events)(libusb_context *ctx);
  223. int (*handle_events_completed)(libusb_context *ctx, int *completed);
  224. } libusb_ctx;
  225. #define libusb_init libusb_ctx.init
  226. #define libusb_exit libusb_ctx.exit
  227. #define libusb_get_device_list libusb_ctx.get_device_list
  228. #define libusb_free_device_list libusb_ctx.free_device_list
  229. #define libusb_get_device_descriptor libusb_ctx.get_device_descriptor
  230. #define libusb_get_active_config_descriptor libusb_ctx.get_active_config_descriptor
  231. #define libusb_get_config_descriptor libusb_ctx.get_config_descriptor
  232. #define libusb_free_config_descriptor libusb_ctx.free_config_descriptor
  233. #define libusb_get_bus_number libusb_ctx.get_bus_number
  234. #define libusb_get_device_address libusb_ctx.get_device_address
  235. #define libusb_open libusb_ctx.open
  236. #define libusb_close libusb_ctx.close
  237. #define libusb_claim_interface libusb_ctx.claim_interface
  238. #define libusb_release_interface libusb_ctx.release_interface
  239. #define libusb_kernel_driver_active libusb_ctx.kernel_driver_active
  240. #define libusb_detach_kernel_driver libusb_ctx.detach_kernel_driver
  241. #define libusb_attach_kernel_driver libusb_ctx.attach_kernel_driver
  242. #define libusb_set_interface_alt_setting libusb_ctx.set_interface_alt_setting
  243. #define libusb_alloc_transfer libusb_ctx.alloc_transfer
  244. #define libusb_submit_transfer libusb_ctx.submit_transfer
  245. #define libusb_cancel_transfer libusb_ctx.cancel_transfer
  246. #define libusb_free_transfer libusb_ctx.free_transfer
  247. #define libusb_control_transfer libusb_ctx.control_transfer
  248. #define libusb_interrupt_transfer libusb_ctx.interrupt_transfer
  249. #define libusb_handle_events libusb_ctx.handle_events
  250. #define libusb_handle_events_completed libusb_ctx.handle_events_completed
  251. #define hid_device_ LIBUSB_hid_device_
  252. #define hid_device LIBUSB_hid_device
  253. #define hid_device_info LIBUSB_hid_device_info
  254. #define hid_init LIBUSB_hid_init
  255. #define hid_exit LIBUSB_hid_exit
  256. #define hid_enumerate LIBUSB_hid_enumerate
  257. #define hid_free_enumeration LIBUSB_hid_free_enumeration
  258. #define hid_open LIBUSB_hid_open
  259. #define hid_open_path LIBUSB_hid_open_path
  260. #define hid_write LIBUSB_hid_write
  261. #define hid_read_timeout LIBUSB_hid_read_timeout
  262. #define hid_read LIBUSB_hid_read
  263. #define hid_set_nonblocking LIBUSB_hid_set_nonblocking
  264. #define hid_send_feature_report LIBUSB_hid_send_feature_report
  265. #define hid_get_feature_report LIBUSB_hid_get_feature_report
  266. #define hid_close LIBUSB_hid_close
  267. #define hid_get_manufacturer_string LIBUSB_hid_get_manufacturer_string
  268. #define hid_get_product_string LIBUSB_hid_get_product_string
  269. #define hid_get_serial_number_string LIBUSB_hid_get_serial_number_string
  270. #define hid_get_indexed_string LIBUSB_hid_get_indexed_string
  271. #define hid_error LIBUSB_hid_error
  272. #define new_hid_device LIBUSB_new_hid_device
  273. #define free_hid_device LIBUSB_free_hid_device
  274. #define input_report LIBUSB_input_report
  275. #define return_data LIBUSB_return_data
  276. #define make_path LIBUSB_make_path
  277. #define read_thread LIBUSB_read_thread
  278. #ifndef __FreeBSD__
  279. /* this is awkwardly inlined, so we need to re-implement it here
  280. * so we can override the libusb_control_transfer call */
  281. static int
  282. SDL_libusb_get_string_descriptor(libusb_device_handle *dev,
  283. uint8_t descriptor_index, uint16_t lang_id,
  284. unsigned char *data, int length)
  285. {
  286. return libusb_control_transfer(dev,
  287. LIBUSB_ENDPOINT_IN | 0x0, /* Endpoint 0 IN */
  288. LIBUSB_REQUEST_GET_DESCRIPTOR,
  289. (LIBUSB_DT_STRING << 8) | descriptor_index,
  290. lang_id,
  291. data,
  292. (uint16_t) length,
  293. 1000);
  294. }
  295. #define libusb_get_string_descriptor SDL_libusb_get_string_descriptor
  296. #endif /* __FreeBSD__ */
  297. #undef HIDAPI_H__
  298. #include "libusb/hid.c"
  299. #undef hid_device_
  300. #undef hid_device
  301. #undef hid_device_info
  302. #undef hid_init
  303. #undef hid_exit
  304. #undef hid_enumerate
  305. #undef hid_free_enumeration
  306. #undef hid_open
  307. #undef hid_open_path
  308. #undef hid_write
  309. #undef hid_read_timeout
  310. #undef hid_read
  311. #undef hid_set_nonblocking
  312. #undef hid_send_feature_report
  313. #undef hid_get_feature_report
  314. #undef hid_close
  315. #undef hid_get_manufacturer_string
  316. #undef hid_get_product_string
  317. #undef hid_get_serial_number_string
  318. #undef hid_get_indexed_string
  319. #undef hid_error
  320. #undef new_hid_device
  321. #undef free_hid_device
  322. #undef input_report
  323. #undef return_data
  324. #undef make_path
  325. #undef read_thread
  326. #endif /* SDL_LIBUSB_DYNAMIC */
  327. /* Shared HIDAPI Implementation */
  328. #undef HIDAPI_H__
  329. #include "hidapi/hidapi.h"
  330. struct hidapi_backend {
  331. int (*hid_write)(hid_device* device, const unsigned char* data, size_t length);
  332. int (*hid_read_timeout)(hid_device* device, unsigned char* data, size_t length, int milliseconds);
  333. int (*hid_read)(hid_device* device, unsigned char* data, size_t length);
  334. int (*hid_set_nonblocking)(hid_device* device, int nonblock);
  335. int (*hid_send_feature_report)(hid_device* device, const unsigned char* data, size_t length);
  336. int (*hid_get_feature_report)(hid_device* device, unsigned char* data, size_t length);
  337. void (*hid_close)(hid_device* device);
  338. int (*hid_get_manufacturer_string)(hid_device* device, wchar_t* string, size_t maxlen);
  339. int (*hid_get_product_string)(hid_device* device, wchar_t* string, size_t maxlen);
  340. int (*hid_get_serial_number_string)(hid_device* device, wchar_t* string, size_t maxlen);
  341. int (*hid_get_indexed_string)(hid_device* device, int string_index, wchar_t* string, size_t maxlen);
  342. const wchar_t* (*hid_error)(hid_device* device);
  343. };
  344. #if HAVE_PLATFORM_BACKEND
  345. static const struct hidapi_backend PLATFORM_Backend = {
  346. (void*)PLATFORM_hid_write,
  347. (void*)PLATFORM_hid_read_timeout,
  348. (void*)PLATFORM_hid_read,
  349. (void*)PLATFORM_hid_set_nonblocking,
  350. (void*)PLATFORM_hid_send_feature_report,
  351. (void*)PLATFORM_hid_get_feature_report,
  352. (void*)PLATFORM_hid_close,
  353. (void*)PLATFORM_hid_get_manufacturer_string,
  354. (void*)PLATFORM_hid_get_product_string,
  355. (void*)PLATFORM_hid_get_serial_number_string,
  356. (void*)PLATFORM_hid_get_indexed_string,
  357. (void*)PLATFORM_hid_error
  358. };
  359. #endif /* HAVE_PLATFORM_BACKEND */
  360. #if HAVE_DRIVER_BACKEND
  361. static const struct hidapi_backend DRIVER_Backend = {
  362. (void*)DRIVER_hid_write,
  363. (void*)DRIVER_hid_read_timeout,
  364. (void*)DRIVER_hid_read,
  365. (void*)DRIVER_hid_set_nonblocking,
  366. (void*)DRIVER_hid_send_feature_report,
  367. (void*)DRIVER_hid_get_feature_report,
  368. (void*)DRIVER_hid_close,
  369. (void*)DRIVER_hid_get_manufacturer_string,
  370. (void*)DRIVER_hid_get_product_string,
  371. (void*)DRIVER_hid_get_serial_number_string,
  372. (void*)DRIVER_hid_get_indexed_string,
  373. (void*)DRIVER_hid_error
  374. };
  375. #endif /* HAVE_DRIVER_BACKEND */
  376. #ifdef SDL_LIBUSB_DYNAMIC
  377. static const struct hidapi_backend LIBUSB_Backend = {
  378. (void*)LIBUSB_hid_write,
  379. (void*)LIBUSB_hid_read_timeout,
  380. (void*)LIBUSB_hid_read,
  381. (void*)LIBUSB_hid_set_nonblocking,
  382. (void*)LIBUSB_hid_send_feature_report,
  383. (void*)LIBUSB_hid_get_feature_report,
  384. (void*)LIBUSB_hid_close,
  385. (void*)LIBUSB_hid_get_manufacturer_string,
  386. (void*)LIBUSB_hid_get_product_string,
  387. (void*)LIBUSB_hid_get_serial_number_string,
  388. (void*)LIBUSB_hid_get_indexed_string,
  389. (void*)LIBUSB_hid_error
  390. };
  391. #endif /* SDL_LIBUSB_DYNAMIC */
  392. typedef struct _HIDDeviceWrapper HIDDeviceWrapper;
  393. struct _HIDDeviceWrapper
  394. {
  395. hid_device *device; /* must be first field */
  396. const struct hidapi_backend *backend;
  397. };
  398. #if HAVE_PLATFORM_BACKEND || HAVE_DRIVER_BACKEND || defined(SDL_LIBUSB_DYNAMIC)
  399. static HIDDeviceWrapper *
  400. CreateHIDDeviceWrapper(hid_device *device, const struct hidapi_backend *backend)
  401. {
  402. HIDDeviceWrapper *ret = (HIDDeviceWrapper *)SDL_malloc(sizeof(*ret));
  403. ret->device = device;
  404. ret->backend = backend;
  405. return ret;
  406. }
  407. static hid_device *
  408. WrapHIDDevice(HIDDeviceWrapper *wrapper)
  409. {
  410. return (hid_device *)wrapper;
  411. }
  412. #endif /* HAVE_PLATFORM_BACKEND || HAVE_DRIVER_BACKEND || SDL_LIBUSB_DYNAMIC */
  413. static HIDDeviceWrapper *
  414. UnwrapHIDDevice(hid_device *device)
  415. {
  416. return (HIDDeviceWrapper *)device;
  417. }
  418. static void
  419. DeleteHIDDeviceWrapper(HIDDeviceWrapper *device)
  420. {
  421. SDL_free(device);
  422. }
  423. #define COPY_IF_EXISTS(var) \
  424. if (pSrc->var != NULL) { \
  425. pDst->var = SDL_strdup(pSrc->var); \
  426. } else { \
  427. pDst->var = NULL; \
  428. }
  429. #define WCOPY_IF_EXISTS(var) \
  430. if (pSrc->var != NULL) { \
  431. pDst->var = SDL_wcsdup(pSrc->var); \
  432. } else { \
  433. pDst->var = NULL; \
  434. }
  435. #ifdef SDL_LIBUSB_DYNAMIC
  436. static void
  437. LIBUSB_CopyHIDDeviceInfo(struct LIBUSB_hid_device_info *pSrc,
  438. struct hid_device_info *pDst)
  439. {
  440. COPY_IF_EXISTS(path)
  441. pDst->vendor_id = pSrc->vendor_id;
  442. pDst->product_id = pSrc->product_id;
  443. WCOPY_IF_EXISTS(serial_number)
  444. pDst->release_number = pSrc->release_number;
  445. WCOPY_IF_EXISTS(manufacturer_string)
  446. WCOPY_IF_EXISTS(product_string)
  447. pDst->usage_page = pSrc->usage_page;
  448. pDst->usage = pSrc->usage;
  449. pDst->interface_number = pSrc->interface_number;
  450. pDst->interface_class = pSrc->interface_class;
  451. pDst->interface_subclass = pSrc->interface_subclass;
  452. pDst->interface_protocol = pSrc->interface_protocol;
  453. pDst->next = NULL;
  454. }
  455. #endif /* SDL_LIBUSB_DYNAMIC */
  456. #if HAVE_DRIVER_BACKEND
  457. static void
  458. DRIVER_CopyHIDDeviceInfo(struct DRIVER_hid_device_info *pSrc,
  459. struct hid_device_info *pDst)
  460. {
  461. COPY_IF_EXISTS(path)
  462. pDst->vendor_id = pSrc->vendor_id;
  463. pDst->product_id = pSrc->product_id;
  464. WCOPY_IF_EXISTS(serial_number)
  465. pDst->release_number = pSrc->release_number;
  466. WCOPY_IF_EXISTS(manufacturer_string)
  467. WCOPY_IF_EXISTS(product_string)
  468. pDst->usage_page = pSrc->usage_page;
  469. pDst->usage = pSrc->usage;
  470. pDst->interface_number = pSrc->interface_number;
  471. pDst->interface_class = pSrc->interface_class;
  472. pDst->interface_subclass = pSrc->interface_subclass;
  473. pDst->interface_protocol = pSrc->interface_protocol;
  474. pDst->next = NULL;
  475. }
  476. #endif /* HAVE_DRIVER_BACKEND */
  477. #if HAVE_PLATFORM_BACKEND
  478. static void
  479. PLATFORM_CopyHIDDeviceInfo(struct PLATFORM_hid_device_info *pSrc,
  480. struct hid_device_info *pDst)
  481. {
  482. COPY_IF_EXISTS(path)
  483. pDst->vendor_id = pSrc->vendor_id;
  484. pDst->product_id = pSrc->product_id;
  485. WCOPY_IF_EXISTS(serial_number)
  486. pDst->release_number = pSrc->release_number;
  487. WCOPY_IF_EXISTS(manufacturer_string)
  488. WCOPY_IF_EXISTS(product_string)
  489. pDst->usage_page = pSrc->usage_page;
  490. pDst->usage = pSrc->usage;
  491. pDst->interface_number = pSrc->interface_number;
  492. pDst->interface_class = pSrc->interface_class;
  493. pDst->interface_subclass = pSrc->interface_subclass;
  494. pDst->interface_protocol = pSrc->interface_protocol;
  495. pDst->next = NULL;
  496. }
  497. #endif /* HAVE_PLATFORM_BACKEND */
  498. #undef COPY_IF_EXISTS
  499. #undef WCOPY_IF_EXISTS
  500. static SDL_bool SDL_hidapi_wasinit = SDL_FALSE;
  501. int HID_API_EXPORT HID_API_CALL hid_init(void)
  502. {
  503. int attempts = 0, success = 0;
  504. if (SDL_hidapi_wasinit == SDL_TRUE) {
  505. return 0;
  506. }
  507. #ifdef SDL_LIBUSB_DYNAMIC
  508. ++attempts;
  509. libusb_ctx.libhandle = SDL_LoadObject(SDL_LIBUSB_DYNAMIC);
  510. if (libusb_ctx.libhandle != NULL) {
  511. SDL_bool loaded = SDL_TRUE;
  512. #define LOAD_LIBUSB_SYMBOL(func) \
  513. if (!(libusb_ctx.func = SDL_LoadFunction(libusb_ctx.libhandle, "libusb_" #func))) {loaded = SDL_FALSE;}
  514. LOAD_LIBUSB_SYMBOL(init)
  515. LOAD_LIBUSB_SYMBOL(exit)
  516. LOAD_LIBUSB_SYMBOL(get_device_list)
  517. LOAD_LIBUSB_SYMBOL(free_device_list)
  518. LOAD_LIBUSB_SYMBOL(get_device_descriptor)
  519. LOAD_LIBUSB_SYMBOL(get_active_config_descriptor)
  520. LOAD_LIBUSB_SYMBOL(get_config_descriptor)
  521. LOAD_LIBUSB_SYMBOL(free_config_descriptor)
  522. LOAD_LIBUSB_SYMBOL(get_bus_number)
  523. LOAD_LIBUSB_SYMBOL(get_device_address)
  524. LOAD_LIBUSB_SYMBOL(open)
  525. LOAD_LIBUSB_SYMBOL(close)
  526. LOAD_LIBUSB_SYMBOL(claim_interface)
  527. LOAD_LIBUSB_SYMBOL(release_interface)
  528. LOAD_LIBUSB_SYMBOL(kernel_driver_active)
  529. LOAD_LIBUSB_SYMBOL(detach_kernel_driver)
  530. LOAD_LIBUSB_SYMBOL(attach_kernel_driver)
  531. LOAD_LIBUSB_SYMBOL(set_interface_alt_setting)
  532. LOAD_LIBUSB_SYMBOL(alloc_transfer)
  533. LOAD_LIBUSB_SYMBOL(submit_transfer)
  534. LOAD_LIBUSB_SYMBOL(cancel_transfer)
  535. LOAD_LIBUSB_SYMBOL(free_transfer)
  536. LOAD_LIBUSB_SYMBOL(control_transfer)
  537. LOAD_LIBUSB_SYMBOL(interrupt_transfer)
  538. LOAD_LIBUSB_SYMBOL(handle_events)
  539. LOAD_LIBUSB_SYMBOL(handle_events_completed)
  540. #undef LOAD_LIBUSB_SYMBOL
  541. if (!loaded) {
  542. SDL_UnloadObject(libusb_ctx.libhandle);
  543. libusb_ctx.libhandle = NULL;
  544. /* SDL_LogWarn(SDL_LOG_CATEGORY_INPUT, SDL_LIBUSB_DYNAMIC " found but could not load function"); */
  545. } else if (LIBUSB_hid_init() < 0) {
  546. SDL_UnloadObject(libusb_ctx.libhandle);
  547. libusb_ctx.libhandle = NULL;
  548. } else {
  549. ++success;
  550. }
  551. }
  552. #endif /* SDL_LIBUSB_DYNAMIC */
  553. #if HAVE_PLATFORM_BACKEND
  554. ++attempts;
  555. #if __LINUX__
  556. udev_ctx = SDL_UDEV_GetUdevSyms();
  557. #endif /* __LINUX __ */
  558. if (udev_ctx && PLATFORM_hid_init() == 0) {
  559. ++success;
  560. }
  561. #endif /* HAVE_PLATFORM_BACKEND */
  562. if (attempts > 0 && success == 0) {
  563. return -1;
  564. }
  565. SDL_hidapi_wasinit = SDL_TRUE;
  566. return 0;
  567. }
  568. int HID_API_EXPORT HID_API_CALL hid_exit(void)
  569. {
  570. int result = 0;
  571. if (SDL_hidapi_wasinit == SDL_FALSE) {
  572. return 0;
  573. }
  574. SDL_hidapi_wasinit = SDL_FALSE;
  575. #if HAVE_PLATFORM_BACKEND
  576. if (udev_ctx) {
  577. result |= PLATFORM_hid_exit();
  578. }
  579. #endif /* HAVE_PLATFORM_BACKEND */
  580. #ifdef SDL_LIBUSB_DYNAMIC
  581. if (libusb_ctx.libhandle) {
  582. result |= LIBUSB_hid_exit();
  583. SDL_UnloadObject(libusb_ctx.libhandle);
  584. libusb_ctx.libhandle = NULL;
  585. }
  586. #endif /* SDL_LIBUSB_DYNAMIC */
  587. return result;
  588. }
  589. struct hid_device_info HID_API_EXPORT * HID_API_CALL hid_enumerate(unsigned short vendor_id, unsigned short product_id)
  590. {
  591. #if HAVE_PLATFORM_BACKEND || HAVE_DRIVER_BACKEND || defined(SDL_LIBUSB_DYNAMIC)
  592. #ifdef SDL_LIBUSB_DYNAMIC
  593. struct LIBUSB_hid_device_info *usb_devs = NULL;
  594. struct LIBUSB_hid_device_info *usb_dev;
  595. #endif
  596. #if HAVE_DRIVER_BACKEND
  597. struct DRIVER_hid_device_info* driver_devs = NULL;
  598. struct DRIVER_hid_device_info* driver_dev;
  599. #endif
  600. #if HAVE_PLATFORM_BACKEND
  601. struct PLATFORM_hid_device_info *raw_devs = NULL;
  602. struct PLATFORM_hid_device_info *raw_dev;
  603. #endif
  604. struct hid_device_info *devs = NULL, *last = NULL, *new_dev;
  605. if (hid_init() != 0) {
  606. return NULL;
  607. }
  608. #ifdef SDL_LIBUSB_DYNAMIC
  609. if (libusb_ctx.libhandle) {
  610. usb_devs = LIBUSB_hid_enumerate(vendor_id, product_id);
  611. #ifdef DEBUG_HIDAPI
  612. SDL_Log("libusb devices found:");
  613. #endif
  614. for (usb_dev = usb_devs; usb_dev; usb_dev = usb_dev->next) {
  615. new_dev = (struct hid_device_info*) SDL_malloc(sizeof(struct hid_device_info));
  616. if (!new_dev) {
  617. LIBUSB_hid_free_enumeration(usb_devs);
  618. hid_free_enumeration(devs);
  619. SDL_OutOfMemory();
  620. return NULL;
  621. }
  622. LIBUSB_CopyHIDDeviceInfo(usb_dev, new_dev);
  623. #ifdef DEBUG_HIDAPI
  624. SDL_Log(" - %ls %ls 0x%.4hx 0x%.4hx",
  625. usb_dev->manufacturer_string, usb_dev->product_string,
  626. usb_dev->vendor_id, usb_dev->product_id);
  627. #endif
  628. if (last != NULL) {
  629. last->next = new_dev;
  630. } else {
  631. devs = new_dev;
  632. }
  633. last = new_dev;
  634. }
  635. }
  636. #endif /* SDL_LIBUSB_DYNAMIC */
  637. #ifdef HAVE_DRIVER_BACKEND
  638. driver_devs = DRIVER_hid_enumerate(vendor_id, product_id);
  639. for (driver_dev = driver_devs; driver_dev; driver_dev = driver_dev->next) {
  640. new_dev = (struct hid_device_info*) SDL_malloc(sizeof(struct hid_device_info));
  641. DRIVER_CopyHIDDeviceInfo(driver_dev, new_dev);
  642. if (last != NULL) {
  643. last->next = new_dev;
  644. } else {
  645. devs = new_dev;
  646. }
  647. last = new_dev;
  648. }
  649. #endif /* HAVE_DRIVER_BACKEND */
  650. #if HAVE_PLATFORM_BACKEND
  651. if (udev_ctx) {
  652. raw_devs = PLATFORM_hid_enumerate(vendor_id, product_id);
  653. #ifdef DEBUG_HIDAPI
  654. SDL_Log("hidraw devices found:");
  655. #endif
  656. for (raw_dev = raw_devs; raw_dev; raw_dev = raw_dev->next) {
  657. SDL_bool bFound = SDL_FALSE;
  658. #ifdef DEBUG_HIDAPI
  659. SDL_Log(" - %ls %ls 0x%.4hx 0x%.4hx",
  660. raw_dev->manufacturer_string, raw_dev->product_string,
  661. raw_dev->vendor_id, raw_dev->product_id);
  662. #endif
  663. #ifdef SDL_LIBUSB_DYNAMIC
  664. for (usb_dev = usb_devs; usb_dev; usb_dev = usb_dev->next) {
  665. if (raw_dev->vendor_id == usb_dev->vendor_id &&
  666. raw_dev->product_id == usb_dev->product_id &&
  667. (raw_dev->interface_number < 0 || raw_dev->interface_number == usb_dev->interface_number)) {
  668. bFound = SDL_TRUE;
  669. break;
  670. }
  671. }
  672. #endif
  673. #ifdef HAVE_DRIVER_BACKEND
  674. for (driver_dev = driver_devs; driver_dev; driver_dev = driver_dev->next) {
  675. if (raw_dev->vendor_id == driver_dev->vendor_id &&
  676. raw_dev->product_id == driver_dev->product_id &&
  677. (raw_dev->interface_number < 0 || raw_dev->interface_number == driver_dev->interface_number)) {
  678. bFound = SDL_TRUE;
  679. break;
  680. }
  681. }
  682. #endif
  683. if (!bFound) {
  684. new_dev = (struct hid_device_info*) SDL_malloc(sizeof(struct hid_device_info));
  685. if (!new_dev) {
  686. #ifdef SDL_LIBUSB_DYNAMIC
  687. if (libusb_ctx.libhandle) {
  688. LIBUSB_hid_free_enumeration(usb_devs);
  689. }
  690. #endif
  691. PLATFORM_hid_free_enumeration(raw_devs);
  692. hid_free_enumeration(devs);
  693. SDL_OutOfMemory();
  694. return NULL;
  695. }
  696. PLATFORM_CopyHIDDeviceInfo(raw_dev, new_dev);
  697. new_dev->next = NULL;
  698. if (last != NULL) {
  699. last->next = new_dev;
  700. } else {
  701. devs = new_dev;
  702. }
  703. last = new_dev;
  704. }
  705. }
  706. PLATFORM_hid_free_enumeration(raw_devs);
  707. }
  708. #endif /* HAVE_PLATFORM_BACKEND */
  709. #ifdef SDL_LIBUSB_DYNAMIC
  710. if (libusb_ctx.libhandle) {
  711. LIBUSB_hid_free_enumeration(usb_devs);
  712. }
  713. #endif
  714. return devs;
  715. #else
  716. return NULL;
  717. #endif /* HAVE_PLATFORM_BACKEND || HAVE_DRIVER_BACKEND || SDL_LIBUSB_DYNAMIC */
  718. }
  719. void HID_API_EXPORT HID_API_CALL hid_free_enumeration(struct hid_device_info *devs)
  720. {
  721. while (devs) {
  722. struct hid_device_info *next = devs->next;
  723. SDL_free(devs->path);
  724. SDL_free(devs->serial_number);
  725. SDL_free(devs->manufacturer_string);
  726. SDL_free(devs->product_string);
  727. SDL_free(devs);
  728. devs = next;
  729. }
  730. }
  731. HID_API_EXPORT hid_device * HID_API_CALL hid_open(unsigned short vendor_id, unsigned short product_id, const wchar_t *serial_number)
  732. {
  733. #if HAVE_PLATFORM_BACKEND || HAVE_DRIVER_BACKEND || defined(SDL_LIBUSB_DYNAMIC)
  734. hid_device *pDevice = NULL;
  735. if (hid_init() != 0) {
  736. return NULL;
  737. }
  738. #if HAVE_PLATFORM_BACKEND
  739. if (udev_ctx &&
  740. (pDevice = (hid_device*) PLATFORM_hid_open(vendor_id, product_id, serial_number)) != NULL) {
  741. HIDDeviceWrapper *wrapper = CreateHIDDeviceWrapper(pDevice, &PLATFORM_Backend);
  742. return WrapHIDDevice(wrapper);
  743. }
  744. #endif /* HAVE_PLATFORM_BACKEND */
  745. #if HAVE_DRIVER_BACKEND
  746. if ((pDevice = (hid_device*) DRIVER_hid_open(vendor_id, product_id, serial_number)) != NULL) {
  747. HIDDeviceWrapper *wrapper = CreateHIDDeviceWrapper(pDevice, &DRIVER_Backend);
  748. return WrapHIDDevice(wrapper);
  749. }
  750. #endif /* HAVE_DRIVER_BACKEND */
  751. #ifdef SDL_LIBUSB_DYNAMIC
  752. if (libusb_ctx.libhandle &&
  753. (pDevice = (hid_device*) LIBUSB_hid_open(vendor_id, product_id, serial_number)) != NULL) {
  754. HIDDeviceWrapper *wrapper = CreateHIDDeviceWrapper(pDevice, &LIBUSB_Backend);
  755. return WrapHIDDevice(wrapper);
  756. }
  757. #endif /* SDL_LIBUSB_DYNAMIC */
  758. #endif /* HAVE_PLATFORM_BACKEND || HAVE_DRIVER_BACKEND || SDL_LIBUSB_DYNAMIC */
  759. return NULL;
  760. }
  761. HID_API_EXPORT hid_device * HID_API_CALL hid_open_path(const char *path, int bExclusive /* = false */)
  762. {
  763. #if HAVE_PLATFORM_BACKEND || HAVE_DRIVER_BACKEND || defined(SDL_LIBUSB_DYNAMIC)
  764. hid_device *pDevice = NULL;
  765. if (hid_init() != 0) {
  766. return NULL;
  767. }
  768. #if HAVE_PLATFORM_BACKEND
  769. if (udev_ctx &&
  770. (pDevice = (hid_device*) PLATFORM_hid_open_path(path, bExclusive)) != NULL) {
  771. HIDDeviceWrapper *wrapper = CreateHIDDeviceWrapper(pDevice, &PLATFORM_Backend);
  772. return WrapHIDDevice(wrapper);
  773. }
  774. #endif /* HAVE_PLATFORM_BACKEND */
  775. #if HAVE_DRIVER_BACKEND
  776. if ((pDevice = (hid_device*) DRIVER_hid_open_path(path, bExclusive)) != NULL) {
  777. HIDDeviceWrapper *wrapper = CreateHIDDeviceWrapper(pDevice, &DRIVER_Backend);
  778. return WrapHIDDevice(wrapper);
  779. }
  780. #endif /* HAVE_DRIVER_BACKEND */
  781. #ifdef SDL_LIBUSB_DYNAMIC
  782. if (libusb_ctx.libhandle &&
  783. (pDevice = (hid_device*) LIBUSB_hid_open_path(path, bExclusive)) != NULL) {
  784. HIDDeviceWrapper *wrapper = CreateHIDDeviceWrapper(pDevice, &LIBUSB_Backend);
  785. return WrapHIDDevice(wrapper);
  786. }
  787. #endif /* SDL_LIBUSB_DYNAMIC */
  788. #endif /* HAVE_PLATFORM_BACKEND || HAVE_DRIVER_BACKEND || SDL_LIBUSB_DYNAMIC */
  789. return NULL;
  790. }
  791. int HID_API_EXPORT HID_API_CALL hid_write(hid_device *device, const unsigned char *data, size_t length)
  792. {
  793. HIDDeviceWrapper *wrapper = UnwrapHIDDevice(device);
  794. return wrapper->backend->hid_write(wrapper->device, data, length);
  795. }
  796. int HID_API_EXPORT HID_API_CALL hid_read_timeout(hid_device *device, unsigned char *data, size_t length, int milliseconds)
  797. {
  798. HIDDeviceWrapper *wrapper = UnwrapHIDDevice(device);
  799. return wrapper->backend->hid_read_timeout(wrapper->device, data, length, milliseconds);
  800. }
  801. int HID_API_EXPORT HID_API_CALL hid_read(hid_device *device, unsigned char *data, size_t length)
  802. {
  803. HIDDeviceWrapper *wrapper = UnwrapHIDDevice(device);
  804. return wrapper->backend->hid_read(wrapper->device, data, length);
  805. }
  806. int HID_API_EXPORT HID_API_CALL hid_set_nonblocking(hid_device *device, int nonblock)
  807. {
  808. HIDDeviceWrapper *wrapper = UnwrapHIDDevice(device);
  809. return wrapper->backend->hid_set_nonblocking(wrapper->device, nonblock);
  810. }
  811. int HID_API_EXPORT HID_API_CALL hid_send_feature_report(hid_device *device, const unsigned char *data, size_t length)
  812. {
  813. HIDDeviceWrapper *wrapper = UnwrapHIDDevice(device);
  814. return wrapper->backend->hid_send_feature_report(wrapper->device, data, length);
  815. }
  816. int HID_API_EXPORT HID_API_CALL hid_get_feature_report(hid_device *device, unsigned char *data, size_t length)
  817. {
  818. HIDDeviceWrapper *wrapper = UnwrapHIDDevice(device);
  819. return wrapper->backend->hid_get_feature_report(wrapper->device, data, length);
  820. }
  821. void HID_API_EXPORT HID_API_CALL hid_close(hid_device *device)
  822. {
  823. HIDDeviceWrapper *wrapper = UnwrapHIDDevice(device);
  824. wrapper->backend->hid_close(wrapper->device);
  825. DeleteHIDDeviceWrapper(wrapper);
  826. }
  827. int HID_API_EXPORT_CALL hid_get_manufacturer_string(hid_device *device, wchar_t *string, size_t maxlen)
  828. {
  829. HIDDeviceWrapper *wrapper = UnwrapHIDDevice(device);
  830. return wrapper->backend->hid_get_manufacturer_string(wrapper->device, string, maxlen);
  831. }
  832. int HID_API_EXPORT_CALL hid_get_product_string(hid_device *device, wchar_t *string, size_t maxlen)
  833. {
  834. HIDDeviceWrapper *wrapper = UnwrapHIDDevice(device);
  835. return wrapper->backend->hid_get_product_string(wrapper->device, string, maxlen);
  836. }
  837. int HID_API_EXPORT_CALL hid_get_serial_number_string(hid_device *device, wchar_t *string, size_t maxlen)
  838. {
  839. HIDDeviceWrapper *wrapper = UnwrapHIDDevice(device);
  840. return wrapper->backend->hid_get_serial_number_string(wrapper->device, string, maxlen);
  841. }
  842. int HID_API_EXPORT_CALL hid_get_indexed_string(hid_device *device, int string_index, wchar_t *string, size_t maxlen)
  843. {
  844. HIDDeviceWrapper *wrapper = UnwrapHIDDevice(device);
  845. return wrapper->backend->hid_get_indexed_string(wrapper->device, string_index, string, maxlen);
  846. }
  847. HID_API_EXPORT const wchar_t* HID_API_CALL hid_error(hid_device *device)
  848. {
  849. HIDDeviceWrapper *wrapper = UnwrapHIDDevice(device);
  850. return wrapper->backend->hid_error(wrapper->device);
  851. }
  852. #ifdef HAVE_ENABLE_GAMECUBE_ADAPTORS
  853. /* This is needed to enable input for Nyko and EVORETRO GameCube adaptors */
  854. void SDL_EnableGameCubeAdaptors(void)
  855. {
  856. #ifdef SDL_LIBUSB_DYNAMIC
  857. libusb_context *usb_context = NULL;
  858. libusb_device **devs = NULL;
  859. libusb_device_handle *handle = NULL;
  860. struct libusb_device_descriptor desc;
  861. ssize_t i, num_devs;
  862. int kernel_detached = 0;
  863. if (libusb_ctx.libhandle == NULL) {
  864. return;
  865. }
  866. if (libusb_init(&usb_context) == 0) {
  867. num_devs = libusb_get_device_list(usb_context, &devs);
  868. for (i = 0; i < num_devs; ++i) {
  869. if (libusb_get_device_descriptor(devs[i], &desc) != 0) {
  870. continue;
  871. }
  872. if (desc.idVendor != 0x057e || desc.idProduct != 0x0337) {
  873. continue;
  874. }
  875. if (libusb_open(devs[i], &handle) != 0) {
  876. continue;
  877. }
  878. if (libusb_kernel_driver_active(handle, 0)) {
  879. if (libusb_detach_kernel_driver(handle, 0) == 0) {
  880. kernel_detached = 1;
  881. }
  882. }
  883. if (libusb_claim_interface(handle, 0) == 0) {
  884. libusb_control_transfer(handle, 0x21, 11, 0x0001, 0, NULL, 0, 1000);
  885. libusb_release_interface(handle, 0);
  886. }
  887. if (kernel_detached) {
  888. libusb_attach_kernel_driver(handle, 0);
  889. }
  890. libusb_close(handle);
  891. }
  892. libusb_free_device_list(devs, 1);
  893. libusb_exit(usb_context);
  894. }
  895. #endif /* SDL_LIBUSB_DYNAMIC */
  896. }
  897. #endif /* HAVE_ENABLE_GAMECUBE_ADAPTORS */
  898. #endif /* SDL_JOYSTICK_HIDAPI */
  899. /* vi: set sts=4 ts=4 sw=4 expandtab: */