2 // C++ Interface: hcidriver
7 // Author: root <root@ubuntu>, (C) 2008
9 // Copyright: See COPYING file that comes with this distribution
16 #include<sys/socket.h>
20 /* HCI ioctl defines */
21 #define HCIDEVUP _IOW('H', 201, int)
22 #define HCIDEVDOWN _IOW('H', 202, int)
23 #define HCIDEVRESET _IOW('H', 203, int)
24 #define HCIDEVRESTAT _IOW('H', 204, int)
26 #define HCIGETDEVLIST _IOR('H', 210, int)
27 #define HCIGETDEVINFO _IOR('H', 211, int)
28 #define HCIGETCONNLIST _IOR('H', 212, int)
29 #define HCIGETCONNINFO _IOR('H', 213, int)
31 #define HCISETRAW _IOW('H', 220, int)
32 #define HCISETSCAN _IOW('H', 221, int)
33 #define HCISETAUTH _IOW('H', 222, int)
34 #define HCISETENCRYPT _IOW('H', 223, int)
35 #define HCISETPTYPE _IOW('H', 224, int)
36 #define HCISETLINKPOL _IOW('H', 225, int)
37 #define HCISETLINKMODE _IOW('H', 226, int)
38 #define HCISETACLMTU _IOW('H', 227, int)
39 #define HCISETSCOMTU _IOW('H', 228, int)
41 #define HCISETSECMGR _IOW('H', 230, int)
43 #define HCIINQUIRY _IOR('H', 240, int)
45 /* HCI socket options*/
49 #define HCI_FLT_TYPE_BITS 31
50 #define HCI_FLT_EVENT_BITS 63
51 #define HCI_FLT_OGF_BITS 63
52 #define HCI_FLT_OCF_BITS 127
55 #define HCI_COMMAND_PKT 0x01
56 #define HCI_ACLDATA_PKT 0x02
57 #define HCI_EVENT_PKT 0x04
58 #define HCI_VENDOR_PKT 0xFF
60 /* HCI packet types */
61 #define HCI_DM1 0x0008
62 #define HCI_DM3 0x0400
63 #define HCI_DM5 0x4000
64 #define HCI_DH1 0x0010
65 #define HCI_DH3 0x0800
66 #define HCI_DH5 0x8000
68 #define HCI_HV1 0x0020
69 #define HCI_HV2 0x0040
70 #define HCI_HV3 0x0080
74 #define ACL_START 0x02
75 #define ACL_ACTIVE_BCAST 0x04
76 #define ACL_PICO_BCAST 0x08
78 /* Connection states */
79 #define DISCONNECTED 0
84 #define BTPROTO_L2CAP 0
87 #define BTPROTO_RFCOMM 3
88 #define BTPROTO_BNEP 4
89 #define BTPROTO_CMTP 5
90 #define BTPROTO_HIDP 6
91 #define BTPROTO_AVDTP 7
99 #define HCI_MAX_EVENT_SIZE 260
101 #define max(a, b) ((a) > (b) ? (a) : (b))
102 #define min(a, b) ((a) < (b) ? (a) : (b))
108 } __attribute__((packed)) bt_address;
112 } __attribute__((packed)) dev_lap;
122 struct hci_dev_stats {
155 struct hci_dev_stats stat;
166 bt_device_req dev_req[HCI_MAX_DEV];
175 int event; //for setting event filter , some hci commands have own events
186 sa_family_t hci_family;
197 /*HCI packet headers*/
200 uint16_t opcode; /* OCF & OGF */
202 } __attribute__ ((packed)) hci_command_hdr;
203 #define HCI_COMMAND_HDR_SIZE 3
208 } __attribute__ ((packed)) hci_event_hdr;
209 #define HCI_EVENT_HDR_SIZE 2
212 uint16_t handle; /* Handle & Flags(PB, BC) */
214 } __attribute__ ((packed)) hci_acl_hdr;
215 #define HCI_ACL_HDR_SIZE 4
220 /*Link control commands*/
221 #define OCF_INQUIRY_CMD 0x0001
222 #define HCI_INQUIRY_CMD_PARL 0x05
227 } __attribute__ ((packed)) hci_inquiry_cmd;
229 #define OCF_INQUIRY_CANCEL_CMD 0x0002
231 #define OCF_CREATE_CONNECTION_CMD 0x0005
232 #define HCI_CREATE_CONNECTION_CMD_PARL 0x0D
240 } __attribute__ ((packed)) hci_create_connection_cmd;
242 #define OCF_DISCONNECT_CMD 0x0006
243 struct hci_disconnect_cmd{
245 } __attribute__ ((packed));
247 #define OCF_CREATE_CONNECTION_CANCEL_CMD 0x0008
248 struct hci_create_connection_cancel_cmd{
250 } __attribute__ ((packed));
252 #define OCF_ACCEPT_CONNECTION_REQ_CMD 0x0009
253 struct hci_accept_connection_req_cmd{
256 } __attribute__ ((packed));
258 #define OCF_REJECT_CONNECTION_REQ_CMD 0x000A
259 struct hci_reject_connection_req_cmd{
262 } __attribute__ ((packed));
264 #define OCF_REMOTE_NAME_REQ_CMD 0x0019
270 } __attribute__ ((packed)) hci_remote_name_req_cmd;
272 /*Link policy commands*/
273 #define OCF_RESET_CMD 0x0003
276 /*Informational parameters commands */
277 #define OGF_INFO_CMD 0x04
279 #define OCF_READ_BD_ADDR_CMD 0x0009
280 #define READ_BD_ADDR_CMD_PARL 7
286 } __attribute__ ((packed)) read_bd_addr_cmd;
288 /*Controllers and baseband commands */
289 #define OGF_CON_AND_BSB_CMD 0x03
291 #define OCF_READ_LOCAL_NAME_CMD 0x0014
297 #define INQUIRY_COMPLETE_EV 0x01
301 } __attribute__ ((packed)) hci_inquiry_complete_ev;
303 #define INQUIRY_RESULT_EV 0x02
304 #define INQUIRY_RESULT_EV_PARL 0x0F
305 //lenght for one responsing device
313 __u16 clock_offset_array;
314 } __attribute__ ((packed)) hci_inquiry_result_ev;
316 #define INQUIRY_RESULT_RSSI_EV 0x22
317 #define INQUIRY_RESULT_RSSI_EV_PARL 0x0F
318 //lenght for one responsing device
324 cl_device dev_class_array;
325 __u16 clock_offset_array;
327 } __attribute__ ((packed)) hci_inquiry_result_RSSI_ev;
329 #define CONNECTION_COMPLETE_EV 0x03
330 #define CONNECTION_COMPLETE_EV_PARL 0x0B
331 struct hci_connection_complete_ev{
332 __u8 status; // error code 00 status ok
337 } __attribute__ ((packed));
339 #define CONNECTION_REQUEST_EV 0x04
340 struct hci_connection_request_ev{
342 cl_device cod; //clas of device
344 } __attribute__ ((packed));
346 #define DISCONNECTION_COMPLETE_EV 0x05
347 struct hci_disconnection_complete_ev{
348 __u8 status; // error code 00 status ok
351 } __attribute__ ((packed));
353 #define REMOTE_NAME_REQUEST_EV 0x07
357 __u8 remote_name[247]; // array for 248 Octets
358 } __attribute__ ((packed)) hci_remote_name_request_complete_ev;
360 #define CMD_COMPLETE_EV 0x0E
361 #define CMD_COMPLETE_EV_SIZE 3
364 __u8 cmd_packets_number;
366 __u8 return_param[31];
367 } __attribute__ ((packed)) hci_cmd_complete_ev;
369 #define CMD_STATUS_EV 0x0F
372 __u8 cmd_packets_number;
374 } __attribute__ ((packed)) hci_cmd_status_ev;
376 #define HARDWARE_ERROR_EV 0x10
377 struct hci_hardware_error_ev{
379 } __attribute__ ((packed));
381 extern int call_hci_inquiry_cmd(int dd, bt_address *p_addressarray,int timeout);
382 extern int call_hci_read_bd_addr_cmd(int dd,bt_address *p_address, int timeout);
383 extern int call_hci_create_connection_cmd(int dd, bt_address *p_address, int timeout);
384 extern int hci_open_device(int dev_id);
385 extern int hci_send_command(int dd, hci_request *p_req);
386 extern int hci_send_request(int dd, hci_request *p_req,int timeout);
387 extern void print_device_list(int ctl);
388 extern int hci_close_dev(int dd);
391 extern void assemble_hci_data(void *p_con_handle,void *p_data_size,void *p_data);
392 extern void assemble_ocf_ogf(__u8 ogf,__u8 ocf,__u16 *p_ocf_ogf);
393 extern __u8 swap8(__u8 byte1);
394 extern __u16 swap16(__u16 byte2);
395 //extern void bacpy(bt_address p_dest, bt_address p_source);
396 extern void fill_add(bt_address *addr,__u8 first, __u8 sec, __u8 third, __u8 forth, __u8 fifth, __u8 sixth);
397 extern void printba(bt_address *ba);
398 extern int compare_bda(bt_address *p_first, bt_address *p_second);
399 extern void fill_zero(bt_address *p_addr);
400 extern void swap_addrbytes(bt_address *p_addr);
403 static inline void hci_set_bit(int nr, void *addr)
405 *((uint32_t *) addr + (nr >> 5)) |= (1 << (nr & 31));
408 static inline void hci_clear_bit(int nr, void *addr)
410 *((uint32_t *) addr + (nr >> 5)) &= ~(1 << (nr & 31));
413 static inline int hci_test_bit(int nr, void *addr)
415 return *((uint32_t *) addr + (nr >> 5)) & (1 << (nr & 31));
418 /* HCI filter tools */
419 static inline void hci_filter_clear(struct hci_filter *f)
421 memset(f, 0, sizeof(*f));
423 static inline void hci_filter_set_ptype(int t, struct hci_filter *f)
425 hci_set_bit((t == HCI_VENDOR_PKT) ? 0 : (t & HCI_FLT_TYPE_BITS), &f->type_mask);
427 static inline void hci_filter_clear_ptype(int t, struct hci_filter *f)
429 hci_clear_bit((t == HCI_VENDOR_PKT) ? 0 : (t & HCI_FLT_TYPE_BITS), &f->type_mask);
431 static inline int hci_filter_test_ptype(int t, struct hci_filter *f)
433 return hci_test_bit((t == HCI_VENDOR_PKT) ? 0 : (t & HCI_FLT_TYPE_BITS), &f->type_mask);
435 static inline void hci_filter_all_ptypes(struct hci_filter *f)
437 memset((void *) &f->type_mask, 0xff, sizeof(f->type_mask));
439 static inline void hci_filter_set_event(int e, struct hci_filter *f)
441 hci_set_bit((e & HCI_FLT_EVENT_BITS), &f->event_mask);
443 static inline void hci_filter_clear_event(int e, struct hci_filter *f)
445 hci_clear_bit((e & HCI_FLT_EVENT_BITS), &f->event_mask);
447 static inline int hci_filter_test_event(int e, struct hci_filter *f)
449 return hci_test_bit((e & HCI_FLT_EVENT_BITS), &f->event_mask);
451 static inline void hci_filter_all_events(struct hci_filter *f)
453 memset((void *) f->event_mask, 0xff, sizeof(f->event_mask));
455 static inline void hci_filter_set_opcode(int opcode, struct hci_filter *f)
459 static inline void hci_filter_clear_opcode(struct hci_filter *f)
463 static inline int hci_filter_test_opcode(int opcode, struct hci_filter *f)
465 return (f->opcode == opcode);
468 static inline int bacmp(const bt_address *ba1, const bt_address *ba2)
470 return memcmp(ba1, ba2, sizeof(bt_address));
472 static inline void bacpy(bt_address *dst, const bt_address *src)
474 memcpy(dst, src, sizeof(bt_address));
478 #endif /* __HCIDRIVER */