diff --git a/src/btstack_defines.h b/src/btstack_defines.h index f98084f3e..6984cf0bc 100644 --- a/src/btstack_defines.h +++ b/src/btstack_defines.h @@ -3072,5 +3072,13 @@ typedef uint8_t sm_key_t[16]; */ #define MESH_SUBEVENT_CONFIGURATION_APPKEY_INDEX_LIST_ITEM 0x48 - +/** + * @format 12121 + * @param subevent_code + * @param dest + * @param foundation_status + * @param netkey_index_item + * @param identity_status + */ +#define MESH_SUBEVENT_CONFIGURATION_NODE_IDENTITY 0x49 #endif diff --git a/src/btstack_event.h b/src/btstack_event.h index 00721e5f9..7b17ee1d9 100644 --- a/src/btstack_event.h +++ b/src/btstack_event.h @@ -8525,41 +8525,14 @@ static inline uint16_t mesh_subevent_configuration_appkey_index_list_item_get_ne return little_endian_read_16(event, 6); } /** - * @brief Get field num_appkey_indexes from event MESH_SUBEVENT_CONFIGURATION_APPKEY_INDEX_LIST_ITEM + * @brief Get field identity_status from event MESH_SUBEVENT_CONFIGURATION_APPKEY_INDEX_LIST_ITEM * @param event packet - * @return num_appkey_indexes + * @return identity_status * @note: btstack_type 1 */ -static inline uint8_t mesh_subevent_configuration_appkey_index_list_item_get_num_appkey_indexes(const uint8_t * event){ +static inline uint8_t mesh_subevent_configuration_appkey_index_list_item_get_identity_status(const uint8_t * event){ return event[8]; } -/** - * @brief Get field appkey_index_pos from event MESH_SUBEVENT_CONFIGURATION_APPKEY_INDEX_LIST_ITEM - * @param event packet - * @return appkey_index_pos - * @note: btstack_type 1 - */ -static inline uint8_t mesh_subevent_configuration_appkey_index_list_item_get_appkey_index_pos(const uint8_t * event){ - return event[9]; -} -/** - * @brief Get field netkey_index_item from event MESH_SUBEVENT_CONFIGURATION_APPKEY_INDEX_LIST_ITEM - * @param event packet - * @return netkey_index_item - * @note: btstack_type 2 - */ -static inline uint16_t mesh_subevent_configuration_appkey_index_list_item_get_netkey_index_item(const uint8_t * event){ - return little_endian_read_16(event, 10); -} -/** - * @brief Get field appkey_index_item from event MESH_SUBEVENT_CONFIGURATION_APPKEY_INDEX_LIST_ITEM - * @param event packet - * @return appkey_index_item - * @note: btstack_type 2 - */ -static inline uint16_t mesh_subevent_configuration_appkey_index_list_item_get_appkey_index_item(const uint8_t * event){ - return little_endian_read_16(event, 12); -} diff --git a/src/mesh/mesh_configuration_client.c b/src/mesh/mesh_configuration_client.c index 57740ca23..117b5db05 100644 --- a/src/mesh/mesh_configuration_client.c +++ b/src/mesh/mesh_configuration_client.c @@ -256,6 +256,13 @@ static const mesh_access_message_t mesh_configuration_client_appkey_get = { MESH_FOUNDATION_OPERATION_APPKEY_GET, "2" }; +static const mesh_access_message_t mesh_configuration_client_node_identity_get = { + MESH_FOUNDATION_OPERATION_NODE_IDENTITY_GET, "2" +}; +static const mesh_access_message_t mesh_configuration_client_node_identity_set = { + MESH_FOUNDATION_OPERATION_NODE_IDENTITY_SET, "21" +}; + static void mesh_configuration_client_send_acknowledged(uint16_t src, uint16_t dest, uint16_t netkey_index, uint16_t appkey_index, mesh_pdu_t *pdu, uint32_t ack_opcode){ uint8_t ttl = mesh_foundation_default_ttl_get(); mesh_upper_transport_setup_access_pdu_header(pdu, netkey_index, appkey_index, ttl, src, dest, 0); @@ -634,6 +641,30 @@ uint8_t mesh_configuration_client_send_appkey_get(mesh_model_t * mesh_model, uin return ERROR_CODE_SUCCESS; } +uint8_t mesh_configuration_client_send_node_identity_get(mesh_model_t * mesh_model, uint16_t dest, uint16_t netkey_index, uint16_t appkey_index, uint16_t netk_index){ + uint8_t status = mesh_access_validate_envelop_params(mesh_model, dest, netkey_index, appkey_index); + if (status != ERROR_CODE_SUCCESS) return status; + + mesh_transport_pdu_t * transport_pdu = mesh_access_setup_segmented_message(&mesh_configuration_client_node_identity_get, netk_index); + if (!transport_pdu) return BTSTACK_MEMORY_ALLOC_FAILED; + + mesh_configuration_client_send_acknowledged(mesh_access_get_element_address(mesh_model), dest, netkey_index, appkey_index, (mesh_pdu_t *) transport_pdu, MESH_FOUNDATION_OPERATION_NODE_IDENTITY_STATUS); + return ERROR_CODE_SUCCESS; +} + +uint8_t mesh_configuration_client_send_node_identity_set(mesh_model_t * mesh_model, uint16_t dest, uint16_t netkey_index, uint16_t appkey_index, uint16_t netk_index, mesh_node_identity_state_t node_identity_state){ + uint8_t status = mesh_access_validate_envelop_params(mesh_model, dest, netkey_index, appkey_index); + if (status != ERROR_CODE_SUCCESS) return status; + + mesh_transport_pdu_t * transport_pdu = mesh_access_setup_segmented_message(&mesh_configuration_client_node_identity_set, netk_index, node_identity_state); + if (!transport_pdu) return BTSTACK_MEMORY_ALLOC_FAILED; + + mesh_configuration_client_send_acknowledged(mesh_access_get_element_address(mesh_model), dest, netkey_index, appkey_index, (mesh_pdu_t *) transport_pdu, MESH_FOUNDATION_OPERATION_NODE_IDENTITY_STATUS); + return ERROR_CODE_SUCCESS; +} + + + // Model Operations static void mesh_configuration_client_composition_data_status_handler(mesh_model_t *mesh_model, mesh_pdu_t * pdu){ // Composition Data has variable of element descriptions, with two lists of model lists @@ -933,7 +964,7 @@ static void mesh_configuration_client_appkey_handler(mesh_model_t *mesh_model, m static void mesh_configuration_client_appkey_list_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 status = 0; + uint8_t status = 0; uint8_t list_size = mesh_access_parser_available(&parser)/2; uint8_t event[12]; @@ -958,6 +989,30 @@ static void mesh_configuration_client_appkey_list_handler(mesh_model_t *mesh_mod mesh_access_message_processed(pdu); } +static void mesh_configuration_client_node_identity_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 status = mesh_access_parser_get_u8(&parser); + uint16_t netkey_index = mesh_access_parser_get_u8(&parser); + uint8_t identity_status = mesh_access_parser_get_u8(&parser); + + uint8_t event[9]; + int pos = 0; + event[pos++] = HCI_EVENT_MESH_META; + event[pos++] = sizeof(event) - 2; + event[pos++] = MESH_SUBEVENT_CONFIGURATION_NODE_IDENTITY; + // dest + little_endian_store_16(event, pos, mesh_pdu_src(pdu)); + pos += 2; + event[pos++] = status; + little_endian_store_16(event, pos, netkey_index); + pos += 2; + event[pos++] = identity_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, 1, mesh_configuration_client_beacon_status_handler }, { MESH_FOUNDATION_OPERATION_COMPOSITION_DATA_STATUS, 10, mesh_configuration_client_composition_data_status_handler }, @@ -972,6 +1027,7 @@ const static mesh_operation_t mesh_configuration_client_model_operations[] = { { MESH_FOUNDATION_OPERATION_NETKEY_LIST, 0, mesh_configuration_client_netkey_list_handler }, { MESH_FOUNDATION_OPERATION_APPKEY_STATUS, 4, mesh_configuration_client_appkey_handler }, { MESH_FOUNDATION_OPERATION_APPKEY_LIST, 3, mesh_configuration_client_appkey_list_handler }, + { MESH_FOUNDATION_OPERATION_NODE_IDENTITY_STATUS, 4, mesh_configuration_client_node_identity_handler }, { 0, 0, NULL } }; diff --git a/src/mesh/mesh_configuration_client.h b/src/mesh/mesh_configuration_client.h index bde8df8ee..0f4b99c78 100644 --- a/src/mesh/mesh_configuration_client.h +++ b/src/mesh/mesh_configuration_client.h @@ -499,6 +499,26 @@ uint8_t mesh_configuration_client_send_appkey_delete(mesh_model_t * mesh_model, */ uint8_t mesh_configuration_client_send_appkey_get(mesh_model_t * mesh_model, uint16_t dest, uint16_t netkey_index, uint16_t appkey_index, uint16_t netk_index); +/** + * @brief Get the current Node Identity state for a subnet. + * @param mesh_model + * @param dest element_address + * @param netkey_index + * @param netk_index + * @return status ERROR_CODE_SUCCESS if successful, otherwise BTSTACK_MEMORY_ALLOC_FAILED or ERROR_CODE_PARAMETER_OUT_OF_MANDATORY_RANGE + */ +uint8_t mesh_configuration_client_send_node_identity_get(mesh_model_t * mesh_model, uint16_t dest, uint16_t netkey_index, uint16_t appkey_index, uint16_t netk_index); + +/** + * @brief Set the current Node Identity state for a subnet. + * @param mesh_model + * @param dest element_address + * @param netkey_index + * @param netk_index + * @param node_identity_state + * @return status ERROR_CODE_SUCCESS if successful, otherwise BTSTACK_MEMORY_ALLOC_FAILED or ERROR_CODE_PARAMETER_OUT_OF_MANDATORY_RANGE + */ +uint8_t mesh_configuration_client_send_node_identity_set(mesh_model_t * mesh_model, uint16_t dest, uint16_t netkey_index, uint16_t appkey_index, uint16_t netk_index, mesh_node_identity_state_t node_identity_state); #ifdef __cplusplus } /* end of extern "C" */ #endif