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 Reply Children
No Data
Related