mesh: implement key_refresh_phase_get foundation message

This commit is contained in:
Milanka Ringwald 2019-06-03 16:36:31 +02:00 committed by Matthias Ringwald
parent a406d8c208
commit da7a2b6df2
2 changed files with 60 additions and 15 deletions

View File

@ -1015,6 +1015,10 @@ const mesh_access_message_t mesh_foundation_config_network_transmit_status = {
const mesh_access_message_t mesh_foundation_node_identity_status = { const mesh_access_message_t mesh_foundation_node_identity_status = {
MESH_FOUNDATION_OPERATION_NODE_IDENTITY_STATUS, "121" MESH_FOUNDATION_OPERATION_NODE_IDENTITY_STATUS, "121"
}; };
const mesh_access_message_t mesh_key_refresh_phase_status = {
MESH_FOUNDATION_OPERATION_KEY_REFRESH_PHASE_STATUS, "121"
};
// message parser // message parser
static int mesh_access_get_opcode(uint8_t * buffer, uint16_t buffer_size, uint32_t * opcode, uint16_t * opcode_size){ static int mesh_access_get_opcode(uint8_t * buffer, uint16_t buffer_size, uint32_t * opcode, uint16_t * opcode_size){
@ -1331,10 +1335,11 @@ static mesh_transport_pdu_t * mesh_access_setup_segmented_message(const mesh_acc
#define MESH_SIG_MODEL_ID_GENERIC_ON_OFF_CLIENT 0x1001u #define MESH_SIG_MODEL_ID_GENERIC_ON_OFF_CLIENT 0x1001u
typedef enum { typedef enum {
MESH_FOUNDATION_NODE_IDENTITY_STATE_ADVERTISING_STOPPED = 0, MESH_NODE_IDENTITY_STATE_ADVERTISING_STOPPED = 0,
MESH_FOUNDATION_NODE_IDENTITY_STATE_ADVERTISING_RUNNING, MESH_NODE_IDENTITY_STATE_ADVERTISING_RUNNING,
MESH_FOUNDATION_NODE_IDENTITY_STATE_ADVERTISING_NOT_SUPPORTED MESH_NODE_IDENTITY_STATE_ADVERTISING_NOT_SUPPORTED
} mesh_foundation_node_identity_state_t; } mesh_node_identity_state_t;
static btstack_crypto_aes128_cmac_t configuration_server_cmac_request; static btstack_crypto_aes128_cmac_t configuration_server_cmac_request;
@ -2587,6 +2592,39 @@ static void config_heartbeat_publication_get_handler(mesh_model_t *mesh_model, m
mesh_access_message_processed(pdu); mesh_access_message_processed(pdu);
} }
static void config_key_refresh_phase_status(mesh_model_t *mesh_model, uint16_t netkey_index_dest, uint16_t dest, uint8_t status, uint16_t netkey_index,
mesh_key_refresh_state_t key_refresh_state){
// setup message
mesh_transport_pdu_t * transport_pdu = mesh_access_setup_segmented_message(
&mesh_key_refresh_phase_status,
status,
netkey_index_dest,
key_refresh_state);
if (!transport_pdu) return;
// send as segmented access pdu
config_server_send_message(mesh_model, netkey_index_dest, dest, (mesh_pdu_t *) transport_pdu);
}
static void config_key_refresh_phase_get_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);
uint16_t netkey_index = mesh_access_parser_get_u16(&parser);
mesh_network_key_t * network_key = mesh_network_key_list_get(netkey_index);
uint8_t status = MESH_FOUNDATION_STATUS_INVALID_NETKEY_INDEX;
mesh_key_refresh_state_t key_refresh_state = MESH_KEY_REFRESH_NOT_ACTIVE;
if (network_key != NULL){
status = MESH_FOUNDATION_STATUS_SUCCESS;
key_refresh_state = network_key->key_refresh;
}
config_key_refresh_phase_status(mesh_model, mesh_pdu_netkey_index(pdu), mesh_pdu_src(pdu), status, netkey_index, key_refresh_state);
mesh_access_message_processed(pdu);
}
static void config_node_reset_status(mesh_model_t *mesh_model, uint16_t netkey_index, uint16_t dest){ static void config_node_reset_status(mesh_model_t *mesh_model, uint16_t netkey_index, uint16_t dest){
// setup message // setup message
mesh_transport_pdu_t * transport_pdu = mesh_access_setup_segmented_message(&mesh_foundation_node_reset_status); mesh_transport_pdu_t * transport_pdu = mesh_access_setup_segmented_message(&mesh_foundation_node_reset_status);
@ -2596,14 +2634,14 @@ static void config_node_reset_status(mesh_model_t *mesh_model, uint16_t netkey_i
config_server_send_message(mesh_model, netkey_index, dest, (mesh_pdu_t *) transport_pdu); config_server_send_message(mesh_model, netkey_index, dest, (mesh_pdu_t *) transport_pdu);
} }
static void config_node_reset_handler(mesh_model_t *mesh_model, mesh_pdu_t * pdu) { static void config_node_reset_handler(mesh_model_t *mesh_model, mesh_pdu_t * pdu){
mesh_foundation_node_reset(); mesh_foundation_node_reset();
config_node_reset_status(mesh_model, mesh_pdu_netkey_index(pdu), mesh_pdu_src(pdu)); config_node_reset_status(mesh_model, mesh_pdu_netkey_index(pdu), mesh_pdu_src(pdu));
mesh_access_message_processed(pdu); mesh_access_message_processed(pdu);
} }
static void config_node_identity_status(mesh_model_t *mesh_model, uint16_t netkey_index_dest, uint16_t dest, uint8_t status, uint16_t netkey_index, static void config_node_identity_status(mesh_model_t *mesh_model, uint16_t netkey_index_dest, uint16_t dest, uint8_t status, uint16_t netkey_index,
mesh_foundation_node_identity_state_t node_identity_state) { mesh_node_identity_state_t node_identity_state){
// setup message // setup message
mesh_transport_pdu_t * transport_pdu = mesh_access_setup_segmented_message( mesh_transport_pdu_t * transport_pdu = mesh_access_setup_segmented_message(
&mesh_foundation_node_identity_status, &mesh_foundation_node_identity_status,
@ -2623,16 +2661,16 @@ static void config_node_identity_get_handler(mesh_model_t *mesh_model, mesh_pdu_
mesh_network_key_t * network_key = mesh_network_key_list_get(netkey_index); mesh_network_key_t * network_key = mesh_network_key_list_get(netkey_index);
uint8_t status = MESH_FOUNDATION_STATUS_SUCCESS; uint8_t status = MESH_FOUNDATION_STATUS_SUCCESS;
mesh_foundation_node_identity_state_t node_identity_state = MESH_FOUNDATION_NODE_IDENTITY_STATE_ADVERTISING_NOT_SUPPORTED; mesh_node_identity_state_t node_identity_state = MESH_NODE_IDENTITY_STATE_ADVERTISING_NOT_SUPPORTED;
if (network_key == NULL){ if (network_key == NULL){
status = MESH_FOUNDATION_STATUS_INVALID_NETKEY_INDEX; status = MESH_FOUNDATION_STATUS_INVALID_NETKEY_INDEX;
} else { } else {
#ifdef ENABLE_MESH_PROXY_SERVER #ifdef ENABLE_MESH_PROXY_SERVER
if (network_key->node_id_advertisement_running == 0){ if (network_key->node_id_advertisement_running == 0){
node_identity_state = MESH_FOUNDATION_NODE_IDENTITY_STATE_ADVERTISING_STOPPED; node_identity_state = MESH_NODE_IDENTITY_STATE_ADVERTISING_STOPPED;
} else { } else {
node_identity_state = MESH_FOUNDATION_NODE_IDENTITY_STATE_ADVERTISING_RUNNING; node_identity_state = MESH_NODE_IDENTITY_STATE_ADVERTISING_RUNNING;
} }
#endif #endif
} }
@ -2645,7 +2683,7 @@ static void config_node_identity_set_handler(mesh_model_t *mesh_model, mesh_pdu_
mesh_access_parser_state_t parser; mesh_access_parser_state_t parser;
mesh_access_parser_init(&parser, (mesh_pdu_t*) pdu); mesh_access_parser_init(&parser, (mesh_pdu_t*) pdu);
uint16_t netkey_index = mesh_access_parser_get_u16(&parser); uint16_t netkey_index = mesh_access_parser_get_u16(&parser);
mesh_foundation_node_identity_state_t node_identity_state = (mesh_foundation_node_identity_state_t) mesh_access_parser_get_u8(&parser); mesh_node_identity_state_t node_identity_state = (mesh_node_identity_state_t) mesh_access_parser_get_u8(&parser);
uint8_t status = MESH_FOUNDATION_STATUS_FEATURE_NOT_SUPPORTED; uint8_t status = MESH_FOUNDATION_STATUS_FEATURE_NOT_SUPPORTED;
@ -2655,11 +2693,11 @@ static void config_node_identity_set_handler(mesh_model_t *mesh_model, mesh_pdu_
} else { } else {
#ifdef ENABLE_MESH_PROXY_SERVER #ifdef ENABLE_MESH_PROXY_SERVER
switch (node_identity_state){ switch (node_identity_state){
case MESH_FOUNDATION_NODE_IDENTITY_STATE_ADVERTISING_STOPPED: case MESH_NODE_IDENTITY_STATE_ADVERTISING_STOPPED:
network_key->node_id_advertisement_running = 0; network_key->node_id_advertisement_running = 0;
status = MESH_FOUNDATION_STATUS_SUCCESS; status = MESH_FOUNDATION_STATUS_SUCCESS;
break; break;
case MESH_FOUNDATION_NODE_IDENTITY_STATE_ADVERTISING_RUNNING: case MESH_NODE_IDENTITY_STATE_ADVERTISING_RUNNING:
network_key->node_id_advertisement_running = 1; network_key->node_id_advertisement_running = 1;
status = MESH_FOUNDATION_STATUS_SUCCESS; status = MESH_FOUNDATION_STATUS_SUCCESS;
break; break;
@ -2725,7 +2763,7 @@ static mesh_operation_t mesh_configuration_server_model_operations[] = {
{ MESH_FOUNDATION_OPERATION_HEARTBEAT_PUBLICATION_SET, 9, config_heartbeat_publication_set_handler}, { MESH_FOUNDATION_OPERATION_HEARTBEAT_PUBLICATION_SET, 9, config_heartbeat_publication_set_handler},
// { MESH_FOUNDATION_OPERATION_HEARTBEAT_SUBSCRIPTION_GET, 0, config_heartbeat_subscription_get_handler}, // { MESH_FOUNDATION_OPERATION_HEARTBEAT_SUBSCRIPTION_GET, 0, config_heartbeat_subscription_get_handler},
// { MESH_FOUNDATION_OPERATION_HEARTBEAT_SUBSCRIPTION_SET, 5, config_heartbeat_subscription_set_handler}, // { MESH_FOUNDATION_OPERATION_HEARTBEAT_SUBSCRIPTION_SET, 5, config_heartbeat_subscription_set_handler},
// { MESH_FOUNDATION_OPERATION_KEY_REFRESH_PHASE_GET, 2, config_key_refresh_phase_get_handler}, { MESH_FOUNDATION_OPERATION_KEY_REFRESH_PHASE_GET, 2, config_key_refresh_phase_get_handler},
// { MESH_FOUNDATION_OPERATION_KEY_REFRESH_PHASE_SET, 3, config_key_refresh_phase_set_handler}, // { MESH_FOUNDATION_OPERATION_KEY_REFRESH_PHASE_SET, 3, config_key_refresh_phase_set_handler},
{ MESH_FOUNDATION_OPERATION_NODE_RESET, 0, config_node_reset_handler}, { MESH_FOUNDATION_OPERATION_NODE_RESET, 0, config_node_reset_handler},
// { MESH_FOUNDATION_OPERATION_LOW_POWER_NODE_POLL_TIMEOUT_GET, 2, config_low_power_node_poll_timeout_get_handler }, // { MESH_FOUNDATION_OPERATION_LOW_POWER_NODE_POLL_TIMEOUT_GET, 2, config_low_power_node_poll_timeout_get_handler },

View File

@ -50,6 +50,13 @@ extern "C"
#include "ble/mesh/mesh_network.h" #include "ble/mesh/mesh_network.h"
#include "ble/mesh/adv_bearer.h" #include "ble/mesh/adv_bearer.h"
typedef enum {
MESH_KEY_REFRESH_NOT_ACTIVE = 0,
MESH_KEY_REFRESH_FIRST_PHASE,
MESH_KEY_REFRESH_SECOND_PHASE
} mesh_key_refresh_state_t;
typedef struct { typedef struct {
btstack_linked_item_t item; btstack_linked_item_t item;
@ -73,8 +80,8 @@ typedef struct {
uint8_t encryption_key[16]; uint8_t encryption_key[16];
uint8_t privacy_key[16]; uint8_t privacy_key[16];
// key refresth // key refresh
uint8_t key_refresh; mesh_key_refresh_state_t key_refresh;
// subnet state // subnet state
uint8_t node_id_advertisement_running; uint8_t node_id_advertisement_running;