mirror of
https://github.com/bluekitchen/btstack.git
synced 2025-02-27 03:39:56 +00:00
mesh: persist foundation state
This commit is contained in:
parent
9162eb2998
commit
09de233823
@ -445,6 +445,8 @@ static void packet_handler (uint8_t packet_type, uint16_t channel, uint8_t *pack
|
|||||||
mesh_load_subscriptions();
|
mesh_load_subscriptions();
|
||||||
// load model publications
|
// load model publications
|
||||||
mesh_load_publications();
|
mesh_load_publications();
|
||||||
|
// load foundation state
|
||||||
|
mesh_foundation_state_load();
|
||||||
|
|
||||||
// dump PTS MeshOptions.ini
|
// dump PTS MeshOptions.ini
|
||||||
mesh_pts_dump_mesh_options();
|
mesh_pts_dump_mesh_options();
|
||||||
|
@ -674,6 +674,49 @@ static uint32_t mesh_network_key_tag_for_internal_index(uint16_t internal_index)
|
|||||||
return ((uint32_t) 'M' << 24) | ((uint32_t) 'N' << 16) | ((uint32_t) internal_index);
|
return ((uint32_t) 'M' << 24) | ((uint32_t) 'N' << 16) | ((uint32_t) internal_index);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 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 Network Keys
|
// Mesh Network Keys
|
||||||
typedef struct {
|
typedef struct {
|
||||||
uint16_t netkey_index;
|
uint16_t netkey_index;
|
||||||
|
@ -238,6 +238,9 @@ 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);
|
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);
|
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
|
// message builder transport
|
||||||
mesh_transport_pdu_t * mesh_access_transport_init(uint32_t opcode);
|
mesh_transport_pdu_t * mesh_access_transport_init(uint32_t opcode);
|
||||||
|
@ -526,7 +526,7 @@ static void config_composition_data_get_handler(mesh_model_t *mesh_model, mesh_p
|
|||||||
static void config_model_beacon_status(mesh_model_t * mesh_model, uint16_t netkey_index, uint16_t dest){
|
static void config_model_beacon_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_config_beacon_status,
|
mesh_transport_pdu_t * transport_pdu = mesh_access_setup_segmented_message(&mesh_foundation_config_beacon_status,
|
||||||
mesh_foundation_becaon_get());
|
mesh_foundation_beacon_get());
|
||||||
if (!transport_pdu) return;
|
if (!transport_pdu) return;
|
||||||
|
|
||||||
// send as segmented access pdu
|
// send as segmented access pdu
|
||||||
@ -550,6 +550,8 @@ static void config_beacon_set_handler(mesh_model_t *mesh_model, mesh_pdu_t * pdu
|
|||||||
|
|
||||||
// store
|
// store
|
||||||
mesh_foundation_beacon_set(beacon_enabled);
|
mesh_foundation_beacon_set(beacon_enabled);
|
||||||
|
mesh_foundation_state_store();
|
||||||
|
|
||||||
//
|
//
|
||||||
config_model_beacon_status(mesh_model, mesh_pdu_netkey_index(pdu), mesh_pdu_src(pdu));
|
config_model_beacon_status(mesh_model, mesh_pdu_netkey_index(pdu), mesh_pdu_src(pdu));
|
||||||
|
|
||||||
@ -582,6 +584,8 @@ static void config_default_ttl_set_handler(mesh_model_t *mesh_model, mesh_pdu_t
|
|||||||
if (new_ttl > 0x7f || new_ttl == 0x01) return;
|
if (new_ttl > 0x7f || new_ttl == 0x01) return;
|
||||||
// store
|
// store
|
||||||
mesh_foundation_default_ttl_set(new_ttl);
|
mesh_foundation_default_ttl_set(new_ttl);
|
||||||
|
mesh_foundation_state_store();
|
||||||
|
|
||||||
//
|
//
|
||||||
config_model_default_ttl_status(mesh_model, mesh_pdu_netkey_index(pdu), mesh_pdu_src(pdu));
|
config_model_default_ttl_status(mesh_model, mesh_pdu_netkey_index(pdu), mesh_pdu_src(pdu));
|
||||||
|
|
||||||
@ -616,6 +620,7 @@ static void config_friend_set_handler(mesh_model_t *mesh_model, mesh_pdu_t * pdu
|
|||||||
// store if supported
|
// store if supported
|
||||||
if (mesh_foundation_friend_get() != MESH_FOUNDATION_STATE_NOT_SUPPORTED){
|
if (mesh_foundation_friend_get() != MESH_FOUNDATION_STATE_NOT_SUPPORTED){
|
||||||
mesh_foundation_friend_set(new_friend_state);
|
mesh_foundation_friend_set(new_friend_state);
|
||||||
|
mesh_foundation_state_store();
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
@ -650,6 +655,8 @@ static void config_gatt_proxy_set_handler(mesh_model_t *mesh_model, mesh_pdu_t *
|
|||||||
if (enabled > 1) return;
|
if (enabled > 1) return;
|
||||||
// store
|
// store
|
||||||
mesh_foundation_gatt_proxy_set(enabled);
|
mesh_foundation_gatt_proxy_set(enabled);
|
||||||
|
mesh_foundation_state_store();
|
||||||
|
|
||||||
//
|
//
|
||||||
config_model_gatt_proxy_status(mesh_model, mesh_pdu_netkey_index(pdu), mesh_pdu_src(pdu));
|
config_model_gatt_proxy_status(mesh_model, mesh_pdu_netkey_index(pdu), mesh_pdu_src(pdu));
|
||||||
|
|
||||||
@ -689,6 +696,7 @@ static void config_relay_set_handler(mesh_model_t *mesh_model, mesh_pdu_t * pdu)
|
|||||||
if (mesh_foundation_relay_get() != MESH_FOUNDATION_STATE_NOT_SUPPORTED){
|
if (mesh_foundation_relay_get() != MESH_FOUNDATION_STATE_NOT_SUPPORTED){
|
||||||
mesh_foundation_relay_set(relay);
|
mesh_foundation_relay_set(relay);
|
||||||
mesh_foundation_relay_retransmit_set(relay_retransmit);
|
mesh_foundation_relay_retransmit_set(relay_retransmit);
|
||||||
|
mesh_foundation_state_store();
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
@ -721,6 +729,8 @@ static void config_model_network_transmit_set_handler(mesh_model_t * mesh_model,
|
|||||||
|
|
||||||
// store
|
// store
|
||||||
mesh_foundation_network_transmit_set(new_ttl);
|
mesh_foundation_network_transmit_set(new_ttl);
|
||||||
|
mesh_foundation_state_store();
|
||||||
|
|
||||||
//
|
//
|
||||||
config_model_network_transmit_status(mesh_model, mesh_pdu_netkey_index(pdu), mesh_pdu_src(pdu));
|
config_model_network_transmit_status(mesh_model, mesh_pdu_netkey_index(pdu), mesh_pdu_src(pdu));
|
||||||
|
|
||||||
|
@ -64,7 +64,7 @@ void mesh_foundation_beacon_set(uint8_t ttl){
|
|||||||
mesh_foundation_beacon = ttl;
|
mesh_foundation_beacon = ttl;
|
||||||
printf("MESH: Secure Network Beacon %x\n", mesh_foundation_beacon);
|
printf("MESH: Secure Network Beacon %x\n", mesh_foundation_beacon);
|
||||||
}
|
}
|
||||||
uint8_t mesh_foundation_becaon_get(void){
|
uint8_t mesh_foundation_beacon_get(void){
|
||||||
return mesh_foundation_beacon;
|
return mesh_foundation_beacon;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -190,7 +190,7 @@ void mesh_foundation_beacon_set(uint8_t ttl);
|
|||||||
*
|
*
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
uint8_t mesh_foundation_becaon_get(void);
|
uint8_t mesh_foundation_beacon_get(void);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
|
Loading…
x
Reference in New Issue
Block a user