]> rtime.felk.cvut.cz Git - tiny-bt.git/blob - src2/tiny_bt_hci_cmd.h
Better coding style and evt_array is setted on zeros in init function
[tiny-bt.git] / src2 / tiny_bt_hci_cmd.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 __TINI_BT_HCI_CMD
13 #define __TINI_BT_HCI_CMD
14
15 #include <asm/types.h>
16 #include <string.h>
17 #include "hciembeded.h"
18
19
20
21 /* CMD ocf and ogf */
22
23 #define INQUIRY_CMD_OP                  0x0104
24 #define INQUIRY_CANCEL_CMD_OP           0x0204
25 #define CREATE_CONNECTION_CMD_OP        0x0504
26 #define ACCEPT_CONNECTION_REQ_OP        0x0904
27 #define DISCONNECT_CMD_OP               0x0604
28 #define REMOTE_NAME_REQUEST_CMD_OP      0x1904
29 #define RESET_CMD_OP                    0x030C
30 #define WRITE_LOCAL_NAME_CMD_OP         0x130C
31 #define READ_LOCAL_NAME_CMD_OP          0x140C
32 #define READ_BD_ADDR_CMD_OP             0x0910
33
34 #define max(a, b)       ((a) > (b) ? (a) : (b))
35 #define min(a, b)       ((a) < (b) ? (a) : (b))
36
37 typedef enum{
38         T1s28 = 1,
39         T2s56 = 2,      
40         T4s24 = 3,
41         T5s52 = 4,
42         T7s20 = 5,
43         T14s40 = 10
44 } inq_time;
45
46 typedef enum{
47         NUM_RSP_5 = 5,
48         NUM_RSP_10 = 10,
49         NUM_RSP_20 = 20
50 } responce_num;
51
52 /* BD_ADDR  (bluetooth.h)*/
53
54 typedef struct{
55         __u8 byte[3];
56 } __attribute__((packed)) dev_lap;
57
58
59 /* Class of device*/
60
61 typedef struct{
62         __u8 byte[3];
63 } cl_device;
64
65 typedef struct{
66         char *p_data;
67         __u16 lenght;
68         __u16 *p_chandle;
69 } hci_data_request;
70
71
72 typedef struct{
73         __u16 OCF_OGF;
74         void *p_cmdp;
75         __u16 cmdp_len;
76 } hci_cmd_request;
77
78 /* next function structures*/
79
80 extern int send_hci_inquiry_cmd(void);
81 extern int send_hci_read_bd_addr_cmd(void);
82 extern int send_hci_read_local_name_cmd(void);
83 extern int send_hci_create_connection_cmd(bt_address *p_dest_addr);
84 extern int send_hci_accept_conn_req_cmd(bt_address *p_address);
85 extern int send_hci_disconnect_cmd(__u16 handle);
86 extern int send_hci_data(char *p_data, __u16 lenght, __u16 *p_chandle);
87
88 extern int send_cmd(hci_cmd_request *p_creq);
89 extern int send_data(hci_data_request *p_dreq);
90
91 extern void assemble_ocf_ogf(__u8 ogf,__u8 ocf,__u16 *p_ocf_ogf);
92 extern void printba(bt_address *ba);
93 extern int compare_bda(bt_address *p_first, bt_address *p_second);
94 extern void fill_zero(bt_address *p_addr);
95 extern void swap_addrbytes(bt_address *p_addr);
96 extern __u16 swap_2_bytes(__u16 twobytes);
97 extern __u8 swap8(__u8 byte1);
98 extern __u16 swap16(__u16 byte2);
99 extern __u16 swap_2_bytes(__u16 twobytes);
100 extern void fill_add(bt_address *addr,__u8 first, 
101                 __u8 sec, __u8 third, __u8 forth, __u8 fifth, __u8 sixth);
102
103 static inline void hci_set_bit(int nr, void *addr)
104 {
105         *((uint32_t *) addr + (nr >> 5)) |= (1 << (nr & 31));
106 }
107
108 static inline void hci_clear_bit(int nr, void *addr)
109 {
110         *((uint32_t *) addr + (nr >> 5)) &= ~(1 << (nr & 31));
111 }
112
113 static inline int hci_test_bit(int nr, void *addr)
114 {
115         return *((uint32_t *) addr + (nr >> 5)) & (1 << (nr & 31));
116 }
117
118 /* HCI filter tools */
119 static inline void hci_filter_clear(struct hci_filter *f)
120 {
121         memset(f, 0, sizeof(*f));
122 }
123 static inline void hci_filter_set_ptype(int t, struct hci_filter *f)
124 {
125         hci_set_bit((t == HCI_VENDOR_PKT) ? 0 : (t & HCI_FLT_TYPE_BITS), &f->type_mask);
126 }
127 static inline void hci_filter_clear_ptype(int t, struct hci_filter *f)
128 {
129         hci_clear_bit((t == HCI_VENDOR_PKT) ? 0 : (t & HCI_FLT_TYPE_BITS), &f->type_mask);
130 }
131 static inline int hci_filter_test_ptype(int t, struct hci_filter *f)
132 {
133         return hci_test_bit((t == HCI_VENDOR_PKT) ? 0 : (t & HCI_FLT_TYPE_BITS), &f->type_mask);
134 }
135 static inline void hci_filter_all_ptypes(struct hci_filter *f)
136 {
137         memset((void *) &f->type_mask, 0xff, sizeof(f->type_mask));
138 }
139 static inline void hci_filter_set_event(int e, struct hci_filter *f)
140 {
141         hci_set_bit((e & HCI_FLT_EVENT_BITS), &f->event_mask);
142 }
143 static inline void hci_filter_clear_event(int e, struct hci_filter *f)
144 {
145         hci_clear_bit((e & HCI_FLT_EVENT_BITS), &f->event_mask);
146 }
147 static inline int hci_filter_test_event(int e, struct hci_filter *f)
148 {
149         return hci_test_bit((e & HCI_FLT_EVENT_BITS), &f->event_mask);
150 }
151 static inline void hci_filter_all_events(struct hci_filter *f)
152 {
153         memset((void *) f->event_mask, 0xff, sizeof(f->event_mask));
154 }
155 static inline void hci_filter_set_opcode(int opcode, struct hci_filter *f)
156 {
157         f->opcode = opcode;
158 }
159 static inline void hci_filter_clear_opcode(struct hci_filter *f)
160 {
161         f->opcode = 0;
162 }
163 static inline int hci_filter_test_opcode(int opcode, struct hci_filter *f)
164 {
165         return (f->opcode == opcode);
166 }
167
168 static inline int bacmp(const bt_address *ba1, const bt_address *ba2)
169 {
170         return memcmp(ba1, ba2, sizeof(bt_address));
171 }
172 static inline void bacpy(bt_address *dst, const bt_address *src)
173 {
174         memcpy(dst, src, sizeof(bt_address));
175 }
176
177
178 #endif  /* __HCIDRIVER */