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 __IWMBT_FW_H__ 31 #define __IWMBT_FW_H__ 32 33 #include <sys/types.h> 34 #define L2CAP_SOCKET_CHECKED 35 #include <bluetooth.h> 36 37 #define RSA_HEADER_LEN 644 38 #define ECDSA_HEADER_LEN 320 39 #define ECDSA_OFFSET RSA_HEADER_LEN 40 #define CSS_HEADER_OFFSET 8 41 42 struct iwmbt_version { 43 uint8_t status; 44 uint8_t hw_platform; 45 uint8_t hw_variant; 46 uint8_t hw_revision; 47 uint8_t fw_variant; 48 uint8_t fw_revision; 49 uint8_t fw_build_num; 50 uint8_t fw_build_ww; 51 uint8_t fw_build_yy; 52 uint8_t fw_patch_num; 53 } __attribute__ ((packed)); 54 55 /* Known values for fw_variant */ 56 #define FW_VARIANT_BOOTLOADER 0x06 /* Bootloader mode */ 57 #define FW_VARIANT_OPERATIONAL 0x23 /* Operational mode */ 58 59 struct iwmbt_boot_params { 60 uint8_t status; 61 uint8_t otp_format; 62 uint8_t otp_content; 63 uint8_t otp_patch; 64 uint16_t dev_revid; 65 uint8_t secure_boot; 66 uint8_t key_from_hdr; 67 uint8_t key_type; 68 uint8_t otp_lock; 69 uint8_t api_lock; 70 uint8_t debug_lock; 71 uint8_t otp_bdaddr[6]; 72 uint8_t min_fw_build_nn; 73 uint8_t min_fw_build_cw; 74 uint8_t min_fw_build_yy; 75 uint8_t limited_cce; 76 uint8_t unlocked_state; 77 } __attribute__ ((packed)); 78 79 enum { 80 IWMBT_TLV_CNVI_TOP = 0x10, 81 IWMBT_TLV_CNVR_TOP, 82 IWMBT_TLV_CNVI_BT, 83 IWMBT_TLV_CNVR_BT, 84 IWMBT_TLV_CNVI_OTP, 85 IWMBT_TLV_CNVR_OTP, 86 IWMBT_TLV_DEV_REV_ID, 87 IWMBT_TLV_USB_VENDOR_ID, 88 IWMBT_TLV_USB_PRODUCT_ID, 89 IWMBT_TLV_PCIE_VENDOR_ID, 90 IWMBT_TLV_PCIE_DEVICE_ID, 91 IWMBT_TLV_PCIE_SUBSYSTEM_ID, 92 IWMBT_TLV_IMAGE_TYPE, 93 IWMBT_TLV_TIME_STAMP, 94 IWMBT_TLV_BUILD_TYPE, 95 IWMBT_TLV_BUILD_NUM, 96 IWMBT_TLV_FW_BUILD_PRODUCT, 97 IWMBT_TLV_FW_BUILD_HW, 98 IWMBT_TLV_FW_STEP, 99 IWMBT_TLV_BT_SPEC, 100 IWMBT_TLV_MFG_NAME, 101 IWMBT_TLV_HCI_REV, 102 IWMBT_TLV_LMP_SUBVER, 103 IWMBT_TLV_OTP_PATCH_VER, 104 IWMBT_TLV_SECURE_BOOT, 105 IWMBT_TLV_KEY_FROM_HDR, 106 IWMBT_TLV_OTP_LOCK, 107 IWMBT_TLV_API_LOCK, 108 IWMBT_TLV_DEBUG_LOCK, 109 IWMBT_TLV_MIN_FW, 110 IWMBT_TLV_LIMITED_CCE, 111 IWMBT_TLV_SBE_TYPE, 112 IWMBT_TLV_OTP_BDADDR, 113 IWMBT_TLV_UNLOCKED_STATE 114 }; 115 116 struct iwmbt_version_tlv { 117 uint32_t cnvi_top; 118 uint32_t cnvr_top; 119 uint32_t cnvi_bt; 120 uint32_t cnvr_bt; 121 uint16_t dev_rev_id; 122 uint8_t img_type; 123 uint16_t timestamp; 124 uint8_t build_type; 125 uint32_t build_num; 126 uint8_t secure_boot; 127 uint8_t otp_lock; 128 uint8_t api_lock; 129 uint8_t debug_lock; 130 uint8_t min_fw_build_nn; 131 uint8_t min_fw_build_cw; 132 uint8_t min_fw_build_yy; 133 uint8_t limited_cce; 134 uint8_t sbe_type; 135 bdaddr_t otp_bd_addr; 136 }; 137 138 /* Known TLV img_type values */ 139 #define TLV_IMG_TYPE_BOOTLOADER 0x01 /* Bootloader mode */ 140 #define TLV_IMG_TYPE_OPERATIONAL 0x03 /* Operational mode */ 141 142 struct iwmbt_firmware { 143 char *fwname; 144 int len; 145 unsigned char *buf; 146 }; 147 148 extern int iwmbt_fw_read(struct iwmbt_firmware *fw, const char *fwname); 149 extern void iwmbt_fw_free(struct iwmbt_firmware *fw); 150 extern char *iwmbt_get_fwname(struct iwmbt_version *ver, 151 struct iwmbt_boot_params *params, const char *prefix, 152 const char *suffix); 153 extern char *iwmbt_get_fwname_tlv(struct iwmbt_version_tlv *ver, 154 const char *prefix, const char *suffix); 155 156 #endif 157