mirror of
https://github.com/bluekitchen/btstack.git
synced 2025-02-20 18:40:31 +00:00
add memory pool for whitelist entries
This commit is contained in:
parent
652b03395e
commit
656bec4f48
@ -32,6 +32,7 @@
|
||||
#define MAX_NO_GATT_CLIENTS 1
|
||||
#define MAX_ATT_DB_SIZE 200
|
||||
#define MAX_NO_HFP_CONNECTIONS 0
|
||||
#define MAX_NO_WHITELIST_ENTRIES 1
|
||||
|
||||
|
||||
#endif
|
@ -35,6 +35,7 @@
|
||||
#define MAX_NO_DB_MEM_DEVICE_NAMES 0
|
||||
#define MAX_NO_DB_MEM_SERVICES 1
|
||||
#define MAX_NO_HFP_CONNECTIONS 0
|
||||
#define MAX_NO_WHITELIST_ENTRIES 1
|
||||
|
||||
#endif
|
||||
|
||||
|
@ -35,6 +35,7 @@
|
||||
#define MAX_NO_DB_MEM_DEVICE_NAMES 0
|
||||
#define MAX_NO_DB_MEM_SERVICES 1
|
||||
#define MAX_NO_HFP_CONNECTIONS 0
|
||||
#define MAX_NO_WHITELIST_ENTRIES 1
|
||||
|
||||
#endif
|
||||
|
||||
|
@ -35,6 +35,7 @@
|
||||
#define MAX_NO_DB_MEM_DEVICE_NAMES 0
|
||||
#define MAX_NO_DB_MEM_SERVICES 1
|
||||
#define MAX_NO_HFP_CONNECTIONS 0
|
||||
#define MAX_NO_WHITELIST_ENTRIES 1
|
||||
|
||||
#endif
|
||||
|
||||
|
@ -32,5 +32,6 @@
|
||||
#define MAX_NO_BNEP_SERVICES 0
|
||||
#define MAX_NO_BNEP_CHANNELS 0
|
||||
#define MAX_NO_HFP_CONNECTIONS 0
|
||||
#define MAX_NO_WHITELIST_ENTRIES 1
|
||||
|
||||
#endif
|
@ -32,5 +32,6 @@
|
||||
#define MAX_NO_BNEP_SERVICES 0
|
||||
#define MAX_NO_BNEP_CHANNELS 0
|
||||
#define MAX_NO_HFP_CONNECTIONS 0
|
||||
#define MAX_NO_WHITELIST_ENTRIES 1
|
||||
|
||||
#endif
|
@ -507,6 +507,38 @@ void btstack_memory_gatt_subclient_free(gatt_subclient_t *gatt_subclient){
|
||||
#endif
|
||||
|
||||
|
||||
// MARK: whitelist_entry_t
|
||||
#ifdef MAX_NO_WHITELIST_ENTRIES
|
||||
#if MAX_NO_WHITELIST_ENTRIES > 0
|
||||
static whitelist_entry_t whitelist_entry_storage[MAX_NO_WHITELIST_ENTRIES];
|
||||
static memory_pool_t whitelist_entry_pool;
|
||||
whitelist_entry_t * btstack_memory_whitelist_entry_get(void){
|
||||
return (whitelist_entry_t *) memory_pool_get(&whitelist_entry_pool);
|
||||
}
|
||||
void btstack_memory_whitelist_entry_free(whitelist_entry_t *whitelist_entry){
|
||||
memory_pool_free(&whitelist_entry_pool, whitelist_entry);
|
||||
}
|
||||
#else
|
||||
whitelist_entry_t * btstack_memory_whitelist_entry_get(void){
|
||||
return NULL;
|
||||
}
|
||||
void btstack_memory_whitelist_entry_free(whitelist_entry_t *whitelist_entry){
|
||||
// silence compiler warning about unused parameter in a portable way
|
||||
(void) whitelist_entry;
|
||||
};
|
||||
#endif
|
||||
#elif defined(HAVE_MALLOC)
|
||||
whitelist_entry_t * btstack_memory_whitelist_entry_get(void){
|
||||
return (whitelist_entry_t*) malloc(sizeof(whitelist_entry_t));
|
||||
}
|
||||
void btstack_memory_whitelist_entry_free(whitelist_entry_t *whitelist_entry){
|
||||
free(whitelist_entry);
|
||||
}
|
||||
#else
|
||||
#error "Neither HAVE_MALLOC nor MAX_NO_WHITELIST_ENTRIES for struct whitelist_entry is defined. Please, edit the config file."
|
||||
#endif
|
||||
|
||||
|
||||
#endif
|
||||
// init
|
||||
void btstack_memory_init(void){
|
||||
@ -553,5 +585,8 @@ void btstack_memory_init(void){
|
||||
#if MAX_NO_GATT_SUBCLIENTS > 0
|
||||
memory_pool_create(&gatt_subclient_pool, gatt_subclient_storage, MAX_NO_GATT_SUBCLIENTS, sizeof(gatt_subclient_t));
|
||||
#endif
|
||||
#if MAX_NO_WHITELIST_ENTRIES > 0
|
||||
memory_pool_create(&whitelist_entry_pool, whitelist_entry_storage, MAX_NO_WHITELIST_ENTRIES, sizeof(whitelist_entry_t));
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
@ -110,11 +110,13 @@ hfp_connection_t * btstack_memory_hfp_connection_get(void);
|
||||
void btstack_memory_hfp_connection_free(hfp_connection_t *hfp_connection);
|
||||
|
||||
#ifdef HAVE_BLE
|
||||
// gatt_client, gatt_subclient
|
||||
// gatt_client, gatt_subclient, whitelist_entry
|
||||
gatt_client_t * btstack_memory_gatt_client_get(void);
|
||||
void btstack_memory_gatt_client_free(gatt_client_t *gatt_client);
|
||||
gatt_subclient_t * btstack_memory_gatt_subclient_get(void);
|
||||
void btstack_memory_gatt_subclient_free(gatt_subclient_t *gatt_subclient);
|
||||
whitelist_entry_t * btstack_memory_whitelist_entry_get(void);
|
||||
void btstack_memory_whitelist_entry_free(whitelist_entry_t *whitelist_entry);
|
||||
#endif
|
||||
|
||||
#if defined __cplusplus
|
||||
|
17
src/hci.h
17
src/hci.h
@ -598,9 +598,22 @@ enum {
|
||||
LE_ADVERTISEMENT_TASKS_DISABLE = 1 << 0,
|
||||
LE_ADVERTISEMENT_TASKS_SET_DATA = 1 << 1,
|
||||
LE_ADVERTISEMENT_TASKS_SET_PARAMS = 1 << 2,
|
||||
LE_ADVERTISEMENT_TASKS_ENABLE = 1 << 4,
|
||||
LE_ADVERTISEMENT_TASKS_ENABLE = 1 << 3,
|
||||
};
|
||||
|
||||
enum {
|
||||
LE_WHITELIST_VALID = 1 << 0,
|
||||
LE_WHITELIST_ON_CONTROLLER = 1 << 1,
|
||||
LE_WHITELIST_ADD_TO_CONTROLLER = 1 << 2,
|
||||
LE_WHITELIST_REMOVE_FROM_CONTROLLR = 1 << 3,
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
bd_addr_t addr;
|
||||
bd_addr_type_t type;
|
||||
uint8_t state;
|
||||
} whitelist_entry_t;
|
||||
|
||||
/**
|
||||
* main data structure
|
||||
*/
|
||||
@ -712,7 +725,7 @@ typedef struct {
|
||||
bd_addr_t le_advertisements_direct_address;
|
||||
|
||||
// LE Whitelist Management
|
||||
uint16_t le_white_list_capacity;
|
||||
uint16_t le_white_list_capacity;
|
||||
|
||||
// custom BD ADDR
|
||||
bd_addr_t custom_bd_addr;
|
||||
|
@ -28,6 +28,7 @@
|
||||
#define MAX_NO_DB_MEM_DEVICE_LINK_KEYS 2
|
||||
#define MAX_NO_DB_MEM_DEVICE_NAMES 2
|
||||
#define MAX_NO_DB_MEM_SERVICES 1
|
||||
#define MAX_NO_WHITELIST_ENTRIES 1
|
||||
#define HAVE_MALLOC
|
||||
|
||||
// DeLock 4.0 Dongle (Broadcom BCM20702A0)
|
||||
|
@ -147,13 +147,16 @@ def writeln(f, data):
|
||||
|
||||
def replacePlaceholder(template, struct_name):
|
||||
struct_type = struct_name + '_t'
|
||||
pool_count = "MAX_NO_" + struct_name.upper() + "S"
|
||||
if struct_name.endswith('try'):
|
||||
pool_count = "MAX_NO_" + struct_name.upper()[:-3] + "TRIES"
|
||||
else:
|
||||
pool_count = "MAX_NO_" + struct_name.upper() + "S"
|
||||
|
||||
snippet = template.replace("STRUCT_TYPE", struct_type).replace("STRUCT_NAME", struct_name).replace("POOL_COUNT", pool_count)
|
||||
return snippet
|
||||
|
||||
list_of_structs = [ ["hci_connection"], ["l2cap_service", "l2cap_channel"], ["rfcomm_multiplexer", "rfcomm_service", "rfcomm_channel"], ["db_mem_device_name", "db_mem_device_link_key", "db_mem_service"], ["bnep_service", "bnep_channel"], ["hfp_connection"]]
|
||||
list_of_le_structs = [["gatt_client", "gatt_subclient"]]
|
||||
list_of_le_structs = [["gatt_client", "gatt_subclient","whitelist_entry"]]
|
||||
|
||||
file_name = "../src/btstack_memory"
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user