diff --git a/platforms/arduino/btstack-config.h b/platforms/arduino/btstack-config.h index db1ad9aae..c7f5615c8 100644 --- a/platforms/arduino/btstack-config.h +++ b/platforms/arduino/btstack-config.h @@ -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 \ No newline at end of file diff --git a/platforms/ez430-rf2560/btstack-config.h b/platforms/ez430-rf2560/btstack-config.h index ad50bebe0..65124ea4d 100644 --- a/platforms/ez430-rf2560/btstack-config.h +++ b/platforms/ez430-rf2560/btstack-config.h @@ -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 diff --git a/platforms/msp-exp430f5438-cc2564b/btstack-config.h b/platforms/msp-exp430f5438-cc2564b/btstack-config.h index ad50bebe0..65124ea4d 100644 --- a/platforms/msp-exp430f5438-cc2564b/btstack-config.h +++ b/platforms/msp-exp430f5438-cc2564b/btstack-config.h @@ -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 diff --git a/platforms/msp430f5229lp-cc2564b/btstack-config.h b/platforms/msp430f5229lp-cc2564b/btstack-config.h index ad50bebe0..65124ea4d 100644 --- a/platforms/msp430f5229lp-cc2564b/btstack-config.h +++ b/platforms/msp430f5229lp-cc2564b/btstack-config.h @@ -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 diff --git a/platforms/pic32-harmony/src/btstack-config.h b/platforms/pic32-harmony/src/btstack-config.h index 92859c809..18c45e675 100644 --- a/platforms/pic32-harmony/src/btstack-config.h +++ b/platforms/pic32-harmony/src/btstack-config.h @@ -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 \ No newline at end of file diff --git a/platforms/stm32-f103rb-nucleo/btstack-config.h b/platforms/stm32-f103rb-nucleo/btstack-config.h index d41f30259..ee8e45a63 100644 --- a/platforms/stm32-f103rb-nucleo/btstack-config.h +++ b/platforms/stm32-f103rb-nucleo/btstack-config.h @@ -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 \ No newline at end of file diff --git a/src/btstack_memory.c b/src/btstack_memory.c index 2f0877f36..f6f2667c5 100644 --- a/src/btstack_memory.c +++ b/src/btstack_memory.c @@ -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 } diff --git a/src/btstack_memory.h b/src/btstack_memory.h index 349506261..73cbec47a 100644 --- a/src/btstack_memory.h +++ b/src/btstack_memory.h @@ -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 diff --git a/src/hci.h b/src/hci.h index 45ab0f4d0..3ad53a99c 100644 --- a/src/hci.h +++ b/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; diff --git a/test/btstack-config.h b/test/btstack-config.h index a98cc3a9b..5d16289a8 100644 --- a/test/btstack-config.h +++ b/test/btstack-config.h @@ -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) diff --git a/tools/btstack_memory_generator.py b/tools/btstack_memory_generator.py index 79ffdd1ef..4a8f3bae1 100755 --- a/tools/btstack_memory_generator.py +++ b/tools/btstack_memory_generator.py @@ -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"