hc
2023-11-06 15ade055295d13f95d49e3d99b09f3bbfb4a43e7
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
/*
 * Copyright (C) 2015 Spreadtrum Communications Inc.
 *
 * This software is licensed under the terms of the GNU General Public
 * License version 2, as published by the Free Software Foundation, and
 * may be copied, distributed, and modified under those terms.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 */
 
#ifndef __MHCI_H
#define __MHCI_H
 
#define HCI_CMD         0x01
#define HCI_ACL         0x02
#define HCI_SCO         0x03
#define HCI_EVT         0x04
 
#define PACKET_TYPE     0
#define EVT_HEADER_TYPE     0
#define EVT_HEADER_EVENT    1
#define EVT_HEADER_SIZE     2
#define EVT_VENDOR_CODE_LSB 3
#define EVT_VENDOR_CODE_MSB 4
#define EVT_LE_META_SUBEVT  3
#define EVT_ADV_LENGTH     13
 
#define BT_HCI_EVT_CMD_COMPLETE                 0x0e
#define BT_HCI_EVT_CMD_STATUS                   0x0f
 
#define ACL_HEADER_SIZE_LB  3
#define ACL_HEADER_SIZE_HB  4
#define EVT_HEADER_STATUS   4
 
#define HCI_CMD_MAX_LEN 258
#define BD_ADDR_LEN     6
 
#define UINT8_TO_STREAM(p, u8)   {*(p)++ = (uint8_t)(u8);}
#define UINT16_TO_STREAM(p, u16) {*(p)++ = (uint8_t)(u16); *(p)++ = (uint8_t)((u16) >> 8);}
#define ARRAY_TO_STREAM(p, a, len) {register int ijk; for (ijk = 0; ijk < len;        ijk++) *(p)++ = (uint8_t) a[ijk];}
#define STREAM_TO_UINT8(u8, p)   {u8 = (uint8_t)(*(p)); (p) += 1;}
#define STREAM_TO_UINT16(u16, p) {u16 = ((uint16_t)(*(p)) + (((uint16_t)(*((p) + 1))) << 8)); (p) += 2;}
#define BDADDR_TO_STREAM(p, a)   {register int ijk; for (ijk = 0; ijk < BD_ADDR_LEN;  ijk++) *(p)++ = (uint8_t) a[BD_ADDR_LEN - 1 - ijk];}
#define STREAM_TO_ARRAY(a, p, len) {register int ijk; for (ijk = 0; ijk < len; ijk++) ((uint8_t *) a)[ijk] = *p++;}
 
#define BT_HCI_OP_RESET             0x0c03
#define BT_HCI_OP_ENABLE            0xfca1
#define BT_HCI_OP_WOBLE             0xfd08
 
#define UNISOC_WOBLE_UUID           0xfd01
 
#define BT_HCI_OP_SET_SLEEPMODE     0xfd09
#define BT_HCI_OP_ADD_WAKEUPLIST    0xfd0a
#define BT_HCI_OP_CLEANUP_WAKEUPLIST    0xfd0b
#define BT_HCI_OP_SET_STARTSLEEP    0xfd0d
 
#define BT_HCI_OP_LE_SET_EX_SCAN_PARAMETERS     0x2041
#define BT_HCI_OP_LE_SET_EX_SCAN_ENABLE         0x2042
 
 
#define WOBLE_DEVICES_SIZE 10
 
struct HC_BT_HDR
{
    unsigned short event;
    unsigned short len;
    unsigned short offset;
    unsigned short layer_specific;
    unsigned char data[];
};
 
struct hci_cmd_t
{
    unsigned short opcode;
    struct semaphore wait;
    struct HC_BT_HDR response;
};
 
 
typedef enum {
    WOBLE_MOD_DISABLE = 0,
    WOBLE_MOD_ENABLE,
    WOBLE_MOD_UNDEFINE = 0xff,
} WOBLE_MOD;
 
typedef enum {
    WOBLE_SLEEP_MOD_COULD_KNOW = 0,
    WOBLE_SLEEP_MOD_COULD_NOT_KNOW
} WOBLE_SLEEP_MOD;
 
typedef enum {
    WOBLE_SLEEP_MOD_NOT_NEED_NOTITY = 0,
    WOBLE_SLEEP_MOD_NEED_NOTITY,
} WOBLE_NOFITY_MOD;
 
typedef enum {
    WOBLE_IS_NOT_SHUTDOWN = 0,
    WOBLE_IS_SHUTDOWN,
} WOBLE_SHUTDOWN_MOD;
 
typedef enum {
    WOBLE_IS_NOT_RESUME = 0,
    WOBLE_IS_RESUME,
} WOBLE_RESUME_MOD;
 
typedef struct {
    unsigned char woble_mod;
    unsigned char sleep_mod;
    unsigned short timeout;
    unsigned char notify;
} woble_config_t;
 
typedef enum {
    ADV_PUBLIC_ADDRESS = 0,
    ADV_RANDOM_ADDRESS,
    ADV_ADDRESS_FROM_WHITTLIST = 0XFF,
} ADV_ADDRESS_TYPE;
 
#define ANY_ADV                     ( 1 )
#define ANY_DATA_ON_LINK            ( 1 << 1 )
#define ADV_IN_FILTER               ( 1 << 2 )
#define DATA_IN_FILTER_ON_LINK      ( 1 << 3 )
#define SUB_ADV_DATA_FILTER         ( 1 << 4 )
 
typedef enum {
    KEEP_THE_LINK = 0,
    DISCONNECT_WITH_DEVICE,
} ADV_STATE;
 
typedef struct mtty_bt_wake_t {
    unsigned char addr[6];
    char *addr_str;
    unsigned char dev_tp;
    char *dev_tp_str;
    unsigned char addr_tp;
    char *addr_tp_str;
} mtty_bt_wake_t;
 
int hci_init(void);
int hci_destory(void);
void hci_cleanup(void);
void hci_woble_enable(void);
int rx_data_recv(const unsigned char *buf, int count, int (*upper_cb)(const unsigned char *buf, int count));
int update_woble_devices(unsigned char type, unsigned short handler, unsigned char *bd_addr);
int del_woble_devices(unsigned char type, unsigned char *bd_addr);
int clear_woble_devices(void);
int set_random_address(unsigned char *bd_addr);
void dump_woble_devices(void);
int hci_cmd_send_sync(unsigned short opcode, struct HC_BT_HDR *py, struct HC_BT_HDR *rsp);
 
void hci_set_ap_sleep_mode(int is_shutdown, int is_resume);
void hci_cleanup_wakeup_list(void);
void hci_add_device_to_wakeup_list(void);
void hci_set_ap_start_sleep(void);
void hci_set_scan_parameters(void);
void hci_set_scan_enable(int enable);
 
typedef enum
{
    WOBLE_KERNEL_OP_CLEAR,
    WOBLE_KERNEL_OP_SET_OWN,
    WOBLE_KERNEL_OP_ADD_RMT,
    WOBLE_KERNEL_OP_DEL_RMT,
    WOBLE_KERNEL_OP_ENABLE_BLE_INDICATE,
    WOBLE_KERNEL_OP_DISABLE_BLE_INDICATE,
} WOBLE_KERNEL_OP;
 
 
#endif