hc
2024-03-26 e0728245c89800c2038c23308f2d88969d5b41c8
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
#ifndef __SITM_H
#define __SITM_H
 
#include <linux/types.h>
#include <linux/kfifo.h>
 
#define PREAMBLE_BUFFER_SIZE 5
#define PACKET_TYPE_TO_INDEX(type) ((type) - 1)
#define HCI_COMMAND_PREAMBLE_SIZE 3
#define HCI_ACL_PREAMBLE_SIZE 4
#define HCI_SCO_PREAMBLE_SIZE 3
#define HCI_EVENT_PREAMBLE_SIZE 2
#define RETRIEVE_ACL_LENGTH(preamble) \
   ((((preamble)[4] & 0xFFFF) << 8) | (preamble)[3])
#define HCI_HAL_SERIAL_BUFFER_SIZE 1026
 
#define BYTE_ALIGNMENT 4
 
enum receive_state_t {
   BRAND_NEW,
   PREAMBLE,
   BODY,
   IGNORE,
   FINISHED
};
 
enum serial_data_type_t {
   DATA_TYPE_COMMAND = 1,
   DATA_TYPE_ACL     = 2,
   DATA_TYPE_SCO     = 3,
   DATA_TYPE_EVENT   = 4
};
 
 
struct packet_receive_data_t {
   enum receive_state_t state;
   uint16_t bytes_remaining;
   uint8_t type;
   uint8_t preamble[PREAMBLE_BUFFER_SIZE];
   uint16_t index;
   struct kfifo fifo;
   uint8_t buffer[HCI_HAL_SERIAL_BUFFER_SIZE + BYTE_ALIGNMENT];
};
 
typedef int (*frame_complete_cb)(uint8_t *data, size_t len);
typedef int (*data_ready_cb)(uint8_t *data, uint32_t len);
 
 
int sitm_write(const uint8_t *buf, int count, frame_complete_cb frame_complete);
int sitm_ini(void);
int sitm_cleanup(void);
#endif