bluetooth.odin 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. // +build windows
  2. package sys_windows
  3. foreign import "system:bthprops.lib"
  4. HBLUETOOTH_DEVICE_FIND :: distinct HANDLE
  5. HBLUETOOTH_RADIO_FIND :: distinct HANDLE
  6. BLUETOOTH_FIND_RADIO_PARAMS :: struct {
  7. dw_size: DWORD,
  8. }
  9. BLUETOOTH_RADIO_INFO :: struct {
  10. dw_size: DWORD, // Size of this structure
  11. address: BLUETOOTH_ADDRESS, // Address of radio
  12. name: [BLUETOOTH_MAX_NAME_SIZE]u16, // Name of the radio
  13. device_class: ULONG, // Bluetooth "Class of Device". See: https://btprodspecificationrefs.blob.core.windows.net/assigned-numbers/Assigned%20Number%20Types/Baseband.pdf
  14. lmp_minor_version: USHORT, // This member contains data specific to individual Bluetooth device manufacturers.
  15. manufacturer: USHORT, // Manufacturer of the Bluetooth radio, expressed as a BTH_MFG_Xxx value. See https://www.bluetooth.com/specifications/assigned-numbers/company-identifiers/
  16. }
  17. BLUETOOTH_DEVICE_SEARCH_PARAMS :: struct {
  18. dw_size: DWORD, // Size of this structure
  19. return_authenticated: BOOL, // Return authenticated devices
  20. return_remembered: BOOL, // Return remembered devices
  21. return_unknown: BOOL, // Return unknown devices
  22. return_connected: BOOL, // Return connected devices
  23. issue_inquiry: BOOL, // Issue a new inquiry
  24. timeout_multiplier: UCHAR, // Timeout for the inquiry, expressed in increments of 1.28 seconds
  25. radio: HANDLE, // Handle to radio to enumerate - NULL == all radios will be searched
  26. }
  27. BLUETOOTH_ADDRESS :: struct #raw_union {
  28. addr: u64,
  29. val: [6]u8, // The first 3 bytes can be used to find the Manufacturer using http://standards-oui.ieee.org/oui/oui.txt
  30. }
  31. BLUETOOTH_MAX_NAME_SIZE :: 248
  32. BLUETOOTH_DEVICE_INFO :: struct {
  33. dw_size: DWORD, // Size in bytes of this structure - must be the size_of(BLUETOOTH_DEVICE_INFO)
  34. address: BLUETOOTH_ADDRESS, // Bluetooth address
  35. device_class: ULONG, // Bluetooth "Class of Device". See: https://btprodspecificationrefs.blob.core.windows.net/assigned-numbers/Assigned%20Number%20Types/Baseband.pdf
  36. connected: BOOL, // Device connected/in use
  37. remembered: BOOL, // Device remembered
  38. authenticated: BOOL, // Device authenticated/paired/bonded
  39. last_seen: SYSTEMTIME, // Last time the device was seen
  40. last_used: SYSTEMTIME, // Last time the device was used for other than RNR, inquiry, or SDP
  41. name: [BLUETOOTH_MAX_NAME_SIZE]u16, // Name of the device
  42. }
  43. @(default_calling_convention = "std")
  44. foreign bthprops {
  45. /*
  46. Version
  47. */
  48. @(link_name="BluetoothIsVersionAvailable") bluetooth_is_version_available :: proc(
  49. major: u8, minor: u8,
  50. ) -> BOOL ---
  51. /*
  52. Radio enumeration
  53. */
  54. @(link_name="BluetoothFindFirstRadio") bluetooth_find_first_radio :: proc(
  55. find_radio_params: ^BLUETOOTH_FIND_RADIO_PARAMS, radio: ^HANDLE,
  56. ) -> HBLUETOOTH_RADIO_FIND ---
  57. @(link_name="BluetoothFindNextRadio") bluetooth_find_next_radio :: proc(
  58. handle: HBLUETOOTH_RADIO_FIND, radio: ^HANDLE,
  59. ) -> BOOL ---
  60. @(link_name="BluetoothFindRadioClose") bluetooth_find_radio_close :: proc(
  61. handle: HBLUETOOTH_RADIO_FIND,
  62. ) -> BOOL ---
  63. @(link_name="BluetoothGetRadioInfo") bluetooth_get_radio_info :: proc(
  64. radio: HANDLE, radio_info: ^BLUETOOTH_RADIO_INFO,
  65. ) -> DWORD ---
  66. /*
  67. Device enumeration
  68. */
  69. @(link_name="BluetoothFindFirstDevice") bluetooth_find_first_device :: proc(
  70. search_params: ^BLUETOOTH_DEVICE_SEARCH_PARAMS, device_info: ^BLUETOOTH_DEVICE_INFO,
  71. ) -> HBLUETOOTH_DEVICE_FIND ---
  72. @(link_name="BluetoothFindNextDevice") bluetooth_find_next_device :: proc(
  73. handle: HBLUETOOTH_DEVICE_FIND, device_info: ^BLUETOOTH_DEVICE_INFO,
  74. ) -> BOOL ---
  75. @(link_name="BluetoothFindDeviceClose") bluetooth_find_device_close :: proc(
  76. handle: HBLUETOOTH_DEVICE_FIND,
  77. ) -> BOOL ---
  78. @(link_name="BluetoothGetDeviceInfo") bluetooth_get_device_info :: proc(
  79. radio: HANDLE, device_info: ^BLUETOOTH_DEVICE_INFO,
  80. ) -> DWORD ---
  81. @(link_name="BluetoothDisplayDeviceProperties") bluetooth_display_device_properties :: proc(
  82. hwnd_parent: HWND, device_info: ^BLUETOOTH_DEVICE_INFO,
  83. ) -> BOOL ---
  84. }