]> rtime.felk.cvut.cz Git - tiny-bt.git/blobdiff - src2/hcidriver.h
new version
[tiny-bt.git] / src2 / hcidriver.h
diff --git a/src2/hcidriver.h b/src2/hcidriver.h
new file mode 100644 (file)
index 0000000..c3dc5f4
--- /dev/null
@@ -0,0 +1,197 @@
+//
+// C++ Interface: hcidriver
+//
+// 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. 
+//
+//
+// Author: root <root@ubuntu>, (C) 2008
+//
+// Copyright: See COPYING file that comes with this distribution
+//
+//
+#ifndef __HCIDRIVER
+#define __HCIDRIVER
+
+#include<asm/types.h>
+#include<sys/socket.h>
+#include<string.h>
+#include "hciembeded.h"
+
+
+
+
+
+/* BT protocols(from bluetooth.h)*/
+#define BTPROTO_L2CAP  0
+#define BTPROTO_HCI    1
+#define BTPROTO_SCO    2
+#define BTPROTO_RFCOMM 3
+#define BTPROTO_BNEP   4
+#define BTPROTO_CMTP   5
+#define BTPROTO_HIDP   6
+#define BTPROTO_AVDTP  7
+
+#define SOL_HCI                0
+#define SOL_L2CAP      6
+#define SOL_SCO                17
+#define SOL_RFCOMM     18
+
+/* CMD ocf and ogf */
+
+#define INQUIRY_CMD_OP                 0x0104
+#define INQUIRY_CANCEL_CMD_OP          0x0204
+#define CREATE_CONNECTION_CMD_OP       0x0504
+#define ACCEPT_CONNECTION_REQ_OP       0x0904
+#define DISCONNECT_CMD_OP              0x0604
+#define REMOTE_NAME_REQUEST_CMD_OP     0x1904
+#define RESET_CMD_OP                   0x030C
+#define        WRITE_LOCAL_NAME_CMD_OP         0x130C
+#define        READ_LOCAL_NAME_CMD_OP          0x140C
+#define READ_BD_ADDR_CMD_OP            0x0910
+
+#define max(a, b)       ((a) > (b) ? (a) : (b))
+#define min(a, b)       ((a) < (b) ? (a) : (b))
+
+typedef enum{
+       T1s28 = 1,
+       T2s56 = 2,      
+       T4s24 = 3,
+       T5s52 = 4,
+       T7s20 = 5,
+       T14s40 = 10
+}inq_time;
+
+typedef enum{
+       NUM_RSP_5 = 5,
+       NUM_RSP_10 = 10,
+       NUM_RSP_20 = 20
+}responce_num;
+
+
+/* BD_ADDR  (bluetooth.h)*/
+
+
+typedef struct{
+       __u8 byte[3];
+} __attribute__((packed)) dev_lap;
+
+
+
+/* Class of device*/
+
+typedef struct{
+       __u8 byte[3];
+}cl_device;
+
+
+typedef struct{
+       __u16 OCF_OGF;
+       void *p_cmdp;
+       __u16 cmdp_len;
+}hci_cmd_request;
+
+
+
+/* next function structures*/
+
+
+extern int send_hci_inquiry_cmd(void);
+extern int send_hci_read_bd_addr_cmd(void);
+extern int send_hci_read_local_name_cmd(void);
+extern int send_hci_create_connection_cmd(bt_address *p_dest_addr);
+extern int send_hci_accept_conn_req_cmd(bt_address *p_address);
+
+extern int send_cmd(hci_cmd_request *p_creq);
+
+extern static void callback_hci_read_bd_addr(void *p_arg, void *p_recbuf);
+extern static void callback_hci_read_local_name(void *p_arg, void *p_recbuf);
+extern static void callback_hci_inquiry_RSSI(void *p_arg, void *p_recbuf);
+extern static void callback_hci_create_connection(void *p_arg, void *p_recbuf);
+
+extern void assemble_ocf_ogf(__u8 ogf,__u8 ocf,__u16 *p_ocf_ogf);
+extern void printba(bt_address *ba);
+extern int compare_bda(bt_address *p_first, bt_address *p_second);
+extern void fill_zero(bt_address *p_addr);
+extern void swap_addrbytes(bt_address *p_addr);
+extern __u16 swap_2_bytes(__u16 twobytes);
+extern __u8 swap8(__u8 byte1);
+extern __u16 swap16(__u16 byte2);
+extern __u16 swap_2_bytes(__u16 twobytes);
+extern void fill_add(bt_address *addr,__u8 first, __u8 sec, __u8 third, __u8 forth, __u8 fifth, __u8 sixth);
+
+static inline void hci_set_bit(int nr, void *addr)
+{
+       *((uint32_t *) addr + (nr >> 5)) |= (1 << (nr & 31));
+}
+
+static inline void hci_clear_bit(int nr, void *addr)
+{
+       *((uint32_t *) addr + (nr >> 5)) &= ~(1 << (nr & 31));
+}
+
+static inline int hci_test_bit(int nr, void *addr)
+{
+       return *((uint32_t *) addr + (nr >> 5)) & (1 << (nr & 31));
+}
+
+/* HCI filter tools */
+static inline void hci_filter_clear(struct hci_filter *f)
+{
+       memset(f, 0, sizeof(*f));
+}
+static inline void hci_filter_set_ptype(int t, struct hci_filter *f)
+{
+       hci_set_bit((t == HCI_VENDOR_PKT) ? 0 : (t & HCI_FLT_TYPE_BITS), &f->type_mask);
+}
+static inline void hci_filter_clear_ptype(int t, struct hci_filter *f)
+{
+       hci_clear_bit((t == HCI_VENDOR_PKT) ? 0 : (t & HCI_FLT_TYPE_BITS), &f->type_mask);
+}
+static inline int hci_filter_test_ptype(int t, struct hci_filter *f)
+{
+       return hci_test_bit((t == HCI_VENDOR_PKT) ? 0 : (t & HCI_FLT_TYPE_BITS), &f->type_mask);
+}
+static inline void hci_filter_all_ptypes(struct hci_filter *f)
+{
+       memset((void *) &f->type_mask, 0xff, sizeof(f->type_mask));
+}
+static inline void hci_filter_set_event(int e, struct hci_filter *f)
+{
+       hci_set_bit((e & HCI_FLT_EVENT_BITS), &f->event_mask);
+}
+static inline void hci_filter_clear_event(int e, struct hci_filter *f)
+{
+       hci_clear_bit((e & HCI_FLT_EVENT_BITS), &f->event_mask);
+}
+static inline int hci_filter_test_event(int e, struct hci_filter *f)
+{
+       return hci_test_bit((e & HCI_FLT_EVENT_BITS), &f->event_mask);
+}
+static inline void hci_filter_all_events(struct hci_filter *f)
+{
+       memset((void *) f->event_mask, 0xff, sizeof(f->event_mask));
+}
+static inline void hci_filter_set_opcode(int opcode, struct hci_filter *f)
+{
+       f->opcode = opcode;
+}
+static inline void hci_filter_clear_opcode(struct hci_filter *f)
+{
+       f->opcode = 0;
+}
+static inline int hci_filter_test_opcode(int opcode, struct hci_filter *f)
+{
+       return (f->opcode == opcode);
+}
+
+static inline int bacmp(const bt_address *ba1, const bt_address *ba2)
+{
+       return memcmp(ba1, ba2, sizeof(bt_address));
+}
+static inline void bacpy(bt_address *dst, const bt_address *src)
+{
+       memcpy(dst, src, sizeof(bt_address));
+}
+
+
+#endif  /* __HCIDRIVER */