This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Ble mesh: Error when adding device key??

Hi: it's me again, sorry to bother everyone once more.

This time I can finish provisioning... almost. You see, at the end of the whole provision process, a function must be called(in provisioner.c):

provisioner_prov_complete_cb

eventually, when executing the above function, this function will be called(in main.c):

dsm_devkey_add.

and then this section of code will be run(in device_state_manager.c):

 else if (dev_key_handle_get(raw_unicast_addr, &handle))
{
    return NRF_ERROR_FORBIDDEN;
}

it returns "NRF_ERROR_FORBIDDEN" all the time. I looked into the "dev_key_handle_get" function and decided that it is this part of code which is problematic (using debug breakpoints, 100% sure):

if (bitfield_get(m_devkey_allocated, i))
    {
        if (m_devkeys[i].key_owner == owner_addr)
        {
            *p_handle = DSM_DEVKEY_HANDLE_START + i;
            return true;
        }
    }

So it appears to me that the provisionee keep sending a key that is already in use, so 2 possibilities:

  1. The provisioner should have cleared the devkey cache and "forget" about the key first but failed to do so.

  2. The provisionee should have sent a different key.

Below is a more detailed hypothesis:

When finishing provisioning a node, the provisioner will try to add the address of the provisionee it just provisioned.

So to add it, it must first ensure that the address provisionee sent to it (it referring to the provisioner of course) isn't used.

So using the "dev_key_handle_get" function, provisioner try to see if this key is available.

But for some reason, the provisioner always found an identical key in the cache, already claimed. So it returns error results.

Now the question:what should I do?

Edit: I've found the probelm, and I believe it's a sort of bug:

As I guessed, if I wipe the chip clean, that probelm no longer appears. If I reset and run, it keeps entering the same error handler.

In other words, once the provisioner provisioned a device, it add the relevant info not to the RAM, but to the FLASH region.

So next time it provisions, it looks up the FLASH memory to see if relevant information existed before.

This is actually in accordance with the BLE mesh specs, as far as I'm concerned. Provisioners are supposed to store information.

So what is the problem? I think the problem is that instead of going straight for error, the provsioner program should switch to a different behavior, mark the provisionee as "already provisioned" adjust behavior accordingly and move on.

I mean even for demo purposes, you can't expect me to erase the entire chip every time I need to show others how privisioning is done???

Parents
  • Hi Mitch,

    You cannot add a device key for the same source address twice. The dsm_devkey_add() is in your case called with the same mesh unicast address twice. For demo purposes you can consider building the mesh stack and examples with #define PERSISTENT_STORAGE 0 (see nrf_mesh_config_core.h). Otherwise, your provisioner shouldn't try to add two device keys for the same node, but delete the old one first if that's the intention.

    -Thomas

Reply
  • Hi Mitch,

    You cannot add a device key for the same source address twice. The dsm_devkey_add() is in your case called with the same mesh unicast address twice. For demo purposes you can consider building the mesh stack and examples with #define PERSISTENT_STORAGE 0 (see nrf_mesh_config_core.h). Otherwise, your provisioner shouldn't try to add two device keys for the same node, but delete the old one first if that's the intention.

    -Thomas

Children
No Data
Related