1 /* 2 * SPDX-FileCopyrightText: 2015-2021 Espressif Systems (Shanghai) CO LTD 3 * 4 * SPDX-License-Identifier: Apache-2.0 5 */ 6 7 #ifndef __ESP_BT_DEFS_H__ 8 #define __ESP_BT_DEFS_H__ 9 10 #include <stdint.h> 11 #include <stdbool.h> 12 13 #ifdef __cplusplus 14 extern "C" { 15 #endif 16 17 #define ESP_BLUEDROID_STATUS_CHECK(status) \ 18 if (esp_bluedroid_get_status() != (status)) { \ 19 return ESP_ERR_INVALID_STATE; \ 20 } 21 22 #define ESP_BT_STATUS_BASE_FOR_HCI_ERR 0X0100 /* base for coverting HCI error code to ESP status */ 23 24 /* relate to BT_STATUS_xxx in bt_def.h */ 25 /// Status Return Value 26 typedef enum { 27 ESP_BT_STATUS_SUCCESS = 0, /* relate to BT_STATUS_SUCCESS in bt_def.h */ 28 ESP_BT_STATUS_FAIL, /* relate to BT_STATUS_FAIL in bt_def.h */ 29 ESP_BT_STATUS_NOT_READY, /* relate to BT_STATUS_NOT_READY in bt_def.h */ 30 ESP_BT_STATUS_NOMEM, /* relate to BT_STATUS_NOMEM in bt_def.h */ 31 ESP_BT_STATUS_BUSY, /* relate to BT_STATUS_BUSY in bt_def.h */ 32 ESP_BT_STATUS_DONE = 5, /* relate to BT_STATUS_DONE in bt_def.h */ 33 ESP_BT_STATUS_UNSUPPORTED, /* relate to BT_STATUS_UNSUPPORTED in bt_def.h */ 34 ESP_BT_STATUS_PARM_INVALID, /* relate to BT_STATUS_PARM_INVALID in bt_def.h */ 35 ESP_BT_STATUS_UNHANDLED, /* relate to BT_STATUS_UNHANDLED in bt_def.h */ 36 ESP_BT_STATUS_AUTH_FAILURE, /* relate to BT_STATUS_AUTH_FAILURE in bt_def.h */ 37 ESP_BT_STATUS_RMT_DEV_DOWN = 10, /* relate to BT_STATUS_RMT_DEV_DOWN in bt_def.h */ 38 ESP_BT_STATUS_AUTH_REJECTED, /* relate to BT_STATUS_AUTH_REJECTED in bt_def.h */ 39 ESP_BT_STATUS_INVALID_STATIC_RAND_ADDR, /* relate to BT_STATUS_INVALID_STATIC_RAND_ADDR in bt_def.h */ 40 ESP_BT_STATUS_PENDING, /* relate to BT_STATUS_PENDING in bt_def.h */ 41 ESP_BT_STATUS_UNACCEPT_CONN_INTERVAL, /* relate to BT_UNACCEPT_CONN_INTERVAL in bt_def.h */ 42 ESP_BT_STATUS_PARAM_OUT_OF_RANGE, /* relate to BT_PARAM_OUT_OF_RANGE in bt_def.h */ 43 ESP_BT_STATUS_TIMEOUT, /* relate to BT_STATUS_TIMEOUT in bt_def.h */ 44 ESP_BT_STATUS_PEER_LE_DATA_LEN_UNSUPPORTED, /* relate to BTM_PEER_LE_DATA_LEN_UNSUPPORTED in stack/btm_api.h */ 45 ESP_BT_STATUS_CONTROL_LE_DATA_LEN_UNSUPPORTED,/* relate to BTM_CONTROL_LE_DATA_LEN_UNSUPPORTED in stack/btm_api.h */ 46 ESP_BT_STATUS_ERR_ILLEGAL_PARAMETER_FMT, /* relate to HCI_ERR_ILLEGAL_PARAMETER_FMT in stack/hcidefs.h */ 47 ESP_BT_STATUS_MEMORY_FULL = 20, /* relate to BT_STATUS_MEMORY_FULL in bt_def.h */ 48 ESP_BT_STATUS_EIR_TOO_LARGE, /* relate to BT_STATUS_EIR_TOO_LARGE in bt_def.h */ 49 ESP_BT_STATUS_HCI_SUCCESS = ESP_BT_STATUS_BASE_FOR_HCI_ERR, 50 ESP_BT_STATUS_HCI_PENDING, 51 ESP_BT_STATUS_HCI_ILLEGAL_COMMAND, 52 ESP_BT_STATUS_HCI_NO_CONNECTION, 53 ESP_BT_STATUS_HCI_HW_FAILURE, 54 ESP_BT_STATUS_HCI_PAGE_TIMEOUT, 55 ESP_BT_STATUS_HCI_AUTH_FAILURE, 56 ESP_BT_STATUS_HCI_KEY_MISSING, 57 ESP_BT_STATUS_HCI_MEMORY_FULL, 58 ESP_BT_STATUS_HCI_CONNECTION_TOUT, 59 ESP_BT_STATUS_HCI_MAX_NUM_OF_CONNECTIONS, 60 ESP_BT_STATUS_HCI_MAX_NUM_OF_SCOS, 61 ESP_BT_STATUS_HCI_CONNECTION_EXISTS, 62 ESP_BT_STATUS_HCI_COMMAND_DISALLOWED, 63 ESP_BT_STATUS_HCI_HOST_REJECT_RESOURCES, 64 ESP_BT_STATUS_HCI_HOST_REJECT_SECURITY, 65 ESP_BT_STATUS_HCI_HOST_REJECT_DEVICE, 66 ESP_BT_STATUS_HCI_HOST_TIMEOUT, 67 ESP_BT_STATUS_HCI_UNSUPPORTED_VALUE, 68 ESP_BT_STATUS_HCI_ILLEGAL_PARAMETER_FMT, 69 ESP_BT_STATUS_HCI_PEER_USER, 70 ESP_BT_STATUS_HCI_PEER_LOW_RESOURCES, 71 ESP_BT_STATUS_HCI_PEER_POWER_OFF, 72 ESP_BT_STATUS_HCI_CONN_CAUSE_LOCAL_HOST, 73 ESP_BT_STATUS_HCI_REPEATED_ATTEMPTS, 74 ESP_BT_STATUS_HCI_PAIRING_NOT_ALLOWED, 75 ESP_BT_STATUS_HCI_UNKNOWN_LMP_PDU, 76 ESP_BT_STATUS_HCI_UNSUPPORTED_REM_FEATURE, 77 ESP_BT_STATUS_HCI_SCO_OFFSET_REJECTED, 78 ESP_BT_STATUS_HCI_SCO_INTERVAL_REJECTED, 79 ESP_BT_STATUS_HCI_SCO_AIR_MODE, 80 ESP_BT_STATUS_HCI_INVALID_LMP_PARAM, 81 ESP_BT_STATUS_HCI_UNSPECIFIED, 82 ESP_BT_STATUS_HCI_UNSUPPORTED_LMP_PARAMETERS, 83 ESP_BT_STATUS_HCI_ROLE_CHANGE_NOT_ALLOWED, 84 ESP_BT_STATUS_HCI_LMP_RESPONSE_TIMEOUT, 85 ESP_BT_STATUS_HCI_LMP_ERR_TRANS_COLLISION, 86 ESP_BT_STATUS_HCI_LMP_PDU_NOT_ALLOWED, 87 ESP_BT_STATUS_HCI_ENCRY_MODE_NOT_ACCEPTABLE, 88 ESP_BT_STATUS_HCI_UNIT_KEY_USED, 89 ESP_BT_STATUS_HCI_QOS_NOT_SUPPORTED, 90 ESP_BT_STATUS_HCI_INSTANT_PASSED, 91 ESP_BT_STATUS_HCI_PAIRING_WITH_UNIT_KEY_NOT_SUPPORTED, 92 ESP_BT_STATUS_HCI_DIFF_TRANSACTION_COLLISION, 93 ESP_BT_STATUS_HCI_UNDEFINED_0x2B, 94 ESP_BT_STATUS_HCI_QOS_UNACCEPTABLE_PARAM, 95 ESP_BT_STATUS_HCI_QOS_REJECTED, 96 ESP_BT_STATUS_HCI_CHAN_CLASSIF_NOT_SUPPORTED, 97 ESP_BT_STATUS_HCI_INSUFFCIENT_SECURITY, 98 ESP_BT_STATUS_HCI_PARAM_OUT_OF_RANGE, 99 ESP_BT_STATUS_HCI_UNDEFINED_0x31, 100 ESP_BT_STATUS_HCI_ROLE_SWITCH_PENDING, 101 ESP_BT_STATUS_HCI_UNDEFINED_0x33, 102 ESP_BT_STATUS_HCI_RESERVED_SLOT_VIOLATION, 103 ESP_BT_STATUS_HCI_ROLE_SWITCH_FAILED, 104 ESP_BT_STATUS_HCI_INQ_RSP_DATA_TOO_LARGE, 105 ESP_BT_STATUS_HCI_SIMPLE_PAIRING_NOT_SUPPORTED, 106 ESP_BT_STATUS_HCI_HOST_BUSY_PAIRING, 107 ESP_BT_STATUS_HCI_REJ_NO_SUITABLE_CHANNEL, 108 ESP_BT_STATUS_HCI_CONTROLLER_BUSY, 109 ESP_BT_STATUS_HCI_UNACCEPT_CONN_INTERVAL, 110 ESP_BT_STATUS_HCI_DIRECTED_ADVERTISING_TIMEOUT, 111 ESP_BT_STATUS_HCI_CONN_TOUT_DUE_TO_MIC_FAILURE, 112 ESP_BT_STATUS_HCI_CONN_FAILED_ESTABLISHMENT, 113 ESP_BT_STATUS_HCI_MAC_CONNECTION_FAILED, 114 } esp_bt_status_t; 115 116 117 /*Define the bt octet 16 bit size*/ 118 #define ESP_BT_OCTET16_LEN 16 119 typedef uint8_t esp_bt_octet16_t[ESP_BT_OCTET16_LEN]; /* octet array: size 16 */ 120 121 #define ESP_BT_OCTET8_LEN 8 122 typedef uint8_t esp_bt_octet8_t[ESP_BT_OCTET8_LEN]; /* octet array: size 8 */ 123 124 typedef uint8_t esp_link_key[ESP_BT_OCTET16_LEN]; /* Link Key */ 125 126 /// Default GATT interface id 127 #define ESP_DEFAULT_GATT_IF 0xff 128 129 #define ESP_BLE_PRIM_ADV_INT_MIN 0x000020 /*!< Minimum advertising interval for undirected and low duty cycle directed advertising */ 130 #define ESP_BLE_PRIM_ADV_INT_MAX 0xFFFFFF /*!< Maximum advertising interval for undirected and low duty cycle directed advertising */ 131 #define ESP_BLE_CONN_INT_MIN 0x0006 /*!< relate to BTM_BLE_CONN_INT_MIN in stack/btm_ble_api.h */ 132 #define ESP_BLE_CONN_INT_MAX 0x0C80 /*!< relate to BTM_BLE_CONN_INT_MAX in stack/btm_ble_api.h */ 133 #define ESP_BLE_CONN_LATENCY_MAX 499 /*!< relate to ESP_BLE_CONN_LATENCY_MAX in stack/btm_ble_api.h */ 134 #define ESP_BLE_CONN_SUP_TOUT_MIN 0x000A /*!< relate to BTM_BLE_CONN_SUP_TOUT_MIN in stack/btm_ble_api.h */ 135 #define ESP_BLE_CONN_SUP_TOUT_MAX 0x0C80 /*!< relate to ESP_BLE_CONN_SUP_TOUT_MAX in stack/btm_ble_api.h */ 136 #define ESP_BLE_CONN_PARAM_UNDEF 0xffff /* use this value when a specific value not to be overwritten */ /* relate to ESP_BLE_CONN_PARAM_UNDEF in stack/btm_ble_api.h */ 137 #define ESP_BLE_SCAN_PARAM_UNDEF 0xffffffff /* relate to ESP_BLE_SCAN_PARAM_UNDEF in stack/btm_ble_api.h */ 138 139 /// Check the param is valid or not 140 #define ESP_BLE_IS_VALID_PARAM(x, min, max) (((x) >= (min) && (x) <= (max)) || ((x) == ESP_BLE_CONN_PARAM_UNDEF)) 141 142 /// UUID type 143 typedef struct { 144 #define ESP_UUID_LEN_16 2 145 #define ESP_UUID_LEN_32 4 146 #define ESP_UUID_LEN_128 16 147 uint16_t len; /*!< UUID length, 16bit, 32bit or 128bit */ 148 union { 149 uint16_t uuid16; /*!< 16bit UUID */ 150 uint32_t uuid32; /*!< 32bit UUID */ 151 uint8_t uuid128[ESP_UUID_LEN_128]; /*!< 128bit UUID */ 152 } uuid; /*!< UUID */ 153 } __attribute__((packed)) esp_bt_uuid_t; 154 155 /// Bluetooth device type 156 typedef enum { 157 ESP_BT_DEVICE_TYPE_BREDR = 0x01, 158 ESP_BT_DEVICE_TYPE_BLE = 0x02, 159 ESP_BT_DEVICE_TYPE_DUMO = 0x03, 160 } esp_bt_dev_type_t; 161 162 /// Bluetooth address length 163 #define ESP_BD_ADDR_LEN 6 164 165 /// Bluetooth device address 166 typedef uint8_t esp_bd_addr_t[ESP_BD_ADDR_LEN]; 167 168 /// BLE device address type 169 typedef enum { 170 BLE_ADDR_TYPE_PUBLIC = 0x00, 171 BLE_ADDR_TYPE_RANDOM = 0x01, 172 BLE_ADDR_TYPE_RPA_PUBLIC = 0x02, 173 BLE_ADDR_TYPE_RPA_RANDOM = 0x03, 174 } esp_ble_addr_type_t; 175 176 /// white list address type 177 typedef enum { 178 BLE_WL_ADDR_TYPE_PUBLIC = 0x00, 179 BLE_WL_ADDR_TYPE_RANDOM = 0x01, 180 } esp_ble_wl_addr_type_t; 181 182 /// Used to exchange the encryption key in the init key & response key 183 #define ESP_BLE_ENC_KEY_MASK (1 << 0) /* relate to BTM_BLE_ENC_KEY_MASK in stack/btm_api.h */ 184 /// Used to exchange the IRK key in the init key & response key 185 #define ESP_BLE_ID_KEY_MASK (1 << 1) /* relate to BTM_BLE_ID_KEY_MASK in stack/btm_api.h */ 186 /// Used to exchange the CSRK key in the init key & response key 187 #define ESP_BLE_CSR_KEY_MASK (1 << 2) /* relate to BTM_BLE_CSR_KEY_MASK in stack/btm_api.h */ 188 /// Used to exchange the link key(this key just used in the BLE & BR/EDR coexist mode) in the init key & response key 189 #define ESP_BLE_LINK_KEY_MASK (1 << 3) /* relate to BTM_BLE_LINK_KEY_MASK in stack/btm_api.h */ 190 typedef uint8_t esp_ble_key_mask_t; /* the key mask type */ 191 192 /// Minimum of the application id 193 #define ESP_APP_ID_MIN 0x0000 194 /// Maximum of the application id 195 #define ESP_APP_ID_MAX 0x7fff 196 197 #define ESP_BD_ADDR_STR "%02x:%02x:%02x:%02x:%02x:%02x" 198 #define ESP_BD_ADDR_HEX(addr) addr[0], addr[1], addr[2], addr[3], addr[4], addr[5] 199 200 #ifdef __cplusplus 201 } 202 #endif 203 204 #endif /* __ESP_BT_DEFS_H__ */ 205