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 struct iwmbt_boot_params { 56 uint8_t status; 57 uint8_t otp_format; 58 uint8_t otp_content; 59 uint8_t otp_patch; 60 uint16_t dev_revid; 61 uint8_t secure_boot; 62 uint8_t key_from_hdr; 63 uint8_t key_type; 64 uint8_t otp_lock; 65 uint8_t api_lock; 66 uint8_t debug_lock; 67 uint8_t otp_bdaddr[6]; 68 uint8_t min_fw_build_nn; 69 uint8_t min_fw_build_cw; 70 uint8_t min_fw_build_yy; 71 uint8_t limited_cce; 72 uint8_t unlocked_state; 73 } __attribute__ ((packed)); 74 75 enum { 76 IWMBT_TLV_CNVI_TOP = 0x10, 77 IWMBT_TLV_CNVR_TOP, 78 IWMBT_TLV_CNVI_BT, 79 IWMBT_TLV_CNVR_BT, 80 IWMBT_TLV_CNVI_OTP, 81 IWMBT_TLV_CNVR_OTP, 82 IWMBT_TLV_DEV_REV_ID, 83 IWMBT_TLV_USB_VENDOR_ID, 84 IWMBT_TLV_USB_PRODUCT_ID, 85 IWMBT_TLV_PCIE_VENDOR_ID, 86 IWMBT_TLV_PCIE_DEVICE_ID, 87 IWMBT_TLV_PCIE_SUBSYSTEM_ID, 88 IWMBT_TLV_IMAGE_TYPE, 89 IWMBT_TLV_TIME_STAMP, 90 IWMBT_TLV_BUILD_TYPE, 91 IWMBT_TLV_BUILD_NUM, 92 IWMBT_TLV_FW_BUILD_PRODUCT, 93 IWMBT_TLV_FW_BUILD_HW, 94 IWMBT_TLV_FW_STEP, 95 IWMBT_TLV_BT_SPEC, 96 IWMBT_TLV_MFG_NAME, 97 IWMBT_TLV_HCI_REV, 98 IWMBT_TLV_LMP_SUBVER, 99 IWMBT_TLV_OTP_PATCH_VER, 100 IWMBT_TLV_SECURE_BOOT, 101 IWMBT_TLV_KEY_FROM_HDR, 102 IWMBT_TLV_OTP_LOCK, 103 IWMBT_TLV_API_LOCK, 104 IWMBT_TLV_DEBUG_LOCK, 105 IWMBT_TLV_MIN_FW, 106 IWMBT_TLV_LIMITED_CCE, 107 IWMBT_TLV_SBE_TYPE, 108 IWMBT_TLV_OTP_BDADDR, 109 IWMBT_TLV_UNLOCKED_STATE 110 }; 111 112 struct iwmbt_version_tlv { 113 uint32_t cnvi_top; 114 uint32_t cnvr_top; 115 uint32_t cnvi_bt; 116 uint32_t cnvr_bt; 117 uint16_t dev_rev_id; 118 uint8_t img_type; 119 uint16_t timestamp; 120 uint8_t build_type; 121 uint32_t build_num; 122 uint8_t secure_boot; 123 uint8_t otp_lock; 124 uint8_t api_lock; 125 uint8_t debug_lock; 126 uint8_t min_fw_build_nn; 127 uint8_t min_fw_build_cw; 128 uint8_t min_fw_build_yy; 129 uint8_t limited_cce; 130 uint8_t sbe_type; 131 bdaddr_t otp_bd_addr; 132 }; 133 134 struct iwmbt_firmware { 135 char *fwname; 136 int len; 137 unsigned char *buf; 138 }; 139 140 extern int iwmbt_fw_read(struct iwmbt_firmware *fw, const char *fwname); 141 extern void iwmbt_fw_free(struct iwmbt_firmware *fw); 142 extern char *iwmbt_get_fwname(struct iwmbt_version *ver, 143 struct iwmbt_boot_params *params, const char *prefix, 144 const char *suffix); 145 extern char *iwmbt_get_fwname_tlv(struct iwmbt_version_tlv *ver, 146 const char *prefix, const char *suffix); 147 148 #endif 149