Path: blob/main/usr.sbin/bluetooth/rtlbtfw/rtlbt_fw.h
106929 views
/*-1* SPDX-License-Identifier: BSD-2-Clause2*3* Copyright (c) 2013 Adrian Chadd <[email protected]>4* Copyright (c) 2019 Vladimir Kondratyev <[email protected]>5* Copyright (c) 2023 Future Crew LLC.6*7* Redistribution and use in source and binary forms, with or without8* modification, are permitted provided that the following conditions9* are met:10* 1. Redistributions of source code must retain the above copyright11* notice, this list of conditions and the following disclaimer.12* 2. Redistributions in binary form must reproduce the above copyright13* notice, this list of conditions and the following disclaimer in the14* documentation and/or other materials provided with the distribution.15*16* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND17* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE18* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE19* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE20* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL21* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS22* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)23* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT24* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY25* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF26* SUCH DAMAGE.27*/2829#ifndef __RTLBT_FW_H__30#define __RTLBT_FW_H__3132#include <sys/queue.h>33#include <sys/queue_mergesort.h>3435#define RTLBT_ROM_LMP_8703B 0x870336#define RTLBT_ROM_LMP_8723A 0x120037#define RTLBT_ROM_LMP_8723B 0x872338#define RTLBT_ROM_LMP_8821A 0x882139#define RTLBT_ROM_LMP_8761A 0x876140#define RTLBT_ROM_LMP_8822B 0x882241#define RTLBT_ROM_LMP_8852A 0x885242#define RTLBT_ROM_LMP_8851B 0x885143#define RTLBT_ROM_LMP_8922A 0x89224445#define RTLBT_PATCH_SNIPPETS 0x0146#define RTLBT_PATCH_DUMMY_HEADER 0x0247#define RTLBT_PATCH_SECURITY_HEADER 0x034849enum rtlbt_fw_type {50RTLBT_FW_TYPE_UNKNOWN,51RTLBT_FW_TYPE_V1,52RTLBT_FW_TYPE_V2,53};5455struct rtlbt_id_table {56uint16_t lmp_subversion;57uint16_t hci_revision;58uint8_t hci_version;59uint8_t flags;60#define RTLBT_IC_FLAG_SIMPLE (0 << 1)61#define RTLBT_IC_FLAG_CONFIG (1 << 1)62#define RTLBT_IC_FLAG_MSFT (2 << 1)63const char *fw_name;64const char *fw_suffix;65};6667struct rtlbt_firmware {68char *fwname;69size_t len;70unsigned char *buf;71};7273SLIST_HEAD(rtlbt_patch_list, rtlbt_patch_entry);7475struct rtlbt_patch_entry {76SLIST_ENTRY(rtlbt_patch_entry) next;77uint32_t opcode;78uint32_t len;79uint8_t prio;80uint8_t *data;81};8283struct rtlbt_iov {84uint8_t *data;85uint32_t len;86};8788struct rtlbt_fw_header_v1 {89uint8_t signature[8];90uint32_t fw_version;91uint16_t num_patches;92} __attribute__ ((packed));9394struct rtlbt_fw_header_v2 {95uint8_t signature[8];96uint8_t fw_version[8];97uint32_t num_sections;98} __attribute__ ((packed));99100struct rtlbt_section {101uint32_t opcode;102uint32_t len;103uint8_t data[];104} __attribute__ ((packed));105106struct rtlbt_sec_hdr {107uint16_t num;108uint16_t reserved;109} __attribute__ ((packed));110111struct rtlbt_subsec_hdr {112uint8_t eco;113uint8_t prio;114uint8_t cb[2];115uint32_t len;116} __attribute__ ((packed));117118struct rtlbt_subsec_security_hdr {119uint8_t eco;120uint8_t prio;121uint8_t key_id;122uint8_t reserved;123uint32_t len;124} __attribute__ ((packed));125126int rtlbt_fw_read(struct rtlbt_firmware *fw, const char *fwname);127void rtlbt_fw_free(struct rtlbt_firmware *fw);128char *rtlbt_get_fwname(const char *fw_name, const char *prefix,129const char *suffix);130const struct rtlbt_id_table *rtlbt_get_ic(uint16_t lmp_subversion,131uint16_t hci_revision, uint8_t hci_version);132enum rtlbt_fw_type rtlbt_get_fw_type(struct rtlbt_firmware *fw,133uint16_t *fw_lmp_subversion);134int rtlbt_parse_fwfile_v1(struct rtlbt_firmware *fw, uint8_t rom_version);135int rtlbt_parse_fwfile_v2(struct rtlbt_firmware *fw, uint8_t rom_version,136uint8_t reg_id);137int rtlbt_append_fwfile(struct rtlbt_firmware *fw, struct rtlbt_firmware *opt);138139#endif140141142