mirror of
https://github.com/bluekitchen/btstack.git
synced 2025-04-01 13:20:50 +00:00
mesh: validate AppKey index for model publication updates
This commit is contained in:
parent
8935b776ed
commit
7e7c4c9ac1
@ -1508,7 +1508,7 @@ config_model_publication_set_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);
|
||||
|
||||
// ElementAddress - Address of the element - should be us
|
||||
// ElementAddress
|
||||
uint16_t element_address = mesh_access_parser_get_u16(&parser);
|
||||
|
||||
// PublishAddress, 16 bit
|
||||
@ -1530,16 +1530,29 @@ config_model_publication_set_handler(mesh_model_t *mesh_model, mesh_pdu_t * pdu)
|
||||
|
||||
// Model Identifier
|
||||
uint32_t model_identifier = mesh_access_parser_get_model_identifier(&parser);
|
||||
|
||||
// Get Model for Element + Model Identifier
|
||||
uint8_t status;
|
||||
mesh_model_t * target_model = mesh_access_model_for_address_and_model_identifier(element_address, model_identifier, &status);
|
||||
|
||||
// TODO validate params
|
||||
|
||||
if (target_model){
|
||||
// Check if publicatation model struct provided
|
||||
if (status == MESH_FOUNDATION_STATUS_SUCCESS) {
|
||||
if (target_model->publication_model == NULL){
|
||||
status = MESH_FOUNDATION_STATUS_CANNOT_SET;
|
||||
} else {
|
||||
}
|
||||
}
|
||||
|
||||
// Check AppKey
|
||||
if (status == MESH_FOUNDATION_STATUS_SUCCESS){
|
||||
// check if appkey already exists
|
||||
mesh_transport_key_t * app_key = mesh_transport_key_get(configuration_server_publication_model.appkey_index);
|
||||
if (app_key == NULL) {
|
||||
status = MESH_FOUNDATION_STATUS_INVALID_APPKEY_INDEX;
|
||||
}
|
||||
}
|
||||
|
||||
// Accept set
|
||||
if (status == MESH_FOUNDATION_STATUS_SUCCESS){
|
||||
// decrease ref count if old virtual address
|
||||
if (mesh_network_address_virtual(configuration_server_publication_model.address)) {
|
||||
mesh_virtual_address_t * current_virtual_address = mesh_virtual_address_for_pseudo_dst(configuration_server_publication_model.address);
|
||||
@ -1549,7 +1562,6 @@ config_model_publication_set_handler(mesh_model_t *mesh_model, mesh_pdu_t * pdu)
|
||||
// restart publication
|
||||
config_model_publication_changed(target_model, &configuration_server_publication_model);
|
||||
}
|
||||
}
|
||||
|
||||
// send status
|
||||
config_model_publication_status(mesh_model, mesh_pdu_netkey_index(pdu), mesh_pdu_src(pdu), status, element_address, model_identifier, &configuration_server_publication_model);
|
||||
@ -1621,13 +1633,25 @@ config_model_publication_virtual_address_set_handler(mesh_model_t *mesh_model,
|
||||
// Model Identifier
|
||||
configuration_server_model_identifier = mesh_access_parser_get_model_identifier(&parser);
|
||||
|
||||
// Get Model for Element + Model Identifier
|
||||
uint8_t status;
|
||||
configuration_server_target_model = mesh_access_model_for_address_and_model_identifier(configuration_server_element_address, configuration_server_model_identifier, &status);
|
||||
|
||||
// model exists, but no publication model
|
||||
if (configuration_server_target_model != NULL && configuration_server_target_model->publication_model == NULL){
|
||||
// Check if publicatation model struct provided
|
||||
if (status == MESH_FOUNDATION_STATUS_SUCCESS) {
|
||||
if (configuration_server_target_model->publication_model == NULL){
|
||||
status = MESH_FOUNDATION_STATUS_CANNOT_SET;
|
||||
}
|
||||
}
|
||||
|
||||
// Check AppKey
|
||||
if (status == MESH_FOUNDATION_STATUS_SUCCESS){
|
||||
// check if appkey already exists
|
||||
mesh_transport_key_t * app_key = mesh_transport_key_get(configuration_server_publication_model.appkey_index);
|
||||
if (app_key == NULL) {
|
||||
status = MESH_FOUNDATION_STATUS_INVALID_APPKEY_INDEX;
|
||||
}
|
||||
}
|
||||
|
||||
// on error, no need to calculate virtual address hash
|
||||
if (status != MESH_FOUNDATION_STATUS_SUCCESS){
|
||||
@ -1653,11 +1677,11 @@ config_model_publication_get_handler(mesh_model_t *mesh_model, mesh_pdu_t * pdu)
|
||||
// Model Identifier
|
||||
uint32_t model_identifier = mesh_access_parser_get_model_identifier(&parser);
|
||||
|
||||
// Get Model for Element + Model Identifier
|
||||
uint8_t status;
|
||||
mesh_model_t * target_model = mesh_access_model_for_address_and_model_identifier(element_address, model_identifier, &status);
|
||||
|
||||
mesh_publication_model_t * publication_model;
|
||||
|
||||
if (target_model == NULL){
|
||||
// use defaults
|
||||
memset(&configuration_server_publication_model, 0, sizeof(mesh_publication_model_t));
|
||||
|
Loading…
x
Reference in New Issue
Block a user