#ifndef __RTLBT_HW_H__
#define __RTLBT_HW_H__
#include <netgraph/bluetooth/include/ng_hci.h>
struct rtlbt_hci_cmd {
uint16_t opcode;
uint8_t length;
uint8_t data[];
} __attribute__ ((packed));
#define RTLBT_HCI_CMD_SIZE(cmd) \
((cmd)->length + offsetof(struct rtlbt_hci_cmd, data))
struct rtlbt_hci_evhdr {
uint8_t event;
uint8_t length;
} __attribute__ ((packed));
struct rtlbt_hci_event {
struct rtlbt_hci_evhdr header;
uint8_t data[];
} __attribute__ ((packed));
struct rtlbt_hci_event_cmd_compl {
struct rtlbt_hci_evhdr header;
uint8_t numpkt;
uint16_t opcode;
uint8_t data[];
} __attribute__ ((packed));
#define RTLBT_HCI_EVT_COMPL_SIZE(payload) \
(offsetof(struct rtlbt_hci_event_cmd_compl, data) + sizeof(payload))
#define RTLBT_CONTROL_ENDPOINT_ADDR 0x00
#define RTLBT_INTERRUPT_ENDPOINT_ADDR 0x81
#define RTLBT_HCI_MAX_CMD_SIZE 256
#define RTLBT_HCI_MAX_EVENT_SIZE 16
#define RTLBT_MSEC2TS(msec) \
(struct timespec) { \
.tv_sec = (msec) / 1000, \
.tv_nsec = ((msec) % 1000) * 1000000 \
};
#define RTLBT_TS2MSEC(ts) ((ts).tv_sec * 1000 + (ts).tv_nsec / 1000000)
#define RTLBT_HCI_CMD_TIMEOUT 2000
#define RTLBT_LOADCMPL_TIMEOUT 5000
#define RTLBT_MAX_CMD_DATA_LEN 252
struct rtlbt_rom_ver_rp {
uint8_t status;
uint8_t version;
} __attribute__ ((packed));
struct rtlbt_hci_dl_cmd {
uint8_t index;
uint8_t data[RTLBT_MAX_CMD_DATA_LEN];
} __attribute__ ((packed));
struct rtlbt_hci_dl_rp {
uint8_t status;
uint8_t index;
} __attribute__ ((packed));
struct rtlbt_vendor_cmd {
uint8_t data[5];
} __attribute__ ((packed));
#define RTLBT_SEC_PROJ (&(struct rtlbt_vendor_cmd) {{0x10, 0xA4, 0x0D, 0x00, 0xb0}})
struct rtlbt_vendor_rp {
uint8_t status;
uint8_t data[2];
};
int rtlbt_read_local_ver(struct libusb_device_handle *hdl,
ng_hci_read_local_ver_rp *ver);
int rtlbt_read_rom_ver(struct libusb_device_handle *hdl, uint8_t *ver);
int rtlbt_read_reg16(struct libusb_device_handle *hdl,
struct rtlbt_vendor_cmd *cmd, uint8_t *resp);
int rtlbt_load_fwfile(struct libusb_device_handle *hdl,
const struct rtlbt_firmware *fw);
#endif