mirror of
https://github.com/bluekitchen/btstack.git
synced 2025-02-28 06:39:49 +00:00
mesh: validate appkey index for access messages
This commit is contained in:
parent
ae26178409
commit
cbc8da7c60
@ -223,6 +223,17 @@ uint16_t mesh_pdu_netkey_index(mesh_pdu_t * pdu){
|
||||
}
|
||||
}
|
||||
|
||||
uint16_t mesh_pdu_appkey_index(mesh_pdu_t * pdu){
|
||||
switch (pdu->pdu_type){
|
||||
case MESH_PDU_TYPE_TRANSPORT:
|
||||
return ((mesh_transport_pdu_t*) pdu)->appkey_index;
|
||||
case MESH_PDU_TYPE_NETWORK:
|
||||
return ((mesh_network_pdu_t *) pdu)->appkey_index;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
uint16_t mesh_pdu_len(mesh_pdu_t * pdu){
|
||||
switch (pdu->pdu_type){
|
||||
case MESH_PDU_TYPE_TRANSPORT:
|
||||
@ -556,6 +567,13 @@ static const mesh_operation_t * mesh_model_lookup_operation(mesh_model_t * model
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static int mesh_access_validate_appkey_index(mesh_model_t * model, uint16_t appkey_index){
|
||||
// DeviceKey is valid for all models
|
||||
if (appkey_index == MESH_DEVICE_KEY_INDEX) return 1;
|
||||
// check if AppKey that is bound to this particular model
|
||||
return mesh_model_contains_appkey(model, appkey_index);
|
||||
}
|
||||
|
||||
static void mesh_access_message_process_handler(mesh_pdu_t * pdu){
|
||||
// get opcode and size
|
||||
uint32_t opcode = 0;
|
||||
@ -580,9 +598,8 @@ static void mesh_access_message_process_handler(mesh_pdu_t * pdu){
|
||||
break;
|
||||
}
|
||||
|
||||
// TODO: check if used AppKey is bound to particular model
|
||||
|
||||
uint16_t dst = mesh_pdu_dst(pdu);
|
||||
uint16_t appkey_index = mesh_pdu_appkey_index(pdu);
|
||||
if (mesh_network_address_unicast(dst)){
|
||||
// loookup element by unicast address
|
||||
mesh_element_t * element = mesh_element_for_unicast_address(dst);
|
||||
@ -595,6 +612,7 @@ static void mesh_access_message_process_handler(mesh_pdu_t * pdu){
|
||||
// find opcode in table
|
||||
const mesh_operation_t * operation = mesh_model_lookup_operation(model, pdu);
|
||||
if (operation == NULL) break;
|
||||
if (mesh_access_validate_appkey_index(model, appkey_index) == 0) break;
|
||||
operation->handler(model, pdu);
|
||||
return;
|
||||
}
|
||||
@ -613,6 +631,7 @@ static void mesh_access_message_process_handler(mesh_pdu_t * pdu){
|
||||
// find opcode in table
|
||||
const mesh_operation_t * operation = mesh_model_lookup_operation(model, pdu);
|
||||
if (operation == NULL) break;
|
||||
if (mesh_access_validate_appkey_index(model, appkey_index) == 0) break;
|
||||
operation->handler(model, pdu);
|
||||
return;
|
||||
}
|
||||
@ -795,3 +814,12 @@ void mesh_model_unbind_appkey(mesh_model_t * mesh_model, uint16_t appkey_index){
|
||||
}
|
||||
}
|
||||
|
||||
int mesh_model_contains_appkey(mesh_model_t * mesh_model, uint16_t appkey_index){
|
||||
uint16_t i;
|
||||
for (i=0;i<MAX_NR_MESH_APPKEYS_PER_MODEL;i++){
|
||||
if (mesh_model->appkey_indices[i] == appkey_index) return 1;
|
||||
}
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
|
@ -194,6 +194,7 @@ mesh_model_t * mesh_access_model_for_address_and_model_identifier(uint16_t eleme
|
||||
uint16_t mesh_pdu_src(mesh_pdu_t * pdu);
|
||||
uint16_t mesh_pdu_dst(mesh_pdu_t * pdu);
|
||||
uint16_t mesh_pdu_netkey_index(mesh_pdu_t * pdu);
|
||||
uint16_t mesh_pdu_appkey_index(mesh_pdu_t * pdu);
|
||||
uint16_t mesh_pdu_len(mesh_pdu_t * pdu);
|
||||
uint8_t * mesh_pdu_data(mesh_pdu_t * pdu);
|
||||
|
||||
@ -213,6 +214,7 @@ void mesh_delete_appkey_lists(void);
|
||||
void mesh_model_reset_appkeys(mesh_model_t * mesh_model);
|
||||
uint8_t mesh_model_bind_appkey(mesh_model_t * mesh_model, uint16_t appkey_index);
|
||||
void mesh_model_unbind_appkey(mesh_model_t * mesh_model, uint16_t appkey_index);
|
||||
int mesh_model_contains_appkey(mesh_model_t * mesh_model, uint16_t appkey_index);
|
||||
|
||||
// Mesh Access Parser
|
||||
int mesh_access_pdu_get_opcode(mesh_pdu_t * pdu, uint32_t * opcode, uint16_t * opcode_size);
|
||||
|
Loading…
x
Reference in New Issue
Block a user