]> rtime.felk.cvut.cz Git - tiny-bt.git/blob - src/hcidriver.h
8002b68eece26466b3341e3a901c954dd9257354
[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<string.h>
18 #include "hciembeded.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 INQ_TIME_1s28   1
40 #define INQ_TIME_2s56   2
41 #define INQ_TIME_4s24   3
42 #define INQ_TIME_5s52   4
43 #define INQ_TIME_7s20   5
44 #define INQ_TIME_14s40  10
45
46 #define NUM_RSP_5       5
47 #define NUM_RSP_10      10
48 #define NUM_RSP_20      20
49
50 #define max(a, b)       ((a) > (b) ? (a) : (b))
51 #define min(a, b)       ((a) < (b) ? (a) : (b))
52
53
54 /* BD_ADDR  (bluetooth.h)*/
55
56
57 typedef struct{
58         __u8 byte[3];
59 } __attribute__((packed)) dev_lap;
60
61
62
63 /* Class of device*/
64
65 typedef struct{
66         __u8 byte[3];
67 }cl_device;
68
69
70 typedef struct{
71         __u16 *p_OCF_OGF;
72         void *p_cmdp;
73         void *p_retcmdp;
74         __u16 cmdp_len;
75         __u16 retcmdp_len;
76         int event;      //for setting event filter , some hci commands have own events
77 }hci_request;
78
79
80
81 /* next function structures*/
82
83
84 extern int call_hci_inquiry_cmd(int dd, void *p_addressarray,__u16 *p_ocf_ogf);
85 extern int call_hci_read_bd_addr_cmd(int dd,bt_address *p_address,__u16 *p_ocf_ogf);
86 extern int call_hci_read_local_name_cmd(int dd, void *p_name,__u16 *p_ocf_ogf);
87 extern int call_hci_create_connection_cmd(int dd, bt_address *p_address, __u16 *p_ocf_ogf);
88 extern int hci_open_device(int dev_id);
89 extern int hci_send_command(int dd, hci_request *p_req);
90 extern int hci_send_request(int dd, hci_request *p_req,int timeout);
91 //extern void print_device_list(int ctl);
92 extern int hci_close_dev(int dd);
93
94
95 extern void assemble_hci_data(void *p_con_handle,void *p_data_size,void *p_data);
96 extern void assemble_ocf_ogf(__u8 ogf,__u8 ocf,__u16 *p_ocf_ogf);
97 extern __u16 swap_2_bytes(__u16 twobytes);
98 extern __u8 swap8(__u8 byte1);
99 extern __u16 swap16(__u16 byte2);
100 //extern void bacpy(bt_address p_dest, bt_address p_source);
101 extern void fill_add(bt_address *addr,__u8 first, __u8 sec, __u8 third, __u8 forth, __u8 fifth, __u8 sixth);
102 extern void printba(bt_address *ba);
103 extern int compare_bda(bt_address *p_first, bt_address *p_second);
104 extern void fill_zero(bt_address *p_addr);
105 extern void swap_addrbytes(bt_address *p_addr);
106
107
108 static inline void hci_set_bit(int nr, void *addr)
109 {
110         *((uint32_t *) addr + (nr >> 5)) |= (1 << (nr & 31));
111 }
112
113 static inline void hci_clear_bit(int nr, void *addr)
114 {
115         *((uint32_t *) addr + (nr >> 5)) &= ~(1 << (nr & 31));
116 }
117
118 static inline int hci_test_bit(int nr, void *addr)
119 {
120         return *((uint32_t *) addr + (nr >> 5)) & (1 << (nr & 31));
121 }
122
123 /* HCI filter tools */
124 static inline void hci_filter_clear(struct hci_filter *f)
125 {
126         memset(f, 0, sizeof(*f));
127 }
128 static inline void hci_filter_set_ptype(int t, struct hci_filter *f)
129 {
130         hci_set_bit((t == HCI_VENDOR_PKT) ? 0 : (t & HCI_FLT_TYPE_BITS), &f->type_mask);
131 }
132 static inline void hci_filter_clear_ptype(int t, struct hci_filter *f)
133 {
134         hci_clear_bit((t == HCI_VENDOR_PKT) ? 0 : (t & HCI_FLT_TYPE_BITS), &f->type_mask);
135 }
136 static inline int hci_filter_test_ptype(int t, struct hci_filter *f)
137 {
138         return hci_test_bit((t == HCI_VENDOR_PKT) ? 0 : (t & HCI_FLT_TYPE_BITS), &f->type_mask);
139 }
140 static inline void hci_filter_all_ptypes(struct hci_filter *f)
141 {
142         memset((void *) &f->type_mask, 0xff, sizeof(f->type_mask));
143 }
144 static inline void hci_filter_set_event(int e, struct hci_filter *f)
145 {
146         hci_set_bit((e & HCI_FLT_EVENT_BITS), &f->event_mask);
147 }
148 static inline void hci_filter_clear_event(int e, struct hci_filter *f)
149 {
150         hci_clear_bit((e & HCI_FLT_EVENT_BITS), &f->event_mask);
151 }
152 static inline int hci_filter_test_event(int e, struct hci_filter *f)
153 {
154         return hci_test_bit((e & HCI_FLT_EVENT_BITS), &f->event_mask);
155 }
156 static inline void hci_filter_all_events(struct hci_filter *f)
157 {
158         memset((void *) f->event_mask, 0xff, sizeof(f->event_mask));
159 }
160 static inline void hci_filter_set_opcode(int opcode, struct hci_filter *f)
161 {
162         f->opcode = opcode;
163 }
164 static inline void hci_filter_clear_opcode(struct hci_filter *f)
165 {
166         f->opcode = 0;
167 }
168 static inline int hci_filter_test_opcode(int opcode, struct hci_filter *f)
169 {
170         return (f->opcode == opcode);
171 }
172
173 static inline int bacmp(const bt_address *ba1, const bt_address *ba2)
174 {
175         return memcmp(ba1, ba2, sizeof(bt_address));
176 }
177 static inline void bacpy(bt_address *dst, const bt_address *src)
178 {
179         memcpy(dst, src, sizeof(bt_address));
180 }
181
182
183 #endif  /* __HCIDRIVER */