]> rtime.felk.cvut.cz Git - tiny-bt.git/blob - testf/t4/tiny_bt_hci_cmd.h
6824a54330c1c093019ff8ef15d3012f0b57c18a
[tiny-bt.git] / testf / t4 / 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
53 /* BD_ADDR  (bluetooth.h)*/
54
55
56 typedef struct{
57         __u8 byte[3];
58 } __attribute__((packed)) dev_lap;
59
60
61
62 /* Class of device*/
63
64 typedef struct{
65         __u8 byte[3];
66 }cl_device;
67
68
69 typedef struct{
70         __u16 OCF_OGF;
71         void *p_cmdp;
72         __u16 cmdp_len;
73 }hci_cmd_request;
74
75
76
77 /* next function structures*/
78
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
86 extern int send_cmd(hci_cmd_request *p_creq);
87
88 extern void assemble_ocf_ogf(__u8 ogf,__u8 ocf,__u16 *p_ocf_ogf);
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);
93 extern __u16 swap_2_bytes(__u16 twobytes);
94 extern __u8 swap8(__u8 byte1);
95 extern __u16 swap16(__u16 byte2);
96 extern __u16 swap_2_bytes(__u16 twobytes);
97 extern void fill_add(bt_address *addr,__u8 first, __u8 sec, __u8 third, __u8 forth, __u8 fifth, __u8 sixth);
98
99 static inline void hci_set_bit(int nr, void *addr)
100 {
101         *((uint32_t *) addr + (nr >> 5)) |= (1 << (nr & 31));
102 }
103
104 static inline void hci_clear_bit(int nr, void *addr)
105 {
106         *((uint32_t *) addr + (nr >> 5)) &= ~(1 << (nr & 31));
107 }
108
109 static inline int hci_test_bit(int nr, void *addr)
110 {
111         return *((uint32_t *) addr + (nr >> 5)) & (1 << (nr & 31));
112 }
113
114 /* HCI filter tools */
115 static inline void hci_filter_clear(struct hci_filter *f)
116 {
117         memset(f, 0, sizeof(*f));
118 }
119 static inline void hci_filter_set_ptype(int t, struct hci_filter *f)
120 {
121         hci_set_bit((t == HCI_VENDOR_PKT) ? 0 : (t & HCI_FLT_TYPE_BITS), &f->type_mask);
122 }
123 static inline void hci_filter_clear_ptype(int t, struct hci_filter *f)
124 {
125         hci_clear_bit((t == HCI_VENDOR_PKT) ? 0 : (t & HCI_FLT_TYPE_BITS), &f->type_mask);
126 }
127 static inline int hci_filter_test_ptype(int t, struct hci_filter *f)
128 {
129         return hci_test_bit((t == HCI_VENDOR_PKT) ? 0 : (t & HCI_FLT_TYPE_BITS), &f->type_mask);
130 }
131 static inline void hci_filter_all_ptypes(struct hci_filter *f)
132 {
133         memset((void *) &f->type_mask, 0xff, sizeof(f->type_mask));
134 }
135 static inline void hci_filter_set_event(int e, struct hci_filter *f)
136 {
137         hci_set_bit((e & HCI_FLT_EVENT_BITS), &f->event_mask);
138 }
139 static inline void hci_filter_clear_event(int e, struct hci_filter *f)
140 {
141         hci_clear_bit((e & HCI_FLT_EVENT_BITS), &f->event_mask);
142 }
143 static inline int hci_filter_test_event(int e, struct hci_filter *f)
144 {
145         return hci_test_bit((e & HCI_FLT_EVENT_BITS), &f->event_mask);
146 }
147 static inline void hci_filter_all_events(struct hci_filter *f)
148 {
149         memset((void *) f->event_mask, 0xff, sizeof(f->event_mask));
150 }
151 static inline void hci_filter_set_opcode(int opcode, struct hci_filter *f)
152 {
153         f->opcode = opcode;
154 }
155 static inline void hci_filter_clear_opcode(struct hci_filter *f)
156 {
157         f->opcode = 0;
158 }
159 static inline int hci_filter_test_opcode(int opcode, struct hci_filter *f)
160 {
161         return (f->opcode == opcode);
162 }
163
164 static inline int bacmp(const bt_address *ba1, const bt_address *ba2)
165 {
166         return memcmp(ba1, ba2, sizeof(bt_address));
167 }
168 static inline void bacpy(bt_address *dst, const bt_address *src)
169 {
170         memcpy(dst, src, sizeof(bt_address));
171 }
172
173
174 #endif  /* __HCIDRIVER */