1 /***************************************************************************** 2 * @file blestack.h 3 * 4 * @brief Header file for BLE stack 5 ***************************************************************************** 6 * @attention 7 * 8 * Copyright (c) 2018-2024 STMicroelectronics. 9 * All rights reserved. 10 * 11 * This software is licensed under terms that can be found in the LICENSE file 12 * in the root directory of this software component. 13 * If no LICENSE file comes with this software, it is provided AS-IS. 14 * 15 ***************************************************************************** 16 */ 17 18 #ifndef BLESTACK_H__ 19 #define BLESTACK_H__ 20 21 22 #include "auto/ble_types.h" 23 #include "ble_bufsize.h" 24 25 26 /* 27 * Definitions for return value of BleStack_Process( ) 28 */ 29 enum 30 { 31 BLE_SLEEPMODE_RUNNING = 0, 32 BLE_SLEEPMODE_CPU_HALT = 1, 33 BLE_SLEEPMODE_WAKETIMER = 2, 34 BLE_SLEEPMODE_NOTIMER = 3, 35 }; 36 37 /* 38 * Definitions for 'options' parameter 39 */ 40 enum 41 { 42 BLE_OPTIONS_LL_ONLY = 0x0001U, 43 BLE_OPTIONS_NO_SVC_CHANGE_DESC = 0x0002U, 44 BLE_OPTIONS_DEV_NAME_READ_ONLY = 0x0004U, 45 BLE_OPTIONS_EXTENDED_ADV = 0x0008U, 46 BLE_OPTIONS_REDUCED_DB_IN_NVM = 0x0020U, 47 BLE_OPTIONS_GATT_CACHING = 0x0040U, 48 BLE_OPTIONS_POWER_CLASS_1 = 0x0080U, 49 BLE_OPTIONS_APPEARANCE_WRITABLE = 0x0100U, 50 BLE_OPTIONS_ENHANCED_ATT = 0x0200U, 51 }; 52 53 /* 54 * Definitions for 'debug' parameter 55 */ 56 enum 57 { 58 BLE_DEBUG_RAND_ADDR_INIT = 0x00000010UL, 59 }; 60 61 /* 62 * This structure contains memory and low level hardware configuration data 63 * for the device 64 */ 65 typedef struct 66 { 67 /* Start address of the RAM buffer allocated for BLE stack library. 68 * It must be a 32bit aligned RAM area. 69 */ 70 uint8_t* bleStartRamAddress; 71 72 /* Size of the RAM buffer allocated for BLE stack library. 73 * (could be filled with BLE_TOTAL_BUFFER_SIZE return value) 74 */ 75 uint32_t total_buffer_size; 76 77 /* Start address of the RAM buffer allocated for GATT database. 78 * It must be a 32bit aligned RAM area. 79 */ 80 uint8_t* bleStartRamAddress_GATT; 81 82 /* Size of the RAM buffer allocated for GATT database. 83 * (could be filled with BLE_TOTAL_BUFFER_SIZE_GATT return value) 84 */ 85 uint32_t total_buffer_size_GATT; 86 87 /* Maximum number of Attributes (i.e. the number of characteristic + the 88 * number of characteristic values + the number of descriptors, excluding the 89 * services) that can be stored in the GATT database. 90 * Note that certain characteristics and relative descriptors are added 91 * automatically during device initialization so this parameters should be 9 92 * (or 6 w.r.t. options) plus the number of user Attributes (NUM_GATT_ 93 * ATTRIBUTES used in the calculation of BLE TOTAL_BUFFER_SIZE_GATT) 94 */ 95 uint16_t numAttrRecord; 96 97 /* Maximum number of Services that can be stored in the GATT database. 98 * Note that the GAP and GATT services are automatically added so this 99 * parameter should be 2 plus the number of user services (NUM_GATT_SERVICES 100 * used in the calculation of BLE_TOTAL_BUFFER_SIZE_GATT) 101 */ 102 uint16_t numAttrServ; 103 104 /* Size of the storage area for Attribute values (ATT_VALUE_ARRAY_SIZE used 105 * in the calculation of BLE_TOTAL_BUFFER_SIZE_GATT) 106 * This value depends on the number of attributes used by application. In 107 * particular the sum of the following quantities (in octets) should be made 108 * for each attribute: 109 * - attribute value length 110 * - 5, if UUID is 16 bit; 19, if UUID is 128 bit 111 * - 2, if server configuration descriptor is used 112 * - 2*numOfLinks, if client configuration descriptor is used 113 * - 2, if extended properties is used 114 * The total amount of memory needed is the sum of the above quantities for 115 * each attribute. 116 */ 117 uint16_t attrValueArrSize; 118 119 /* Maximum number of simultaneous connections that the device will support. 120 * Valid values are from 1 to 8 (NUM_LINKS used in the calculation of 121 * BLE_TOTAL_BUFFER_SIZE). 122 */ 123 uint8_t numOfLinks; 124 125 /* Prepare Write List size in terms of number of packet with ATT_MTU=23 bytes 126 */ 127 uint8_t prWriteListSize; 128 129 /* Number of allocated memory blocks 130 */ 131 uint16_t mblockCount; 132 133 /* Maximum supported ATT_MTU size 134 */ 135 uint16_t attMtu; 136 137 /* Maximum value of the connection-oriented channel Maximum Payload Size 138 * Range: 23 .. (BLE_EVT_MAX_PARAM_LEN - 7) 139 */ 140 uint16_t max_coc_mps; 141 142 /* Maximum number of connection-oriented channels. 143 * Range: 0 .. 64 144 */ 145 uint8_t max_coc_nbr; 146 147 /* Maximum number of connection-oriented channels in initiator mode. 148 * Range: 0 .. max_coc_nbr 149 */ 150 uint8_t max_coc_initiator_nbr; 151 152 /* Options flags 153 * Bitmap of the "BLE_OPTIONS_..." definitions (see above). 154 * - bit 0: 1: LL only 0: LL + host 155 * - bit 1: 1: no service change desc. 0: with service change desc. 156 * - bit 2: 1: device name Read-Only 0: device name R/W 157 * - bit 3: 1: extended adv supported 0: extended adv not supported 158 * - bit 5: 1: Reduced GATT db in NVM 0: Full GATT db in NVM 159 * - bit 6: 1: GATT caching is used 0: GATT caching is not used 160 * - bit 7: 1: LE Power Class 1 0: LE Power Class 2-3 161 * - bit 8: 1: appearance Writable 0: appearance Read-Only 162 * - bit 9: 1: Enhanced ATT supported 0: Enhanced ATT not supported 163 * - other bits: reserved 164 */ 165 uint16_t options; 166 167 /* Debug flags 168 * Bitmap of the "BLE_DEBUG_..." definitions (see above). 169 */ 170 uint32_t debug; 171 172 } BleStack_init_t; 173 174 /* 175 * BleStack_Init 176 * 177 * @brief The BLE Stack initialization routine 178 * 179 * @param[in] Init_params_p pointer to the const structure containing 180 * memory and low level hardware configuration 181 * data for the device 182 * 183 * @return Value indicating success or error code. 184 */ 185 extern tBleStatus BleStack_Init( const BleStack_init_t* init_params_p ); 186 187 /* 188 * BleStack_Process 189 * 190 * @brief This function executes the processing of all Host Stack layers. 191 * It has to be executed regularly to process incoming Link Layer packets and 192 * to process Host Layers procedures. All stack callbacks are called by this 193 * function. 194 * 195 * No BLE stack function must be called while the BleStack_Process is running. 196 * For example, if a BLE stack function may be called inside an 197 * interrupt routine, that interrupt must be disabled during the execution of 198 * BleStack_Process(). 199 * 200 * @return 201 * BLE_SLEEPMODE_RUNNING (0) -> BLE Stack Process has to be executed, 202 * BLE_SLEEPMODE_CPU_HALT (1) -> BLE Stack Process does not have to be 203 * executed, 204 */ 205 extern uint8_t BleStack_Process( void ); 206 207 /* 208 * BleStack_Request 209 * 210 * @brief This function gives a request from application to the BLE stack. 211 * The input parameter is a buffer of bytes in the BLE standard format: 212 * HCI/ACI command packet or ACL data packet. 213 * The response packet is returned in the same buffer and the size (in bytes) 214 * of the response is given by the function return value. 215 */ 216 extern uint16_t BleStack_Request( uint8_t* buffer ); 217 218 /* 219 * BLECB_Indication 220 * 221 * @brief Callback called by the BLE stack (from BleStack_Process() context) 222 * to send an indication to the application. The indication is a BLE standard 223 * packet that can be either an ACI/HCI event or an ACL data. 224 */ 225 extern uint8_t BLECB_Indication( const uint8_t* data, 226 uint16_t length, 227 const uint8_t* ext_data, 228 uint16_t ext_length ); 229 230 231 #endif /* BLESTACK_H__ */ 232