1use shared::bthdef::{AUTHENTICATION_REQUIREMENTS, BTH_ADDR, BTH_MAX_PIN_SIZE};
7use shared::bthsdpdef::{SDP_LARGE_INTEGER_16, SDP_SPECIFICTYPE, SDP_TYPE, SDP_ULARGE_INTEGER_16};
8use shared::guiddef::GUID;
9use shared::minwindef::{BOOL, DWORD, LPBYTE, LPVOID, PULONG, UCHAR, ULONG, USHORT};
10use shared::windef::HWND;
11use um::minwinbase::SYSTEMTIME;
12use um::winnt::{
13 CHAR, HANDLE, LONG, LONGLONG, LPCWSTR, LPWSTR, PVOID, PWSTR, SHORT, ULONGLONG, WCHAR,
14};
15pub const BLUETOOTH_MAX_NAME_SIZE: usize = 248;
16pub const BLUETOOTH_MAX_PASSKEY_SIZE: usize = 16;
17pub const BLUETOOTH_MAX_PASSKEY_BUFFER_SIZE: usize = BLUETOOTH_MAX_PASSKEY_SIZE + 1;
18pub const BLUETOOTH_MAX_SERVICE_NAME_SIZE: usize = 256;
19pub const BLUETOOTH_DEVICE_NAME_SIZE: usize = 256;
20pub type BLUETOOTH_ADDRESS = BTH_ADDR;
21pub const BLUETOOTH_NULL_ADDRESS: BLUETOOTH_ADDRESS = 0x0;
22STRUCT!{struct BLUETOOTH_LOCAL_SERVICE_INFO {
23 Enabled: BOOL,
24 btAddr: BLUETOOTH_ADDRESS,
25 szName: [WCHAR; BLUETOOTH_MAX_SERVICE_NAME_SIZE],
26 szDeviceString: [WCHAR; BLUETOOTH_DEVICE_NAME_SIZE],
27}}
28pub type PBLUETOOTH_LOCAL_SERVICE_INFO = *mut BLUETOOTH_LOCAL_SERVICE_INFO;
29STRUCT!{struct BLUETOOTH_FIND_RADIO_PARAMS {
30 dwSize: DWORD,
31}}
32pub type HBLUETOOTH_RADIO_FIND = HANDLE;
33extern "system" {
34 pub fn BluetoothFindFirstRadio(
35 pbtfrp: *const BLUETOOTH_FIND_RADIO_PARAMS,
36 phRadio: *mut HANDLE,
37 ) -> HBLUETOOTH_RADIO_FIND;
38 pub fn BluetoothFindNextRadio(
39 hFind: HBLUETOOTH_RADIO_FIND,
40 phRadio: *mut HANDLE,
41 ) -> BOOL;
42 pub fn BluetoothFindRadioClose(
43 hFind: HBLUETOOTH_RADIO_FIND,
44 ) -> BOOL;
45}
46STRUCT!{struct BLUETOOTH_RADIO_INFO {
47 dwSize: DWORD,
48 address: BLUETOOTH_ADDRESS,
49 szName: [WCHAR; BLUETOOTH_MAX_NAME_SIZE],
50 ulClassofDevice: ULONG,
51 lmpSubversion: USHORT,
52 manufacturer: USHORT,
53}}
54pub type PBLUETOOTH_RADIO_INFO = *mut BLUETOOTH_RADIO_INFO;
55extern "system" {
56 pub fn BluetoothGetRadioInfo(
57 hRadio: HANDLE,
58 pRadioInfo: PBLUETOOTH_RADIO_INFO,
59 ) -> DWORD;
60}
61STRUCT!{struct BLUETOOTH_DEVICE_INFO {
62 dwSize: DWORD,
63 Address: BLUETOOTH_ADDRESS,
64 ulClassofDevice: ULONG,
65 fConnected: BOOL,
66 fRemembered: BOOL,
67 fAuthenticated: BOOL,
68 stLastSeen: SYSTEMTIME,
69 stLastUsed: SYSTEMTIME,
70 szName: [WCHAR; BLUETOOTH_MAX_NAME_SIZE],
71}}
72pub type PBLUETOOTH_DEVICE_INFO = *mut BLUETOOTH_DEVICE_INFO;
73ENUM!{enum BLUETOOTH_AUTHENTICATION_METHOD {
74 BLUETOOTH_AUTHENTICATION_METHOD_LEGACY = 0x1,
75 BLUETOOTH_AUTHENTICATION_METHOD_OOB,
76 BLUETOOTH_AUTHENTICATION_METHOD_NUMERIC_COMPARISON,
77 BLUETOOTH_AUTHENTICATION_METHOD_PASSKEY_NOTIFICATION,
78 BLUETOOTH_AUTHENTICATION_METHOD_PASSKEY,
79}}
80pub type PBLUETOOTH_AUTHENTICATION_METHOD = *mut BLUETOOTH_AUTHENTICATION_METHOD;
81ENUM!{enum BLUETOOTH_IO_CAPABILITY {
82 BLUETOOTH_IO_CAPABILITY_DISPLAYONLY = 0x00,
83 BLUETOOTH_IO_CAPABILITY_DISPLAYYESNO = 0x01,
84 BLUETOOTH_IO_CAPABILITY_KEYBOARDONLY = 0x02,
85 BLUETOOTH_IO_CAPABILITY_NOINPUTNOOUTPUT = 0x03,
86 BLUETOOTH_IO_CAPABILITY_UNDEFINED = 0xff,
87}}
88ENUM!{enum BLUETOOTH_AUTHENTICATION_REQUIREMENTS {
89 BLUETOOTH_MITM_ProtectionNotRequired = 0,
90 BLUETOOTH_MITM_ProtectionRequired = 0x1,
91 BLUETOOTH_MITM_ProtectionNotRequiredBonding = 0x2,
92 BLUETOOTH_MITM_ProtectionRequiredBonding = 0x3,
93 BLUETOOTH_MITM_ProtectionNotRequiredGeneralBonding = 0x4,
94 BLUETOOTH_MITM_ProtectionRequiredGeneralBonding = 0x5,
95 BLUETOOTH_MITM_ProtectionNotDefined = 0xff,
96}}
97UNION!{union BLUETOOTH_AUTHENTICATION_CALLBACK_PARAMS_u {
98 [u32; 1],
99 Numeric_Value Numeric_Value_mut: ULONG,
100 Passkey Passkey_mut: ULONG,
101}}
102STRUCT!{struct BLUETOOTH_AUTHENTICATION_CALLBACK_PARAMS {
103 deviceInfo: BLUETOOTH_DEVICE_INFO,
104 authenticationMethod: BLUETOOTH_AUTHENTICATION_METHOD,
105 ioCapability: BLUETOOTH_IO_CAPABILITY,
106 authenticationRequirements: BLUETOOTH_AUTHENTICATION_REQUIREMENTS,
107 u: BLUETOOTH_AUTHENTICATION_CALLBACK_PARAMS_u,
108}}
109pub type PBLUETOOTH_AUTHENTICATION_CALLBACK_PARAMS = *mut BLUETOOTH_AUTHENTICATION_CALLBACK_PARAMS;
110STRUCT!{struct BLUETOOTH_DEVICE_SEARCH_PARAMS {
111 dwSize: DWORD,
112 fReturnAuthenticated: BOOL,
113 fReturnRemembered: BOOL,
114 fReturnUnknown: BOOL,
115 fReturnConnected: BOOL,
116 fIssueInquiry: BOOL,
117 cTimeoutMultiplier: UCHAR,
118 hRadio: HANDLE,
119}}
120pub type HBLUETOOTH_DEVICE_FIND = HANDLE;
121extern "system" {
122 pub fn BluetoothFindFirstDevice(
123 pbtsp: *const BLUETOOTH_DEVICE_SEARCH_PARAMS,
124 pbtdi: *mut BLUETOOTH_DEVICE_INFO,
125 ) -> HBLUETOOTH_DEVICE_FIND;
126 pub fn BluetoothFindNextDevice(
127 hFind: HBLUETOOTH_DEVICE_FIND,
128 pbtdi: *mut BLUETOOTH_DEVICE_INFO,
129 ) -> BOOL;
130 pub fn BluetoothFindDeviceClose(
131 hFind: HBLUETOOTH_DEVICE_FIND,
132 ) -> BOOL;
133 pub fn BluetoothGetDeviceInfo(
134 hRadio: HANDLE,
135 pbtdi: *mut BLUETOOTH_DEVICE_INFO,
136 ) -> DWORD;
137 pub fn BluetoothUpdateDeviceRecord(
138 pbtdi: *const BLUETOOTH_DEVICE_INFO,
139 ) -> DWORD;
140 pub fn BluetoothRemoveDevice(
141 pAddress: *const BLUETOOTH_ADDRESS,
142 ) -> DWORD;
143}
144STRUCT!{struct BLUETOOTH_COD_PAIRS {
145 ulCODMask: ULONG,
146 pcszDescription: LPCWSTR,
147}}
148FN!{stdcall PFN_DEVICE_CALLBACK(
149 pvParam: LPVOID,
150 pDevice: *const BLUETOOTH_DEVICE_INFO,
151) -> BOOL}
152STRUCT!{struct BLUETOOTH_SELECT_DEVICE_PARAMS {
153 dwSize: DWORD,
154 cNumOfClasses: ULONG,
155 prgClassOfDevices: *mut BLUETOOTH_COD_PAIRS,
156 pszInfo: LPWSTR,
157 hwndParent: HWND,
158 fForceAuthentication: BOOL,
159 fShowAuthenticated: BOOL,
160 fShowRemembered: BOOL,
161 fShowUnknown: BOOL,
162 fAddNewDeviceWizard: BOOL,
163 fSkipServicesPage: BOOL,
164 pfnDeviceCallback: PFN_DEVICE_CALLBACK,
165 pvParam: LPVOID,
166 cNumDevices: DWORD,
167 pDevices: PBLUETOOTH_DEVICE_INFO,
168}}
169extern "system" {
170 pub fn BluetoothSelectDevices(
171 pbtsdp: *mut BLUETOOTH_SELECT_DEVICE_PARAMS,
172 ) -> BOOL;
173 pub fn BluetoothSelectDevicesFree(
174 pbtsdp: *mut BLUETOOTH_SELECT_DEVICE_PARAMS,
175 ) -> BOOL;
176 pub fn BluetoothDisplayDeviceProperties(
177 hwndParent: HWND,
178 pbtdi: *mut BLUETOOTH_DEVICE_INFO,
179 ) -> BOOL;
180 pub fn BluetoothAuthenticateDevice(
182 hwndParent: HWND,
183 hRadio: HANDLE,
184 pbtbi: *mut BLUETOOTH_DEVICE_INFO,
185 pszPasskey: PWSTR,
186 ulPasskeyLength: ULONG,
187 ) -> DWORD;
188}
189STRUCT!{struct BLUETOOTH_PIN_INFO {
190 pin: [UCHAR; BTH_MAX_PIN_SIZE],
191 pinLength: UCHAR,
192}}
193pub type PBLUETOOTH_PIN_INFO = *mut BLUETOOTH_PIN_INFO;
194STRUCT!{struct BLUETOOTH_OOB_DATA_INFO {
195 C: [UCHAR; 16],
196 R: [UCHAR; 16],
197}}
198pub type PBLUETOOTH_OOB_DATA_INFO = *mut BLUETOOTH_OOB_DATA_INFO;
199STRUCT!{struct BLUETOOTH_NUMERIC_COMPARISON_INFO {
200 NumericValue: ULONG,
201}}
202pub type PBLUETOOTH_NUMERIC_COMPARISON_INFO = *mut BLUETOOTH_NUMERIC_COMPARISON_INFO;
203STRUCT!{struct BLUETOOTH_PASSKEY_INFO {
204 passkey: ULONG,
205}}
206pub type PBLUETOOTH_PASSKEY_INFO = *mut BLUETOOTH_PASSKEY_INFO;
207extern "system" {
208 pub fn BluetoothAuthenticateDeviceEx(
209 hwndParentIn: HWND,
210 hRadioIn: HANDLE,
211 pbtdiInout: *mut BLUETOOTH_DEVICE_INFO,
212 pbtOobData: PBLUETOOTH_OOB_DATA_INFO,
213 authenticationRequirement: AUTHENTICATION_REQUIREMENTS,
214 ) -> DWORD;
215 pub fn BluetoothAuthenticateMultipleDevices(
217 hwndParent: HWND,
218 hRadio: HANDLE,
219 cDevices: DWORD,
220 rgbtdi: *mut BLUETOOTH_DEVICE_INFO,
221 ) -> DWORD;
222}
223pub const BLUETOOTH_SERVICE_DISABLE: DWORD = 0x00;
224pub const BLUETOOTH_SERVICE_ENABLE: DWORD = 0x01;
225pub const BLUETOOTH_SERVICE_MASK: DWORD = BLUETOOTH_SERVICE_DISABLE | BLUETOOTH_SERVICE_ENABLE;
226extern "system" {
227 pub fn BluetoothSetServiceState(
228 hRadio: HANDLE,
229 pbtdi: *const BLUETOOTH_DEVICE_INFO,
230 pGuidService: *const GUID,
231 dwServiceFlags: DWORD,
232 ) -> DWORD;
233 pub fn BluetoothEnumerateInstalledServices(
234 hRadio: HANDLE,
235 pbtdi: *const BLUETOOTH_DEVICE_INFO,
236 pcServiceInout: *mut DWORD,
237 pGuidServices: *mut GUID,
238 ) -> DWORD;
239 pub fn BluetoothEnableDiscovery(
240 hRadio: HANDLE,
241 fEnabled: BOOL,
242 ) -> BOOL;
243 pub fn BluetoothIsDiscoverable(
244 hRadio: HANDLE,
245 ) -> BOOL;
246 pub fn BluetoothEnableIncomingConnections(
247 hRadio: HANDLE,
248 fEnabled: BOOL,
249 ) -> BOOL;
250 pub fn BluetoothIsConnectable(
251 hRadio: HANDLE,
252 ) -> BOOL;
253}
254pub type HBLUETOOTH_AUTHENTICATION_REGISTRATION = HANDLE;
255FN!{stdcall PFN_AUTHENTICATION_CALLBACK(
256 pvParam: LPVOID,
257 pDevice: PBLUETOOTH_DEVICE_INFO,
258) -> BOOL}
259extern "system" {
260 pub fn BluetoothRegisterForAuthentication(
262 pbtdi: *const BLUETOOTH_DEVICE_INFO,
263 phRegHandle: *mut HBLUETOOTH_AUTHENTICATION_REGISTRATION,
264 pfnCallback: PFN_AUTHENTICATION_CALLBACK,
265 pvParam: PVOID,
266 ) -> DWORD;
267}
268FN!{stdcall PFN_AUTHENTICATION_CALLBACK_EX(
269 pvParam: LPVOID,
270 pAuthCallbackParams: PBLUETOOTH_AUTHENTICATION_CALLBACK_PARAMS,
271) -> BOOL}
272extern "system" {
273 pub fn BluetoothRegisterForAuthenticationEx(
274 pbtdiIn: *const BLUETOOTH_DEVICE_INFO,
275 phRegHandleOut: *mut HBLUETOOTH_AUTHENTICATION_REGISTRATION,
276 pfnCallbackIn: PFN_AUTHENTICATION_CALLBACK_EX,
277 pvParam: PVOID,
278 ) -> DWORD;
279 pub fn BluetoothUnregisterAuthentication(
280 hRegHandle: HBLUETOOTH_AUTHENTICATION_REGISTRATION,
281 ) -> BOOL;
282 pub fn BluetoothSendAuthenticationResponse(
284 hRadio: HANDLE,
285 pbtdi: *const BLUETOOTH_DEVICE_INFO,
286 pszPasskey: LPCWSTR,
287 ) -> DWORD;
288}
289UNION!{union BLUETOOTH_AUTHENTICATE_RESPONSE_u {
290 [u32; 8],
291 pinInfo pinInfo_mut: BLUETOOTH_PIN_INFO,
292 oobInfo oobInfo_mut: BLUETOOTH_OOB_DATA_INFO,
293 numericCompInfo numericCompInfo_mut: BLUETOOTH_NUMERIC_COMPARISON_INFO,
294 passkeyInfo passkeyInfo_mut: BLUETOOTH_PASSKEY_INFO,
295}}
296STRUCT!{struct BLUETOOTH_AUTHENTICATE_RESPONSE {
297 bthAddressRemote: BLUETOOTH_ADDRESS,
298 authMethod: BLUETOOTH_AUTHENTICATION_METHOD,
299 u: BLUETOOTH_AUTHENTICATE_RESPONSE_u,
300 negativeResponse: UCHAR,
301}}
302pub type PBLUETOOTH_AUTHENTICATE_RESPONSE = *mut BLUETOOTH_AUTHENTICATE_RESPONSE;
303extern "system" {
304 pub fn BluetoothSendAuthenticationResponseEx(
305 hRadioIn: HANDLE,
306 pauthResponse: PBLUETOOTH_AUTHENTICATE_RESPONSE,
307 ) -> DWORD;
308}
309STRUCT!{struct SDP_ELEMENT_DATA_data_string {
310 value: LPBYTE,
311 length: ULONG,
312}}
313STRUCT!{struct SDP_ELEMENT_DATA_data_url {
314 value: LPBYTE,
315 length: ULONG,
316}}
317STRUCT!{struct SDP_ELEMENT_DATA_data_sequence {
318 value: LPBYTE,
319 length: ULONG,
320}}
321STRUCT!{struct SDP_ELEMENT_DATA_data_alternative {
322 value: LPBYTE,
323 length: ULONG,
324}}
325UNION!{union SDP_ELEMENT_DATA_data {
326 [u64; 2],
327 int128 int128_mut: SDP_LARGE_INTEGER_16,
328 int64 int64_mut: LONGLONG,
329 int32 int32_mut: LONG,
330 int16 int16_mut: SHORT,
331 int8 int8_mut: CHAR,
332 uint128 uint128_mut: SDP_ULARGE_INTEGER_16,
333 uint64 uint64_mut: ULONGLONG,
334 uint32 uint32_mut: ULONG,
335 uint16 uint16_mut: USHORT,
336 uint8 uint8_mut: UCHAR,
337 booleanVal booleanVal_mut: UCHAR,
338 uuid128 uuid128_mut: GUID,
339 uuid32 uuid32_mut: ULONG,
340 uuid16 uuid16_mut: USHORT,
341 string string_mut: SDP_ELEMENT_DATA_data_string,
342 url url_mut: SDP_ELEMENT_DATA_data_url,
343 sequence sequence_mut: SDP_ELEMENT_DATA_data_sequence,
344 alternative alternative_mut: SDP_ELEMENT_DATA_data_alternative,
345}}
346STRUCT!{struct SDP_ELEMENT_DATA {
347 type_: SDP_TYPE,
348 specificType: SDP_SPECIFICTYPE,
349 data: SDP_ELEMENT_DATA_data,
350}}
351pub type PSDP_ELEMENT_DATA = *mut SDP_ELEMENT_DATA;
352extern "system" {
353 pub fn BluetoothSdpGetElementData(
354 pSdpStream: LPBYTE,
355 cbSdpStreamLength: ULONG,
356 pData: PSDP_ELEMENT_DATA,
357 ) -> DWORD;
358}
359pub type HBLUETOOTH_CONTAINER_ELEMENT = HANDLE;
360extern "system" {
361 pub fn BluetoothSdpGetContainerElementData(
362 pContainerStream: LPBYTE,
363 cbContainerLength: ULONG,
364 pElement: *mut HBLUETOOTH_CONTAINER_ELEMENT,
365 pData: PSDP_ELEMENT_DATA,
366 ) -> DWORD;
367 pub fn BluetoothSdpGetAttributeValue(
368 pRecordStream: LPBYTE,
369 cbRecordLength: ULONG,
370 usAttributeId: USHORT,
371 pAttributeData: PSDP_ELEMENT_DATA,
372 ) -> DWORD;
373}
374STRUCT!{struct SDP_STRING_TYPE_DATA {
375 encoding: USHORT,
376 mibeNum: USHORT,
377 attributeId: USHORT,
378}}
379pub type PSDP_STRING_TYPE_DATA = *mut SDP_STRING_TYPE_DATA;
380extern "system" {
381 pub fn BluetoothSdpGetString(
382 pRecordStream: LPBYTE,
383 cbRecordLength: ULONG,
384 pStringData: PSDP_STRING_TYPE_DATA,
385 usStringOffset: USHORT,
386 pszString: PWSTR,
387 pcchStringLength: PULONG,
388 ) -> DWORD;
389}
390FN!{stdcall PFN_BLUETOOTH_ENUM_ATTRIBUTES_CALLBACK(
391 uAttribId: ULONG,
392 pValueStream: LPBYTE,
393 cbStreamSize: ULONG,
394 pvParam: LPVOID,
395) -> BOOL}
396pub use self::BluetoothSdpEnumAttributes as BluetoothEnumAttributes;
397extern "system" {
398 pub fn BluetoothSdpEnumAttributes(
399 pSDPStream: LPBYTE,
400 cbStreamSize: ULONG,
401 pfnCallback: PFN_BLUETOOTH_ENUM_ATTRIBUTES_CALLBACK,
402 pvParam: LPVOID,
403 ) -> BOOL;
404 pub fn BluetoothSetLocalServiceInfo(
405 hRadioIn: HANDLE,
406 pClassGuid: *const GUID,
407 ulInstance: ULONG,
408 pServiceInfoIn: *const BLUETOOTH_LOCAL_SERVICE_INFO,
409 ) -> DWORD;
410 pub fn BluetoothIsVersionAvailable(
411 MajorVersion: UCHAR,
412 MinorVersion: UCHAR,
413 ) -> BOOL;
414}