1 /*- 2 * SPDX-License-Identifier: BSD-2-Clause 3 * 4 * Copyright (c) 2013 Adrian Chadd <adrian@freebsd.org> 5 * Copyright (c) 2019 Vladimir Kondratyev <wulf@FreeBSD.org> 6 * Copyright (c) 2023 Future Crew LLC. 7 * 8 * Redistribution and use in source and binary forms, with or without 9 * modification, are permitted provided that the following conditions 10 * are met: 11 * 1. Redistributions of source code must retain the above copyright 12 * notice, this list of conditions and the following disclaimer. 13 * 2. Redistributions in binary form must reproduce the above copyright 14 * notice, this list of conditions and the following disclaimer in the 15 * documentation and/or other materials provided with the distribution. 16 * 17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27 * SUCH DAMAGE. 28 */ 29 30 #ifndef __RTLBT_FW_H__ 31 #define __RTLBT_FW_H__ 32 33 #include <stdbool.h> 34 35 #define RTLBT_ROM_LMP_8703B 0x8703 36 #define RTLBT_ROM_LMP_8723A 0x1200 37 #define RTLBT_ROM_LMP_8723B 0x8723 38 #define RTLBT_ROM_LMP_8821A 0x8821 39 #define RTLBT_ROM_LMP_8761A 0x8761 40 #define RTLBT_ROM_LMP_8822B 0x8822 41 #define RTLBT_ROM_LMP_8852A 0x8852 42 #define RTLBT_ROM_LMP_8851B 0x8851 43 44 enum rtlbt_fw_type { 45 RTLBT_FW_TYPE_UNKNOWN, 46 RTLBT_FW_TYPE_V1, 47 #ifdef RTLBTFW_SUPPORTS_FW_V2 48 RTLBT_FW_TYPE_V2, 49 #endif 50 }; 51 52 struct rtlbt_id_table { 53 uint16_t lmp_subversion; 54 uint16_t hci_revision; 55 uint8_t hci_version; 56 uint8_t flags; 57 #define RTLBT_IC_FLAG_SIMPLE (0 << 1) 58 #define RTLBT_IC_FLAG_CONFIG (1 << 1) 59 #define RTLBT_IC_FLAG_MSFT (2 << 1) 60 const char *fw_name; 61 }; 62 63 struct rtlbt_firmware { 64 char *fwname; 65 size_t len; 66 unsigned char *buf; 67 }; 68 69 struct rtlbt_fw_header_v1 { 70 uint8_t signature[8]; 71 uint32_t fw_version; 72 uint16_t num_patches; 73 } __attribute__ ((packed)); 74 75 struct rtlbt_fw_header_v2 { 76 uint8_t signature[8]; 77 uint8_t fw_version[8]; 78 uint32_t num_sections; 79 } __attribute__ ((packed)); 80 81 int rtlbt_fw_read(struct rtlbt_firmware *fw, const char *fwname); 82 void rtlbt_fw_free(struct rtlbt_firmware *fw); 83 char *rtlbt_get_fwname(const char *fw_name, const char *prefix, 84 const char *suffix); 85 const struct rtlbt_id_table *rtlbt_get_ic(uint16_t lmp_subversion, 86 uint16_t hci_revision, uint8_t hci_version); 87 enum rtlbt_fw_type rtlbt_get_fw_type(struct rtlbt_firmware *fw, 88 uint16_t *fw_lmp_subversion); 89 int rtlbt_parse_fwfile_v1(struct rtlbt_firmware *fw, uint8_t rom_version); 90 int rtlbt_append_fwfile(struct rtlbt_firmware *fw, struct rtlbt_firmware *opt); 91 92 #endif 93