2 // C++ Interface: hcidriver
4 // Description: my idea , embeded system will be in waiting state. For this role it will be slave. Master it is a main computer or phone.
7 // Author: root <root@ubuntu>, (C) 2008
9 // Copyright: See COPYING file that comes with this distribution
16 #include<sys/socket.h>
18 #include "hciembeded.h"
24 /* BT protocols(from bluetooth.h)*/
25 #define BTPROTO_L2CAP 0
28 #define BTPROTO_RFCOMM 3
29 #define BTPROTO_BNEP 4
30 #define BTPROTO_CMTP 5
31 #define BTPROTO_HIDP 6
32 #define BTPROTO_AVDTP 7
39 #define max(a, b) ((a) > (b) ? (a) : (b))
40 #define min(a, b) ((a) < (b) ? (a) : (b))
43 /* BD_ADDR (bluetooth.h)*/
48 } __attribute__((packed)) dev_lap;
65 int event; //for setting event filter , some hci commands have own events
70 /* next function structures*/
73 extern int call_hci_inquiry_cmd(int dd, bt_address *p_addressarray,int timeout);
74 extern int call_hci_read_bd_addr_cmd(int dd,bt_address *p_address, int timeout);
75 extern int call_hci_create_connection_cmd(int dd, bt_address *p_address, int timeout);
76 extern int hci_open_device(int dev_id);
77 extern int hci_send_command(int dd, hci_request *p_req);
78 extern int hci_send_request(int dd, hci_request *p_req,int timeout);
79 extern void print_device_list(int ctl);
80 extern int hci_close_dev(int dd);
83 extern void assemble_hci_data(void *p_con_handle,void *p_data_size,void *p_data);
84 extern void assemble_ocf_ogf(__u8 ogf,__u8 ocf,__u16 *p_ocf_ogf);
85 extern __u8 swap8(__u8 byte1);
86 extern __u16 swap16(__u16 byte2);
87 //extern void bacpy(bt_address p_dest, bt_address p_source);
88 extern void fill_add(bt_address *addr,__u8 first, __u8 sec, __u8 third, __u8 forth, __u8 fifth, __u8 sixth);
89 extern void printba(bt_address *ba);
90 extern int compare_bda(bt_address *p_first, bt_address *p_second);
91 extern void fill_zero(bt_address *p_addr);
92 extern void swap_addrbytes(bt_address *p_addr);
95 static inline void hci_set_bit(int nr, void *addr)
97 *((uint32_t *) addr + (nr >> 5)) |= (1 << (nr & 31));
100 static inline void hci_clear_bit(int nr, void *addr)
102 *((uint32_t *) addr + (nr >> 5)) &= ~(1 << (nr & 31));
105 static inline int hci_test_bit(int nr, void *addr)
107 return *((uint32_t *) addr + (nr >> 5)) & (1 << (nr & 31));
110 /* HCI filter tools */
111 static inline void hci_filter_clear(struct hci_filter *f)
113 memset(f, 0, sizeof(*f));
115 static inline void hci_filter_set_ptype(int t, struct hci_filter *f)
117 hci_set_bit((t == HCI_VENDOR_PKT) ? 0 : (t & HCI_FLT_TYPE_BITS), &f->type_mask);
119 static inline void hci_filter_clear_ptype(int t, struct hci_filter *f)
121 hci_clear_bit((t == HCI_VENDOR_PKT) ? 0 : (t & HCI_FLT_TYPE_BITS), &f->type_mask);
123 static inline int hci_filter_test_ptype(int t, struct hci_filter *f)
125 return hci_test_bit((t == HCI_VENDOR_PKT) ? 0 : (t & HCI_FLT_TYPE_BITS), &f->type_mask);
127 static inline void hci_filter_all_ptypes(struct hci_filter *f)
129 memset((void *) &f->type_mask, 0xff, sizeof(f->type_mask));
131 static inline void hci_filter_set_event(int e, struct hci_filter *f)
133 hci_set_bit((e & HCI_FLT_EVENT_BITS), &f->event_mask);
135 static inline void hci_filter_clear_event(int e, struct hci_filter *f)
137 hci_clear_bit((e & HCI_FLT_EVENT_BITS), &f->event_mask);
139 static inline int hci_filter_test_event(int e, struct hci_filter *f)
141 return hci_test_bit((e & HCI_FLT_EVENT_BITS), &f->event_mask);
143 static inline void hci_filter_all_events(struct hci_filter *f)
145 memset((void *) f->event_mask, 0xff, sizeof(f->event_mask));
147 static inline void hci_filter_set_opcode(int opcode, struct hci_filter *f)
151 static inline void hci_filter_clear_opcode(struct hci_filter *f)
155 static inline int hci_filter_test_opcode(int opcode, struct hci_filter *f)
157 return (f->opcode == opcode);
160 static inline int bacmp(const bt_address *ba1, const bt_address *ba2)
162 return memcmp(ba1, ba2, sizeof(bt_address));
164 static inline void bacpy(bt_address *dst, const bt_address *src)
166 memcpy(dst, src, sizeof(bt_address));
170 #endif /* __HCIDRIVER */