From 699be93dacf3719b5d6c6bdda6375ee0fbae1f13 Mon Sep 17 00:00:00 2001 From: Milanka Ringwald Date: Fri, 6 Dec 2019 11:55:48 +0100 Subject: [PATCH] mesh: configuration client, define and send MESH_SUBEVENT_FOUNDATION_BEACON_STATUS event" --- src/btstack_defines.h | 10 ++++++++++ src/btstack_event.h | 28 ++++++++++++++++++++++++++ src/mesh/mesh_configuration_client.c | 30 +++++++++++++++++++++++++++- src/mesh/mesh_configuration_client.h | 2 +- 4 files changed, 68 insertions(+), 2 deletions(-) diff --git a/src/btstack_defines.h b/src/btstack_defines.h index aca4a4d55..89e651f96 100644 --- a/src/btstack_defines.h +++ b/src/btstack_defines.h @@ -2928,4 +2928,14 @@ typedef uint8_t sm_key_t[16]; * @param transition_time_gdtt */ #define MESH_SUBEVENT_GENERIC_DEFAULT_TRANSITION_TIME_STATUS 0x35 + +/** + * @format 1211 + * @param subevent_code + * @param dest + * @param foundation_status + * @param secure_network_beacon_state + */ +#define MESH_SUBEVENT_FOUNDATION_BEACON_STATUS 0x36 + #endif diff --git a/src/btstack_event.h b/src/btstack_event.h index 59975fd61..518af3189 100644 --- a/src/btstack_event.h +++ b/src/btstack_event.h @@ -8008,6 +8008,34 @@ static inline uint8_t mesh_subevent_generic_default_transition_time_status_get_t return event[6]; } +/** + * @brief Get field dest from event MESH_SUBEVENT_FOUNDATION_BEACON_STATUS + * @param event packet + * @return dest + * @note: btstack_type 2 + */ +static inline uint16_t mesh_subevent_foundation_beacon_status_get_dest(const uint8_t * event){ + return little_endian_read_16(event, 3); +} +/** + * @brief Get field foundation_status from event MESH_SUBEVENT_FOUNDATION_BEACON_STATUS + * @param event packet + * @return foundation_status + * @note: btstack_type 1 + */ +static inline uint8_t mesh_subevent_foundation_beacon_status_get_foundation_status(const uint8_t * event){ + return event[5]; +} +/** + * @brief Get field secure_network_beacon_state from event MESH_SUBEVENT_FOUNDATION_BEACON_STATUS + * @param event packet + * @return secure_network_beacon_state + * @note: btstack_type 1 + */ +static inline uint8_t mesh_subevent_foundation_beacon_status_get_secure_network_beacon_state(const uint8_t * event){ + return event[6]; +} + /* API_END */ diff --git a/src/mesh/mesh_configuration_client.c b/src/mesh/mesh_configuration_client.c index 054f60707..21eaca951 100644 --- a/src/mesh/mesh_configuration_client.c +++ b/src/mesh/mesh_configuration_client.c @@ -122,7 +122,7 @@ static const mesh_access_message_t mesh_configuration_client_publication_virtual }; #endif -uint8_t mesh_configuration_send_message_client_config_beacon_get(mesh_model_t * mesh_model, uint16_t dest, uint16_t netkey_index, uint16_t appkey_index){ +uint8_t mesh_configuration_client_send_message_config_beacon_get(mesh_model_t * mesh_model, uint16_t dest, uint16_t netkey_index, uint16_t appkey_index){ uint8_t status = mesh_access_validate_envelop_params(mesh_model, dest, netkey_index, appkey_index); if (status != ERROR_CODE_SUCCESS) return status; @@ -133,6 +133,34 @@ uint8_t mesh_configuration_send_message_client_config_beacon_get(mesh_model_t * return ERROR_CODE_SUCCESS;; } +// Model Operations +static void mesh_configuration_client_status_handler(mesh_model_t *mesh_model, mesh_pdu_t * pdu){ + mesh_access_parser_state_t parser; + mesh_access_parser_init(&parser, (mesh_pdu_t*) pdu); + + uint8_t beacon_status = mesh_access_parser_get_u8(&parser); + + uint8_t event[7] = {HCI_EVENT_MESH_META, 5, MESH_SUBEVENT_FOUNDATION_BEACON_STATUS}; + int pos = 3; + // dest + little_endian_store_16(event, pos, mesh_pdu_src(pdu)); + pos += 2; + event[pos++] = ERROR_CODE_SUCCESS; + event[pos++] = beacon_status; + + (*mesh_model->model_packet_handler)(HCI_EVENT_PACKET, 0, event, pos); + mesh_access_message_processed(pdu); +} + +const static mesh_operation_t mesh_configuration_client_model_operations[] = { + { MESH_FOUNDATION_OPERATION_BEACON_STATUS, 0, mesh_configuration_client_status_handler }, + { 0, 0, NULL } +}; + +const mesh_operation_t * mesh_configuration_client_get_operations(void){ + return mesh_configuration_client_model_operations; +} + void mesh_configuration_client_register_packet_handler(mesh_model_t *configuration_client_model, btstack_packet_handler_t events_packet_handler){ btstack_assert(events_packet_handler != NULL); btstack_assert(configuration_client_model != NULL); diff --git a/src/mesh/mesh_configuration_client.h b/src/mesh/mesh_configuration_client.h index 36ed103ef..642457215 100644 --- a/src/mesh/mesh_configuration_client.h +++ b/src/mesh/mesh_configuration_client.h @@ -62,7 +62,7 @@ void mesh_configuration_client_register_packet_handler(mesh_model_t *configurati * @param appkey_index * @return status ERROR_CODE_SUCCESS if successful, otherwise BTSTACK_MEMORY_ALLOC_FAILED */ -uint8_t mesh_configuration_send_message_client_config_beacon_get(mesh_model_t * mesh_model, uint16_t dest, uint16_t netkey_index, uint16_t appkey_index); +uint8_t mesh_configuration_client_send_message_config_beacon_get(mesh_model_t * mesh_model, uint16_t dest, uint16_t netkey_index, uint16_t appkey_index); #ifdef __cplusplus