+++ /dev/null
-//
-// C++ Interface: hcidriver
-//
-// Description:
-//
-//
-// Author: root <root@ubuntu>, (C) 2008
-//
-// Copyright: See COPYING file that comes with this distribution
-//
-//
-#ifndef __HCIDRIVER
-#define __HCIDRIVER
-
-#include<asm/types.h>
-#include<sys/socket.h>
-#include<string.h>
-#include<stdint.h>
-
-/* HCI ioctl defines */
-#define HCIDEVUP _IOW('H', 201, int)
-#define HCIDEVDOWN _IOW('H', 202, int)
-#define HCIDEVRESET _IOW('H', 203, int)
-#define HCIDEVRESTAT _IOW('H', 204, int)
-
-#define HCIGETDEVLIST _IOR('H', 210, int)
-#define HCIGETDEVINFO _IOR('H', 211, int)
-#define HCIGETCONNLIST _IOR('H', 212, int)
-#define HCIGETCONNINFO _IOR('H', 213, int)
-
-#define HCISETRAW _IOW('H', 220, int)
-#define HCISETSCAN _IOW('H', 221, int)
-#define HCISETAUTH _IOW('H', 222, int)
-#define HCISETENCRYPT _IOW('H', 223, int)
-#define HCISETPTYPE _IOW('H', 224, int)
-#define HCISETLINKPOL _IOW('H', 225, int)
-#define HCISETLINKMODE _IOW('H', 226, int)
-#define HCISETACLMTU _IOW('H', 227, int)
-#define HCISETSCOMTU _IOW('H', 228, int)
-
-#define HCISETSECMGR _IOW('H', 230, int)
-
-#define HCIINQUIRY _IOR('H', 240, int)
-
-/* HCI socket options*/
-#define HCI_FILTER 2
-#define SOL_HCI 0
-
-#define HCI_FLT_TYPE_BITS 31
-#define HCI_FLT_EVENT_BITS 63
-#define HCI_FLT_OGF_BITS 63
-#define HCI_FLT_OCF_BITS 127
-
-/* HCI data types */
-#define HCI_COMMAND_PKT 0x01
-#define HCI_ACLDATA_PKT 0x02
-#define HCI_EVENT_PKT 0x04
-#define HCI_VENDOR_PKT 0xFF
-
-/* HCI packet types */
-#define HCI_DM1 0x0008
-#define HCI_DM3 0x0400
-#define HCI_DM5 0x4000
-#define HCI_DH1 0x0010
-#define HCI_DH3 0x0800
-#define HCI_DH5 0x8000
-
-#define HCI_HV1 0x0020
-#define HCI_HV2 0x0040
-#define HCI_HV3 0x0080
-
-/* ACL flags */
-#define ACL_CONT 0x01
-#define ACL_START 0x02
-#define ACL_ACTIVE_BCAST 0x04
-#define ACL_PICO_BCAST 0x08
-
-/* Connection states */
-#define DISCONNECTED 0
-#define CONNECTED 1
-#define PENDING 2
-
-/* BT protocols*/
-#define BTPROTO_L2CAP 0
-#define BTPROTO_HCI 1
-#define BTPROTO_SCO 2
-#define BTPROTO_RFCOMM 3
-#define BTPROTO_BNEP 4
-#define BTPROTO_CMTP 5
-#define BTPROTO_HIDP 6
-#define BTPROTO_AVDTP 7
-
-#define SOL_HCI 0
-#define SOL_L2CAP 6
-#define SOL_SCO 17
-#define SOL_RFCOMM 18
-
-#define HCI_MAX_DEV 4
-#define HCI_MAX_EVENT_SIZE 260
-
-#define max(a, b) ((a) > (b) ? (a) : (b))
-#define min(a, b) ((a) < (b) ? (a) : (b))
-
-
-/* BD_ADDR */
-typedef struct{
- __u8 byte[6];
-} __attribute__((packed)) bt_address;
-
-typedef struct{
- __u8 byte[3];
-} __attribute__((packed)) dev_lap;
-
-
-
-/* Class of device*/
-
-typedef struct{
- __u8 byte[3];
-}cl_device;
-
-struct hci_dev_stats {
- __u32 err_rx;
- __u32 err_tx;
- __u32 cmd_tx;
- __u32 evt_rx;
- __u32 acl_tx;
- __u32 acl_rx;
- __u32 sco_tx;
- __u32 sco_rx;
- __u32 byte_rx;
- __u32 byte_tx;
-};
-
-typedef struct{
- __u16 dev_id;
- char name[8];
-
- bt_address bdaddr;
-
- __u32 flags;
- __u8 type;
-
- __u8 features[8];
-
- __u32 pkt_type;
- __u32 link_policy;
- __u32 link_mode;
-
- __u16 acl_mtu;
- __u16 acl_pkts;
- __u16 sco_mtu;
- __u16 sco_pkts;
-
- struct hci_dev_stats stat;
-}bt_device;
-
-
-typedef struct{
- __u16 dev_id;
- __u32 dev_opt;
-}bt_device_req;
-
-typedef struct{
- __u16 dev_num;
- bt_device_req dev_req[HCI_MAX_DEV];
-}bt_device_req_list;
-
-typedef struct{
- __u16 *p_OCF_OGF;
- void *p_cmdp;
- void *p_retcmdp;
- __u16 cmdp_len;
- __u16 retcmdp_len;
- int event; //for setting event filter , some hci commands have own events
-}hci_request;
-
-struct hci_filter{
- __u32 type_mask;
- __u32 event_mask[2];
- __u16 opcode;
-};
-
-/* Socket address*/
-typedef struct{
- sa_family_t hci_family;
- __u8 dev_id;
-}sockaddr_hci;
-
-typedef struct{
- __u16 con_id;
- __u8 con_state;
- int socket_fd;
-}connection_hci;
-
-
-/*HCI packet headers*/
-
-typedef struct {
- uint16_t opcode; /* OCF & OGF */
- uint8_t plen;
-} __attribute__ ((packed)) hci_command_hdr;
-#define HCI_COMMAND_HDR_SIZE 3
-
-typedef struct {
- uint8_t evt;
- uint8_t plen;
-} __attribute__ ((packed)) hci_event_hdr;
-#define HCI_EVENT_HDR_SIZE 2
-
-typedef struct {
- uint16_t handle; /* Handle & Flags(PB, BC) */
- uint16_t dlen;
-} __attribute__ ((packed)) hci_acl_hdr;
-#define HCI_ACL_HDR_SIZE 4
-
-
-
-/*HCI Commands */
-/*Link control commands*/
-#define OCF_INQUIRY_CMD 0x0001
-struct hci_inquiry_cmd {
- __u8 lap[3];
- __u8 inquiry_length;
- __u8 num_responces;
-} __attribute__ ((packed));
-
-#define OCF_INQUIRY_CANCEL_CMD 0x0002
-
-#define OCF_CREATE_CONNECTION_CMD 0x0005
-struct hci_create_connection_cmd{
- bt_address address;
- __u16 packet_type;
- __u8 rep_mode;
- __u8 reserved;
- __u16 clock_offset;
- __u8 role_switch;
-} __attribute__ ((packed));
-
-#define OCF_DISCONNECT_CMD 0x0006
-struct hci_disconnect_cmd{
- __u8 reason;
-} __attribute__ ((packed));
-
-#define OCF_CREATE_CONNECTION_CANCEL_CMD 0x0008
-struct hci_create_connection_cancel_cmd{
- bt_address address;
-} __attribute__ ((packed));
-
-#define OCF_ACCEPT_CONNECTION_REQ_CMD 0x0009
-struct hci_accept_connection_req_cmd{
- bt_address address;
- __u8 role;
-} __attribute__ ((packed));
-
-#define OCF_REJECT_CONNECTION_REQ_CMD 0x000A
-struct hci_reject_connection_req_cmd{
- bt_address address;
- __u8 reason;
-} __attribute__ ((packed));
-
-#define OCF_REMOTE_NAME_REQ_CMD 0x0019
-typedef struct {
- bt_address address;
- __u8 rep_mode;
- __u8 reserved;
- __u16 clock_offset;
-} __attribute__ ((packed)) hci_remote_name_req_cmd;
-
-/*Link policy commands*/
-#define OCF_RESET_CMD 0x0003
-
-
-/*Informational parameters commands */
-#define OGF_INFO_CMD 0x04
-
-#define OCF_READ_BD_ADDR_CMD 0x0009
-#define READ_BD_ADDR_CMD_PARL 7
-typedef struct{
-
- //return parameters
- __u8 status;
- bt_address address;
-} __attribute__ ((packed)) read_bd_addr_cmd;
-
-/*Controllers and baseband commands */
-#define OGF_CON_AND_BSB_CMD 0x03
-
-#define OCF_READ_LOCAL_NAME_CMD 0x0014
-
-
-
-/* HCI events */
-
-#define INQUIRY_COMPLETE_EV 0x01
-struct hci_inquiry_complete_ev{
- __u8 status;
-} __attribute__ ((packed));
-
-#define INQUIRY_RESULT_EV 0x02
-struct hci_inquiry_result_ev{
- __u8 num_responces;
- bt_address ba_array;
- __u8 rep_mode_array;
- __u8 per_mode_array;
- __u8 reserved_array;
- cl_device cod_array;
- __u16 clock_offset_array;
-} __attribute__ ((packed));
-
-#define CONNECTION_COMPLETE_EV 0x03
-struct hci_connection_complete_ev{
- __u8 status; // error code 00 status ok
- __u16 con_handle;
- bt_address adress;
- __u8 link_type;
- __u8 encrypt_mode;
-} __attribute__ ((packed));
-
-#define CONNECTION_REQUEST_EV 0x04
-struct hci_connection_request_ev{
- bt_address adress;
- cl_device cod; //clas of device
- __u8 link_type;
-} __attribute__ ((packed));
-
-#define DISCONNECTION_COMPLETE_EV 0x05
-struct hci_disconnection_complete_ev{
- __u8 status; // error code 00 status ok
- __u16 con_handle;
- __u8 reason;
-} __attribute__ ((packed));
-
-#define REMOTE_NAME_REQUEST_EV 0x07
-typedef struct {
- __u8 status;
- bt_address address;
- __u8 remote_name[247]; // array for 248 Octets
-} __attribute__ ((packed)) hci_remote_name_request_complete_ev;
-
-#define CMD_COMPLETE_EV 0x0E
-#define CMD_COMPLETE_EV_SIZE 3
-// !!!!!!
-typedef struct {
- __u8 cmd_packets_number;
- __u16 cmd_opcode;
- __u8 return_param[31];
-} __attribute__ ((packed)) hci_cmd_complete_ev;
-
-#define CMD_STATUS_EV 0x0F
-typedef struct {
- __u8 status;
- __u8 cmd_packets_number;
- __u16 cmd_opcode;
-} __attribute__ ((packed)) hci_cmd_status_ev;
-
-#define HARDWARE_ERROR_EV 0x10
-struct hci_hardware_error_ev{
- __u8 hw_code;
-} __attribute__ ((packed));
-
-extern void call_hci_inquiry_cmd(dev_lap lap, __u8 inq_length, __u8 resp_count);
-extern int call_hci_read_bd_addr_cmd(int dd, bt_address *p_bdaddr, int timeout);
-extern int hci_open_device(int dev_id);
-extern int hci_send_command(int dd, hci_request *p_req);
-extern int hci_send_request(int dd, hci_request *p_req,int timeout);
-extern void print_device_list(int ctl);
-extern int hci_close_dev(int dd);
-
-
-extern void assemble_hci_data(void *p_con_handle,void *p_data_size,void *p_data);
-extern void assemble_ocf_ogf(__u8 ogf,__u8 ocf,__u16 *p_ocf_ogf);
-extern __u8 swap8(__u8 byte1);
-extern __u16 swap16(__u16 byte2);
-//extern void bacpy(bt_address p_dest, bt_address p_source);
-extern void fill_add(bt_address *addr,__u8 first, __u8 sec, __u8 third, __u8 forth, __u8 fifth, __u8 sixth);
-extern void printba(bt_address *ba);
-
-static inline void hci_set_bit(int nr, void *addr)
-{
- *((uint32_t *) addr + (nr >> 5)) |= (1 << (nr & 31));
-}
-
-static inline void hci_clear_bit(int nr, void *addr)
-{
- *((uint32_t *) addr + (nr >> 5)) &= ~(1 << (nr & 31));
-}
-
-static inline int hci_test_bit(int nr, void *addr)
-{
- return *((uint32_t *) addr + (nr >> 5)) & (1 << (nr & 31));
-}
-
-/* HCI filter tools */
-static inline void hci_filter_clear(struct hci_filter *f)
-{
- memset(f, 0, sizeof(*f));
-}
-static inline void hci_filter_set_ptype(int t, struct hci_filter *f)
-{
- hci_set_bit((t == HCI_VENDOR_PKT) ? 0 : (t & HCI_FLT_TYPE_BITS), &f->type_mask);
-}
-static inline void hci_filter_clear_ptype(int t, struct hci_filter *f)
-{
- hci_clear_bit((t == HCI_VENDOR_PKT) ? 0 : (t & HCI_FLT_TYPE_BITS), &f->type_mask);
-}
-static inline int hci_filter_test_ptype(int t, struct hci_filter *f)
-{
- return hci_test_bit((t == HCI_VENDOR_PKT) ? 0 : (t & HCI_FLT_TYPE_BITS), &f->type_mask);
-}
-static inline void hci_filter_all_ptypes(struct hci_filter *f)
-{
- memset((void *) &f->type_mask, 0xff, sizeof(f->type_mask));
-}
-static inline void hci_filter_set_event(int e, struct hci_filter *f)
-{
- hci_set_bit((e & HCI_FLT_EVENT_BITS), &f->event_mask);
-}
-static inline void hci_filter_clear_event(int e, struct hci_filter *f)
-{
- hci_clear_bit((e & HCI_FLT_EVENT_BITS), &f->event_mask);
-}
-static inline int hci_filter_test_event(int e, struct hci_filter *f)
-{
- return hci_test_bit((e & HCI_FLT_EVENT_BITS), &f->event_mask);
-}
-static inline void hci_filter_all_events(struct hci_filter *f)
-{
- memset((void *) f->event_mask, 0xff, sizeof(f->event_mask));
-}
-static inline void hci_filter_set_opcode(int opcode, struct hci_filter *f)
-{
- f->opcode = opcode;
-}
-static inline void hci_filter_clear_opcode(struct hci_filter *f)
-{
- f->opcode = 0;
-}
-static inline int hci_filter_test_opcode(int opcode, struct hci_filter *f)
-{
- return (f->opcode == opcode);
-}
-
-static inline int bacmp(const bt_address *ba1, const bt_address *ba2)
-{
- return memcmp(ba1, ba2, sizeof(bt_address));
-}
-static inline void bacpy(bt_address *dst, const bt_address *src)
-{
- memcpy(dst, src, sizeof(bt_address));
-}
-
-
-#endif /* __HCIDRIVER */