Don't suppose anybody's had a chance to look at this yet? I've been notified there's been a few different engineers assigned but no replies so far. Could really do with some help on this.
Hi,
Steve Butler said:Could really do with some help on this.
I am sorry for the delays. Have you gotten any further on your own?
I may have just misunderstood the capabilities of the sensor server with _ns builds so please let me know if it's not possible to have a sensor server on a _ns target, but the documentation for the mesh light ctrl sample leads me to believe you can.
Documentation indeed indicates that ns build targets should work. For later SDK releases it even recommends to use the ns variant of the board target, for more security. However, the nRF5340 is not listed as a supported board, and (at least in later SDK releases) the unmodified sample won't build for the DK.
Using addr2line, I've traced the fault to the following line inside the SDK file nrf/subsys/bluetooth/mesh/sensor_types.c:const struct scalar_repr *repr = format->user_data;I believe this suggests my non-secure application is trying to access a pointer (format->user_data) that points to a secure memory region, causing a secure fault.
I agree, your explanation sounds plausible, yes. If so, I would expect that the offending variable format came from the following call:
int rc = bt_mesh_sensor_value_from_micro(sensor->type->channels[0].format, micro, rsp);
Are you able to trigger the error there already, by trying to access sensor->type->channels[0].format directly, in that context? I.e. where you now call bt_mesh_sensor_value_from_micro in your code?
Regards,
Terje
Hi,
Steve Butler said:Could really do with some help on this.
I am sorry for the delays. Have you gotten any further on your own?
I may have just misunderstood the capabilities of the sensor server with _ns builds so please let me know if it's not possible to have a sensor server on a _ns target, but the documentation for the mesh light ctrl sample leads me to believe you can.
Documentation indeed indicates that ns build targets should work. For later SDK releases it even recommends to use the ns variant of the board target, for more security. However, the nRF5340 is not listed as a supported board, and (at least in later SDK releases) the unmodified sample won't build for the DK.
Using addr2line, I've traced the fault to the following line inside the SDK file nrf/subsys/bluetooth/mesh/sensor_types.c:const struct scalar_repr *repr = format->user_data;I believe this suggests my non-secure application is trying to access a pointer (format->user_data) that points to a secure memory region, causing a secure fault.
I agree, your explanation sounds plausible, yes. If so, I would expect that the offending variable format came from the following call:
int rc = bt_mesh_sensor_value_from_micro(sensor->type->channels[0].format, micro, rsp);
Are you able to trigger the error there already, by trying to access sensor->type->channels[0].format directly, in that context? I.e. where you now call bt_mesh_sensor_value_from_micro in your code?
Regards,
Terje
Thanks for the response Terje,
So I've updated the energy_use_get function to the below:
static int energy_use_get(struct bt_mesh_sensor_srv *srv,
struct bt_mesh_sensor *sensor,
struct bt_mesh_msg_ctx *ctx,
struct bt_mesh_sensor_value *rsp)
{
/* Report energy usage as dummy value, and increase it by one every time
* a get callback is triggered. The logic and hardware for mesuring
* the actual energy usage of the device should be implemented here.
*/
// int64_t micro = (int64_t)dummy_energy_use * 1000000LL;
const struct bt_mesh_sensor_format* fmt = sensor->type->channels[0].format;
if (!fmt) {
printf("bt_mesh_sensor_format: (null)\n");
return;
}
printf("bt_mesh_sensor_format @%p {\n", (void *)fmt);
printf(" cb : %p\n", (void *)fmt->cb);
printf(" user_data : %p\n", fmt->user_data);
printf(" size : %zu\n", fmt->size);
#ifdef CONFIG_BT_MESH_SENSOR_LABELS
printf(" unit : %p\n", (void *)fmt->unit);
#endif
printf("}\n");
// int rc = bt_mesh_sensor_value_from_micro(sensor->type->channels[0].format, micro, rsp);
// if (rc)
// {
// LOG_ERR("energy_use_get: bt_mesh_sensor_value_from_micro failed: %d", rc);
// return rc;
// }
dummy_energy_use++;
LOG_INF("energy_use_get: success dummy=%d", dummy_energy_use);
return 0;
}
And when I try get sensor information the console reads:
if (fmt->cb->compare(&threshold->range.high,
Is there any chance of a response on this? Again I've received a few notifications that engineers have been assigned but no replies as of yet
void print_sensor_format(const struct bt_mesh_sensor_format *fmt)
{
if (!fmt)
{
printf("bt_mesh_sensor_format: (null)\n");
return;
}
printf("bt_mesh_sensor_format @%p {\n", (void *)fmt);
printf("\tcb: %p\n", (void *)fmt->cb);
printf("\tcb->to_float: %p\n", (void *)fmt->cb->to_float);
printf("\tcb->to_micro: %p\n", (void *)fmt->cb->to_micro);
printf("\tcb->to_string: %p\n", (void *)fmt->cb->to_string);
printf("\tcb->compare: %p\n", (void *)fmt->cb->compare);
printf("\tuser_data: %p\n", fmt->user_data);
printf("\tsize: %zu\n", fmt->size);
printf("}\n");
}