File: /usr/src/linux/include/net/bluetooth/hci.h
1 /*
2 BlueZ - Bluetooth protocol stack for Linux
3 Copyright (C) 2000-2001 Qualcomm Incorporated
4
5 Written 2000,2001 by Maxim Krasnyansky <maxk@qualcomm.com>
6
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License version 2 as
9 published by the Free Software Foundation;
10
11 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
12 OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
13 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS.
14 IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) AND AUTHOR(S) BE LIABLE FOR ANY
15 CLAIM, OR ANY SPECIAL INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES
16 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
17 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
18 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
19
20 ALL LIABILITY, INCLUDING LIABILITY FOR INFRINGEMENT OF ANY PATENTS,
21 COPYRIGHTS, TRADEMARKS OR OTHER RIGHTS, RELATING TO USE OF THIS
22 SOFTWARE IS DISCLAIMED.
23 */
24
25 /*
26 * $Id: hci.h,v 1.15 2001/08/05 06:02:15 maxk Exp $
27 */
28
29 #ifndef __HCI_H
30 #define __HCI_H
31
32 #include <asm/byteorder.h>
33
34 #define HCI_MAX_DEV 8
35 #define HCI_MAX_FRAME_SIZE 2048
36
37 /* HCI dev events */
38 #define HCI_DEV_REG 1
39 #define HCI_DEV_UNREG 2
40 #define HCI_DEV_UP 3
41 #define HCI_DEV_DOWN 4
42
43 /* HCI device types */
44 #define HCI_UART 0
45 #define HCI_USB 1
46 #define HCI_VHCI 2
47
48 /* HCI device modes */
49 #define HCI_NORMAL 0x0001
50 #define HCI_RAW 0x0002
51 #define HCI_MODE_MASK (HCI_NORMAL | HCI_RAW)
52 #define HCI_SOCK 0x1000
53
54 /* HCI device states */
55 #define HCI_INIT 0x0010
56 #define HCI_UP 0x0020
57 #define HCI_RUNNING 0x0040
58
59 /* HCI device flags */
60 #define HCI_PSCAN 0x0100
61 #define HCI_ISCAN 0x0200
62 #define HCI_AUTH 0x0400
63
64 /* HCI Ioctl defines */
65 #define HCIDEVUP _IOW('H', 201, int)
66 #define HCIDEVDOWN _IOW('H', 202, int)
67 #define HCIDEVRESET _IOW('H', 203, int)
68 #define HCIRESETSTAT _IOW('H', 204, int)
69 #define HCIGETINFO _IOR('H', 205, int)
70 #define HCIGETDEVLIST _IOR('H', 206, int)
71 #define HCISETRAW _IOW('H', 207, int)
72 #define HCISETSCAN _IOW('H', 208, int)
73 #define HCISETAUTH _IOW('H', 209, int)
74 #define HCIINQUIRY _IOR('H', 210, int)
75 #define HCISETPTYPE _IOW('H', 211, int)
76 #define HCIGETCONNLIST _IOR('H', 212, int)
77
78 #ifndef __NO_HCI_DEFS
79
80 /* HCI Packet types */
81 #define HCI_COMMAND_PKT 0x01
82 #define HCI_ACLDATA_PKT 0x02
83 #define HCI_SCODATA_PKT 0x03
84 #define HCI_EVENT_PKT 0x04
85 #define HCI_UNKNOWN_PKT 0xff
86
87 /* HCI Packet types */
88 #define HCI_DM1 0x0008
89 #define HCI_DM3 0x0400
90 #define HCI_DM5 0x4000
91 #define HCI_DH1 0x0010
92 #define HCI_DH3 0x0800
93 #define HCI_DH5 0x8000
94
95 /* ACL flags */
96 #define ACL_CONT 0x0001
97 #define ACL_START 0x0002
98 #define ACL_ACTIVE_BCAST 0x0010
99 #define ACL_PICO_BCAST 0x0020
100
101 /* Baseband links */
102 #define SCO_LINK 0x00
103 #define ACL_LINK 0x01
104
105 /* LMP features */
106 #define LMP_3SLOT 0x01
107 #define LMP_5SLOT 0x02
108 #define LMP_ENCRYPT 0x04
109 #define LMP_SOFFSET 0x08
110 #define LMP_TACCURACY 0x10
111 #define LMP_RSWITCH 0x20
112 #define LMP_HOLD 0x40
113 #define LMP_SNIF 0x80
114
115 #define LMP_PARK 0x01
116 #define LMP_RSSI 0x02
117 #define LMP_QUALITY 0x04
118 #define LMP_SCO 0x08
119 #define LMP_HV2 0x10
120 #define LMP_HV3 0x20
121 #define LMP_ULAW 0x40
122 #define LMP_ALAW 0x80
123
124 #define LMP_CVSD 0x01
125 #define LMP_PSCHEME 0x02
126 #define LMP_PCONTROL 0x04
127
128 /* ----- HCI Commands ----- */
129 /* OGF & OCF values */
130
131 /* Informational Parameters */
132 #define OGF_INFO_PARAM 0x04
133
134 #define OCF_READ_LOCAL_VERSION 0x0001
135 typedef struct {
136 __u8 status;
137 __u8 hci_ver;
138 __u16 hci_rev;
139 __u8 lmp_ver;
140 __u16 man_name;
141 __u16 lmp_sub;
142 } __attribute__ ((packed)) read_local_version_rp;
143
144 #define OCF_READ_LOCAL_FEATURES 0x0003
145 typedef struct {
146 __u8 status;
147 __u8 features[8];
148 } __attribute__ ((packed)) read_local_features_rp;
149
150 #define OCF_READ_BUFFER_SIZE 0x0005
151 typedef struct {
152 __u8 status;
153 __u16 acl_mtu;
154 __u8 sco_mtu;
155 __u16 acl_max_pkt;
156 __u16 sco_max_pkt;
157 } __attribute__ ((packed)) read_buffer_size_rp;
158
159 #define OCF_READ_BD_ADDR 0x0009
160 typedef struct {
161 __u8 status;
162 bdaddr_t bdaddr;
163 } __attribute__ ((packed)) read_bd_addr_rp;
164
165 /* Host Controller and Baseband */
166 #define OGF_HOST_CTL 0x03
167 #define OCF_RESET 0x0003
168 #define OCF_WRITE_AUTH_ENABLE 0x0020
169 #define AUTH_DISABLED 0x00
170 #define AUTH_ENABLED 0x01
171
172 #define OCF_WRITE_CA_TIMEOUT 0x0016
173 #define OCF_WRITE_PG_TIMEOUT 0x0018
174
175 #define OCF_WRITE_SCAN_ENABLE 0x001A
176 #define SCANS_DISABLED 0x00
177 #define IS_ENA_PS_DIS 0x01
178 #define IS_DIS_PS_ENA 0x02
179 #define IS_ENA_PS_ENA 0x03
180
181 #define OCF_SET_EVENT_FLT 0x0005
182 typedef struct {
183 __u8 flt_type;
184 __u8 cond_type;
185 __u8 condition[0];
186 } __attribute__ ((packed)) set_event_flt_cp;
187 #define SET_EVENT_FLT_CP_SIZE 2
188
189 /* Filter types */
190 #define FLT_CLEAR_ALL 0x00
191 #define FLT_INQ_RESULT 0x01
192 #define FLT_CONN_SETUP 0x02
193
194 /* CONN_SETUP Condition types */
195 #define CONN_SETUP_ALLOW_ALL 0x00
196 #define CONN_SETUP_ALLOW_CLASS 0x01
197 #define CONN_SETUP_ALLOW_BDADDR 0x02
198
199 /* CONN_SETUP Conditions */
200 #define CONN_SETUP_AUTO_OFF 0x01
201 #define CONN_SETUP_AUTO_ON 0x02
202
203 #define OCF_CHANGE_LOCAL_NAME 0x0013
204 typedef struct {
205 __u8 name[248];
206 } __attribute__ ((packed)) change_local_name_cp;
207 #define CHANGE_LOCAL_NAME_CP_SIZE 248
208
209 #define OCF_READ_LOCAL_NAME 0x0014
210 typedef struct {
211 __u8 status;
212 __u8 name[248];
213 } __attribute__ ((packed)) read_local_name_rp;
214 #define READ_LOCAL_NAME_RP_SIZE 249
215
216 #define OCF_READ_CLASS_OF_DEV 0x0023
217 typedef struct {
218 __u8 status;
219 __u8 dev_class[3];
220 } __attribute__ ((packed)) read_class_of_dev_rp;
221 #define READ_CLASS_OF_DEV_RP_SIZE 4
222
223 #define OCF_WRITE_CLASS_OF_DEV 0x0024
224 typedef struct {
225 __u8 dev_class[3];
226 } __attribute__ ((packed)) write_class_of_dev_cp;
227 #define WRITE_CLASS_OF_DEV_CP_SIZE 3
228
229 /* Link Control */
230 #define OGF_LINK_CTL 0x01
231 #define OCF_CREATE_CONN 0x0005
232 typedef struct {
233 bdaddr_t bdaddr;
234 __u16 pkt_type;
235 __u8 pscan_rep_mode;
236 __u8 pscan_mode;
237 __u16 clock_offset;
238 __u8 role_switch;
239 } __attribute__ ((packed)) create_conn_cp;
240 #define CREATE_CONN_CP_SIZE 13
241
242 #define OCF_ACCEPT_CONN_REQ 0x0009
243 typedef struct {
244 bdaddr_t bdaddr;
245 __u8 role;
246 } __attribute__ ((packed)) accept_conn_req_cp;
247 #define ACCEPT_CONN_REQ_CP_SIZE 7
248
249 #define OCF_DISCONNECT 0x0006
250 typedef struct {
251 __u16 handle;
252 __u8 reason;
253 } __attribute__ ((packed)) disconnect_cp;
254 #define DISCONNECT_CP_SIZE 3
255
256 #define OCF_INQUIRY 0x0001
257 typedef struct {
258 __u8 lap[3];
259 __u8 lenght;
260 __u8 num_rsp;
261 } __attribute__ ((packed)) inquiry_cp;
262 #define INQUIRY_CP_SIZE 5
263
264 #define OGF_LINK_POLICY 0x02 /* Link Policy */
265
266 /* --------- HCI Events --------- */
267 #define EVT_INQUIRY_COMPLETE 0x01
268
269 #define EVT_INQUIRY_RESULT 0x02
270 typedef struct {
271 bdaddr_t bdaddr;
272 __u8 pscan_rep_mode;
273 __u8 pscan_period_mode;
274 __u8 pscan_mode;
275 __u8 class[3];
276 __u16 clock_offset;
277 } __attribute__ ((packed)) inquiry_info;
278 #define INQUIRY_INFO_SIZE 14
279
280 #define EVT_CONN_COMPLETE 0x03
281 typedef struct {
282 __u8 status;
283 __u16 handle;
284 bdaddr_t bdaddr;
285 __u8 link_type;
286 __u8 encr_mode;
287 } __attribute__ ((packed)) evt_conn_complete;
288 #define EVT_CONN_COMPLETE_SIZE 13
289
290 #define EVT_CONN_REQUEST 0x04
291 typedef struct {
292 bdaddr_t bdaddr;
293 __u8 dev_class[3];
294 __u8 link_type;
295 } __attribute__ ((packed)) evt_conn_request;
296 #define EVT_CONN_REQUEST_SIZE 10
297
298 #define EVT_DISCONN_COMPLETE 0x05
299 typedef struct {
300 __u8 status;
301 __u16 handle;
302 __u8 reason;
303 } __attribute__ ((packed)) evt_disconn_complete;
304 #define EVT_DISCONN_COMPLETE_SIZE 4
305
306 #define EVT_CMD_COMPLETE 0x0e
307 typedef struct {
308 __u8 ncmd;
309 __u16 opcode;
310 } __attribute__ ((packed)) evt_cmd_complete;
311 #define EVT_CMD_COMPLETE_SIZE 3
312
313 #define EVT_CMD_STATUS 0x0f
314 typedef struct {
315 __u8 status;
316 __u8 ncmd;
317 __u16 opcode;
318 } __attribute__ ((packed)) evt_cmd_status;
319 #define EVT_CMD_STATUS_SIZE 4
320
321 #define EVT_NUM_COMP_PKTS 0x13
322 typedef struct {
323 __u8 num_hndl;
324 /* variable lenght part */
325 } __attribute__ ((packed)) evt_num_comp_pkts;
326 #define EVT_NUM_COMP_PKTS_SIZE 1
327
328 #define EVT_HCI_DEV_EVENT 0xfd
329 typedef struct {
330 __u16 event;
331 __u16 param;
332 } __attribute__ ((packed)) evt_hci_dev_event;
333 #define EVT_HCI_DEV_EVENT_SIZE 4
334
335 /* -------- HCI Packet structures -------- */
336 #define HCI_TYPE_LEN 1
337
338 typedef struct {
339 __u16 opcode; /* OCF & OGF */
340 __u8 plen;
341 } __attribute__ ((packed)) hci_command_hdr;
342 #define HCI_COMMAND_HDR_SIZE 3
343
344 typedef struct {
345 __u8 evt;
346 __u8 plen;
347 } __attribute__ ((packed)) hci_event_hdr;
348 #define HCI_EVENT_HDR_SIZE 2
349
350 typedef struct {
351 __u16 handle; /* Handle & Flags(PB, BC) */
352 __u16 dlen;
353 } __attribute__ ((packed)) hci_acl_hdr;
354 #define HCI_ACL_HDR_SIZE 4
355
356 typedef struct {
357 __u16 handle;
358 __u8 dlen;
359 } __attribute__ ((packed)) hci_sco_hdr;
360 #define HCI_SCO_HDR_SIZE 3
361
362 /* Command opcode pack/unpack */
363 #define cmd_opcode_pack(ogf, ocf) (__u16)((ocf & 0x03ff)|(ogf << 10))
364 #define cmd_opcode_ogf(op) (op >> 10)
365 #define cmd_opcode_ocf(op) (op & 0x03ff)
366
367 /* ACL handle and flags pack/unpack */
368 #define acl_handle_pack(h, f) (__u16)((h & 0x0fff)|(f << 12))
369 #define acl_handle(h) (h & 0x0fff)
370 #define acl_flags(h) (h >> 12)
371
372 #endif /* _NO_HCI_DEFS */
373
374 /* HCI Socket options */
375 #define HCI_DATA_DIR 0x0001
376 #define HCI_FILTER 0x0002
377
378 /* HCI CMSG flags */
379 #define HCI_CMSG_DIR 0x0001
380
381 struct sockaddr_hci {
382 sa_family_t hci_family;
383 unsigned short hci_dev;
384 };
385 #define HCI_DEV_NONE 0xffff
386
387 struct hci_filter {
388 __u32 type_mask;
389 __u32 event_mask[2];
390 };
391
392 struct hci_dev_req {
393 __u16 dev_id;
394 __u32 dev_opt;
395 };
396
397 struct hci_dev_list_req {
398 __u16 dev_num;
399 struct hci_dev_req dev_req[0]; /* hci_dev_req structures */
400 };
401
402 struct hci_inquiry_req {
403 __u16 dev_id;
404 __u16 flags;
405 __u8 lap[3];
406 __u8 length;
407 __u8 num_rsp;
408 };
409 #define IREQ_CACHE_FLUSH 0x0001
410
411 struct hci_dev_stats {
412 __u32 err_rx;
413 __u32 err_tx;
414 __u32 cmd_tx;
415 __u32 evt_rx;
416 __u32 acl_tx;
417 __u32 acl_rx;
418 __u32 sco_tx;
419 __u32 sco_rx;
420 __u32 byte_rx;
421 __u32 byte_tx;
422 };
423
424 struct hci_dev_info {
425 __u16 dev_id;
426 char name[8];
427
428 bdaddr_t bdaddr;
429
430 __u32 flags;
431 __u8 type;
432
433 __u8 features[8];
434
435 __u32 pkt_type;
436
437 __u16 acl_mtu;
438 __u16 acl_max;
439 __u16 sco_mtu;
440 __u16 sco_max;
441
442 struct hci_dev_stats stat;
443 };
444
445 struct hci_conn_info {
446 __u16 handle;
447 bdaddr_t bdaddr;
448 };
449
450 struct hci_conn_list_req {
451 __u16 dev_id;
452 __u16 conn_num;
453 struct hci_conn_info conn_info[0];
454 };
455
456 #endif /* __HCI_H */
457