From ae079c1fc5d990ba55714d4b3a51b19f96edaec4 Mon Sep 17 00:00:00 2001 From: WXK <287788329@qq.com> Date: 星期四, 24 四月 2025 16:01:43 +0800 Subject: [PATCH] 改为中断来低电平触发发送当前扫描数据,3s内扫描不到的会退出,串口来55 AA 75 70 64 61 74 65,进入升级模式 --- 01_SDK/nimble/host/nimble/nimble/host/store/config/src/ble_store_config.c | 101 +++++++++++++++++++++++++++++++++++++++++++++++--- 1 files changed, 95 insertions(+), 6 deletions(-) diff --git a/01_SDK/nimble/host/nimble/nimble/host/store/config/src/ble_store_config.c b/01_SDK/nimble/host/nimble/nimble/host/store/config/src/ble_store_config.c index 2505cf9..53f9e61 100644 --- a/01_SDK/nimble/host/nimble/nimble/host/store/config/src/ble_store_config.c +++ b/01_SDK/nimble/host/nimble/nimble/host/store/config/src/ble_store_config.c @@ -23,9 +23,18 @@ #include "sysinit/sysinit.h" #include "nimble_syscfg.h" #include "host/ble_hs.h" -#include "store/config/ble_store_config.h" #include "ble_store_config_priv.h" #include "os/panchip_mempool.h" +#if MYNEWT_VAL_BLE_STORE_CONFIG_PERSIST +#include "kv_store_api.h" +#endif + +#if SMP_MULTI_ADDR_MODE_EN +#include "host/ble_hs_id.h" +#endif + +#define BLE_STORE_LOG_EN 0 + #ifdef IP_101x struct ble_store_value_sec *ble_store_config_our_secs; @@ -50,9 +59,43 @@ ble_store_config_cccds[MYNEWT_VAL(BLE_STORE_MAX_CCCDS)]; int ble_store_config_num_cccds; #endif + +#if SMP_MULTI_ADDR_MODE_EN +struct ble_store_value_sec *ble_store_config_get_our_secs(uint8_t id) +{ + return &ble_store_config_our_secs[id]; +} + +struct ble_store_value_sec *ble_store_config_get_peer_secs(uint8_t id) +{ + return &ble_store_config_peer_secs[id]; +} + +struct ble_store_value_cccd *ble_store_config_get_cccds(uint8_t id) +{ + return &ble_store_config_cccds[id]; +} + +int ble_store_config_get_our_secs_num(void) +{ + return ble_store_config_num_our_secs; +} + +int ble_store_config_get_peer_secs_num(void) +{ + return ble_store_config_num_peer_secs; +} + +int ble_store_config_get_cccds_num(void) +{ + return ble_store_config_num_cccds; +} +#endif + /***************************************************************************** * $sec * *****************************************************************************/ +#if BLE_STORE_LOG_EN void ble_hs_log_flat_buf_priv(const void *data, int len) { @@ -64,10 +107,12 @@ printf( "%02x", u8ptr[i]); } } +#endif static void ble_store_config_print_value_sec(const struct ble_store_value_sec *sec) { +#if BLE_STORE_LOG_EN if (sec->ltk_present) { printf( "ediv=%u rand=%llu authenticated=%d ltk= ", sec->ediv, sec->rand_num, sec->authenticated); @@ -86,6 +131,7 @@ } printf( "\n"); +#endif } static void @@ -118,9 +164,28 @@ cur = value_secs + i; if (ble_addr_cmp(&key_sec->peer_addr, BLE_ADDR_ANY)) { + #if SMP_MULTI_ADDR_MODE_EN + ble_addr_t own_addr; + if(key_sec->is_own_addr_valid == 0xAA){ + own_addr = key_sec->own_addr; + } + else{ + own_addr.type = ble_hs_id_get_used_addr_type(); + int rc = ble_hs_id_copy_addr(own_addr.type, own_addr.val, NULL); + if(rc != 0){ + return -1; + } + } + + if (ble_addr_cmp(&cur->peer_addr, &key_sec->peer_addr) || + ble_addr_cmp(&cur->own_addr, &own_addr)) { + continue; + } + #else if (ble_addr_cmp(&cur->peer_addr, &key_sec->peer_addr)) { continue; } + #endif } if (key_sec->ediv_rand_present) { @@ -342,9 +407,28 @@ cccd = ble_store_config_cccds + i; if (ble_addr_cmp(&key->peer_addr, BLE_ADDR_ANY)) { + #if SMP_MULTI_ADDR_MODE_EN + ble_addr_t own_addr; + if(key->is_own_addr_valid == 0xAA){ + own_addr = key->own_addr; + } + else{ + own_addr.type = ble_hs_id_get_used_addr_type(); + int rc = ble_hs_id_copy_addr(own_addr.type, own_addr.val, NULL); + if(rc != 0){ + return -1; + } + } + + if (ble_addr_cmp(&cccd->peer_addr, &key->peer_addr) || + ble_addr_cmp(&cccd->own_addr, &own_addr)) { + continue; + } + #else if (ble_addr_cmp(&cccd->peer_addr, &key->peer_addr)) { continue; } + #endif } if (key->chr_val_handle != 0) { @@ -417,8 +501,9 @@ idx = ble_store_config_find_cccd(&key_cccd); if (idx == -1) { if (ble_store_config_num_cccds >= MYNEWT_VAL(BLE_STORE_MAX_CCCDS)) { - printf("error persisting cccd; too many entries (%d)\n", - ble_store_config_num_cccds); + #if BLE_STORE_LOG_EN + printf("error persisting cccd; too many entries (%d)\n", ble_store_config_num_cccds); + #endif return BLE_HS_ESTORE_CAP; } @@ -539,15 +624,19 @@ ble_store_config_init(void) { /* Ensure this function only gets called by sysinit. */ - #ifdef IP_101x +#ifdef IP_101x ble_store_config_our_secs = panchip_mem_get((MYNEWT_VAL(BLE_STORE_MAX_BONDS)) * sizeof(struct ble_store_value_sec), 8); ble_store_config_peer_secs = panchip_mem_get((MYNEWT_VAL(BLE_STORE_MAX_BONDS)) * sizeof(struct ble_store_value_sec), 8); ble_store_config_cccds = panchip_mem_get((MYNEWT_VAL(BLE_STORE_MAX_CCCDS)) * sizeof(struct ble_store_value_cccd), 4); - #endif +#endif SYSINIT_ASSERT_ACTIVE(); - host_kvstore_init(); +#if MYNEWT_VAL_BLE_STORE_CONFIG_PERSIST + /* kv initialization */ + extern void kv_init(void); + kv_init(); +#endif ble_hs_cfg.store_read_cb = ble_store_config_read; ble_hs_cfg.store_write_cb = ble_store_config_write; -- Gitblit v1.9.3