1 // Licensed under the Apache License, Version 2.0
2 // <LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
3 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your option.
4 // All files in the project carrying such notice may not be copied, modified, or distributed
5 // except according to those terms.
6 use shared::bthdef::{BTH_ADDR, BTH_DEVICE_INFO, MAX_UUIDS_IN_QUERY};
7 use shared::bthsdpdef::{SdpAttributeRange, SdpQueryUuid};
8 use shared::minwindef::{DWORD, UCHAR, ULONG, USHORT};
9 use shared::ntdef::{BOOLEAN, ULONGLONG};
10 use um::winioctl::{FILE_ANY_ACCESS, FILE_DEVICE_BLUETOOTH, METHOD_BUFFERED, METHOD_NEITHER};
11 pub const BTH_IOCTL_BASE: DWORD = 0;
12 pub const IOCTL_INTERNAL_BTH_SUBMIT_BRB: DWORD = BTH_KERNEL_CTL!(BTH_IOCTL_BASE + 0x00);
13 pub const IOCTL_INTERNAL_BTHENUM_GET_ENUMINFO: DWORD = BTH_KERNEL_CTL!(BTH_IOCTL_BASE + 0x01);
14 pub const IOCTL_INTERNAL_BTHENUM_GET_DEVINFO: DWORD = BTH_KERNEL_CTL!(BTH_IOCTL_BASE + 0x02);
15 pub const IOCTL_BTH_GET_LOCAL_INFO: DWORD = BTH_CTL!(BTH_IOCTL_BASE + 0x00);
16 pub const IOCTL_BTH_GET_RADIO_INFO: DWORD = BTH_CTL!(BTH_IOCTL_BASE + 0x01);
17 pub const IOCTL_BTH_GET_DEVICE_INFO: DWORD = BTH_CTL!(BTH_IOCTL_BASE + 0x02);
18 pub const IOCTL_BTH_DISCONNECT_DEVICE: DWORD = BTH_CTL!(BTH_IOCTL_BASE + 0x03);
19 pub const IOCTL_BTH_HCI_VENDOR_COMMAND: DWORD = BTH_CTL!(BTH_IOCTL_BASE + 0x14);
20 pub const IOCTL_BTH_SDP_CONNECT: DWORD = BTH_CTL!(BTH_IOCTL_BASE + 0x80);
21 pub const IOCTL_BTH_SDP_DISCONNECT: DWORD = BTH_CTL!(BTH_IOCTL_BASE + 0x81);
22 pub const IOCTL_BTH_SDP_SERVICE_SEARCH: DWORD = BTH_CTL!(BTH_IOCTL_BASE + 0x82);
23 pub const IOCTL_BTH_SDP_ATTRIBUTE_SEARCH: DWORD = BTH_CTL!(BTH_IOCTL_BASE + 0x83);
24 pub const IOCTL_BTH_SDP_SERVICE_ATTRIBUTE_SEARCH: DWORD = BTH_CTL!(BTH_IOCTL_BASE + 0x84);
25 pub const IOCTL_BTH_SDP_SUBMIT_RECORD: DWORD = BTH_CTL!(BTH_IOCTL_BASE + 0x85);
26 pub const IOCTL_BTH_SDP_REMOVE_RECORD: DWORD = BTH_CTL!(BTH_IOCTL_BASE + 0x86);
27 pub const IOCTL_BTH_SDP_SUBMIT_RECORD_WITH_INFO: DWORD = BTH_CTL!(BTH_IOCTL_BASE + 0x87);
28 pub const IOCTL_BTH_GET_HOST_SUPPORTED_FEATURES: DWORD = BTH_CTL!(BTH_IOCTL_BASE + 0x88);
29 STRUCT!{#[repr(packed)] struct BTH_DEVICE_INFO_LIST {
30     numOfDevices: ULONG,
31     deviceList: [BTH_DEVICE_INFO; 1],
32 }}
33 pub type PBTH_DEVICE_INFO_LIST = *mut BTH_DEVICE_INFO_LIST;
34 STRUCT!{#[repr(packed)] struct BTH_RADIO_INFO {
35     lmpSupportedFeatures: ULONGLONG,
36     mfg: USHORT,
37     lmpSubversion: USHORT,
38     lmpVersion: UCHAR,
39 }}
40 pub type PBTH_RADIO_INFO = *mut BTH_RADIO_INFO;
41 STRUCT!{#[repr(packed)] struct BTH_LOCAL_RADIO_INFO {
42     localInfo: BTH_DEVICE_INFO,
43     flags: ULONG,
44     hciRevision: USHORT,
45     hciVersion: UCHAR,
46     radioInfo: BTH_RADIO_INFO,
47 }}
48 pub type PBTH_LOCAL_RADIO_INFO = *mut BTH_LOCAL_RADIO_INFO;
49 pub const SDP_CONNECT_CACHE: ULONG = 0x00000001;
50 pub const SDP_CONNECT_ALLOW_PIN: ULONG = 0x00000002;
51 pub const SDP_REQUEST_TO_DEFAULT: UCHAR = 0;
52 pub const SDP_REQUEST_TO_MIN: UCHAR = 10;
53 pub const SDP_REQUEST_TO_MAX: UCHAR = 45;
54 pub const SERVICE_OPTION_DO_NOT_PUBLISH: ULONG = 0x00000002;
55 pub const SERVICE_OPTION_NO_PUBLIC_BROWSE: ULONG = 0x00000004;
56 pub const SERVICE_OPTION_DO_NOT_PUBLISH_EIR: ULONG = 0x00000008;
57 pub const SERVICE_SECURITY_USE_DEFAULTS: ULONG = 0x00000000;
58 pub const SERVICE_SECURITY_NONE: ULONG = 0x00000001;
59 pub const SERVICE_SECURITY_AUTHORIZE: ULONG = 0x00000002;
60 pub const SERVICE_SECURITY_AUTHENTICATE: ULONG = 0x00000004;
61 pub const SERVICE_SECURITY_ENCRYPT_REQUIRED: ULONG = 0x00000010;
62 pub const SERVICE_SECURITY_ENCRYPT_OPTIONAL: ULONG = 0x00000020;
63 pub const SERVICE_SECURITY_DISABLED: ULONG = 0x10000000;
64 pub const SERVICE_SECURITY_NO_ASK: ULONG = 0x20000000;
65 pub const SDP_SEARCH_NO_PARSE_CHECK: ULONG = 0x00000001;
66 pub const SDP_SEARCH_NO_FORMAT_CHECK: ULONG = 0x00000002;
67 pub type HANDLE_SDP = ULONGLONG;
68 pub type PHANDLE_SDP = *mut ULONGLONG;
69 pub type HANDLE_SDP_TYPE = HANDLE_SDP;
70 pub const HANDLE_SDP_NULL: HANDLE_SDP = 0x0;
71 pub const HANDLE_SDP_LOCAL: HANDLE_SDP = -2i64 as u64;
72 STRUCT!{#[repr(packed)] struct BTH_SDP_CONNECT {
73     bthAddress: BTH_ADDR,
74     fSdpConnect: ULONG,
75     hConnection: HANDLE_SDP_TYPE,
76     requestTimeout: UCHAR,
77 }}
78 pub type PBTH_SDP_CONNECT = *mut BTH_SDP_CONNECT;
79 STRUCT!{#[repr(packed)] struct BTH_SDP_DISCONNECT {
80     hConnection: HANDLE_SDP_TYPE,
81 }}
82 pub type PBTH_SDP_DISCONNECT = *mut BTH_SDP_DISCONNECT;
83 STRUCT!{#[repr(packed)] struct BTH_SDP_RECORD {
84     fSecurity: ULONG,
85     fOptions: ULONG,
86     fCodService: ULONG,
87     recordLength: ULONG,
88     record: [UCHAR; 1],
89 }}
90 pub type PBTH_SDP_RECORD = *mut BTH_SDP_RECORD;
91 STRUCT!{#[repr(packed)] struct BTH_SDP_SERVICE_SEARCH_REQUEST {
92     hConnection: HANDLE_SDP_TYPE,
93     uuids: [SdpQueryUuid; MAX_UUIDS_IN_QUERY],
94 }}
95 pub type PBTH_SDP_SERVICE_SEARCH_REQUEST = *mut BTH_SDP_SERVICE_SEARCH_REQUEST;
96 STRUCT!{#[repr(packed)] struct BTH_SDP_ATTRIBUTE_SEARCH_REQUEST {
97     hConnection: HANDLE_SDP_TYPE,
98     searchFlags: ULONG,
99     recordHandle: ULONG,
100     range: [SdpAttributeRange; 1],
101 }}
102 pub type PBTH_SDP_ATTRIBUTE_SEARCH_REQUEST = *mut BTH_SDP_ATTRIBUTE_SEARCH_REQUEST;
103 STRUCT!{#[repr(packed)] struct BTH_SDP_SERVICE_ATTRIBUTE_SEARCH_REQUEST {
104     hConnection: HANDLE_SDP_TYPE,
105     searchFlags: ULONG,
106     uuids: [SdpQueryUuid; MAX_UUIDS_IN_QUERY],
107     range: [SdpAttributeRange; 1],
108 }}
109 pub type PBTH_SDP_SERVICE_ATTRIBUTE_SEARCH_REQUEST = *mut BTH_SDP_SERVICE_ATTRIBUTE_SEARCH_REQUEST;
110 STRUCT!{#[repr(packed)] struct BTH_SDP_STREAM_RESPONSE {
111     requiredSize: ULONG,
112     responseSize: ULONG,
113     response: [UCHAR; 1],
114 }}
115 pub type PBTH_SDP_STREAM_RESPONSE = *mut BTH_SDP_STREAM_RESPONSE;
116 STRUCT!{#[repr(packed)] struct BTH_COMMAND_HEADER {
117     OpCode: USHORT,
118     TotalParameterLength: UCHAR,
119 }}
120 pub type PBTH_COMMAND_HEADER = *mut BTH_COMMAND_HEADER;
121 STRUCT!{#[repr(packed)] struct BTH_VENDOR_SPECIFIC_COMMAND {
122     ManufacturerId: ULONG,
123     LmpVersion: UCHAR,
124     MatchAnySinglePattern: BOOLEAN,
125     HciHeader: BTH_COMMAND_HEADER,
126     Data: [UCHAR; 1],
127 }}
128 pub type PBTH_VENDOR_SPECIFIC_COMMAND = *mut BTH_VENDOR_SPECIFIC_COMMAND;
129 STRUCT!{#[repr(packed)] struct BTH_VENDOR_PATTERN {
130     Offset: UCHAR,
131     Size: UCHAR,
132     Pattern: [UCHAR; 1],
133 }}
134 pub type PBTH_VENDOR_PATTERN = *mut BTH_VENDOR_PATTERN;
135 STRUCT!{#[repr(packed)] struct BTH_VENDOR_EVENT_INFO {
136     BthAddress: BTH_ADDR,
137     EventSize: ULONG,
138     EventInfo: [UCHAR; 1],
139 }}
140 pub type PBTH_VENDOR_EVENT_INFO = *mut BTH_VENDOR_EVENT_INFO;
141 pub const BTH_HOST_FEATURE_ENHANCED_RETRANSMISSION_MODE: ULONGLONG = 0x0000000000000001;
142 pub const BTH_HOST_FEATURE_STREAMING_MODE: ULONGLONG = 0x0000000000000002;
143 pub const BTH_HOST_FEATURE_LOW_ENERGY: ULONGLONG = 0x0000000000000004;
144 pub const BTH_HOST_FEATURE_SCO_HCI: ULONGLONG = 0x0000000000000008;
145 pub const BTH_HOST_FEATURE_SCO_HCIBYPASS: ULONGLONG = 0x0000000000000010;
146 STRUCT!{#[repr(packed)] struct BTH_HOST_FEATURE_MASK {
147     Mask: ULONGLONG,
148     Reserved1: ULONGLONG,
149     Reserved2: ULONGLONG,
150 }}
151 pub type PBTH_HOST_FEATURE_MASK = *mut BTH_HOST_FEATURE_MASK;
152