1 /* 2 * Copyright (c) 2021 Chipsea Technologies (Shenzhen) Corp., Ltd. All rights reserved. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 #ifndef RWBLE_HL_CONFIG_H_ 16 #define RWBLE_HL_CONFIG_H_ 17 18 #include "ble_hl_error.h" 19 20 /// Data packet transmission size and duration 21 /// These values represent what the device supports 22 #define BLE_MIN_OCTETS (27) // number of octets 23 #define BLE_MIN_TIME (328) // in us 24 #define BLE_MAX_OCTETS (251) // number of octets 25 #define BLE_MAX_TIME (17040) // in us 26 27 /// Maximum time to remain advertising when in the Limited 28 /// Discover able mode: TGAP(lim_adv_timeout) 29 /// required value: 180s: (18000 for ke timer) 30 #define GAP_TMR_LIM_ADV_TIMEOUT 0x4650 31 32 /// Minimum time to perform scanning when performing 33 /// the General Discovery procedure: TGAP(gen_disc_scan_min) 34 /// recommended value: 10.24s: (1024 for ke timer) 35 #define GAP_TMR_GEN_DISC_SCAN 0x0400 36 37 /// Minimum time to perform scanning when performing the 38 /// Limited Discovery procedure: TGAP(lim_disc_scan_min) 39 /// recommended value: 10.24s: (1024 for ke timer) 40 #define GAP_TMR_LIM_DISC_SCAN 0x0400 41 42 /// Minimum time interval between private address change 43 /// TGAP(private_addr_int) 44 /// recommended value: 15 minutes 45 /// Minimum value 150s 46 #define GAP_TMR_PRIV_ADDR_MIN (150) 47 /// Maximum time interval between private address change 48 /// 0xA1B8 (approximately 11.5 hours) 49 #define GAP_TMR_PRIV_ADDR_MAX (0xA1B8) 50 51 52 /// Timer used in connection parameter update procedure 53 /// TGAP(conn_param_timeout) 54 /// recommended value: 30 s: (3000 for ke timer) 55 #define GAP_TMR_CONN_PARAM_TIMEOUT 0x0BB8 56 57 /// Timer used in LE credit based connection procedure 58 /// TGAP(lecb_conn_timeout) 59 /// recommended value: 30 s: (3000 for ke timer) 60 #define GAP_TMR_LECB_CONN_TIMEOUT 0x0BB8 61 62 /// Timer used in LE credit based disconnection procedure 63 /// TGAP(lecb_disconn_timeout) 64 /// recommended value: 30 s: (3000 for ke timer) 65 #define GAP_TMR_LECB_DISCONN_TIMEOUT 0x0BB8 66 67 /// Maximal authorized MTU value - Implementation supports up to (2^12 -1) = 4095 bytes 68 #define GAP_MAX_LE_MTU (2048) 69 70 /// Maximum GAP device name size 71 #define GAP_MAX_NAME_SIZE (0x20) 72 73 74 75 76 /// Maximum Transmission Unit 77 #define ATT_DEFAULT_MTU (23) 78 /// 30 seconds transaction timer 79 #define ATT_TRANS_RTX (0x0BB8) 80 /// Acceptable encryption key size - strict access 81 #define ATT_SEC_ENC_KEY_SIZE (0x10) 82 83 84 /// Maximum attribute value length 85 #define ATT_MAX_VALUE (GAP_MAX_LE_MTU) 86 87 88 /******************************************************************************************/ 89 /* ------------------------- BLE PARTITIONING -------------------------------------*/ 90 /******************************************************************************************/ 91 92 93 /******************************************************************************************/ 94 /* -------------------------- INTERFACES ----------------------------------------*/ 95 /******************************************************************************************/ 96 97 98 #if BLE_APP_PRESENT 99 #define APP_MAIN_TASK TASK_APP 100 #else // BLE_APP_PRESENT 101 #define APP_MAIN_TASK TASK_AHI 102 #endif // BLE_APP_PRESENT 103 104 // Host Controller Interface (Host side) 105 #define BLEHL_HCIH_ITF HCIH_ITF 106 107 /******************************************************************************************/ 108 /* -------------------------- COEX SETUP ----------------------------------------*/ 109 /******************************************************************************************/ 110 111 ///WLAN coex 112 #define BLEHL_WLAN_COEX RW_WLAN_COEX 113 ///WLAN test mode 114 #define BLEHL_WLAN_COEX_TEST RW_WLAN_COEX_TEST 115 116 /******************************************************************************************/ 117 /* -------------------------- HOST MODULES ----------------------------------------*/ 118 /******************************************************************************************/ 119 120 #define BLE_GAPM 1 121 #if (BLE_OBSERVER) 122 #define BLE_GAPM_HEAP_ENV_SIZE (sizeof(struct gapm_actv_scan_tag) + KE_HEAP_MEM_RESERVED) 123 #elif (BLE_PERIPHERAL) 124 #define BLE_GAPM_HEAP_ENV_SIZE (sizeof(struct gapm_actv_adv_tag) + KE_HEAP_MEM_RESERVED) 125 #else //(BLE_PERIPHERAL) 126 #define BLE_GAPM_HEAP_ENV_SIZE 0 127 #endif //(BLE_PERIPHERAL) 128 129 #if (BLE_CENTRAL || BLE_PERIPHERAL) 130 #define BLE_GAPC 1 131 #define BLE_GAPC_HEAP_ENV_SIZE (sizeof(struct gapc_env_tag) + KE_HEAP_MEM_RESERVED) 132 #else //(BLE_CENTRAL || BLE_PERIPHERAL) 133 #define BLE_GAPC 0 134 #define BLE_GAPC_HEAP_ENV_SIZE 0 135 #endif //(BLE_CENTRAL || BLE_PERIPHERAL) 136 137 #if (BLE_CENTRAL || BLE_PERIPHERAL) 138 #define BLE_L2CM 1 139 #define BLE_L2CC 1 140 #define BLE_ATTM 1 141 #define BLE_GATTM 1 142 #define BLE_GATTC 1 143 #define BLE_GATTC_HEAP_ENV_SIZE (sizeof(struct gattc_env_tag) + KE_HEAP_MEM_RESERVED) 144 #define BLE_L2CC_HEAP_ENV_SIZE (sizeof(struct l2cc_env_tag) + KE_HEAP_MEM_RESERVED) 145 #else //(BLE_CENTRAL || BLE_PERIPHERAL) 146 #define BLE_L2CM 0 147 #define BLE_L2CC 0 148 #define BLE_ATTC 0 149 #define BLE_ATTS 0 150 #define BLE_ATTM 0 151 #define BLE_GATTM 0 152 #define BLE_GATTC 0 153 #define BLE_GATTC_HEAP_ENV_SIZE 0 154 #define BLE_L2CC_HEAP_ENV_SIZE 0 155 #endif //(BLE_CENTRAL || BLE_PERIPHERAL) 156 157 #define BLE_SMPM 1 158 #if (BLE_CENTRAL || BLE_PERIPHERAL) 159 #define BLE_SMPC 1 160 #else //(BLE_CENTRAL || BLE_PERIPHERAL) 161 #define BLE_SMPC 0 162 #endif //(BLE_CENTRAL || BLE_PERIPHERAL) 163 164 165 /******************************************************************************************/ 166 /* -------------------------- ATT DB ----------------------------------------*/ 167 /******************************************************************************************/ 168 169 //ATT DB,Testing and Qualification related flags 170 #if (BLE_CENTRAL || BLE_PERIPHERAL) 171 /// Support of External DB Management 172 #if defined(CFG_EXT_DB) 173 #define BLE_EXT_ATT_DB 1 174 #else 175 #define BLE_EXT_ATT_DB 0 176 #endif // defined(CFG_EXT_DB) 177 #else 178 #define BLE_EXT_ATT_DB 0 179 #endif // (BLE_CENTRAL || BLE_PERIPHERAL) 180 /******************************************************************************************/ 181 /* -------------------------- PROFILES ----------------------------------------*/ 182 /******************************************************************************************/ 183 #ifdef CFG_PRF 184 #define BLE_PROFILES (1) 185 /// Number of Profile tasks managed by GAP manager. 186 #define BLE_NB_PROFILES (CFG_NB_PRF) 187 #include "ble_profile_config.h" 188 #else 189 #define BLE_PROFILES (0) 190 #define BLE_NB_PROFILES (0) 191 #endif // CFG_PRF 192 193 194 #ifndef BLE_ATTS 195 #if (BLE_CENTRAL || BLE_PERIPHERAL || defined(CFG_ATTS)) 196 #define BLE_ATTS 1 197 #else 198 #define BLE_ATTS 0 199 #endif // (BLE_CENTRAL || BLE_PERIPHERAL || defined(CFG_ATTS)) 200 #endif // BLE_ATTS 201 202 203 #ifndef BLE_ATTC 204 #if (BLE_CENTRAL || defined(CFG_ATTC)) 205 #define BLE_ATTC 1 206 #else 207 #define BLE_ATTC 0 208 #endif // (BLE_CENTRAL || defined(CFG_ATTC)) 209 #endif // BLE_ATTC 210 211 #ifndef BLE_LECB 212 #if (BLE_CENTRAL || BLE_PERIPHERAL) 213 #define BLE_LECB 1 214 #else 215 #define BLE_LECB 0 216 #endif // (BLE_CENTRAL || defined(CFG_ATTC)) 217 #endif // BLE_ATTC 218 219 220 /// Attribute Server 221 #if (BLE_ATTS) 222 #define BLE_ATTS 1 223 #else 224 #define BLE_ATTS 0 225 #endif //(BLE_ATTS) 226 227 228 /// Size of the heap 229 #if (BLE_CENTRAL || BLE_PERIPHERAL) 230 /// some heap must be reserved for attribute database 231 #if (BLE_ATTS || BLE_ATTC) 232 /// Can be tuned based on supported profiles 233 #if PLF_BT_STACK 234 #ifdef CFG_BLE_ONLY 235 #define BLEHL_HEAP_DB_SIZE (3072) 236 #else 237 #define BLEHL_HEAP_DB_SIZE (256) 238 #endif 239 #else 240 #define BLEHL_HEAP_DB_SIZE (3072) 241 #endif 242 #else 243 #define BLEHL_HEAP_DB_SIZE (0) 244 #endif /* (BLE_ATTS || BLE_ATTC) */ 245 246 #if (BLE_EMB_PRESENT) 247 /// Needed "security" heap size for reception of max supported MTU through prepare write procedure 248 /// If retention memory is used, this additionnal heap can be part of the size allocated for the retention memory 249 #define BLEHL_HEAP_DATA_THP_SIZE (3 * GAP_MAX_LE_MTU) 250 #else // !(BLE_EMB_PRESENT) 251 #if PLF_BT_STACK 252 #ifdef CFG_BLE_ONLY 253 #define BLEHL_HEAP_DATA_THP_SIZE (4 * GAP_MAX_LE_MTU) 254 #else 255 #define BLEHL_HEAP_DATA_THP_SIZE (GAP_MAX_LE_MTU) 256 #endif 257 #else 258 #define BLEHL_HEAP_DATA_THP_SIZE (4 * GAP_MAX_LE_MTU) 259 #endif 260 #endif // (BLE_EMB_PRESENT) 261 #if (SECURE_CONNECTIONS) 262 /// Need more heap because of structure allocated for secure connection 263 #define BLEHL_HEAP_MSG_SIZE_PER_CON (400) 264 #else 265 #define BLEHL_HEAP_MSG_SIZE_PER_CON (256) 266 #endif //(SECURE_CONNECTIONS) 267 268 #define BLEHL_HEAP_MSG_SIZE (((BLEHL_HEAP_MSG_SIZE_PER_CON * BLE_CONNECTION_MAX) > BLEHL_HEAP_DATA_THP_SIZE) \ 269 ? (BLEHL_HEAP_MSG_SIZE_PER_CON * BLE_CONNECTION_MAX) : BLEHL_HEAP_DATA_THP_SIZE) 270 #elif (BLE_MESH) 271 #define BLEHL_HEAP_MSG_SIZE (1024) 272 #define BLEHL_HEAP_DB_SIZE (3072) 273 #else 274 #define BLEHL_HEAP_MSG_SIZE (256) 275 #define BLEHL_HEAP_DB_SIZE (0) 276 #endif /* #if (BLE_CENTRAL || BLE_PERIPHERAL) */ 277 278 279 280 281 /// Number of BLE HL tasks 282 #define BLEHL_TASK_SIZE BLE_HOST_TASK_SIZE + BLE_PRF_TASK_SIZE 283 284 /// Size of environment variable needed on BLE Host Stack for one link 285 #define BLEHL_HEAP_ENV_SIZE ( BLE_CONNECTION_MAX * ( BLE_GAPC_HEAP_ENV_SIZE \ 286 + BLE_GATTC_HEAP_ENV_SIZE \ 287 + BLE_L2CC_HEAP_ENV_SIZE ) \ 288 + BLE_ACTIVITY_MAX * BLE_GAPM_HEAP_ENV_SIZE ) 289 290 #endif // RWBLE_HL_CONFIG_H_ 291