Hi all,

With further debug effort the disconnect happens with HCI error 0x3d: BLE_ERR_CONN_TERM_MIC.

Once the connection is establish, if we disconnect and try to reconnect it is disconnecting with said reason.

I am attaching logs with additional prints. Please help me to know if I am making any obvious mistake.


Regards

Prasad

On 11/02/19 7:10 PM, prasad wrote:

Hi all,

Are there any pointers/documentation for storing NIMBLE bond information in NVS memory?

I tried to quickly implement simple application by modifying '*ble_store_ram.c*'. I modified /ble_hs_cfg.store_read_cb/store_write_cb/store_delete_cb/ callbacks according to the requirement. I find this much of change is not sufficient to get NVS bond stored in NVS as I am continuously getting disconnect HCI event.

FYI, I am putting snippet of my code for each of these 3 callbacks which will help you understand the changes I have made.

1.**/*ble_hs_cfg.store_read_cb* :
/

/case BLE_STORE_OBJ_TYPE_OUR_SEC:
        nvs_open("nimble_bond", NVS_READWRITE, &nimble_handle);

        BLE_HS_LOG(DEBUG, "looking up our sec; ");
        err = nvs_get_blob(nimble_handle, "our_sec_key", NULL, &required_size);
        if (err != ESP_OK && err != ESP_ERR_NVS_NOT_FOUND) return err;
        if (required_size == 0) {
            nvs_close(nimble_handle);
            return BLE_HS_ENOENT;
        } else {
            struct ble_store_key_sec* our_sec_key = malloc(required_size);
            err = nvs_get_blob(nimble_handle, "our_sec_key", our_sec_key, &required_size);
            if (err != ESP_OK) {
                free(our_sec_key);
                return err;
            }

            if (ble_addr_cmp(&key->sec.peer_addr, BLE_ADDR_ANY)) {
                if (ble_addr_cmp(&our_sec_key->peer_addr, &key->sec.peer_addr)){             err = nvs_get_blob(nimble_handle, "our_sec", NULL, &required_size);
            if (err != ESP_OK && err != ESP_ERR_NVS_NOT_FOUND) return err;

            struct ble_store_value_sec* our_sec = malloc(required_size);
            err = nvs_get_blob(nimble_handle, "our_sec", our_sec, &required_size);
            if (err != ESP_OK) {
                free(our_sec);
                return err;
            }

            memcpy(&value->sec, our_sec, required_size);
            free(our_sec);
                }
            }

            free(our_sec_key);
        }
        /* NVS Close */
        nvs_close(nimble_handle);

/

/2. ///*ble_hs_cfg.store_write_cb
*//

//case BLE_STORE_OBJ_TYPE_OUR_SEC:
        ble_store_key_from_value_sec(&key_sec, &val->sec);

        required_size = sizeof(struct ble_store_key_sec);
        err = nvs_set_blob(nimble_handle, "our_sec_key", &key_sec, required_size);
        required_size = sizeof(struct ble_store_value_sec);
        err = nvs_set_blob(nimble_handle, "our_sec", &val->sec, required_size);

        /* NVS Commit */
        err = nvs_commit(nimble_handle);
        if (err != ESP_OK) return err;
        /* NVS Close */
        nvs_close(nimble_handle);

        return 0;//

Regards

Prasad

disconnect; reason=531 handle=0 our_ota_addr_type=0 
our_ota_addr=24:0a:c4:23:be:76 our_id_addr_type=0 our_id_addr=24:0a:c4:23:be:76 
peer_ota_addr_type=1 peer_ota_addr=4c:fb:ae:cb:1e:d0 peer_id_addr_type=1 
peer_id_addr=4c:fb:ae:cb:1e:d0 conn_itvl=36 conn_latency=0 
supervision_timeout=500 encrypted=1 authenticated=1 bonded=1

ble_hs_hci_cmd_send: ogf=0x08 ocf=0x0007 len=0
0x07 0x20 0x00 
ble_hs_hci_cmd_send: ogf=0x08 ocf=0x0008 len=32
0x08 0x20 0x20 0x1f 0x02 0x01 0x06 0x03 0x03 0x11 0x18 0x14 0x09 0x42 0x4f 0x4e 
0x44 0x5f 0x6e 0x69 0x6d 0x62 0x6c 0x65 0x2d 0x62 0x6c 0x65 0x70 0x72 0x70 0x68 
0x02 0x0a 0x03 
GAP procedure initiated: advertise; disc_mode=2 adv_channel_map=0 
own_addr_type=0 adv_filter_policy=0 adv_itvl_min=0 adv_itvl_max=0
ble_hs_hci_cmd_send: ogf=0x08 ocf=0x0006 len=15
0x06 0x20 0x0f 0x30 0x00 0x60 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 
0x07 0x00 
ble_hs_hci_cmd_send: ogf=0x08 ocf=0x000a len=1
0x0a 0x20 0x01 0x01 

* ble_hs_hci_evt_process:: Data=003e *
I (31215) NIMBLE_BLE_PRPH: Entered event BLE_GAP_EVENT_CONNECT

 *Entered ble_sm_slave_initiate...* 

 *proc result called from ble_SM_SLAVE_initiate * 

 ** Entered into ble_sm_process_result ** 

 ** res->exec=1, res->app_status=0, proc->state=8,  ** 

-* Entered into ble_sm_sec_req_exec * - 
ble_sm_sec_req:: auth_req:: 13 sm_sm_sc_sm_MITM_^_sm_bondinghost tx hci data; 
handle=0 length=6
ble_hs_hci_acl_tx(): 0x00 0x00 0x06 0x00 0x02 0x00 0x06 0x00 0x0b 0x0d 
connection established; status=0 handle=0 our_ota_addr_type=0 
our_ota_addr=24:0a:c4:23:be:76 our_id_addr_type=0 our_id_addr=24:0a:c4:23:be:76 
peer_ota_addr_type=1 peer_ota_addr=4c:fb:ae:cb:1e:d0 peer_id_addr_type=1 
peer_id_addr=4c:fb:ae:cb:1e:d0 conn_itvl=36 conn_latency=0 
supervision_timeout=500 encrypted=0 authenticated=0 bonded=0

ble_hs_hci_cmd_send: ogf=0x08 ocf=0x0016 len=2
0x16 0x20 0x02 0x00 0x00 

* ble_hs_hci_evt_process:: Data=003e *

* ble_hs_hci_evt_process:: Data=0013 *

* ble_hs_hci_evt_process:: Data=003e *

**Calling ble_sm_ltk_req_rx from ble_hs_hci_evt_le_lt_key_req...* 

**Entered into ble_sm_ltk_req_rx**

**from ble_sm_retrieve_ltk to store_read_our...  ** 

** ble_store_read_our_sec **

* Calling callback fn store_read_cb...key_peer addr = 0001 ediv-> 0000, rand = 
0000* 
D (31425) nvs: nvs_open_from_partition nimble_bond 1
looking up our sec; D (31435) nvs: nvs_get_str_or_blob our_sec_key
D (31435) nvs: nvs_get_str_or_blob our_sec_key
D (31445) nvs: nvs_close 7

process result called from ble_sm_ltk_req_rx 

 ** Entered into ble_sm_process_result ** 

 ** res->exec=1, res->app_status=0, proc->state=4,  ** 
ble_hs_hci_cmd_send: ogf=0x08 ocf=0x001a len=18
0x1a 0x20 0x12 0x00 0x00 0x50 0x67 0xfc 0x3f 0x0c 0x00 0x00 0x00 0x7c 0xfc 0x0e 
0x80 0x80 0x6a 0xfc 0x3f 

* ble_hs_hci_evt_process:: Data=0005 *

ble_hs_hci_evt_disconn_complete: data: 0005, event_code = 0005
process result called from connection_broken 

 ** Entered into ble_sm_process_result ** 

 ** res->exec=0, res->app_status=7, proc->state=6,  ** 

 **rm=1, So entering into ble_sm_proc_remove** 

*Entered into res->enc_cb=1.. calling GAP enc event... res->app_status = 7, 
res->restore = 0*

 *Entering into ble_gap_enc_event: * 
encryption change event; status=7 handle=0 our_ota_addr_type=0 
our_ota_addr=24:0a:c4:23:be:76 our_id_addr_type=0 our_id_addr=24:0a:c4:23:be:76 
peer_ota_addr_type=1 peer_ota_addr=4c:fb:ae:cb:1e:d0 peer_id_addr_type=1 
peer_id_addr=4c:fb:ae:cb:1e:d0 conn_itvl=36 conn_latency=0 
supervision_timeout=500 encrypted=0 authenticated=0 bonded=0

disconnect; reason=573 handle=0 our_ota_addr_type=0 
our_ota_addr=24:0a:c4:23:be:76 our_id_addr_type=0 our_id_addr=24:0a:c4:23:be:76 
peer_ota_addr_type=1 peer_ota_addr=4c:fb:ae:cb:1e:d0 peer_id_addr_type=1 
peer_id_addr=4c:fb:ae:cb:1e:d0 conn_itvl=36 conn_latency=0 
supervision_timeout=500 encrypted=0 authenticated=0 bonded=0

ble_hs_hci_cmd_send: ogf=0x08 ocf=0x0007 len=0
0x07 0x20 0x00 
ble_hs_hci_cmd_send: ogf=0x08 ocf=0x0008 len=32
0x08 0x20 0x20 0x1f 0x02 0x01 0x06 0x03 0x03 0x11 0x18 0x14 0x09 0x42 0x4f 0x4e 
0x44 0x5f 0x6e 0x69 0x6d 0x62 0x6c 0x65 0x2d 0x62 0x6c 0x65 0x70 0x72 0x70 0x68 
0x02 0x0a 0x03 
GAP procedure initiated: advertise; disc_mode=2 adv_channel_map=0 
own_addr_type=0 adv_filter_policy=0 adv_itvl_min=0 adv_itvl_max=0
ble_hs_hci_cmd_send: ogf=0x08 ocf=0x0006 len=15
0x06 0x20 0x0f 0x30 0x00 0x60 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 
0x07 0x00 
ble_hs_hci_cmd_send: ogf=0x08 ocf=0x000a len=1
0x0a 0x20 0x01 0x01 

Reply via email to