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::{
7     BTH_ADDR, MAX_L2CAP_INFO_DATA_LENGTH, MAX_L2CAP_PING_DATA_LENGTH, MAX_UUIDS_IN_QUERY,
8 };
9 use shared::bthsdpdef::{SdpAttributeRange, SdpQueryUuid};
10 use shared::guiddef::GUID;
11 use shared::minwindef::{DWORD, PULONG, UCHAR, ULONG, USHORT};
12 use shared::ws2def::IOC_VENDOR;
13 use um::winnt::HANDLE;
14 pub const BT_PORT_ANY: ULONG = -1i32 as ULONG;
15 pub const BT_PORT_MIN: ULONG = 0x1;
16 pub const BT_PORT_MAX: ULONG = 0xffff;
17 pub const BT_PORT_DYN_FIRST: ULONG = 0x1001;
18 pub const AF_BTH: USHORT = 32;
19 pub const PH_BTH: USHORT = AF_BTH;
20 pub const NS_BTH: USHORT = 16;
21 STRUCT!{#[repr(packed)] struct SOCKADDR_BTH {
22     addressFamily: USHORT,
23     btAddr: BTH_ADDR,
24     serviceClassId: GUID,
25     port: ULONG,
26 }}
27 pub type PSOCKADDR_BTH = *mut SOCKADDR_BTH;
28 DEFINE_GUID!{SVCID_BTH_PROVIDER,
29     0x6aa63e0, 0x7d60, 0x41ff, 0xaf, 0xb2, 0x3e, 0xe6, 0xd2, 0xd9, 0x39, 0x2d}
30 pub const BTH_ADDR_STRING_SIZE: DWORD = 12;
31 pub const BTHPROTO_RFCOMM: USHORT = 0x0003;
32 pub const BTHPROTO_L2CAP: USHORT = 0x0100;
33 pub const SOL_RFCOMM: USHORT = BTHPROTO_RFCOMM;
34 pub const SOL_L2CAP: USHORT = BTHPROTO_L2CAP;
35 pub const SOL_SDP: USHORT = 0x0101;
36 pub const SO_BTH_AUTHENTICATE: ULONG = 0x80000001;
37 pub const SO_BTH_ENCRYPT: ULONG = 0x00000002;
38 pub const SO_BTH_MTU: ULONG = 0x80000007;
39 pub const SO_BTH_MTU_MAX: ULONG = 0x80000008;
40 pub const SO_BTH_MTU_MIN: ULONG = 0x8000000a;
41 pub const RFCOMM_MAX_MTU: ULONG = 0x000003F3;
42 pub const RFCOMM_MIN_MTU: ULONG = 0x00000017;
43 pub const BTH_SDP_VERSION: ULONG = 1;
44 STRUCT!{#[repr(packed)] struct BTH_SET_SERVICE {
45     pSdpVersion: PULONG,
46     pRecordHandle: HANDLE,
47     fCodService: ULONG,
48     Reserved: [ULONG; 5],
49     ulRecordLength: ULONG,
50     pRecord: [UCHAR; 1],
51 }}
52 pub type PBTH_SET_SERVICE = *mut BTH_SET_SERVICE;
53 pub const SDP_DEFAULT_INQUIRY_SECONDS: UCHAR = 6;
54 pub const SDP_MAX_INQUIRY_SECONDS: UCHAR = 60;
55 pub const SDP_DEFAULT_INQUIRY_MAX_RESPONSES: UCHAR = 255;
56 pub const SDP_SERVICE_SEARCH_REQUEST: ULONG = 1;
57 pub const SDP_SERVICE_ATTRIBUTE_REQUEST: ULONG = 2;
58 pub const SDP_SERVICE_SEARCH_ATTRIBUTE_REQUEST: ULONG = 3;
59 STRUCT!{#[repr(packed)] struct BTH_QUERY_DEVICE {
60     LAP: ULONG,
61     length: UCHAR,
62 }}
63 pub type PBTH_QUERY_DEVICE = *mut BTH_QUERY_DEVICE;
64 STRUCT!{#[repr(packed)] struct BTH_QUERY_SERVICE {
65     type_: ULONG,
66     serviceHandle: ULONG,
67     uuids: [SdpQueryUuid; MAX_UUIDS_IN_QUERY],
68     numRange: ULONG,
69     pRange: [SdpAttributeRange; 1],
70 }}
71 pub type PBTH_QUERY_SERVICE = *mut BTH_QUERY_SERVICE;
72 pub const BTHNS_RESULT_DEVICE_CONNECTED: DWORD = 0x00010000;
73 pub const BTHNS_RESULT_DEVICE_REMEMBERED: DWORD = 0x00020000;
74 pub const BTHNS_RESULT_DEVICE_AUTHENTICATED: DWORD = 0x00040000;
75 pub const SIO_RFCOMM_SEND_COMMAND: DWORD = _WSAIORW!(IOC_VENDOR, 101);
76 pub const SIO_RFCOMM_WAIT_COMMAND: DWORD = _WSAIORW!(IOC_VENDOR, 102);
77 pub const SIO_BTH_PING: DWORD = _WSAIORW!(IOC_VENDOR, 8);
78 pub const SIO_BTH_INFO: DWORD = _WSAIORW!(IOC_VENDOR, 9);
79 pub const SIO_RFCOMM_SESSION_FLOW_OFF: DWORD = _WSAIORW!(IOC_VENDOR, 103);
80 pub const SIO_RFCOMM_TEST: DWORD = _WSAIORW!(IOC_VENDOR, 104);
81 pub const SIO_RFCOMM_USECFC: DWORD = _WSAIORW!(IOC_VENDOR, 105);
82 macro_rules! BIT {
83     ($b:expr) => {
84         1 << $b
85     };
86 }
87 STRUCT!{#[repr(packed)] struct RFCOMM_MSC_DATA {
88     Signals: UCHAR,
89     Break: UCHAR,
90 }}
91 pub type PRFCOMM_MSC_DATA = *mut RFCOMM_MSC_DATA;
92 pub const MSC_EA_BIT: UCHAR = BIT!(0);
93 pub const MSC_FC_BIT: UCHAR = BIT!(1);
94 pub const MSC_RTC_BIT: UCHAR = BIT!(2);
95 pub const MSC_RTR_BIT: UCHAR = BIT!(3);
96 pub const MSC_RESERVED: UCHAR = BIT!(4) | BIT!(5);
97 pub const MSC_IC_BIT: UCHAR = BIT!(6);
98 pub const MSC_DV_BIT: UCHAR = BIT!(7);
99 pub const MSC_BREAK_BIT: UCHAR = BIT!(1);
100 macro_rules! MSC_SET_BREAK_LENGTH {
101     ($b: expr, $l: expr) => {
102         ($b & 0x3) | (($l & 0xf) << 4)
103     };
104 }
105 STRUCT!{#[repr(packed)] struct RFCOMM_RLS_DATA {
106     LineStatus: UCHAR,
107 }}
108 pub type PRFCOMM_RLS_DATA = *mut RFCOMM_RLS_DATA;
109 pub const RLS_ERROR: UCHAR = 0x01;
110 pub const RLS_OVERRUN: UCHAR = 0x02;
111 pub const RLS_PARITY: UCHAR = 0x04;
112 pub const RLS_FRAMING: UCHAR = 0x08;
113 STRUCT!{#[repr(packed)] struct RFCOMM_RPN_DATA {
114     Baud: UCHAR,
115     Data: UCHAR,
116     FlowControl: UCHAR,
117     XonChar: UCHAR,
118     XoffChar: UCHAR,
119     ParameterMask1: UCHAR,
120     ParameterMask2: UCHAR,
121 }}
122 pub type PRFCOMM_RPN_DATA = *mut RFCOMM_RPN_DATA;
123 pub const RPN_BAUD_2400: UCHAR = 0;
124 pub const RPN_BAUD_4800: UCHAR = 1;
125 pub const RPN_BAUD_7200: UCHAR = 2;
126 pub const RPN_BAUD_9600: UCHAR = 3;
127 pub const RPN_BAUD_19200: UCHAR = 4;
128 pub const RPN_BAUD_38400: UCHAR = 5;
129 pub const RPN_BAUD_57600: UCHAR = 6;
130 pub const RPN_BAUD_115200: UCHAR = 7;
131 pub const RPN_BAUD_230400: UCHAR = 8;
132 pub const RPN_DATA_5: UCHAR = 0x0;
133 pub const RPN_DATA_6: UCHAR = 0x1;
134 pub const RPN_DATA_7: UCHAR = 0x2;
135 pub const RPN_DATA_8: UCHAR = 0x3;
136 pub const RPN_STOP_1: UCHAR = 0x0;
137 pub const RPN_STOP_1_5: UCHAR = 0x4;
138 pub const RPN_PARITY_NONE: UCHAR = 0x00;
139 pub const RPN_PARITY_ODD: UCHAR = 0x08;
140 pub const RPN_PARITY_EVEN: UCHAR = 0x18;
141 pub const RPN_PARITY_MARK: UCHAR = 0x28;
142 pub const RPN_PARITY_SPACE: UCHAR = 0x38;
143 pub const RPN_FLOW_X_IN: UCHAR = 0x01;
144 pub const RPN_FLOW_X_OUT: UCHAR = 0x02;
145 pub const RPN_FLOW_RTR_IN: UCHAR = 0x04;
146 pub const RPN_FLOW_RTR_OUT: UCHAR = 0x08;
147 pub const RPN_FLOW_RTC_IN: UCHAR = 0x10;
148 pub const RPN_FLOW_RTC_OUT: UCHAR = 0x20;
149 pub const RPN_PARAM_BAUD: UCHAR = 0x01;
150 pub const RPN_PARAM_DATA: UCHAR = 0x02;
151 pub const RPN_PARAM_STOP: UCHAR = 0x04;
152 pub const RPN_PARAM_PARITY: UCHAR = 0x08;
153 pub const RPN_PARAM_P_TYPE: UCHAR = 0x10;
154 pub const RPN_PARAM_XON: UCHAR = 0x20;
155 pub const RPN_PARAM_XOFF: UCHAR = 0x40;
156 pub const RPN_PARAM_X_IN: UCHAR = 0x01;
157 pub const RPN_PARAM_X_OUT: UCHAR = 0x02;
158 pub const RPN_PARAM_RTR_IN: UCHAR = 0x04;
159 pub const RPN_PARAM_RTR_OUT: UCHAR = 0x08;
160 pub const RPN_PARAM_RTC_IN: UCHAR = 0x10;
161 pub const RPN_PARAM_RTC_OUT: UCHAR = 0x20;
162 pub const RFCOMM_CMD_NONE: UCHAR = 0;
163 pub const RFCOMM_CMD_MSC: UCHAR = 1;
164 pub const RFCOMM_CMD_RLS: UCHAR = 2;
165 pub const RFCOMM_CMD_RPN: UCHAR = 3;
166 pub const RFCOMM_CMD_RPN_REQUEST: UCHAR = 4;
167 pub const RFCOMM_CMD_RPN_RESPONSE: UCHAR = 5;
168 UNION!{#[repr(packed)] union RFCOMM_COMMAND_Data {
169     [u8; 7],
170     MSC MSC_mut: RFCOMM_MSC_DATA,
171     RLS RLS_mut: RFCOMM_RLS_DATA,
172     RPN RPN_mut: RFCOMM_RPN_DATA,
173 }}
174 STRUCT!{#[repr(packed)] struct RFCOMM_COMMAND {
175     CmdType: ULONG,
176     Data: RFCOMM_COMMAND_Data,
177 }}
178 pub type PRFCOMM_COMMAND = *mut RFCOMM_COMMAND;
179 STRUCT!{#[repr(packed)] struct BTH_PING_REQ {
180     btAddr: BTH_ADDR,
181     dataLen: UCHAR,
182     data: [UCHAR; MAX_L2CAP_PING_DATA_LENGTH],
183 }}
184 pub type PBTH_PING_REQ = *mut BTH_PING_REQ;
185 STRUCT!{#[repr(packed)] struct BTH_PING_RSP {
186     dataLen: UCHAR,
187     data: [UCHAR; MAX_L2CAP_PING_DATA_LENGTH],
188 }}
189 pub type PBTH_PING_RSP = *mut BTH_PING_RSP;
190 STRUCT!{#[repr(packed)] struct BTH_INFO_REQ {
191     btAddr: BTH_ADDR,
192     infoType: USHORT,
193 }}
194 pub type PBTH_INFO_REQ = *mut BTH_INFO_REQ;
195 UNION!{#[repr(packed)] union BTH_INFO_RSP_u {
196     [u8; MAX_L2CAP_INFO_DATA_LENGTH],
197     connectionlessMTU connectionlessMTU_mut: USHORT,
198     data data_mut: [UCHAR; MAX_L2CAP_INFO_DATA_LENGTH],
199 }}
200 STRUCT!{#[repr(packed)] struct BTH_INFO_RSP {
201     result: USHORT,
202     dataLen: UCHAR,
203     u: BTH_INFO_RSP_u,
204 }}
205 pub type PBTH_INFO_RSP = *mut BTH_INFO_RSP;
206 pub type BTHNS_SETBLOB = BTH_SET_SERVICE;
207 pub type PBTHNS_SETBLOB = PBTH_SET_SERVICE;
208 pub type BTHNS_INQUIRYBLOB = BTH_QUERY_DEVICE;
209 pub type PBTHNS_INQUIRYBLOB = PBTH_QUERY_DEVICE;
210 pub type BTHNS_RESTRICTIONBLOB = BTH_QUERY_SERVICE;
211 pub type PBTHNS_RESTRICTIONBLOB = PBTH_QUERY_SERVICE;
212