mirror of
https://github.com/bluekitchen/btstack.git
synced 2025-02-03 20:54:18 +00:00
le_device_db: return BD_ADDR_TYPE_UNKNOWN if device unknown in posix_fs, wiced, and memory implementations
This commit is contained in:
parent
e1086030d9
commit
d14ceebfc8
@ -76,7 +76,6 @@ typedef struct le_device_memory_db {
|
||||
} le_device_memory_db_t;
|
||||
|
||||
#define LE_DEVICE_MEMORY_SIZE 20
|
||||
#define INVALID_ENTRY_ADDR_TYPE 0xff
|
||||
|
||||
#ifndef LE_DEVICE_DB_PATH
|
||||
#ifdef _WIN32
|
||||
@ -155,7 +154,7 @@ static void le_device_db_store(void) {
|
||||
fwrite(csv_header, strlen(csv_header), 1, wFile);
|
||||
fwrite("\n", 1, 1, wFile);
|
||||
for (i=0;i<LE_DEVICE_MEMORY_SIZE;i++){
|
||||
if (le_devices[i].addr_type == INVALID_ENTRY_ADDR_TYPE) continue;
|
||||
if (le_devices[i].addr_type == BD_ADDR_TYPE_UNKNOWN) continue;
|
||||
write_value(wFile, le_devices[i].addr_type, 1);
|
||||
write_str(wFile, bd_addr_to_str(le_devices[i].addr));
|
||||
write_hex(wFile, le_devices[i].irk, 16);
|
||||
@ -223,7 +222,7 @@ static void le_device_db_read(void){
|
||||
memset(&le_devices[i], 0, sizeof(le_device_memory_db_t));
|
||||
le_devices[i].addr_type = read_value(wFile, 1);
|
||||
if (feof(wFile)){
|
||||
le_devices[i].addr_type = INVALID_ENTRY_ADDR_TYPE;
|
||||
le_devices[i].addr_type = BD_ADDR_TYPE_UNKNOWN;
|
||||
break;
|
||||
}
|
||||
read_hex(wFile, le_devices[i].addr, 6);
|
||||
@ -256,7 +255,7 @@ exit:
|
||||
void le_device_db_init(void){
|
||||
int i;
|
||||
for (i=0;i<LE_DEVICE_MEMORY_SIZE;i++){
|
||||
le_devices[i].addr_type = INVALID_ENTRY_ADDR_TYPE;
|
||||
le_devices[i].addr_type = BD_ADDR_TYPE_UNKNOWN;
|
||||
}
|
||||
sprintf(db_path, DB_PATH_TEMPLATE, "00-00-00-00-00-00");
|
||||
}
|
||||
@ -273,7 +272,7 @@ int le_device_db_count(void){
|
||||
int i;
|
||||
int counter = 0;
|
||||
for (i=0;i<LE_DEVICE_MEMORY_SIZE;i++){
|
||||
if (le_devices[i].addr_type != INVALID_ENTRY_ADDR_TYPE) counter++;
|
||||
if (le_devices[i].addr_type != BD_ADDR_TYPE_UNKNOWN) counter++;
|
||||
}
|
||||
return counter;
|
||||
}
|
||||
@ -284,7 +283,7 @@ int le_device_db_max_count(void){
|
||||
|
||||
// free device
|
||||
void le_device_db_remove(int index){
|
||||
le_devices[index].addr_type = INVALID_ENTRY_ADDR_TYPE;
|
||||
le_devices[index].addr_type = BD_ADDR_TYPE_UNKNOWN;
|
||||
le_device_db_store();
|
||||
}
|
||||
|
||||
@ -292,7 +291,7 @@ int le_device_db_add(int addr_type, bd_addr_t addr, sm_key_t irk){
|
||||
int i;
|
||||
int index = -1;
|
||||
for (i=0;i<LE_DEVICE_MEMORY_SIZE;i++){
|
||||
if (le_devices[i].addr_type == INVALID_ENTRY_ADDR_TYPE){
|
||||
if (le_devices[i].addr_type == BD_ADDR_TYPE_UNKNOWN){
|
||||
index = i;
|
||||
break;
|
||||
}
|
||||
@ -420,7 +419,7 @@ void le_device_db_dump(void){
|
||||
log_info("Central Device DB dump, devices: %d", le_device_db_count());
|
||||
int i;
|
||||
for (i=0;i<LE_DEVICE_MEMORY_SIZE;i++){
|
||||
if (le_devices[i].addr_type == INVALID_ENTRY_ADDR_TYPE) continue;
|
||||
if (le_devices[i].addr_type == BD_ADDR_TYPE_UNKNOWN) continue;
|
||||
log_info("%u: %u %s", i, le_devices[i].addr_type, bd_addr_to_str(le_devices[i].addr));
|
||||
log_info_key("ltk", le_devices[i].ltk);
|
||||
log_info_key("irk", le_devices[i].irk);
|
||||
|
@ -58,8 +58,6 @@
|
||||
// Link Key Magic
|
||||
#define LE_DEVICE_MAGIC ((uint32_t) 'L' << 24 | 'E' << 16 | 'D' << 8 | 'B')
|
||||
|
||||
#define INVALID_ENTRY_ADDR_TYPE 0xff
|
||||
|
||||
typedef struct le_device_nvm {
|
||||
uint32_t magic;
|
||||
uint32_t seq_nr; // used for "last recently stored" eviction strategy
|
||||
@ -201,7 +199,14 @@ int le_device_db_max_count(void){
|
||||
void le_device_db_info(int device_index, int * addr_type, bd_addr_t addr, sm_key_t irk){
|
||||
int absolute_index = le_device_db_get_absolute_index_for_device_index(device_index);
|
||||
le_device_nvm_t entry;
|
||||
le_device_db_entry_read(absolute_index, &entry);
|
||||
int valid = le_device_db_entry_read(absolute_index, &entry);
|
||||
|
||||
// set defaults if not found
|
||||
if (!valid) {
|
||||
memset(&entry, 0, sizeof(le_device_db_entry_t));
|
||||
entry.addr_type = BD_ADDR_TYPE_UNKNOWN;
|
||||
}
|
||||
|
||||
if (addr_type) *addr_type = entry.addr_type;
|
||||
if (addr) memcpy(addr, entry.addr, 6);
|
||||
if (irk) memcpy(irk, entry.irk, 16);
|
||||
|
@ -77,8 +77,6 @@ typedef struct le_device_memory_db {
|
||||
|
||||
} le_device_memory_db_t;
|
||||
|
||||
#define INVALID_ENTRY_ADDR_TYPE 0xff
|
||||
|
||||
#ifndef MAX_NR_LE_DEVICE_DB_ENTRIES
|
||||
#error "MAX_NR_LE_DEVICE_DB_ENTRIES not defined, please define in btstack_config.h"
|
||||
#endif
|
||||
@ -101,7 +99,7 @@ int le_device_db_count(void){
|
||||
int i;
|
||||
int counter = 0;
|
||||
for (i=0;i<MAX_NR_LE_DEVICE_DB_ENTRIES;i++){
|
||||
if (le_devices[i].addr_type != INVALID_ENTRY_ADDR_TYPE) counter++;
|
||||
if (le_devices[i].addr_type != BD_ADDR_TYPE_UNKNOWN) counter++;
|
||||
}
|
||||
return counter;
|
||||
}
|
||||
@ -112,14 +110,14 @@ int le_device_db_max_count(void){
|
||||
|
||||
// free device
|
||||
void le_device_db_remove(int index){
|
||||
le_devices[index].addr_type = INVALID_ENTRY_ADDR_TYPE;
|
||||
le_devices[index].addr_type = BD_ADDR_TYPE_UNKNOWN;
|
||||
}
|
||||
|
||||
int le_device_db_add(int addr_type, bd_addr_t addr, sm_key_t irk){
|
||||
int i;
|
||||
int index = -1;
|
||||
for (i=0;i<MAX_NR_LE_DEVICE_DB_ENTRIES;i++){
|
||||
if (le_devices[i].addr_type == INVALID_ENTRY_ADDR_TYPE){
|
||||
if (le_devices[i].addr_type == BD_ADDR_TYPE_UNKNOWN){
|
||||
index = i;
|
||||
break;
|
||||
}
|
||||
@ -234,7 +232,7 @@ void le_device_db_dump(void){
|
||||
log_info("LE Device DB dump, devices: %d", le_device_db_count());
|
||||
int i;
|
||||
for (i=0;i<MAX_NR_LE_DEVICE_DB_ENTRIES;i++){
|
||||
if (le_devices[i].addr_type == INVALID_ENTRY_ADDR_TYPE) continue;
|
||||
if (le_devices[i].addr_type == BD_ADDR_TYPE_UNKNOWN) continue;
|
||||
log_info("%u: %u %s", i, le_devices[i].addr_type, bd_addr_to_str(le_devices[i].addr));
|
||||
log_info_key("irk", le_devices[i].irk);
|
||||
#ifdef ENABLE_LE_SIGNED_WRITE
|
||||
|
Loading…
x
Reference in New Issue
Block a user