mesh: move foundation load/store to mesh from access

This commit is contained in:
Matthias Ringwald 2019-07-15 13:11:40 +02:00
parent 726dac53ea
commit a55e84a9c0
4 changed files with 43 additions and 48 deletions

View File

@ -100,6 +100,16 @@ typedef struct {
uint8_t key[16];
} mesh_persistent_app_key_t;
typedef struct {
uint8_t gatt_proxy;
uint8_t beacon;
uint8_t default_ttl;
uint8_t network_transmit;
uint8_t relay;
uint8_t relay_retransmit;
uint8_t friend;
} mesh_persistent_foundation_t;
static btstack_packet_handler_t provisioning_device_packet_handler;
static btstack_packet_callback_registration_t hci_event_callback_registration;
static int provisioned;
@ -249,6 +259,35 @@ static void hci_packet_handler (uint8_t packet_type, uint16_t channel, uint8_t *
}
}
// Foundation state
static const uint32_t mesh_foundation_state_tag = ((uint32_t) 'M' << 24) | ((uint32_t) 'F' << 16) | ((uint32_t) 'N' << 8) | ((uint32_t) 'D' << 8);
void mesh_foundation_state_load(void){
mesh_persistent_foundation_t data;
int foundation_state_len = btstack_tlv_singleton_impl->get_tag(btstack_tlv_singleton_context, mesh_foundation_state_tag, (uint8_t *) &data, sizeof(data));
if (foundation_state_len != sizeof(data)) return;
mesh_foundation_gatt_proxy_set(data.gatt_proxy);
mesh_foundation_beacon_set(data.gatt_proxy);
mesh_foundation_default_ttl_set(data.default_ttl);
mesh_foundation_friend_set(data.friend);
mesh_foundation_network_transmit_set(data.network_transmit);
mesh_foundation_relay_set(data.relay);
mesh_foundation_relay_retransmit_set(data.relay_retransmit);
}
void mesh_foundation_state_store(void){
mesh_persistent_foundation_t data;
data.gatt_proxy = mesh_foundation_gatt_proxy_get();
data.gatt_proxy = mesh_foundation_beacon_get();
data.default_ttl = mesh_foundation_default_ttl_get();
data.friend = mesh_foundation_friend_get();
data.network_transmit = mesh_foundation_network_transmit_get();
data.relay = mesh_foundation_relay_get();
data.relay_retransmit = mesh_foundation_relay_retransmit_get();
btstack_tlv_singleton_impl->store_tag(btstack_tlv_singleton_context, mesh_foundation_state_tag, (uint8_t *) &data, sizeof(data));
}
// Mesh Network Keys
static uint32_t mesh_network_key_tag_for_internal_index(uint16_t internal_index){

View File

@ -58,6 +58,10 @@ void mesh_init(void);
*/
void mesh_register_provisioning_device_packet_handler(btstack_packet_handler_t packet_handler);
// Foundation state
void mesh_foundation_state_load(void);
void mesh_foundation_state_store(void);
// Mesh NetKey List
void mesh_store_network_key(mesh_network_key_t * network_key);
void mesh_delete_network_key(uint16_t internal_index);

View File

@ -996,50 +996,6 @@ int mesh_model_contains_subscription(mesh_model_t * mesh_model, uint16_t address
return 0;
}
// Foundation state
static const uint32_t mesh_foundation_state_tag = ((uint32_t) 'M' << 24) | ((uint32_t) 'F' << 16) | ((uint32_t) 'N' << 8) | ((uint32_t) 'D' << 8);
typedef struct {
uint8_t gatt_proxy;
uint8_t beacon;
uint8_t default_ttl;
uint8_t network_transmit;
uint8_t relay;
uint8_t relay_retransmit;
uint8_t friend;
} mesh_persistent_foundation_t;
void mesh_foundation_state_load(void){
mesh_access_setup_tlv();
mesh_persistent_foundation_t data;
int app_key_len = btstack_tlv_singleton_impl->get_tag(btstack_tlv_singleton_context, mesh_foundation_state_tag, (uint8_t *) &data, sizeof(data));
if (app_key_len == 0) return;
mesh_foundation_gatt_proxy_set(data.gatt_proxy);
mesh_foundation_beacon_set(data.gatt_proxy);
mesh_foundation_default_ttl_set(data.default_ttl);
mesh_foundation_friend_set(data.friend);
mesh_foundation_network_transmit_set(data.network_transmit);
mesh_foundation_relay_set(data.relay);
mesh_foundation_relay_retransmit_set(data.relay_retransmit);
}
void mesh_foundation_state_store(void){
mesh_access_setup_tlv();
mesh_persistent_foundation_t data;
data.gatt_proxy = mesh_foundation_gatt_proxy_get();
data.gatt_proxy = mesh_foundation_beacon_get();
data.default_ttl = mesh_foundation_default_ttl_get();
data.friend = mesh_foundation_friend_get();
data.network_transmit = mesh_foundation_network_transmit_get();
data.relay = mesh_foundation_relay_get();
data.relay_retransmit = mesh_foundation_relay_retransmit_get();
btstack_tlv_singleton_impl->store_tag(btstack_tlv_singleton_context, mesh_foundation_state_tag, (uint8_t *) &data, sizeof(data));
}
// Mesh IV Index
static uint32_t mesh_tag_for_iv_index_and_seq_number(void){
return ((uint32_t) 'M' << 24) | ((uint32_t) 'F' << 16) | ((uint32_t) 'I' << 9) | ((uint32_t) 'S');

View File

@ -375,10 +375,6 @@ void mesh_access_parser_get_label_uuid(mesh_access_parser_state_t * state, uint8
void mesh_access_parser_get_key(mesh_access_parser_state_t * state, uint8_t * dest);
uint32_t mesh_access_parser_get_model_identifier(mesh_access_parser_state_t * parser);
// Foundation state
void mesh_foundation_state_load(void);
void mesh_foundation_state_store(void);
// message builder transport
mesh_transport_pdu_t * mesh_access_transport_init(uint32_t opcode);
void mesh_access_transport_add_uint8(mesh_transport_pdu_t * pdu, uint8_t value);