apps/blemesh: Add callbacks for mesh health fault handling
This is required for MESH/SR/HM/RFS/* tests.
/* Company ID*/
#define CID_VENDOR 0xFFFF
+#define FAULT_ARR_SIZE 2
+
+static bool has_reg_fault = true;
+
static struct bt_mesh_cfg cfg_srv = {
.relay = BT_MESH_RELAY_DISABLED,
.beacon = BT_MESH_BEACON_ENABLED,
@@ -52,7 +56,83 @@ static struct bt_mesh_cfg cfg_srv = {
.relay_retransmit = BT_MESH_TRANSMIT(2, 20),
};
+static int
+fault_get_cur(struct bt_mesh_model *model,
+ uint8_t *test_id,
+ uint16_t *company_id,
+ uint8_t *faults,
+ uint8_t *fault_count)
+{
+ uint8_t reg_faults[FAULT_ARR_SIZE] = { [0 ... FAULT_ARR_SIZE-1] = 0xff };
+
+ console_printf("fault_get_cur() has_reg_fault %u\n", has_reg_fault);
+
+ *test_id = 0x00;
+ *company_id = CID_VENDOR;
+
+ *fault_count = min(*fault_count, sizeof(reg_faults));
+ memcpy(faults, reg_faults, *fault_count);
+
+ return 0;
+}
+
+static int
+fault_get_reg(struct bt_mesh_model *model,
+ uint16_t company_id,
+ uint8_t *test_id,
+ uint8_t *faults,
+ uint8_t *fault_count)
+{
+ if (company_id != CID_VENDOR) {
+ return -BLE_HS_EINVAL;
+ }
+
+ console_printf("fault_get_reg() has_reg_fault %u\n", has_reg_fault);
+
+ *test_id = 0x00;
+
+ if (has_reg_fault) {
+ uint8_t reg_faults[FAULT_ARR_SIZE] = { [0 ... FAULT_ARR_SIZE-1] = 0xff };
+
+ *fault_count = min(*fault_count, sizeof(reg_faults));
+ memcpy(faults, reg_faults, *fault_count);
+ } else {
+ *fault_count = 0;
+ }
+
+ return 0;
+}
+
+static int
+fault_clear(struct bt_mesh_model *model, uint16_t company_id)
+{
+ if (company_id != CID_VENDOR) {
+ return -BLE_HS_EINVAL;
+ }
+
+ has_reg_fault = false;
+
+ return 0;
+}
+
+static int
+fault_test(struct bt_mesh_model *model, uint8_t test_id, uint16_t company_id)
+{
+ if (company_id != CID_VENDOR) {
+ return -BLE_HS_EINVAL;
+ }
+
+ has_reg_fault = true;
+ bt_mesh_fault_update(model->elem);
+
+ return 0;
+}
+
static struct bt_mesh_health health_srv = {
+ .fault_get_cur = &fault_get_cur,
+ .fault_get_reg = &fault_get_reg,
+ .fault_clear = &fault_clear,
+ .fault_test = &fault_test,
};
static struct bt_mesh_model_pub gen_level_pub;
