1 /** @file 2 * @brief Bluetooth Mesh Health Server Model APIs. 3 */ 4 5 /* 6 * SPDX-FileCopyrightText: 2017 Intel Corporation 7 * 8 * SPDX-License-Identifier: Apache-2.0 9 */ 10 #ifndef _BLE_MESH_HEALTH_SRV_H_ 11 #define _BLE_MESH_HEALTH_SRV_H_ 12 13 #include "mesh_access.h" 14 15 /** 16 * @brief Bluetooth Mesh Health Server Model 17 * @defgroup bt_mesh_health_srv Bluetooth Mesh Health Server Model 18 * @ingroup bt_mesh 19 * @{ 20 */ 21 22 #ifdef __cplusplus 23 extern "C" { 24 #endif 25 26 struct bt_mesh_health_srv_cb { 27 /* Clear registered faults */ 28 void (*fault_clear)(struct bt_mesh_model *model, uint16_t company_id); 29 30 /* Run a specific test */ 31 void (*fault_test)(struct bt_mesh_model *model, uint8_t test_id, 32 uint16_t company_id); 33 34 /* Attention on */ 35 void (*attn_on)(struct bt_mesh_model *model, uint8_t time); 36 37 /* Attention off */ 38 void (*attn_off)(struct bt_mesh_model *model); 39 }; 40 41 /** @def BLE_MESH_HEALTH_PUB_DEFINE 42 * 43 * A helper to define a health publication context 44 * 45 * @param _name Name given to the publication context variable. 46 * @param _max_faults Maximum number of faults the element can have. 47 */ 48 #define BLE_MESH_HEALTH_PUB_DEFINE(_name, _max_faults) \ 49 BLE_MESH_MODEL_PUB_DEFINE(_name, NULL, (1 + 3 + (_max_faults))) 50 51 struct bt_mesh_health_test { 52 uint8_t id_count; /* Number of Health self-test ID */ 53 const uint8_t *test_ids; /* Array of Health self-test IDs */ 54 uint16_t company_id; /* Company ID used to identify the Health Fault state */ 55 uint8_t prev_test_id; /* Most currently performed test id */ 56 uint8_t curr_faults[32]; /* Array of current faults */ 57 uint8_t reg_faults[32]; /* Array of registered faults */ 58 } __attribute__((packed)); 59 60 /** Mesh Health Server Model Context */ 61 struct bt_mesh_health_srv { 62 struct bt_mesh_model *model; 63 64 /* Optional callback struct */ 65 struct bt_mesh_health_srv_cb cb; 66 67 /* Attention Timer state */ 68 struct k_delayed_work attn_timer; 69 70 /* Attention Timer start flag */ 71 bool attn_timer_start; 72 73 /* Health Server fault test */ 74 struct bt_mesh_health_test test; 75 }; 76 77 extern const struct bt_mesh_model_op bt_mesh_health_srv_op[]; 78 extern const struct bt_mesh_model_cb bt_mesh_health_srv_cb; 79 80 /** @def BLE_MESH_MODEL_HEALTH_SRV 81 * 82 * Define a new health server model. Note that this API needs to be 83 * repeated for each element which the application wants to have a 84 * health server model on. Each instance also needs a unique 85 * bt_mesh_health_srv and bt_mesh_model_pub context. 86 * 87 * @param srv Pointer to a unique struct bt_mesh_health_srv. 88 * @param pub Pointer to a unique struct bt_mesh_model_pub. 89 * 90 * @return New mesh model instance. 91 */ 92 #define BLE_MESH_MODEL_HEALTH_SRV(srv, pub) \ 93 BLE_MESH_MODEL_CB(BLE_MESH_MODEL_ID_HEALTH_SRV, \ 94 bt_mesh_health_srv_op, pub, srv, &bt_mesh_health_srv_cb) 95 96 int bt_mesh_fault_update(struct bt_mesh_elem *elem); 97 98 #ifdef __cplusplus 99 } 100 #endif 101 102 /** 103 * @} 104 */ 105 106 #endif /* __BLE_MESH_HEALTH_SRV_H */ 107