]> rtime.felk.cvut.cz Git - tiny-bt.git/blob - src/hcidriver.h
28ec3e9b10a052043d1725b7860dc8e1619ea70e
[tiny-bt.git] / src / hcidriver.h
1 //
2 // C++ Interface: hcidriver
3 //
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. 
5 //
6 //
7 // Author: root <root@ubuntu>, (C) 2008
8 //
9 // Copyright: See COPYING file that comes with this distribution
10 //
11 //
12 #ifndef __HCIDRIVER
13 #define __HCIDRIVER
14
15 #include<asm/types.h>
16 #include<sys/socket.h>
17 #include<bluetooth/hci.h>
18 #include<string.h>
19
20
21
22
23
24 /* BT protocols(from bluetooth.h)*/
25 #define BTPROTO_L2CAP   0
26 #define BTPROTO_HCI     1
27 #define BTPROTO_SCO     2
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
33
34 #define SOL_HCI         0
35 #define SOL_L2CAP       6
36 #define SOL_SCO         17
37 #define SOL_RFCOMM      18
38
39 #define max(a, b)       ((a) > (b) ? (a) : (b))
40 #define min(a, b)       ((a) < (b) ? (a) : (b))
41
42
43 /* BD_ADDR  (bluetooth.h)*/
44 typedef struct{
45         __u8 byte[6];
46 } __attribute__((packed)) bt_address;
47
48 typedef struct{
49         uint8_t b[6];
50 } __attribute__((packed)) bdaddr_t;
51
52 typedef struct{
53         __u8 byte[3];
54 } __attribute__((packed)) dev_lap;
55
56
57
58 /* Class of device*/
59
60 typedef struct{
61         __u8 byte[3];
62 }cl_device;
63
64
65 typedef struct{
66         __u16 *p_OCF_OGF;
67         void *p_cmdp;
68         void *p_retcmdp;
69         __u16 cmdp_len;
70         __u16 retcmdp_len;
71         int event;      //for setting event filter , some hci commands have own events
72 }hci_request;
73
74
75
76 /* next function structures*/
77
78
79 extern int call_hci_inquiry_cmd(int dd, bt_address *p_addressarray,int timeout);
80 extern int call_hci_read_bd_addr_cmd(int dd,bt_address *p_address, int timeout);
81 extern int call_hci_create_connection_cmd(int dd, bt_address *p_address, int timeout);
82 extern int hci_open_device(int dev_id);
83 extern int hci_send_command(int dd, hci_request *p_req);
84 extern int hci_send_request(int dd, hci_request *p_req,int timeout);
85 extern void print_device_list(int ctl);
86 extern int hci_close_dev(int dd);
87
88
89 extern void assemble_hci_data(void *p_con_handle,void *p_data_size,void *p_data);
90 extern void assemble_ocf_ogf(__u8 ogf,__u8 ocf,__u16 *p_ocf_ogf);
91 extern __u8 swap8(__u8 byte1);
92 extern __u16 swap16(__u16 byte2);
93 //extern void bacpy(bt_address p_dest, bt_address p_source);
94 extern void fill_add(bt_address *addr,__u8 first, __u8 sec, __u8 third, __u8 forth, __u8 fifth, __u8 sixth);
95 extern void printba(bt_address *ba);
96 extern int compare_bda(bt_address *p_first, bt_address *p_second);
97 extern void fill_zero(bt_address *p_addr);
98 extern void swap_addrbytes(bt_address *p_addr);
99
100
101 static inline void hci_set_bit(int nr, void *addr)
102 {
103         *((uint32_t *) addr + (nr >> 5)) |= (1 << (nr & 31));
104 }
105
106 static inline void hci_clear_bit(int nr, void *addr)
107 {
108         *((uint32_t *) addr + (nr >> 5)) &= ~(1 << (nr & 31));
109 }
110
111 static inline int hci_test_bit(int nr, void *addr)
112 {
113         return *((uint32_t *) addr + (nr >> 5)) & (1 << (nr & 31));
114 }
115
116 /* HCI filter tools */
117 static inline void hci_filter_clear(struct hci_filter *f)
118 {
119         memset(f, 0, sizeof(*f));
120 }
121 static inline void hci_filter_set_ptype(int t, struct hci_filter *f)
122 {
123         hci_set_bit((t == HCI_VENDOR_PKT) ? 0 : (t & HCI_FLT_TYPE_BITS), &f->type_mask);
124 }
125 static inline void hci_filter_clear_ptype(int t, struct hci_filter *f)
126 {
127         hci_clear_bit((t == HCI_VENDOR_PKT) ? 0 : (t & HCI_FLT_TYPE_BITS), &f->type_mask);
128 }
129 static inline int hci_filter_test_ptype(int t, struct hci_filter *f)
130 {
131         return hci_test_bit((t == HCI_VENDOR_PKT) ? 0 : (t & HCI_FLT_TYPE_BITS), &f->type_mask);
132 }
133 static inline void hci_filter_all_ptypes(struct hci_filter *f)
134 {
135         memset((void *) &f->type_mask, 0xff, sizeof(f->type_mask));
136 }
137 static inline void hci_filter_set_event(int e, struct hci_filter *f)
138 {
139         hci_set_bit((e & HCI_FLT_EVENT_BITS), &f->event_mask);
140 }
141 static inline void hci_filter_clear_event(int e, struct hci_filter *f)
142 {
143         hci_clear_bit((e & HCI_FLT_EVENT_BITS), &f->event_mask);
144 }
145 static inline int hci_filter_test_event(int e, struct hci_filter *f)
146 {
147         return hci_test_bit((e & HCI_FLT_EVENT_BITS), &f->event_mask);
148 }
149 static inline void hci_filter_all_events(struct hci_filter *f)
150 {
151         memset((void *) f->event_mask, 0xff, sizeof(f->event_mask));
152 }
153 static inline void hci_filter_set_opcode(int opcode, struct hci_filter *f)
154 {
155         f->opcode = opcode;
156 }
157 static inline void hci_filter_clear_opcode(struct hci_filter *f)
158 {
159         f->opcode = 0;
160 }
161 static inline int hci_filter_test_opcode(int opcode, struct hci_filter *f)
162 {
163         return (f->opcode == opcode);
164 }
165
166 static inline int bacmp(const bt_address *ba1, const bt_address *ba2)
167 {
168         return memcmp(ba1, ba2, sizeof(bt_address));
169 }
170 static inline void bacpy(bt_address *dst, const bt_address *src)
171 {
172         memcpy(dst, src, sizeof(bt_address));
173 }
174
175
176 #endif  /* __HCIDRIVER */