Path: blob/main/usr.sbin/bluetooth/iwmbtfw/iwmbt_hw.h
108696 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 __IWMBT_HW_H__28#define __IWMBT_HW_H__2930/* USB control request (HCI command) structure */31struct iwmbt_hci_cmd {32uint16_t opcode;33uint8_t length;34uint8_t data[];35} __attribute__ ((packed));3637#define IWMBT_HCI_CMD_SIZE(cmd) \38((cmd)->length + offsetof(struct iwmbt_hci_cmd, data))3940/* USB interrupt transfer HCI event header structure */41struct iwmbt_hci_evhdr {42uint8_t event;43uint8_t length;44} __attribute__ ((packed));4546/* USB interrupt transfer (generic HCI event) structure */47struct iwmbt_hci_event {48struct iwmbt_hci_evhdr header;49uint8_t data[];50} __attribute__ ((packed));5152/* USB interrupt transfer (HCI command completion event) structure */53struct iwmbt_hci_event_cmd_compl {54struct iwmbt_hci_evhdr header;55uint8_t numpkt;56uint16_t opcode;57uint8_t data[];58} __attribute__ ((packed));5960/*61* Manufacturer mode exit type: selects reset type,62* 0x00: simply exit manufacturer mode without a reset.63* 0x01: exit manufacturer mode with a reset and patches disabled64* 0x02: exit manufacturer mode with a reset and patches enabled65*/66enum iwmbt_mm_exit {67IWMBT_MM_EXIT_ONLY = 0x00,68IWMBT_MM_EXIT_COLD_RESET = 0x01,69IWMBT_MM_EXIT_WARM_RESET = 0x02,70};7172#define IWMBT_HCI_EVT_COMPL_SIZE(payload) \73(offsetof(struct iwmbt_hci_event_cmd_compl, data) + sizeof(payload))74#define IWMBT_HCI_EVENT_COMPL_HEAD_SIZE \75(offsetof(struct iwmbt_hci_event_cmd_compl, data) - \76offsetof(struct iwmbt_hci_event_cmd_compl, numpkt))7778#define IWMBT_CONTROL_ENDPOINT_ADDR 0x0079#define IWMBT_INTERRUPT_ENDPOINT_ADDR 0x8180#define IWMBT_BULK_IN_ENDPOINT_ADDR 0x8281#define IWMBT_BULK_OUT_ENDPOINT_ADDR 0x028283#define IWMBT_HCI_MAX_CMD_SIZE 25684#define IWMBT_HCI_MAX_EVENT_SIZE 168586#define IWMBT_MSEC2TS(msec) \87(struct timespec) { \88.tv_sec = (msec) / 1000, \89.tv_nsec = ((msec) % 1000) * 1000000 \90};91#define IWMBT_TS2MSEC(ts) ((ts).tv_sec * 1000 + (ts).tv_nsec / 1000000)92#define IWMBT_HCI_CMD_TIMEOUT 2000 /* ms */93#define IWMBT_LOADCMPL_TIMEOUT 5000 /* ms */9495extern int iwmbt_patch_fwfile(struct libusb_device_handle *hdl,96const struct iwmbt_firmware *fw);97extern int iwmbt_load_rsa_header(struct libusb_device_handle *hdl,98const struct iwmbt_firmware *fw);99extern int iwmbt_load_ecdsa_header(struct libusb_device_handle *hdl,100const struct iwmbt_firmware *fw);101extern int iwmbt_load_fwfile(struct libusb_device_handle *hdl,102const struct iwmbt_firmware *fw, uint32_t *boot_param, int offset);103extern int iwmbt_enter_manufacturer(struct libusb_device_handle *hdl);104extern int iwmbt_exit_manufacturer(struct libusb_device_handle *hdl,105enum iwmbt_mm_exit mode);106extern int iwmbt_get_version(struct libusb_device_handle *hdl,107struct iwmbt_version *version);108extern int iwmbt_get_version_tlv(struct libusb_device_handle *hdl,109struct iwmbt_version_tlv *version);110extern int iwmbt_get_boot_params(struct libusb_device_handle *hdl,111struct iwmbt_boot_params *params);112extern int iwmbt_intel_reset(struct libusb_device_handle *hdl,113uint32_t boot_param);114extern int iwmbt_load_ddc(struct libusb_device_handle *hdl,115const struct iwmbt_firmware *ddc);116extern int iwmbt_set_event_mask(struct libusb_device_handle *hdl);117118#endif119120121