diff --git a/src/btstack_defines.h b/src/btstack_defines.h index e7caf236e..129ec386c 100644 --- a/src/btstack_defines.h +++ b/src/btstack_defines.h @@ -2925,13 +2925,14 @@ typedef uint8_t sm_key_t[16]; #define MESH_SUBEVENT_GENERIC_LEVEL_STATUS 0x32 /** - * @format 1122221 + * @format 1222211 * @param subevent_code * @param dest * @param netkey_index * @param appkey_index * @param company_id * @param test_id + * @param acknowledged */ #define MESH_SUBEVENT_HEALTH_PERFORM_TEST 0x33 diff --git a/src/btstack_event.h b/src/btstack_event.h index 5b0bd7c53..daaa45a79 100644 --- a/src/btstack_event.h +++ b/src/btstack_event.h @@ -7915,24 +7915,6 @@ static inline uint32_t mesh_subevent_generic_level_status_get_remaining_time_ms( return little_endian_read_32(event, 12); } -/** - * @brief Get field element_index from event MESH_SUBEVENT_HEALTH_PERFORM_TEST - * @param event packet - * @return element_index - * @note: btstack_type 1 - */ -static inline uint8_t mesh_subevent_health_perform_test_get_element_index(const uint8_t * event){ - return event[3]; -} -/** - * @brief Get field model_identifier from event MESH_SUBEVENT_HEALTH_PERFORM_TEST - * @param event packet - * @return model_identifier - * @note: btstack_type 4 - */ -static inline uint32_t mesh_subevent_health_perform_test_get_model_identifier(const uint8_t * event){ - return little_endian_read_32(event, 4); -} /** * @brief Get field dest from event MESH_SUBEVENT_HEALTH_PERFORM_TEST * @param event packet @@ -7940,7 +7922,7 @@ static inline uint32_t mesh_subevent_health_perform_test_get_model_identifier(co * @note: btstack_type 2 */ static inline uint16_t mesh_subevent_health_perform_test_get_dest(const uint8_t * event){ - return little_endian_read_16(event, 8); + return little_endian_read_16(event, 3); } /** * @brief Get field netkey_index from event MESH_SUBEVENT_HEALTH_PERFORM_TEST @@ -7949,7 +7931,7 @@ static inline uint16_t mesh_subevent_health_perform_test_get_dest(const uint8_t * @note: btstack_type 2 */ static inline uint16_t mesh_subevent_health_perform_test_get_netkey_index(const uint8_t * event){ - return little_endian_read_16(event, 10); + return little_endian_read_16(event, 5); } /** * @brief Get field appkey_index from event MESH_SUBEVENT_HEALTH_PERFORM_TEST @@ -7958,7 +7940,7 @@ static inline uint16_t mesh_subevent_health_perform_test_get_netkey_index(const * @note: btstack_type 2 */ static inline uint16_t mesh_subevent_health_perform_test_get_appkey_index(const uint8_t * event){ - return little_endian_read_16(event, 12); + return little_endian_read_16(event, 7); } /** * @brief Get field company_id from event MESH_SUBEVENT_HEALTH_PERFORM_TEST @@ -7967,7 +7949,7 @@ static inline uint16_t mesh_subevent_health_perform_test_get_appkey_index(const * @note: btstack_type 2 */ static inline uint16_t mesh_subevent_health_perform_test_get_company_id(const uint8_t * event){ - return little_endian_read_16(event, 14); + return little_endian_read_16(event, 9); } /** * @brief Get field test_id from event MESH_SUBEVENT_HEALTH_PERFORM_TEST @@ -7976,7 +7958,16 @@ static inline uint16_t mesh_subevent_health_perform_test_get_company_id(const ui * @note: btstack_type 1 */ static inline uint8_t mesh_subevent_health_perform_test_get_test_id(const uint8_t * event){ - return event[16]; + return event[11]; +} +/** + * @brief Get field acknowledged from event MESH_SUBEVENT_HEALTH_PERFORM_TEST + * @param event packet + * @return acknowledged + * @note: btstack_type 1 + */ +static inline uint8_t mesh_subevent_health_perform_test_get_acknowledged(const uint8_t * event){ + return event[12]; } /** diff --git a/src/mesh/mesh_health_server.c b/src/mesh/mesh_health_server.c index 8bed0c347..24ba109be 100644 --- a/src/mesh/mesh_health_server.c +++ b/src/mesh/mesh_health_server.c @@ -57,9 +57,6 @@ #include "mesh/mesh_network.h" #include "mesh/mesh_upper_transport.h" -// used for asynchronous calls in the done command to unblock the message queue -static mesh_pdu_t * processed_pdu; - static void health_server_send_message(uint16_t src, uint16_t dest, uint16_t netkey_index, uint16_t appkey_index, mesh_pdu_t *pdu){ uint8_t ttl = mesh_foundation_default_ttl_get(); mesh_upper_transport_setup_access_pdu_header(pdu, netkey_index, appkey_index, ttl, src, dest, 0); @@ -165,7 +162,7 @@ static void health_fault_clear_unacknowledged_handler(mesh_model_t *mesh_model, } -static void health_fault_test_process_message(mesh_model_t *mesh_model, mesh_pdu_t * pdu){ +static void health_fault_test_process_message(mesh_model_t *mesh_model, mesh_pdu_t * pdu, bool acknowledged){ mesh_access_parser_state_t parser; mesh_access_parser_init(&parser, (mesh_pdu_t*) pdu); uint8_t test_id = mesh_access_parser_get_u8(&parser); @@ -178,20 +175,18 @@ static void health_fault_test_process_message(mesh_model_t *mesh_model, mesh_pdu // check if fault state exists for company id mesh_health_fault_t * fault = mesh_health_server_fault_for_company_id(mesh_model, company_id); if (fault == NULL){ - mesh_health_server_report_test_not_supported(dest, netkey_index, appkey_index, test_id, company_id); + return; } // short-cut if not packet handler set, but only for standard test if (mesh_model->model_packet_handler == NULL){ if (test_id == 0) { - mesh_health_server_report_test_done(dest, netkey_index, appkey_index, test_id, company_id); - } else { - mesh_health_server_report_test_not_supported(dest, netkey_index, appkey_index, test_id, company_id); + mesh_health_server_report_test_done(dest, netkey_index, appkey_index, test_id, company_id, acknowledged); } return; } - uint8_t event[12]; + uint8_t event[13]; int pos = 0; event[pos++] = HCI_EVENT_MESH_META; event[pos++] = sizeof(event) - 2; @@ -205,19 +200,20 @@ static void health_fault_test_process_message(mesh_model_t *mesh_model, mesh_pdu pos += 2; little_endian_store_16(event, pos, company_id); pos += 2; + event[pos++] = test_id; + event[pos++] = acknowledged; (*mesh_model->model_packet_handler)(HCI_EVENT_PACKET, 0, event, pos); } static void health_fault_test_handler(mesh_model_t *mesh_model, mesh_pdu_t * pdu){ - processed_pdu = pdu; - health_fault_test_process_message(mesh_model, pdu); + health_fault_test_process_message(mesh_model, pdu, true); + mesh_access_message_processed(pdu); } static void health_fault_test_unacknowledged_handler(mesh_model_t * mesh_model, mesh_pdu_t * pdu){ - processed_pdu = NULL; - health_fault_test_process_message(mesh_model, pdu); + health_fault_test_process_message(mesh_model, pdu, false); mesh_access_message_processed(pdu); } @@ -427,33 +423,15 @@ void mesh_health_server_set_publication_model(mesh_model_t * mesh_model, mesh_pu mesh_model->publication_model = publication_model; } -void mesh_health_server_report_test_not_supported(uint16_t dest, uint16_t netkey_index, uint16_t appkey_index, uint8_t test_id, uint16_t company_id){ - UNUSED(dest); - UNUSED(netkey_index); - UNUSED(appkey_index); - UNUSED(test_id); - UNUSED(company_id); - - // report acknowledged message processed - if (processed_pdu != NULL){ - mesh_pdu_t * pdu = processed_pdu; - processed_pdu = NULL; - mesh_access_message_processed(pdu); - } -} - -void mesh_health_server_report_test_done(uint16_t dest, uint16_t netkey_index, uint16_t appkey_index, uint8_t test_id, uint16_t company_id){ +void mesh_health_server_report_test_done(uint16_t dest, uint16_t netkey_index, uint16_t appkey_index, uint8_t test_id, uint16_t company_id, bool acknowledged){ mesh_model_t * mesh_model = mesh_node_get_health_server(); if (mesh_model == NULL) return; + mesh_health_fault_t * fault = mesh_health_server_fault_for_company_id(mesh_model, company_id); fault->test_id = test_id; // response for acknowledged health fault test - if (processed_pdu != NULL){ - mesh_pdu_t * pdu = processed_pdu; - processed_pdu = NULL; - mesh_access_message_processed(pdu); - + if (acknowledged){ mesh_transport_pdu_t * transport_pdu = (mesh_transport_pdu_t *) health_fault_status(mesh_model, MESH_FOUNDATION_OPERATION_HEALTH_FAULT_STATUS, company_id, company_id); if (!transport_pdu) return; health_server_send_message(mesh_node_get_primary_element_address(), dest, netkey_index, appkey_index, (mesh_pdu_t *) transport_pdu); diff --git a/src/mesh/mesh_health_server.h b/src/mesh/mesh_health_server.h index b94e97d12..d9023efc6 100644 --- a/src/mesh/mesh_health_server.h +++ b/src/mesh/mesh_health_server.h @@ -70,18 +70,9 @@ void mesh_health_server_set_publication_model(mesh_model_t * mesh_model, mesh_pu * @param appkey_index * @param test_id * @param company_id + * @param acknowledged */ -void mesh_health_server_report_test_done(uint16_t dest, uint16_t netkey_index, uint16_t appkey_index, uint8_t test_id, uint16_t company_id); - -/** -* @brief Notify health server that test is not supported (wrong company or test id), params are from MESH_SUBEVENT_HEALTH_PERFORM_TEST -* @param dest -* @param netkey_index -* @param appkey_index -* @param test_id -* @param company_id -*/ -void mesh_health_server_report_test_not_supported(uint16_t dest, uint16_t netkey_index, uint16_t appkey_index, uint8_t test_id, uint16_t company_id); +void mesh_health_server_report_test_done(uint16_t dest, uint16_t netkey_index, uint16_t appkey_index, uint8_t test_id, uint16_t company_id, bool acknowledged); /** * @brief Provide fault state memory