Path: blob/main/usr.sbin/bluetooth/rtlbtfw/rtlbt_hw.h
107607 views
/*-1* SPDX-License-Identifier: BSD-2-Clause2*3* Copyright (c) 2019 Vladimir Kondratyev <[email protected]>4* Copyright (c) 2023 Future Crew LLC.5*6* Redistribution and use in source and binary forms, with or without7* modification, are permitted provided that the following conditions8* are met:9* 1. Redistributions of source code must retain the above copyright10* notice, this list of conditions and the following disclaimer.11* 2. Redistributions in binary form must reproduce the above copyright12* notice, this list of conditions and the following disclaimer in the13* documentation and/or other materials provided with the distribution.14*15* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND16* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE17* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE18* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE19* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL20* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS21* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)22* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT23* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY24* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF25* SUCH DAMAGE.26*/27#ifndef __RTLBT_HW_H__28#define __RTLBT_HW_H__2930#include <netgraph/bluetooth/include/ng_hci.h>3132/* USB control request (HCI command) structure */33struct rtlbt_hci_cmd {34uint16_t opcode;35uint8_t length;36uint8_t data[];37} __attribute__ ((packed));3839#define RTLBT_HCI_CMD_SIZE(cmd) \40((cmd)->length + offsetof(struct rtlbt_hci_cmd, data))4142/* USB interrupt transfer HCI event header structure */43struct rtlbt_hci_evhdr {44uint8_t event;45uint8_t length;46} __attribute__ ((packed));4748/* USB interrupt transfer (generic HCI event) structure */49struct rtlbt_hci_event {50struct rtlbt_hci_evhdr header;51uint8_t data[];52} __attribute__ ((packed));5354/* USB interrupt transfer (HCI command completion event) structure */55struct rtlbt_hci_event_cmd_compl {56struct rtlbt_hci_evhdr header;57uint8_t numpkt;58uint16_t opcode;59uint8_t data[];60} __attribute__ ((packed));6162#define RTLBT_HCI_EVT_COMPL_SIZE(payload) \63(offsetof(struct rtlbt_hci_event_cmd_compl, data) + sizeof(payload))6465#define RTLBT_CONTROL_ENDPOINT_ADDR 0x0066#define RTLBT_INTERRUPT_ENDPOINT_ADDR 0x816768#define RTLBT_HCI_MAX_CMD_SIZE 25669#define RTLBT_HCI_MAX_EVENT_SIZE 167071#define RTLBT_MSEC2TS(msec) \72(struct timespec) { \73.tv_sec = (msec) / 1000, \74.tv_nsec = ((msec) % 1000) * 1000000 \75};76#define RTLBT_TS2MSEC(ts) ((ts).tv_sec * 1000 + (ts).tv_nsec / 1000000)77#define RTLBT_HCI_CMD_TIMEOUT 2000 /* ms */78#define RTLBT_LOADCMPL_TIMEOUT 5000 /* ms */7980#define RTLBT_MAX_CMD_DATA_LEN 2528182struct rtlbt_rom_ver_rp {83uint8_t status;84uint8_t version;85} __attribute__ ((packed));8687struct rtlbt_hci_dl_cmd {88uint8_t index;89uint8_t data[RTLBT_MAX_CMD_DATA_LEN];90} __attribute__ ((packed));9192struct rtlbt_hci_dl_rp {93uint8_t status;94uint8_t index;95} __attribute__ ((packed));9697/* Vendor USB request payload */98struct rtlbt_vendor_cmd {99uint8_t data[5];100} __attribute__ ((packed));101#define RTLBT_SEC_PROJ (&(struct rtlbt_vendor_cmd) {{0x10, 0xA4, 0x0D, 0x00, 0xb0}})102103struct rtlbt_vendor_rp {104uint8_t status;105uint8_t data[2];106};107108int rtlbt_read_local_ver(struct libusb_device_handle *hdl,109ng_hci_read_local_ver_rp *ver);110int rtlbt_read_rom_ver(struct libusb_device_handle *hdl, uint8_t *ver);111int rtlbt_read_reg16(struct libusb_device_handle *hdl,112struct rtlbt_vendor_cmd *cmd, uint8_t *resp);113int rtlbt_load_fwfile(struct libusb_device_handle *hdl,114const struct rtlbt_firmware *fw);115116#endif117118119