From 22aa15123859d4c2e182839ce3a576aefacfac8f Mon Sep 17 00:00:00 2001 From: Matthias Ringwald Date: Sat, 11 Feb 2017 22:44:02 +0100 Subject: [PATCH] le_device_db_memory: make nr of entries configurable via MAX_NR_LE_DEVICE_DB_ENTRIES --- doc/manual/docs/how_to.md | 1 + port/arduino/btstack_config.h | 1 + port/daemon/configure.ac | 3 ++- port/ez430-rf2560/btstack_config.h | 1 + port/ios/btstack_config.h | 1 + port/msp-exp430f5438-cc2564b/btstack_config.h | 1 + port/msp430f5229lp-cc2564b/btstack_config.h | 1 + port/mtk/btstack_config.h | 1 + port/nrf5-zephyr/btstack_config.h | 1 + port/nrf5x/btstack_config.h | 1 + port/pic32-harmony/src/btstack_config.h | 1 + port/stm32-f103rb-nucleo/btstack_config.h | 1 + port/wiced/btstack_config.h | 1 + src/ble/le_device_db_memory.c | 23 +++++++++++-------- 14 files changed, 27 insertions(+), 11 deletions(-) diff --git a/doc/manual/docs/how_to.md b/doc/manual/docs/how_to.md index b4c5e7c2e..852760f03 100644 --- a/doc/manual/docs/how_to.md +++ b/doc/manual/docs/how_to.md @@ -115,6 +115,7 @@ MAX_NR_RFCOMM_SERVICES | Max number of RFCOMM services MAX_NR_SERVICE_RECORD_ITEMS | Max number of SDP service records MAX_NR_SM_LOOKUP_ENTRIES | Max number of items in Security Manager lookup queue MAX_NR_WHITELIST_ENTRIES | Max number of items in GAP LE Whitelist to connect to +MAX_NR_LE_DEVICE_DB_ENTRIES | Max number of items in LE Device DB The memory is set up by calling *btstack_memory_init* function: diff --git a/port/arduino/btstack_config.h b/port/arduino/btstack_config.h index 98d9e284e..b0a48d619 100644 --- a/port/arduino/btstack_config.h +++ b/port/arduino/btstack_config.h @@ -32,4 +32,5 @@ #define MAX_NR_WHITELIST_ENTRIES 1 #define MAX_NR_SM_LOOKUP_ENTRIES 3 #define MAX_NR_SERVICE_RECORD_ITEMS 1 +#define MAX_NR_LE_DEVICE_DB_ENTRIES 1 #endif \ No newline at end of file diff --git a/port/daemon/configure.ac b/port/daemon/configure.ac index 335894dcf..a5b439aac 100644 --- a/port/daemon/configure.ac +++ b/port/daemon/configure.ac @@ -145,7 +145,8 @@ echo "#define ENABLE_SDP_DES_DUMP" >> btstack_config.h echo >> btstack_config.h echo "// BTstack configuration. buffers, sizes, .." >> btstack_config.h -echo "#define HCI_ACL_PAYLOAD_SIZE 1021" >> btstack_config.h +echo "#define HCI_ACL_PAYLOAD_SIZE 1021" >> btstack_config.h +echo "#define MAX_NR_LE_DEVICE_DB_ENTRIES 1" >> btstack_config.h echo >> btstack_config.h echo "// Daemon configuration" >> btstack_config.h diff --git a/port/ez430-rf2560/btstack_config.h b/port/ez430-rf2560/btstack_config.h index 57228be76..ecc0bc147 100644 --- a/port/ez430-rf2560/btstack_config.h +++ b/port/ez430-rf2560/btstack_config.h @@ -34,5 +34,6 @@ #define MAX_NR_WHITELIST_ENTRIES 1 #define MAX_NR_SM_LOOKUP_ENTRIES 3 #define MAX_NR_SERVICE_RECORD_ITEMS 1 +#define MAX_NR_LE_DEVICE_DB_ENTRIES 0 #endif diff --git a/port/ios/btstack_config.h b/port/ios/btstack_config.h index ba96708dc..21399fff1 100644 --- a/port/ios/btstack_config.h +++ b/port/ios/btstack_config.h @@ -19,6 +19,7 @@ // BTstack configuration. buffers, sizes, ... #define HCI_ACL_PAYLOAD_SIZE 1021 +#define MAX_NR_LE_DEVICE_DB_ENTRIES 1 // Daemon configuration #define BTSTACK_DEVICE_NAME_DB_INSTANCE btstack_device_name_db_corefoundation_instance diff --git a/port/msp-exp430f5438-cc2564b/btstack_config.h b/port/msp-exp430f5438-cc2564b/btstack_config.h index 43db9cc9a..d17443c4a 100644 --- a/port/msp-exp430f5438-cc2564b/btstack_config.h +++ b/port/msp-exp430f5438-cc2564b/btstack_config.h @@ -34,6 +34,7 @@ #define MAX_NR_SM_LOOKUP_ENTRIES 3 #define MAX_NR_WHITELIST_ENTRIES 1 #define MAX_SPP_CONNECTIONS 1 +#define MAX_NR_LE_DEVICE_DB_ENTRIES 0 // #endif diff --git a/port/msp430f5229lp-cc2564b/btstack_config.h b/port/msp430f5229lp-cc2564b/btstack_config.h index a22a382cd..68b522856 100644 --- a/port/msp430f5229lp-cc2564b/btstack_config.h +++ b/port/msp430f5229lp-cc2564b/btstack_config.h @@ -34,6 +34,7 @@ #define MAX_NR_WHITELIST_ENTRIES 1 #define MAX_NR_SM_LOOKUP_ENTRIES 3 #define MAX_NR_SERVICE_RECORD_ITEMS 1 +#define MAX_NR_LE_DEVICE_DB_ENTRIES 0 #endif diff --git a/port/mtk/btstack_config.h b/port/mtk/btstack_config.h index 485fbcaff..906c5f6c3 100644 --- a/port/mtk/btstack_config.h +++ b/port/mtk/btstack_config.h @@ -21,6 +21,7 @@ // BTstack configuration. buffers, sizes, ... #define HCI_ACL_PAYLOAD_SIZE 1021 +#define MAX_NR_LE_DEVICE_DB_ENTRIES 1 // Daemon configuration #define ENABLE_SDP diff --git a/port/nrf5-zephyr/btstack_config.h b/port/nrf5-zephyr/btstack_config.h index dcc9f0e5c..2a3b2b55a 100644 --- a/port/nrf5-zephyr/btstack_config.h +++ b/port/nrf5-zephyr/btstack_config.h @@ -31,5 +31,6 @@ #define MAX_NR_BNEP_SERVICES 0 #define MAX_NR_BNEP_CHANNELS 0 #define MAX_NR_SERVICE_RECORD_ITEMS 1 +#define MAX_NR_LE_DEVICE_DB_ENTRIES 1 #endif \ No newline at end of file diff --git a/port/nrf5x/btstack_config.h b/port/nrf5x/btstack_config.h index 8db79f1c9..aaf3ebe02 100644 --- a/port/nrf5x/btstack_config.h +++ b/port/nrf5x/btstack_config.h @@ -33,5 +33,6 @@ #define MAX_NR_WHITELIST_ENTRIES 1 #define MAX_NR_SM_LOOKUP_ENTRIES 3 #define MAX_NR_SERVICE_RECORD_ITEMS 1 +#define MAX_NR_LE_DEVICE_DB_ENTRIES 1 #endif \ No newline at end of file diff --git a/port/pic32-harmony/src/btstack_config.h b/port/pic32-harmony/src/btstack_config.h index 0afde1156..1cf88b9f0 100644 --- a/port/pic32-harmony/src/btstack_config.h +++ b/port/pic32-harmony/src/btstack_config.h @@ -34,5 +34,6 @@ #define MAX_NR_WHITELIST_ENTRIES 1 #define MAX_NR_SM_LOOKUP_ENTRIES 3 #define MAX_NR_SERVICE_RECORD_ITEMS 1 +#define MAX_NR_LE_DEVICE_DB_ENTRIES 1 #endif \ No newline at end of file diff --git a/port/stm32-f103rb-nucleo/btstack_config.h b/port/stm32-f103rb-nucleo/btstack_config.h index d3a8e7b0e..5f46cac7e 100644 --- a/port/stm32-f103rb-nucleo/btstack_config.h +++ b/port/stm32-f103rb-nucleo/btstack_config.h @@ -34,5 +34,6 @@ #define MAX_NR_WHITELIST_ENTRIES 1 #define MAX_NR_SM_LOOKUP_ENTRIES 3 #define MAX_NR_SERVICE_RECORD_ITEMS 1 +#define MAX_NR_LE_DEVICE_DB_ENTRIES 1 #endif \ No newline at end of file diff --git a/port/wiced/btstack_config.h b/port/wiced/btstack_config.h index 9ccfdef59..dc612cd74 100644 --- a/port/wiced/btstack_config.h +++ b/port/wiced/btstack_config.h @@ -35,6 +35,7 @@ #define MAX_NR_WHITELIST_ENTRIES 1 #define MAX_NR_SM_LOOKUP_ENTRIES 3 #define MAX_NR_SERVICE_RECORD_ITEMS 1 +#define MAX_NR_LE_DEVICE_DB_ENTRIES 1 // Nun Link Keys stored in WICED DCT #define NVM_NUM_LINK_KEYS 10 diff --git a/src/ble/le_device_db_memory.c b/src/ble/le_device_db_memory.c index 4dec5f1d3..6ad8b246a 100644 --- a/src/ble/le_device_db_memory.c +++ b/src/ble/le_device_db_memory.c @@ -72,14 +72,17 @@ typedef struct le_device_memory_db { } le_device_memory_db_t; -#define LE_DEVICE_MEMORY_SIZE 4 #define INVALID_ENTRY_ADDR_TYPE 0xff -static le_device_memory_db_t le_devices[LE_DEVICE_MEMORY_SIZE]; +#ifndef MAX_NR_LE_DEVICE_DB_ENTRIES +#error "MAX_NR_LE_DEVICE_DB_ENTRIES not defined, please define in btstack_config.h" +#endif + +static le_device_memory_db_t le_devices[MAX_NR_LE_DEVICE_DB_ENTRIES]; void le_device_db_init(void){ int i; - for (i=0;i= LE_DEVICE_MEMORY_SIZE){ + if (index < 0 || index >= MAX_NR_LE_DEVICE_DB_ENTRIES){ log_error("le_device_db_remote_csrk_get called with invalid index %d", index); return; } @@ -171,7 +174,7 @@ void le_device_db_remote_csrk_get(int index, sm_key_t csrk){ } void le_device_db_remote_csrk_set(int index, sm_key_t csrk){ - if (index < 0 || index >= LE_DEVICE_MEMORY_SIZE){ + if (index < 0 || index >= MAX_NR_LE_DEVICE_DB_ENTRIES){ log_error("le_device_db_remote_csrk_set called with invalid index %d", index); return; } @@ -179,7 +182,7 @@ void le_device_db_remote_csrk_set(int index, sm_key_t csrk){ } void le_device_db_local_csrk_get(int index, sm_key_t csrk){ - if (index < 0 || index >= LE_DEVICE_MEMORY_SIZE){ + if (index < 0 || index >= MAX_NR_LE_DEVICE_DB_ENTRIES){ log_error("le_device_db_local_csrk_get called with invalid index %d", index); return; } @@ -187,7 +190,7 @@ void le_device_db_local_csrk_get(int index, sm_key_t csrk){ } void le_device_db_local_csrk_set(int index, sm_key_t csrk){ - if (index < 0 || index >= LE_DEVICE_MEMORY_SIZE){ + if (index < 0 || index >= MAX_NR_LE_DEVICE_DB_ENTRIES){ log_error("le_device_db_local_csrk_set called with invalid index %d", index); return; } @@ -219,7 +222,7 @@ void le_device_db_local_counter_set(int index, uint32_t counter){ void le_device_db_dump(void){ log_info("Central Device DB dump, devices: %d", le_device_db_count()); int i; - for (i=0;i