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

Error trying to handle incoming message in acces.c

While trying to make a custom server model, based on the on-off model in the documentation, the code breaks when receiving an incoming message. The problem is in the file access.c from the SDK for mesh. I'm sure we are missing something and this is not a bug in the mesh stack itself. The following code handles incoming messages and passes them to the correct model handler:

static void handle_incoming(const access_message_rx_t * p_message)
{
    const nrf_mesh_address_t * p_dst = &p_message->meta_data.dst;

    if (p_dst->type == NRF_MESH_ADDRESS_TYPE_UNICAST)
    {
        dsm_local_unicast_address_t local_addresses;
        dsm_local_unicast_addresses_get(&local_addresses);

        if (p_dst->value >= local_addresses.address_start &&
            p_dst->value <  (local_addresses.address_start + local_addresses.count))
        {
            uint16_t element_index = p_dst->value - local_addresses.address_start;
            for (int i = 0; i < ACCESS_MODEL_COUNT; ++i)
            {
                access_common_t * p_model = &m_model_pool[i];

                uint32_t opcode_index;

                if(i == 2) {
                  __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "Internal state %s", ACCESS_INTERNAL_STATE_IS_ALLOCATED(p_model->internal_state) ? "allocated\n" : "not allocated\n");
                  __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "Element index match %s", p_model->model_info.element_index == element_index ? "yes\n" : "no\n");
                  __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "Bitfield %s", bitfield_get(p_model->model_info.application_keys_bitfield, p_message->meta_data.appkey_handle) ? "Ok\n" : "Not Ok\n");
                  __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "Opcode of model %s", is_opcode_of_model(p_model, p_message->opcode, &opcode_index) ? "Yes\n" : "No\n");


                  __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "bitfield: %d\n", p_model->model_info.application_keys_bitfield);
                  __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "bit: %d\n",  p_message->meta_data.appkey_handle);
                }

                
                if (ACCESS_INTERNAL_STATE_IS_ALLOCATED(p_model->internal_state) &&
                    p_model->model_info.element_index == element_index &&
                    
                    // The code breaks here
                    //bitfield_get(p_model->model_info.application_keys_bitfield, p_message->meta_data.appkey_handle) &&
                    is_opcode_of_model(p_model, p_message->opcode, &opcode_index))
                {
                    access_reliable_message_rx_cb(i, p_message, p_model->p_args);
                    p_model->p_opcode_handlers[opcode_index].handler(i, p_message, p_model->p_args);
                }
            }
        }
    }

It fails on the " bitfield_get(p_model->model_info.application_keys_bitfield, p_message->meta_data.appkey_handle) " check.

Now my question was, does this has something to do with the model, or did we do something wrong while provisioning the device, and what should we do/try to solve this. For now we have solved it by putting that check in comment, but ofcourse that's not the way to go as this bypasses the mesh security. 

Can somebody give me some pointers?

Kind regards,

Maxime

Parents
  • Hi Maxime, 

     

    Yes, it has something to do with the provisioning. Seems that the access layer can't find that the model is bound to the application key. This is done in configuration process (look for PROV_STATE_CONFIG_APPKEY_BIND_ONOFF). 

    Most likely you haven't bind your new model to the appkey in the configuration process. 

  • Hi,

    I'm facing the same error in the bitfield line in handling_incoming(), do i have to do the same configuration like on_off model, i'm using mesh 2.0.1 and configuration happen in node_setup.c file, i only added these two lines in main.c in provisioner.c to configure my new model, and it doesn't work, any idea please ?

    ERROR_CHECK(access_model_application_bind(m_message_client.model_handle, m_dev_handles.m_appkey_handle));
    ERROR_CHECK(access_model_publish_application_set(m_message_client.model_handle, m_dev_handles.m_appkey_handle));

    Thank you, 

Reply
  • Hi,

    I'm facing the same error in the bitfield line in handling_incoming(), do i have to do the same configuration like on_off model, i'm using mesh 2.0.1 and configuration happen in node_setup.c file, i only added these two lines in main.c in provisioner.c to configure my new model, and it doesn't work, any idea please ?

    ERROR_CHECK(access_model_application_bind(m_message_client.model_handle, m_dev_handles.m_appkey_handle));
    ERROR_CHECK(access_model_publish_application_set(m_message_client.model_handle, m_dev_handles.m_appkey_handle));

    Thank you, 

Children
Related