1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
|
#
# Copyright 2002 - 2004, Microsoft Corporation
#
#////////////////////////////////////////////////////////////////////////////
{.deadCodeElim: on.}
when not defined(windows):
{.error: "MSBT is supported by windows".}
const
libbluetooth* = "bthprops.cpl"
import ms_bthdef, ms_bthsdpdef
const
BTH_MAX_PIN_SIZE = 16
const
BLUETOOTH_MAX_NAME_SIZE* = (248)
BLUETOOTH_MAX_PASSKEY_SIZE* = (16)
BLUETOOTH_MAX_PASSKEY_BUFFER_SIZE* = (BLUETOOTH_MAX_PASSKEY_SIZE + 1)
BLUETOOTH_MAX_SERVICE_NAME_SIZE* = (256)
BLUETOOTH_DEVICE_NAME_SIZE* = (256)
# ***************************************************************************
#
# Bluetooth Address
#
# ***************************************************************************
type
INNER_C_UNION_1866013399* = object {.union.}
ullLong*: BTH_ADDR # easier to compare again BLUETOOTH_NULL_ADDRESS
rgBytes*: array[6, BYTE] # easier to format when broken out
BLUETOOTH_ADDRESS_STRUCT* = object
ano_116103095*: INNER_C_UNION_1866013399
BLUETOOTH_ADDRESS* = BLUETOOTH_ADDRESS_STRUCT
const
BLUETOOTH_NULL_ADDRESS* = 0x0'i64
type
BLUETOOTH_LOCAL_SERVICE_INFO_STRUCT* = object
Enabled*: BOOL # If TRUE, the enable the services
btAddr*: BLUETOOTH_ADDRESS # If service is to be advertised for a particular remote device
szName*: array[BLUETOOTH_MAX_SERVICE_NAME_SIZE, WCHAR] # SDP Service Name to be advertised.
szDeviceString*: array[BLUETOOTH_DEVICE_NAME_SIZE, WCHAR] # Local device name (if any) like COM4 or LPT1
BLUETOOTH_LOCAL_SERVICE_INFO* = BLUETOOTH_LOCAL_SERVICE_INFO_STRUCT
PBLUETOOTH_LOCAL_SERVICE_INFO* = ptr BLUETOOTH_LOCAL_SERVICE_INFO
# ***************************************************************************
#
# Radio Enumeration
#
# Description:
# This group of APIs enumerates the installed Bluetooth radios.
#
# Sample Usage:
# HANDLE hRadio;
# BLUETOOTH_FIND_RADIO_PARAMS btfrp = { sizeof(btfrp) };
#
# HBLUETOOTH_RADIO_FIND hFind = BluetoothFindFirstRadio( &btfrp, &hRadio );
# if ( NULL != hFind )
# {
# do
# {
# //
# // TODO: Do something with the radio handle.
# //
#
# CloseHandle( hRadio );
#
# } while( BluetoothFindNextRadio( hFind, &hRadio ) );
#
# BluetoothFindRadioClose( hFind );
# }
#
# ***************************************************************************
type
BLUETOOTH_FIND_RADIO_PARAMS* = object
dwSize*: DWORD # IN sizeof this structure
HBLUETOOTH_RADIO_FIND* = HANDLE
#
# Description:
# Begins the enumeration of local Bluetooth radios.
#
# Parameters:
# pbtfrp
# A pointer to a BLUETOOTH_FIND_RADIO_PARAMS structure. The dwSize
# member of this structure must match the sizeof the of the structure.
#
# phRadio
# A pointer where the first radio HANDLE enumerated will be returned.
#
# Return Values:
# NULL
# Error opening radios or no devices found. Use GetLastError() for
# more info.
#
# ERROR_INVALID_PARAMETER
# pbtfrp parameter is NULL.
#
# ERROR_REVISION_MISMATCH
# The pbtfrp structure is not the right length.
#
# ERROR_OUTOFMEMORY
# Out of memory.
#
# other Win32 errors.
#
# any other
# Success. The return handle is valid and phRadio points to a valid handle.
#
proc BluetoothFindFirstRadio*(pbtfrp: ptr BLUETOOTH_FIND_RADIO_PARAMS;
phRadio: ptr HANDLE): HBLUETOOTH_RADIO_FIND {.
stdcall, importc: "BluetoothFindFirstRadio", dynlib: libbluetooth.}
#
# Description:
# Finds the next installed Bluetooth radio.
#
# Parameters:
# hFind
# The handle returned by BluetoothFindFirstRadio().
#
# phRadio
# A pointer where the next radio HANDLE enumerated will be returned.
#
# Return Values:
# TRUE
# Next device succesfully found. pHandleOut points to valid handle.
#
# FALSE
# No device found. pHandleOut points to an invalid handle. Call
# GetLastError() for more details.
#
# ERROR_INVALID_HANDLE
# The handle is NULL.
#
# ERROR_NO_MORE_ITEMS
# No more radios found.
#
# ERROR_OUTOFMEMORY
# Out of memory.
#
# other Win32 errors
#
proc BluetoothFindNextRadio*(hFind: HBLUETOOTH_RADIO_FIND;
phRadio: ptr HANDLE): BOOL {.stdcall,
importc: "BluetoothFindNextRadio", dynlib: libbluetooth.}
#
# Description:
# Closes the enumeration handle.
#
# Parameters
# hFind
# The handle returned by BluetoothFindFirstRadio().
#
# Return Values:
# TRUE
# Handle succesfully closed.
#
# FALSE
# Failure. Check GetLastError() for details.
#
# ERROR_INVALID_HANDLE
# The handle is NULL.
#
proc BluetoothFindRadioClose*(hFind: HBLUETOOTH_RADIO_FIND): BOOL {.stdcall,
importc: "BluetoothFindRadioClose", dynlib: libbluetooth.}
# ***************************************************************************
#
# Radio Information
#
# ***************************************************************************
type
BLUETOOTH_RADIO_INFO* = object
dwSize*: DWORD # Size, in bytes, of this entire data structure
address*: BLUETOOTH_ADDRESS # Address of the local radio
szName*: array[BLUETOOTH_MAX_NAME_SIZE, WCHAR] # Name of the local radio
ulClassofDevice*: ULONG # Class of device for the local radio
lmpSubversion*: USHORT # lmpSubversion, manufacturer specifc.
manufacturer*: USHORT # Manufacturer of the radio, BTH_MFG_Xxx value. For the most up to date
# list, goto the Bluetooth specification website and get the Bluetooth
# assigned numbers document.
PBLUETOOTH_RADIO_INFO* = ptr BLUETOOTH_RADIO_INFO
#
# Description:
# Retrieves the information about the radio represented by the handle.
#
# Parameters:
# hRadio
# Handle to a local radio retrieved through BluetoothFindFirstRadio()
# et al or SetupDiEnumerateDeviceInterfaces()
#
# pRadioInfo
# Radio information to be filled in. The dwSize member must match the
# size of the structure.
#
# Return Values:
# ERROR_SUCCESS
# The information was retrieved successfully.
#
# ERROR_INVALID_PARAMETER
# pRadioInfo or hRadio is NULL.
#
# ERROR_REVISION_MISMATCH
# pRadioInfo->dwSize is invalid.
#
# other Win32 error codes.
#
proc BluetoothGetRadioInfo*(hRadio: HANDLE;
pRadioInfo: PBLUETOOTH_RADIO_INFO): DWORD {.
stdcall, importc: "BluetoothGetRadioInfo", dynlib: libbluetooth.}
# ***************************************************************************
#
# Device Information Stuctures
#
# ***************************************************************************
type
BLUETOOTH_DEVICE_INFO_STRUCT* = object
dwSize*: DWORD # size, in bytes, of this structure - must be the sizeof(BLUETOOTH_DEVICE_INFO)
Address*: BLUETOOTH_ADDRESS # Bluetooth address
ulClassofDevice*: ULONG # Bluetooth "Class of Device"
fConnected*: BOOL # Device connected/in use
fRemembered*: BOOL # Device remembered
fAuthenticated*: BOOL # Device authenticated/paired/bonded
stLastSeen*: SYSTEMTIME # Last time the device was seen
stLastUsed*: SYSTEMTIME # Last time the device was used for other than RNR, inquiry, or SDP
szName*: array[BLUETOOTH_MAX_NAME_SIZE, WCHAR] # Name of the device
BLUETOOTH_DEVICE_INFO* = BLUETOOTH_DEVICE_INFO_STRUCT
PBLUETOOTH_DEVICE_INFO* = ptr BLUETOOTH_DEVICE_INFO
#
# Support added after KB942567
#
type
INNER_C_UNION_2689769052* = object {.union.}
Numeric_Value*: ULONG
Passkey*: ULONG
type
BLUETOOTH_AUTHENTICATION_METHOD* {.size: sizeof(cint).} = enum
BLUETOOTH_AUTHENTICATION_METHOD_LEGACY = 0x00000001,
BLUETOOTH_AUTHENTICATION_METHOD_OOB,
BLUETOOTH_AUTHENTICATION_METHOD_NUMERIC_COMPARISON,
BLUETOOTH_AUTHENTICATION_METHOD_PASSKEY_NOTIFICATION,
BLUETOOTH_AUTHENTICATION_METHOD_PASSKEY
PBLUETOOTH_AUTHENTICATION_METHOD* = ptr BLUETOOTH_AUTHENTICATION_METHOD
BLUETOOTH_IO_CAPABILITY* {.size: sizeof(cint).} = enum
BLUETOOTH_IO_CAPABILITY_DISPLAYONLY = 0x00000000,
BLUETOOTH_IO_CAPABILITY_DISPLAYYESNO = 0x00000001,
BLUETOOTH_IO_CAPABILITY_KEYBOARDONLY = 0x00000002,
BLUETOOTH_IO_CAPABILITY_NOINPUTNOOUTPUT = 0x00000003,
BLUETOOTH_IO_CAPABILITY_UNDEFINED = 0x000000FF
BLUETOOTH_AUTHENTICATION_REQUIREMENTS* {.size: sizeof(cint).} = enum
BLUETOOTH_MITM_ProtectionNotRequired = 0,
BLUETOOTH_MITM_ProtectionRequired = 0x00000001,
BLUETOOTH_MITM_ProtectionNotRequiredBonding = 0x00000002,
BLUETOOTH_MITM_ProtectionRequiredBonding = 0x00000003,
BLUETOOTH_MITM_ProtectionNotRequiredGeneralBonding = 0x00000004,
BLUETOOTH_MITM_ProtectionRequiredGeneralBonding = 0x00000005,
BLUETOOTH_MITM_ProtectionNotDefined = 0x000000FF
BLUETOOTH_AUTHENTICATION_CALLBACK_PARAMS* = object
deviceInfo*: BLUETOOTH_DEVICE_INFO
authenticationMethod*: BLUETOOTH_AUTHENTICATION_METHOD
ioCapability*: BLUETOOTH_IO_CAPABILITY
authenticationRequirements*: BLUETOOTH_AUTHENTICATION_REQUIREMENTS
ano_869376366*: INNER_C_UNION_2689769052
PBLUETOOTH_AUTHENTICATION_CALLBACK_PARAMS* = ptr BLUETOOTH_AUTHENTICATION_CALLBACK_PARAMS
# ***************************************************************************
#
# Device Enumeration
#
# Description:
# Enumerates the Bluetooth devices. The types of returned device depends
# on the flags set in the BLUETOOTH_DEVICE_SEARCH_PARAMS (see structure
# definition for details).
#
# Sample Usage:
# HBLUETOOTH_DEVICE_FIND hFind;
# BLUETOOTH_DEVICE_SEARCH_PARAMS btsp = { sizeof(btsp) };
# BLUETOOTH_DEVICE_INFO btdi = { sizeof(btdi) };
#
# btsp.fReturnAuthenticated = TRUE;
# btsp.fReturnRemembered = TRUE;
#
# hFind = BluetoothFindFirstDevice( &btsp, &btdi );
# if ( NULL != hFind )
# {
# do
# {
# //
# // TODO: Do something useful with the device info.
# //
#
# } while( BluetoothFindNextDevice( hFind, &btdi ) );
#
# BluetoothFindDeviceClose( hFind );
# }
#
# ***************************************************************************
type
BLUETOOTH_DEVICE_SEARCH_PARAMS* = object
dwSize*: DWORD # IN sizeof this structure
fReturnAuthenticated*: BOOL # IN return authenticated devices
fReturnRemembered*: BOOL # IN return remembered devices
fReturnUnknown*: BOOL # IN return unknown devices
fReturnConnected*: BOOL # IN return connected devices
fIssueInquiry*: BOOL # IN issue a new inquiry
cTimeoutMultiplier*: UCHAR # IN timeout for the inquiry
hRadio*: HANDLE # IN handle to radio to enumerate - NULL == all radios will be searched
HBLUETOOTH_DEVICE_FIND* = HANDLE
#
# Description:
# Begins the enumeration of Bluetooth devices.
#
# Parameters:
# pbtsp
# A pointer to a BLUETOOTH_DEVICE_SEARCH_PARAMS structure. This
# structure contains the flags and inputs used to conduct the search.
# See BLUETOOTH_DEVICE_SEARCH_PARAMS for details.
#
# pbtdi
# A pointer to a BLUETOOTH_DEVICE_INFO structure to return information
# about the first Bluetooth device found. Note that the dwSize member
# of the structure must be the sizeof(BLUETOOTH_DEVICE_INFO) before
# calling because the APIs hast to know the size of the buffer being
# past in. The dwSize member must also match the exact
# sizeof(BLUETOOTH_DEVICE_INFO) or the call will fail.
#
# Return Values:
# NULL
# Error opening radios or not devices found. Use GetLastError for more info.
#
# ERROR_INVALID_PARAMETER
# pbtsp parameter or pbtdi parameter is NULL.
#
# ERROR_REVISION_MISMATCH
# The pbtfrp structure is not the right length.
#
# other Win32 errors
#
# any other value
# Success. The return handle is valid and pbtdi points to valid data.
#
proc BluetoothFindFirstDevice*(pbtsp: ptr BLUETOOTH_DEVICE_SEARCH_PARAMS;
pbtdi: ptr BLUETOOTH_DEVICE_INFO): HBLUETOOTH_DEVICE_FIND {.
stdcall, importc: "BluetoothFindFirstDevice", dynlib: libbluetooth.}
#
# Description:
# Finds the next Bluetooth device in the enumeration.
#
# Parameters:
# hFind
# The handle returned from BluetoothFindFirstDevice().
#
# pbtdi
# A pointer to a BLUETOOTH_DEVICE_INFO structure to return information
# about the first Bluetooth device found. Note that the dwSize member
# of the structure must be the sizeof(BLUETOOTH_DEVICE_INFO) before
# calling because the APIs hast to know the size of the buffer being
# past in. The dwSize member must also match the exact
# sizeof(BLUETOOTH_DEVICE_INFO) or the call will fail.
#
# Return Values:
# TRUE
# Next device succesfully found. pHandleOut points to valid handle.
#
# FALSE
# No device found. pHandleOut points to an invalid handle. Call
# GetLastError() for more details.
#
# ERROR_INVALID_HANDLE
# The handle is NULL.
#
# ERROR_NO_MORE_ITEMS
# No more radios found.
#
# ERROR_OUTOFMEMORY
# Out of memory.
#
# other Win32 errors
#
proc BluetoothFindNextDevice*(hFind: HBLUETOOTH_DEVICE_FIND;
pbtdi: ptr BLUETOOTH_DEVICE_INFO): BOOL {.
stdcall, importc: "BluetoothFindNextDevice", dynlib: libbluetooth.}
#
# Description:
# Closes the enumeration handle.
#
# Parameters:
# hFind
# The handle returned from BluetoothFindFirstDevice().
#
# Return Values:
# TRUE
# Handle succesfully closed.
#
# FALSE
# Failure. Check GetLastError() for details.
#
# ERROR_INVALID_HANDLE
# The handle is NULL.
#
proc BluetoothFindDeviceClose*(hFind: HBLUETOOTH_DEVICE_FIND): BOOL {.
stdcall, importc: "BluetoothFindDeviceClose", dynlib: libbluetooth.}
#
# Description:
# Retrieves information about a remote device.
#
# Fill in the dwSize and the Address members of the pbtdi structure
# being passed in. On success, the rest of the members will be filled
# out with the information that the system knows.
#
# Parameters:
# hRadio
# Handle to a local radio retrieved through BluetoothFindFirstRadio()
# et al or SetupDiEnumerateDeviceInterfaces()
#
# pbtdi
# A pointer to a BLUETOOTH_DEVICE_INFO structure to return information
# about the first Bluetooth device found. The dwSize member of the
# structure must be the sizeof the structure in bytes. The Address
# member must be filled out with the Bluetooth address of the remote
# device.
#
# Return Values:
# ERROR_SUCCESS
# Success. Information returned.
#
# ERROR_REVISION_MISMATCH
# The size of the BLUETOOTH_DEVICE_INFO isn't compatible. Check
# the dwSize member of the BLUETOOTH_DEVICE_INFO structure you
# passed in.
#
# ERROR_NOT_FOUND
# The radio is not known by the system or the Address field of
# the BLUETOOTH_DEVICE_INFO structure is all zeros.
#
# ERROR_INVALID_PARAMETER
# pbtdi is NULL.
#
# other error codes
#
proc BluetoothGetDeviceInfo*(hRadio: HANDLE;
pbtdi: ptr BLUETOOTH_DEVICE_INFO): DWORD {.
stdcall, importc: "BluetoothGetDeviceInfo", dynlib: libbluetooth.}
#
# Description:
# Updates the computer local cache about the device.
#
# Parameters:
# pbtdi
# A pointer to the BLUETOOTH_DEVICE_INFO structure to be updated.
# The following members must be valid:
# dwSize
# Must match the size of the structure.
# Address
# Must be a previously found radio address.
# szName
# New name to be stored.
#
# Return Values:
# ERROR_SUCCESS
# The device information was updated successfully.
#
# ERROR_INVALID_PARAMETER
# pbtdi is NULL.
#
# ERROR_REVISION_MISMATCH
# pbtdi->dwSize is invalid.
#
# other Win32 error codes.
#
proc BluetoothUpdateDeviceRecord*(pbtdi: ptr BLUETOOTH_DEVICE_INFO): DWORD {.
stdcall, importc: "BluetoothUpdateDeviceRecord", dynlib: libbluetooth.}
#
# Description:
# Delete the authentication (aka "bond") between the computer and the
# device. Also purges any cached information about the device.
#
# Return Values:
# ERROR_SUCCESS
# The device was removed successfully.
#
# ERROR_NOT_FOUND
# The device was not found. If no Bluetooth radio is installed,
# the devices could not be enumerated or removed.
#
proc BluetoothRemoveDevice*(pAddress: ptr BLUETOOTH_ADDRESS): DWORD {.
stdcall, importc: "BluetoothRemoveDevice", dynlib: libbluetooth.}
when not (hostCPU == "arm"):
#
# ***************************************************************************
#
# Device Picker Dialog
#
# Description:
# Invokes a common dialog for selecting Bluetooth devices. The list
# of devices displayed to the user is determined by the flags and
# settings the caller specifies in the BLUETOOTH_SELECT_DEVICE_PARAMS
# (see structure definition for more details).
#
# If BluetoothSelectDevices() returns TRUE, the caller must call
# BluetoothSelectDevicesFree() or memory will be leaked within the
# process.
#
# Sample Usage:
#
# BLUETOOTH_SELECT_DEVICE_PARAMS btsdp = { sizeof(btsdp) };
#
# btsdp.hwndParent = hDlg;
# btsdp.fShowUnknown = TRUE;
# btsdp.fAddNewDeviceWizard = TRUE;
#
# BOOL b = BluetoothSelectDevices( &btsdp );
# if ( b )
# {
# BLUETOOTH_DEVICE_INFO * pbtdi = btsdp.pDevices;
# for ( ULONG cDevice = 0; cDevice < btsdp.cNumDevices; cDevice ++ )
# {
# if ( pbtdi->fAuthenticated || pbtdi->fRemembered )
# {
# //
# // TODO: Do something usefull with the device info
# //
# }
#
# pbtdi = (BLUETOOTH_DEVICE_INFO *) ((LPBYTE)pbtdi + pbtdi->dwSize);
# }
#
# BluetoothSelectDevicesFree( &btsdp );
# }
#
#
# ***************************************************************************
type
BLUETOOTH_COD_PAIRS* = object
ulCODMask*: ULONG # ClassOfDevice mask to compare
pcszDescription*: LPCWSTR # Descriptive string of mask
PFN_DEVICE_CALLBACK* = proc (pvParam: LPVOID;
pDevice: ptr BLUETOOTH_DEVICE_INFO): BOOL {.
stdcall.}
BLUETOOTH_SELECT_DEVICE_PARAMS* = object
dwSize*: DWORD # IN sizeof this structure
cNumOfClasses*: ULONG # IN Number in prgClassOfDevice - if ZERO search for all devices
prgClassOfDevices*: ptr BLUETOOTH_COD_PAIRS # IN Array of CODs to find.
pszInfo*: LPWSTR # IN If not NULL, sets the "information" text
hwndParent*: HWND # IN parent window - NULL == no parent
fForceAuthentication*: BOOL # IN If TRUE, authenication will be forced before returning
fShowAuthenticated*: BOOL # IN If TRUE, authenticated devices will be shown in the picker
fShowRemembered*: BOOL # IN If TRUE, remembered devices will be shown in the picker
fShowUnknown*: BOOL # IN If TRUE, unknown devices that are not authenticated or "remember" will be shown.
fAddNewDeviceWizard*: BOOL # IN If TRUE, invokes the add new device wizard.
fSkipServicesPage*: BOOL # IN If TRUE, skips the "Services" page in the wizard.
pfnDeviceCallback*: PFN_DEVICE_CALLBACK # IN If non-NULL, a callback that will be called for each device. If the
# the callback returns TRUE, the item will be added. If the callback is
# is FALSE, the item will not be shown.
pvParam*: LPVOID # IN Parameter to be passed to pfnDeviceCallback as the pvParam.
cNumDevices*: DWORD # IN number calles wants - ZERO == no limit.
# OUT the number of devices returned.
pDevices*: PBLUETOOTH_DEVICE_INFO # OUT pointer to an array for BLUETOOTH_DEVICE_INFOs.
# call BluetoothSelectDevicesFree() to free
#
# Description:
# (See header above)
#
# Return Values:
# TRUE
# User selected a device. pbtsdp->pDevices points to valid data.
# Caller should check the fAuthenticated && fRemembered flags to
# determine which devices we successfuly authenticated or valid
# selections by the user.
#
# Use BluetoothSelectDevicesFree() to free the nessecary data
# such as pDevices only if this function returns TRUE.
#
# FALSE
# No valid data returned. Call GetLastError() for possible details
# of the failure. If GLE() is:
#
# ERROR_CANCELLED
# The user cancelled the request.
#
# ERROR_INVALID_PARAMETER
# The pbtsdp is NULL.
#
# ERROR_REVISION_MISMATCH
# The structure passed in as pbtsdp is of an unknown size.
#
# other WIN32 errors
#
proc BluetoothSelectDevices*(pbtsdp: ptr BLUETOOTH_SELECT_DEVICE_PARAMS): BOOL {.
stdcall, importc: "BluetoothSelectDevices", dynlib: libbluetooth.}
#
# Description:
# This function should only be called if BluetoothSelectDevices() returns
# TRUE. This function will free any memory and resource returned by the
# BluetoothSelectDevices() in the BLUETOOTH_SELECT_DEVICE_PARAMS
# structure.
#
# Return Values:
# TRUE
# Success.
#
# FALSE
# Nothing to free.
#
proc BluetoothSelectDevicesFree*(pbtsdp: ptr BLUETOOTH_SELECT_DEVICE_PARAMS): BOOL {.
stdcall, importc: "BluetoothSelectDevicesFree", dynlib: libbluetooth.}
# ***************************************************************************
#
# Device Property Sheet
#
# ***************************************************************************
#
# Description:
# Invokes the CPLs device info property sheet.
#
# Parameters:
# hwndParent
# HWND to parent the property sheet.
#
# pbtdi
# A pointer to a BLUETOOTH_DEVICE_INFO structure of the device
# to be displayed.
#
# Return Values:
# TRUE
# The property page was successfully displayed.
#
# FALSE
# Failure. The property page was not displayed. Check GetLastError
# for more details.
#
proc BluetoothDisplayDeviceProperties*(hwndParent: HWND;
pbtdi: ptr BLUETOOTH_DEVICE_INFO): BOOL {.stdcall,
importc: "BluetoothDisplayDeviceProperties", dynlib: libbluetooth.}
# ***************************************************************************
#
# Radio Authentication
#
# ***************************************************************************
#
# Description:
# Sends an authentication request to a remote device.
#
# There are two modes of operation. "Wizard mode" and "Blind mode."
#
# "Wizard mode" is invoked when the pszPasskey is NULL. This will cause
# the "Bluetooth Connection Wizard" to be invoked. The user will be
# prompted to enter a passkey during the wizard after which the
# authentication request will be sent. The user will see the success
# or failure of the authentication attempt. The user will also be
# given the oppurtunity to try to fix a failed authentication.
#
# "Blind mode" is invoked when the pszPasskey is non-NULL. This will
# cause the computer to send a authentication request to the remote
# device. No UI is ever displayed. The Bluetooth status code will be
# mapped to a Win32 Error code.
#
# Parameters:
#
# hwndParent
# The window to parent the authentication wizard. If NULL, the
# wizard will be parented off the desktop.
#
# hRadio
# A valid local radio handle or NULL. If NULL, then all radios will
# be tired. If any of the radios succeed, then the call will
# succeed.
#
# pbtdi
# BLUETOOTH_DEVICE_INFO record of the device to be authenticated.
#
# pszPasskey
# PIN to be used to authenticate the device. If NULL, then UI is
# displayed and the user steps through the authentication process.
# If not NULL, no UI is shown. The passkey is NOT NULL terminated.
#
# ulPasskeyLength
# Length of szPassKey in bytes. The length must be less than or
# equal to BLUETOOTH_MAX_PASSKEY_SIZE * sizeof(WCHAR).
#
# Return Values:
#
# ERROR_SUCCESS
# Success.
#
# ERROR_CANCELLED
# User aborted the operation.
#
# ERROR_INVALID_PARAMETER
# The device structure in pbtdi is invalid.
#
# ERROR_NO_MORE_ITEMS
# The device in pbtdi is already been marked as authenticated.
#
# other WIN32 error
# Failure. Return value is the error code.
#
# For "Blind mode," here is the current mapping of Bluetooth status
# code to Win32 error codes:
#
# { BTH_ERROR_SUCCESS, ERROR_SUCCESS },
# { BTH_ERROR_NO_CONNECTION, ERROR_DEVICE_NOT_CONNECTED },
# { BTH_ERROR_PAGE_TIMEOUT, WAIT_TIMEOUT },
# { BTH_ERROR_HARDWARE_FAILURE, ERROR_GEN_FAILURE },
# { BTH_ERROR_AUTHENTICATION_FAILURE, ERROR_NOT_AUTHENTICATED },
# { BTH_ERROR_MEMORY_FULL, ERROR_NOT_ENOUGH_MEMORY },
# { BTH_ERROR_CONNECTION_TIMEOUT, WAIT_TIMEOUT },
# { BTH_ERROR_LMP_RESPONSE_TIMEOUT, WAIT_TIMEOUT },
# { BTH_ERROR_MAX_NUMBER_OF_CONNECTIONS, ERROR_REQ_NOT_ACCEP },
# { BTH_ERROR_PAIRING_NOT_ALLOWED, ERROR_ACCESS_DENIED },
# { BTH_ERROR_UNSPECIFIED_ERROR, ERROR_NOT_READY },
# { BTH_ERROR_LOCAL_HOST_TERMINATED_CONNECTION, ERROR_VC_DISCONNECTED },
#
proc BluetoothAuthenticateDevice*(hwndParent: HWND; hRadio: HANDLE;
pbtbi: ptr BLUETOOTH_DEVICE_INFO;
pszPasskey: PWSTR; ulPasskeyLength: ULONG): DWORD {.
stdcall, importc: "BluetoothAuthenticateDevice", dynlib: libbluetooth,
deprecated.}
#
# Support added after KB942567
#
#
# Replaces previous API
#
#
# Common header for all PIN related structures
#
type
BLUETOOTH_PIN_INFO* = object
pin*: array[BTH_MAX_PIN_SIZE, UCHAR]
pinLength*: UCHAR
PBLUETOOTH_PIN_INFO* = ptr BLUETOOTH_PIN_INFO
BLUETOOTH_OOB_DATA_INFO* = object
C*: array[16, UCHAR]
R*: array[16, UCHAR]
PBLUETOOTH_OOB_DATA_INFO* = ptr BLUETOOTH_OOB_DATA_INFO
BLUETOOTH_NUMERIC_COMPARISON_INFO* = object
NumericValue*: ULONG
PBLUETOOTH_NUMERIC_COMPARISON_INFO* = ptr BLUETOOTH_NUMERIC_COMPARISON_INFO
BLUETOOTH_PASSKEY_INFO* = object
passkey*: ULONG
PBLUETOOTH_PASSKEY_INFO* = ptr BLUETOOTH_PASSKEY_INFO
#
# Description:
# Sends an authentication request to a remote device.
#
# There are two modes of operation. "Wizard mode" and "Blind mode."
#
# "Wizard mode" is invoked when the pbtOobData is NULL. This will cause
# the "Bluetooth Connection Wizard" to be invoked. The user will be
# prompted to respond to the device authentication during the wizard
# after which the authentication request will be sent. The user will see the success
# or failure of the authentication attempt. The user will also be
# given the oppurtunity to try to fix a failed authentication.
#
# "Blind mode" is invoked when the pbtOobData is non-NULL. This will
# cause the computer to send a authentication request to the remote
# device. No UI is ever displayed. The Bluetooth status code will be
# mapped to a Win32 Error code.
#
# Parameters:
#
# hwndParent
# The window to parent the authentication wizard. If NULL, the
# wizard will be parented off the desktop.
#
# hRadio
# A valid local radio handle or NULL. If NULL, then all radios will
# be tired. If any of the radios succeed, then the call will
# succeed.
#
# pbtdi
# BLUETOOTH_DEVICE_INFO record of the device to be authenticated.
#
# pbtOobData
# Out of band data to be used to authenticate the device. If NULL, then UI is
# displayed and the user steps through the authentication process.
# If not NULL, no UI is shown.
#
# authenticationRequirement
# The Authentication Requirement of the caller. MITMProtection*
#
#
# Return Values:
#
# ERROR_SUCCESS
# Success.
#
# ERROR_CANCELLED
# User aborted the operation.
#
# ERROR_INVALID_PARAMETER
# The device structure in pbtdi is invalid.
#
# ERROR_NO_MORE_ITEMS
# The device in pbtdi is already been marked as authenticated.
#
# other WIN32 error
# Failure. Return value is the error code.
#
# For "Blind mode," here is the current mapping of Bluetooth status
# code to Win32 error codes:
#
# { BTH_ERROR_SUCCESS, ERROR_SUCCESS },
# { BTH_ERROR_NO_CONNECTION, ERROR_DEVICE_NOT_CONNECTED },
# { BTH_ERROR_PAGE_TIMEOUT, WAIT_TIMEOUT },
# { BTH_ERROR_HARDWARE_FAILURE, ERROR_GEN_FAILURE },
# { BTH_ERROR_AUTHENTICATION_FAILURE, ERROR_NOT_AUTHENTICATED },
# { BTH_ERROR_MEMORY_FULL, ERROR_NOT_ENOUGH_MEMORY },
# { BTH_ERROR_CONNECTION_TIMEOUT, WAIT_TIMEOUT },
# { BTH_ERROR_LMP_RESPONSE_TIMEOUT, WAIT_TIMEOUT },
# { BTH_ERROR_MAX_NUMBER_OF_CONNECTIONS, ERROR_REQ_NOT_ACCEP },
# { BTH_ERROR_PAIRING_NOT_ALLOWED, ERROR_ACCESS_DENIED },
# { BTH_ERROR_UNSPECIFIED_ERROR, ERROR_NOT_READY },
# { BTH_ERROR_LOCAL_HOST_TERMINATED_CONNECTION, ERROR_VC_DISCONNECTED },
#
proc BluetoothAuthenticateDeviceEx*(hwndParentIn: HWND; hRadioIn: HANDLE;
pbtdiInout: ptr BLUETOOTH_DEVICE_INFO;
pbtOobData: PBLUETOOTH_OOB_DATA_INFO;
authenticationRequirement: BLUETOOTH_AUTHENTICATION_REQUIREMENTS): DWORD {.
stdcall, importc: "BluetoothAuthenticateDeviceEx",
dynlib: libbluetooth.}
#
# Description:
# Allows the caller to prompt for multiple devices to be authenticated
# within a single instance of the "Bluetooth Connection Wizard."
#
# Parameters:
#
# hwndParent
# The window to parent the authentication wizard. If NULL, the
# wizard will be parented off the desktop.
#
# hRadio
# A valid local radio handle or NULL. If NULL, then all radios will
# be tired. If any of the radios succeed, then the call will
# succeed.
#
# cDevices
# Number of devices in the rgbtdi array.
#
# rgbtdi
# An array BLUETOOTH_DEVICE_INFO records of the devices to be
# authenticated.
#
# Return Values:
#
# ERROR_SUCCESS
# Success. Check the fAuthenticate flag on each of the devices.
#
# ERROR_CANCELLED
# User aborted the operation. Check the fAuthenticate flags on
# each device to determine if any of the devices were authenticated
# before the user cancelled the operation.
#
# ERROR_INVALID_PARAMETER
# One of the items in the array of devices is invalid.
#
# ERROR_NO_MORE_ITEMS
# All the devices in the array of devices are already been marked as
# being authenticated.
#
# other WIN32 error
# Failure. Return value is the error code.
#
proc BluetoothAuthenticateMultipleDevices*(hwndParent: HWND; hRadio: HANDLE;
cDevices: DWORD; rgbtdi: ptr BLUETOOTH_DEVICE_INFO): DWORD {.stdcall,
importc: "BluetoothAuthenticateMultipleDevices", dynlib: libbluetooth,
deprecated.}
#
# Deprecated after Vista SP1 and KB942567
#
# ***************************************************************************
#
# Bluetooth Services
#
# ***************************************************************************
const
BLUETOOTH_SERVICE_DISABLE* = 0x00000000
BLUETOOTH_SERVICE_ENABLE* = 0x00000001
BLUETOOTH_SERVICE_MASK* = (
BLUETOOTH_SERVICE_DISABLE or BLUETOOTH_SERVICE_ENABLE)
#
# Description:
# Enables/disables the services for a particular device.
#
# The system maintains a mapping of service guids to supported drivers for
# Bluetooth-enabled devices. Enabling a service installs the corresponding
# device driver. Disabling a service removes the corresponding device driver.
#
# If a non-supported service is enabled, a driver will not be installed.
#
# Parameters
# hRadio
# Handle of the local Bluetooth radio device.
#
# pbtdi
# Pointer to a BLUETOOTH_DEVICE_INFO record.
#
# pGuidService
# The service GUID on the remote device.
#
# dwServiceFlags
# Flags to adjust the service.
# BLUETOOTH_SERVICE_DISABLE - disable the service
# BLUETOOTH_SERVICE_ENABLE - enables the service
#
# Return Values:
# ERROR_SUCCESS
# The call was successful.
#
# ERROR_INVALID_PARAMETER
# dwServiceFlags are invalid.
#
# ERROR_SERVICE_DOES_NOT_EXIST
# The GUID in pGuidService is not supported.
#
# other WIN32 error
# The call failed.
#
proc BluetoothSetServiceState*(hRadio: HANDLE;
pbtdi: ptr BLUETOOTH_DEVICE_INFO;
pGuidService: ptr GUID; dwServiceFlags: DWORD): DWORD {.
stdcall, importc: "BluetoothSetServiceState", dynlib: libbluetooth.}
#
# Description:
# Enumerates the services guids enabled on a particular device. If hRadio
# is NULL, all device will be searched for the device and all the services
# enabled will be returned.
#
# Parameters:
# hRadio
# Handle of the local Bluetooth radio device. If NULL, it will search
# all the radios for the address in the pbtdi.
#
# pbtdi
# Pointer to a BLUETOOTH_DEVICE_INFO record.
#
# pcService
# On input, the number of records pointed to by pGuidServices.
# On output, the number of valid records return in pGuidServices.
#
# pGuidServices
# Pointer to memory that is at least *pcService in length.
#
# Return Values:
# ERROR_SUCCESS
# The call succeeded. pGuidServices is valid.
#
# ERROR_MORE_DATA
# The call succeeded. pGuidService contains an incomplete list of
# enabled service GUIDs.
#
# other WIN32 errors
# The call failed.
#
proc BluetoothEnumerateInstalledServices*(hRadio: HANDLE;
pbtdi: ptr BLUETOOTH_DEVICE_INFO; pcServiceInout: ptr DWORD;
pGuidServices: ptr GUID): DWORD {.stdcall,
importc: "BluetoothEnumerateInstalledServices", dynlib: libbluetooth.}
#
# Description:
# Change the discovery state of the local radio(s).
# If hRadio is NULL, all the radios will be set.
#
# Use BluetoothIsDiscoverable() to determine the radios current state.
#
# The system ensures that a discoverable system is connectable, thus
# the radio must allow incoming connections (see
# BluetoothEnableIncomingConnections) prior to making a radio
# discoverable. Failure to do so will result in this call failing
# (returns FALSE).
#
# Parameters:
# hRadio
# If not NULL, changes the state of a specific radio.
# If NULL, the API will interate through all the radios.
#
# fEnabled
# If FALSE, discovery will be disabled.
#
# Return Values
# TRUE
# State was successfully changed. If the caller specified NULL for
# hRadio, at least of the radios accepted the state change.
#
# FALSE
# State was not changed. If the caller specified NULL for hRadio, all
# of the radios did not accept the state change.
#
proc BluetoothEnableDiscovery*(hRadio: HANDLE; fEnabled: BOOL): BOOL {.
stdcall, importc: "BluetoothEnableDiscovery", dynlib: libbluetooth.}
#
# Description:
# Determines if the Bluetooth radios are discoverable. If there are
# multiple radios, the first one to say it is discoverable will cause
# this function to return TRUE.
#
# Parameters:
# hRadio
# Handle of the radio to check. If NULL, it will check all local
# radios.
#
# Return Values:
# TRUE
# A least one radio is discoverable.
#
# FALSE
# No radios are discoverable.
#
proc BluetoothIsDiscoverable*(hRadio: HANDLE): BOOL {.stdcall,
importc: "BluetoothIsDiscoverable", dynlib: libbluetooth.}
#
# Description:
# Enables/disables the state of a radio to accept incoming connections.
# If hRadio is NULL, all the radios will be set.
#
# Use BluetoothIsConnectable() to determine the radios current state.
#
# The system enforces that a radio that is not connectable is not
# discoverable too. The radio must be made non-discoverable (see
# BluetoothEnableDiscovery) prior to making a radio non-connectionable.
# Failure to do so will result in this call failing (returns FALSE).
#
# Parameters:
# hRadio
# If not NULL, changes the state of a specific radio.
# If NULL, the API will interate through all the radios.
#
# fEnabled
# If FALSE, incoming connection will be disabled.
#
# Return Values
# TRUE
# State was successfully changed. If the caller specified NULL for
# hRadio, at least of the radios accepted the state change.
#
# FALSE
# State was not changed. If the caller specified NULL for hRadio, all
# of the radios did not accept the state change.
#
proc BluetoothEnableIncomingConnections*(hRadio: HANDLE; fEnabled: BOOL): BOOL {.
stdcall, importc: "BluetoothEnableIncomingConnections",
dynlib: libbluetooth.}
#
# Description:
# Determines if the Bluetooth radios are connectable. If there are
# multiple radios, the first one to say it is connectable will cause
# this function to return TRUE.
#
# Parameters:
# hRadio
# Handle of the radio to check. If NULL, it will check all local
# radios.
#
# Return Values:
# TRUE
# A least one radio is allowing incoming connections.
#
# FALSE
# No radios are allowing incoming connections.
#
proc BluetoothIsConnectable*(hRadio: HANDLE): BOOL {.stdcall,
importc: "BluetoothIsConnectable", dynlib: libbluetooth.}
# ***************************************************************************
#
# Authentication Registration
#
# ***************************************************************************
type
HBLUETOOTH_AUTHENTICATION_REGISTRATION* = HANDLE
PFN_AUTHENTICATION_CALLBACK* = proc (pvParam: LPVOID;
pDevice: PBLUETOOTH_DEVICE_INFO): BOOL {.stdcall.}
#
# Description:
# Registers a callback function to be called when a particular device
# requests authentication. The request is sent to the last application
# that requested authentication for a particular device.
#
# Parameters:
# pbtdi
# A pointer to a BLUETOOTH_DEVICE_INFO structure. The Bluetooth
# address will be used for comparision.
#
# phRegHandle
# A pointer to where the registration HANDLE value will be
# stored. Call BluetoothUnregisterAuthentication() to close
# the handle.
#
# pfnCallback
# The function that will be called when the authentication event
# occurs. This function should match PFN_AUTHENTICATION_CALLBACK's
# prototype.
#
# pvParam
# Optional parameter to be past through to the callback function.
# This can be anything the application was to define.
#
# Return Values:
# ERROR_SUCCESS
# Success. A valid registration handle was returned.
#
# ERROR_OUTOFMEMORY
# Out of memory.
#
# other Win32 error.
# Failure. The registration handle is invalid.
#
proc BluetoothRegisterForAuthentication*(pbtdi: ptr BLUETOOTH_DEVICE_INFO;
phRegHandle: ptr HBLUETOOTH_AUTHENTICATION_REGISTRATION;
pfnCallback: PFN_AUTHENTICATION_CALLBACK; pvParam: PVOID): DWORD {.
stdcall, importc: "BluetoothRegisterForAuthentication",
dynlib: libbluetooth,
deprecated.}
#
# Support added in KB942567
#
#
# Replaces previous API
#
type
PFN_AUTHENTICATION_CALLBACK_EX* = proc (pvParam: LPVOID;
pAuthCallbackParams: PBLUETOOTH_AUTHENTICATION_CALLBACK_PARAMS): BOOL {.
stdcall.}
#
# Description:
# Registers a callback function to be called when a particular device
# requests authentication. The request is sent to the last application
# that requested authentication for a particular device.
#
# Parameters:
# pbtdi
# A pointer to a BLUETOOTH_DEVICE_INFO structure. The Bluetooth
# address will be used for comparision.
#
# phRegHandle
# A pointer to where the registration HANDLE value will be
# stored. Call BluetoothUnregisterAuthentication() to close
# the handle.
#
# pfnCallback
# The function that will be called when the authentication event
# occurs. This function should match PFN_AUTHENTICATION_CALLBACK_EX's
# prototype.
#
# pvParam
# Optional parameter to be past through to the callback function.
# This can be anything the application was to define.
#
# Return Values:
# ERROR_SUCCESS
# Success. A valid registration handle was returned.
#
# ERROR_OUTOFMEMORY
# Out of memory.
#
# other Win32 error.
# Failure. The registration handle is invalid.
#
proc BluetoothRegisterForAuthenticationEx*(
pbtdiIn: ptr BLUETOOTH_DEVICE_INFO;
phRegHandleOut: ptr HBLUETOOTH_AUTHENTICATION_REGISTRATION;
pfnCallbackIn: PFN_AUTHENTICATION_CALLBACK_EX; pvParam: PVOID): DWORD {.
stdcall, importc: "BluetoothRegisterForAuthenticationEx",
dynlib: libbluetooth.}
#
# Description:
# Unregisters an authentication callback and closes the handle. See
# BluetoothRegisterForAuthentication() for more information about
# authentication registration.
#
# Parameters:
# hRegHandle
# Handle returned by BluetoothRegisterForAuthentication().
#
# Return Value:
# TRUE
# The handle was successfully closed.
#
# FALSE
# The handle was not successfully closed. Check GetLastError for
# more details.
#
# ERROR_INVALID_HANDLE
# The handle is NULL.
#
# other Win32 errors.
#
proc BluetoothUnregisterAuthentication*(
hRegHandle: HBLUETOOTH_AUTHENTICATION_REGISTRATION): BOOL {.stdcall,
importc: "BluetoothUnregisterAuthentication", dynlib: libbluetooth.}
#
# Description:
# This function should be called after receiving an authentication request
# to send the passkey response.
#
# Parameters:
#
# hRadio
# Optional handle to the local radio. If NULL, the function will try
# each radio until one succeeds.
#
# pbtdi
# A pointer to a BLUETOOTH_DEVICE_INFO structure describing the device
# being authenticated. This can be the same structure passed to the
# callback function.
#
# pszPasskey
# A pointer to UNICODE zero-terminated string of the passkey response
# that should be sent back to the authenticating device.
#
# Return Values:
# ERROR_SUCESS
# The device accepted the passkey response. The device is authenticated.
#
# ERROR_CANCELED
# The device denied the passkey reponse. This also will returned if there
# is a communications problem with the local radio.
#
# E_FAIL
# The device returned a failure code during authentication.
#
# other Win32 error codes
#
proc BluetoothSendAuthenticationResponse*(hRadio: HANDLE;
pbtdi: ptr BLUETOOTH_DEVICE_INFO; pszPasskey: LPCWSTR): DWORD {.stdcall,
importc: "BluetoothSendAuthenticationResponse", dynlib: libbluetooth,
deprecated.}
#
# Support added in KB942567
#
#
# Replaces previous API
#
#
# Structure used when responding to BTH_REMOTE_AUTHENTICATE_REQUEST event
#
type
INNER_C_UNION_1965546500* = object {.union.}
pinInfo*: BLUETOOTH_PIN_INFO
oobInfo*: BLUETOOTH_OOB_DATA_INFO
numericCompInfo*: BLUETOOTH_NUMERIC_COMPARISON_INFO
passkeyInfo*: BLUETOOTH_PASSKEY_INFO
type
BLUETOOTH_AUTHENTICATE_RESPONSE* = object
bthAddressRemote*: BLUETOOTH_ADDRESS
authMethod*: BLUETOOTH_AUTHENTICATION_METHOD
ano_660658457*: INNER_C_UNION_1965546500
negativeResponse*: UCHAR
PBLUETOOTH_AUTHENTICATE_RESPONSE* = ptr BLUETOOTH_AUTHENTICATE_RESPONSE
#
# Description:
# This function should be called after receiving an authentication request
# to send the authentication response. (Bluetooth 2.1 and above)
#
# Parameters:
#
# hRadio
# Optional handle to the local radio. If NULL, the function will try
# each radio until one succeeds.
#
# pbtdi
# A pointer to a BLUETOOTH_DEVICE_INFO structure describing the device
# being authenticated. This can be the same structure passed to the
# callback function.
#
# pauthResponse
# A pointer to a BTH_AUTHENTICATION_RESPONSE structure.
#
# Return Values:
# ERROR_SUCESS
# The device accepted the passkey response. The device is authenticated.
#
# ERROR_CANCELED
# The device denied the passkey reponse. This also will returned if there
# is a communications problem with the local radio.
#
# E_FAIL
# The device returned a failure code during authentication.
#
# other Win32 error codes
#
proc BluetoothSendAuthenticationResponseEx*(hRadioIn: HANDLE;
pauthResponse: PBLUETOOTH_AUTHENTICATE_RESPONSE): DWORD {.stdcall,
importc: "BluetoothSendAuthenticationResponseEx", dynlib: libbluetooth.}
# ***************************************************************************
#
# SDP Parsing Functions
#
# ***************************************************************************
type
INNER_C_STRUCT_3139021411* = object
value*: LPBYTE # raw string buffer, may not be encoded as ANSI, use
# BluetoothSdpGetString to convert the value if it is described
# by the base language attribute ID list
# raw length of the string, may not be NULL terminuated
length*: ULONG
type
INNER_C_STRUCT_467337881* = object
value*: LPBYTE
length*: ULONG
type
INNER_C_STRUCT_4155600511* = object
value*: LPBYTE # raw sequence, starts at sequence element header
# raw sequence length
length*: ULONG
type
INNER_C_STRUCT_1234813489* = object
value*: LPBYTE # raw alternative, starts at alternative element header
# raw alternative length
length*: ULONG
type
INNER_C_UNION_122694421* = object {.union.}
int128*: SDP_LARGE_INTEGER_16 # type == SDP_TYPE_INT
# specificType == SDP_ST_INT128
int64*: LONGLONG # specificType == SDP_ST_INT64
int32*: LONG # specificType == SDP_ST_INT32
int16*: SHORT # specificType == SDP_ST_INT16
int8*: CHAR # specificType == SDP_ST_INT8
# type == SDP_TYPE_UINT
uint128*: SDP_ULARGE_INTEGER_16 # specificType == SDP_ST_UINT128
uint64*: ULONGLONG # specificType == SDP_ST_UINT64
uint32*: ULONG # specificType == SDP_ST_UINT32
uint16*: USHORT # specificType == SDP_ST_UINT16
uint8*: UCHAR # specificType == SDP_ST_UINT8
# type == SDP_TYPE_BOOLEAN
booleanVal*: UCHAR # type == SDP_TYPE_UUID
uuid128*: GUID # specificType == SDP_ST_UUID128
uuid32*: ULONG # specificType == SDP_ST_UUID32
uuid16*: USHORT # specificType == SDP_ST_UUID32
# type == SDP_TYPE_STRING
string*: INNER_C_STRUCT_3139021411 # type == SDP_TYPE_URL
url*: INNER_C_STRUCT_467337881 # type == SDP_TYPE_SEQUENCE
sequence*: INNER_C_STRUCT_4155600511 # type == SDP_TYPE_ALTERNATIVE
alternative*: INNER_C_STRUCT_1234813489
type
SDP_ELEMENT_DATA* = object
`type`*: SDP_TYPE #
# Enumeration of SDP element types. Generic element types will have a
# specificType value other then SDP_ST_NONE. The generic types are:
# o SDP_TYPE_UINT
# o SDP_TYPE_INT
# o SDP_TYPE_UUID
#
#
# Specific types for the generic SDP element types.
#
specificType*: SDP_SPECIFICTYPE #
# Union of all possible data types. type and specificType will indicate
# which field is valid. For types which do not have a valid specificType,
# specific type will be SDP_ST_NONE.
#
data*: INNER_C_UNION_122694421
PSDP_ELEMENT_DATA* = ptr SDP_ELEMENT_DATA
#
# Description:
# Retrieves and parses the element found at pSdpStream
#
# Parameters:
# IN pSdpStream
# pointer to valid SDP stream
#
# IN cbSdpStreamLength
# length of pSdpStream in bytes
#
# OUT pData
# pointer to be filled in with the data of the SDP element at the
# beginning of pSdpStream
#
# Return Values:
# ERROR_INVALID_PARAMETER
# one of required parameters is NULL or the pSdpStream is invalid
#
# ERROR_SUCCESS
# the sdp element was parsed correctly
#
proc BluetoothSdpGetElementData*(pSdpStream: LPBYTE;
cbSdpStreamLength: ULONG;
pData: PSDP_ELEMENT_DATA): DWORD {.stdcall,
importc: "BluetoothSdpGetElementData", dynlib: libbluetooth.}
type
HBLUETOOTH_CONTAINER_ELEMENT* = HANDLE
#
# Description:
# Iterates over a container stream, returning each elemetn contained with
# in the container element at the beginning of pContainerStream
#
# Parameters:
# IN pContainerStream
# pointer to valid SDP stream whose first element is either a sequence
# or alternative
#
# IN cbContainerlength
# length in bytes of pContainerStream
#
# IN OUT pElement
# Value used to keep track of location within the stream. The first
# time this function is called for a particular container, *pElement
# should equal NULL. Upon subsequent calls, the value should be
# unmodified.
#
# OUT pData
# pointer to be filled in with the data of the SDP element at the
# current element of pContainerStream
#
# Return Values:
# ERROR_SUCCESS
# The call succeeded, pData contains the data
#
# ERROR_NO_MORE_ITEMS
# There are no more items in the list, the caller should cease calling
# BluetoothSdpGetContainerElementData for this container.
#
# ERROR_INVALID_PARAMETER
# A required pointer is NULL or the container is not a valid SDP
# stream
#
# Usage example:
#
# HBLUETOOTH_CONTAINER_ELEMENT element;
# SDP_ELEMENT_DATA data;
# ULONG result;
#
# element = NULL;
#
# while (TRUE) {
# result = BluetoothSdpGetContainerElementData(
# pContainer, ulContainerLength, &element, &data);
#
# if (result == ERROR_NO_MORE_ITEMS) {
# // We are done
# break;
# }
# else if (result != ERROR_SUCCESS) {
# // error
# }
#
# // do something with data ...
# }
#
#
proc BluetoothSdpGetContainerElementData*(pContainerStream: LPBYTE;
cbContainerLength: ULONG; pElement: ptr HBLUETOOTH_CONTAINER_ELEMENT;
pData: PSDP_ELEMENT_DATA): DWORD {.stdcall,
importc: "BluetoothSdpGetContainerElementData", dynlib: libbluetooth.}
#
# Description:
# Retrieves the attribute value for the given attribute ID. pRecordStream
# must be an SDP stream that is formatted as an SDP record, a SEQUENCE
# containing UINT16 + element pairs.
#
# Parameters:
# IN pRecordStream
# pointer to a valid SDP stream which is formatted as a singl SDP
# record
#
# IN cbRecordlnegh
# length of pRecordStream in bytes
#
# IN usAttributeId
# the attribute ID to search for. see bthdef.h for SDP_ATTRIB_Xxx
# values.
#
# OUT pAttributeData
# pointer that will contain the attribute ID's value
#
# Return Values:
# ERRROR_SUCCESS
# Call succeeded, pAttributeData contains the attribute value
#
# ERROR_INVALID_PARAMETER
# One of the required pointers was NULL, pRecordStream was not a valid
# SDP stream, or pRecordStream was not a properly formatted SDP record
#
# ERROR_FILE_NOT_FOUND
# usAttributeId was not found in the record
#
# Usage:
#
# ULONG result;
# SDP_DATA_ELEMENT data;
#
# result = BluetoothSdpGetAttributeValue(
# pRecordStream, cbRecordLength, SDP_ATTRIB_RECORD_HANDLE, &data);
# if (result == ERROR_SUCCESS) {
# printf("record handle is 0x%x\n", data.data.uint32);
# }
#
proc BluetoothSdpGetAttributeValue*(pRecordStream: LPBYTE;
cbRecordLength: ULONG;
usAttributeId: USHORT;
pAttributeData: PSDP_ELEMENT_DATA): DWORD {.
stdcall, importc: "BluetoothSdpGetAttributeValue", dynlib: libbluetooth.}
#
# These three fields correspond one to one with the triplets defined in the
# SDP specification for the language base attribute ID list.
#
type
SDP_STRING_TYPE_DATA* = object
encoding*: USHORT #
# How the string is encoded according to ISO 639:1988 (E/F): "Code
# for the representation of names of languages".
#
#
# MIBE number from IANA database
#
mibeNum*: USHORT #
# The base attribute where the string is to be found in the record
#
attributeId*: USHORT
PSDP_STRING_TYPE_DATA* = ptr SDP_STRING_TYPE_DATA
#
# Description:
# Converts a raw string embedded in the SDP record into a UNICODE string
#
# Parameters:
# IN pRecordStream
# a valid SDP stream which is formatted as an SDP record
#
# IN cbRecordLength
# length of pRecordStream in bytes
#
# IN pStringData
# if NULL, then the calling thread's locale will be used to search
# for a matching string in the SDP record. If not NUL, the mibeNum
# and attributeId will be used to find the string to convert.
#
# IN usStringOffset
# the SDP string type offset to convert. usStringOffset is added to
# the base attribute id of the string. SDP specification defined
# offsets are: STRING_NAME_OFFSET, STRING_DESCRIPTION_OFFSET, and
# STRING_PROVIDER_NAME_OFFSET (found in bthdef.h).
#
# OUT pszString
# if NULL, pcchStringLength will be filled in with the required number
# of characters (not bytes) to retrieve the converted string.
#
# IN OUT pcchStringLength
# Upon input, if pszString is not NULL, will contain the length of
# pszString in characters. Upon output, it will contain either the
# number of required characters including NULL if an error is returned
# or the number of characters written to pszString (including NULL).
#
# Return Values:
# ERROR_SUCCES
# Call was successful and pszString contains the converted string
#
# ERROR_MORE_DATA
# pszString was NULL or too small to contain the converted string,
# pccxhStringLength contains the required length in characters
#
# ERROR_INVALID_DATA
# Could not perform the conversion
#
# ERROR_NO_SYSTEM_RESOURCES
# Could not allocate memory internally to perform the conversion
#
# ERROR_INVALID_PARAMETER
# One of the rquired pointers was NULL, pRecordStream was not a valid
# SDP stream, pRecordStream was not a properly formatted record, or
# the desired attribute + offset was not a string.
#
# Other HRESULTs returned by COM
#
proc BluetoothSdpGetString*(pRecordStream: LPBYTE; cbRecordLength: ULONG;
pStringData: PSDP_STRING_TYPE_DATA;
usStringOffset: USHORT; pszString: PWSTR;
pcchStringLength: PULONG): DWORD {.stdcall,
importc: "BluetoothSdpGetString", dynlib: libbluetooth.}
# ***************************************************************************
#
# Raw Attribute Enumeration
#
# ***************************************************************************
type
PFN_BLUETOOTH_ENUM_ATTRIBUTES_CALLBACK* = proc (uAttribId: ULONG;
pValueStream: LPBYTE; cbStreamSize: ULONG; pvParam: LPVOID): BOOL {.
stdcall.}
#
# Description:
# Enumerates through the SDP record stream calling the Callback function
# for each attribute in the record. If the Callback function returns
# FALSE, the enumeration is stopped.
#
# Return Values:
# TRUE
# Success! Something was enumerated.
#
# FALSE
# Failure. GetLastError() could be one of the following:
#
# ERROR_INVALID_PARAMETER
# pSDPStream or pfnCallback is NULL.
#
# ERROR_INVALID_DATA
# The SDP stream is corrupt.
#
# other Win32 errors.
#
proc BluetoothSdpEnumAttributes*(pSDPStream: LPBYTE; cbStreamSize: ULONG;
pfnCallback: PFN_BLUETOOTH_ENUM_ATTRIBUTES_CALLBACK; pvParam: LPVOID): BOOL {.
stdcall, importc: "BluetoothSdpEnumAttributes", dynlib: libbluetooth.}
const
BluetoothEnumAttributes* = BluetoothSdpEnumAttributes
#
# The following APIs are only available on Vista or later
#
proc BluetoothSetLocalServiceInfo*(hRadioIn: HANDLE; pClassGuid: ptr GUID;
ulInstance: ULONG; pServiceInfoIn: ptr BLUETOOTH_LOCAL_SERVICE_INFO): DWORD {.
stdcall, importc: "BluetoothSetLocalServiceInfo", dynlib: libbluetooth.}
#
# Support added in KB942567
#
#
# IsBluetoothVersionAvailable
#
# Description:
# Indicate if the installed Bluetooth binary set supports
# the requested version
#
# Return Values:
# TRUE if the installed bluetooth binaries support the given
# Major & Minor versions
#
# Note this function is only exported in version 2.1 and later.
#
proc BluetoothIsVersionAvailable*(MajorVersion: UCHAR; MinorVersion: UCHAR): BOOL {.
stdcall, importc: "BluetoothIsVersionAvailable", dynlib: libbluetooth.}
|