mirror of
https://github.com/bluekitchen/btstack.git
synced 2025-03-29 22:20:37 +00:00
mesh: prefix mesh_node functions
This commit is contained in:
parent
e4058622b0
commit
001c65e028
@ -188,7 +188,7 @@ static void mesh_lower_transport_send_ack(uint16_t netkey_index, uint8_t ttl, ui
|
||||
if (!network_pdu) return;
|
||||
|
||||
// setup network_pdu
|
||||
mesh_network_setup_pdu(network_pdu, netkey_index, network_key->nid, 1, ttl, mesh_sequence_number_next(), mesh_node_primary_element_address_get(), dest, ack_msg, sizeof(ack_msg));
|
||||
mesh_network_setup_pdu(network_pdu, netkey_index, network_key->nid, 1, ttl, mesh_sequence_number_next(), mesh_node_get_primary_element_address(), dest, ack_msg, sizeof(ack_msg));
|
||||
|
||||
// send network_pdu
|
||||
mesh_network_send_pdu(network_pdu);
|
||||
@ -200,7 +200,7 @@ static void mesh_lower_transport_send_ack_for_transport_pdu(mesh_transport_pdu_t
|
||||
uint16_t dest = mesh_transport_src(transport_pdu);
|
||||
uint16_t netkey_index = transport_pdu->netkey_index;
|
||||
printf("mesh_transport_send_ack_for_transport_pdu %p with netkey_index %x, TTL = %u, SeqZero = %x, SRC = %x, DST = %x\n",
|
||||
transport_pdu, netkey_index, ttl, seq_zero, mesh_node_primary_element_address_get(), dest);
|
||||
transport_pdu, netkey_index, ttl, seq_zero, mesh_node_get_primary_element_address(), dest);
|
||||
mesh_lower_transport_send_ack(netkey_index, ttl, dest, seq_zero, transport_pdu->block_ack);
|
||||
}
|
||||
|
||||
@ -209,7 +209,7 @@ static void mesh_lower_transport_send_ack_for_network_pdu(mesh_network_pdu_t *ne
|
||||
uint16_t dest = mesh_network_src(network_pdu);
|
||||
uint16_t netkey_index = network_pdu->netkey_index;
|
||||
printf("mesh_transport_send_ack_for_network_pdu %p with netkey_index %x, TTL = %u, SeqZero = %x, SRC = %x, DST = %x\n",
|
||||
network_pdu, netkey_index, ttl, seq_zero, mesh_node_primary_element_address_get(), dest);
|
||||
network_pdu, netkey_index, ttl, seq_zero, mesh_node_get_primary_element_address(), dest);
|
||||
mesh_lower_transport_send_ack(netkey_index, ttl, dest, seq_zero, block_ack);
|
||||
}
|
||||
|
||||
|
@ -382,9 +382,9 @@ void mesh_network_message_processed_by_higher_layer(mesh_network_pdu_t * network
|
||||
uint16_t src = mesh_network_src(network_pdu);
|
||||
uint8_t ttl = mesh_network_ttl(network_pdu);
|
||||
|
||||
uint16_t mesh_network_primary_address = mesh_node_primary_element_address_get();
|
||||
uint16_t mesh_network_primary_address = mesh_node_get_primary_element_address();
|
||||
|
||||
if (((src < mesh_network_primary_address) || (src > (mesh_network_primary_address + mesh_element_count()))) && (ttl >= 2)){
|
||||
if (((src < mesh_network_primary_address) || (src > (mesh_network_primary_address + mesh_node_element_count()))) && (ttl >= 2)){
|
||||
|
||||
if ((network_pdu->flags & MESH_NETWORK_PDU_FLAGS_GATT_BEARER) == 0){
|
||||
|
||||
|
@ -53,33 +53,33 @@ void mesh_node_primary_element_address_set(uint16_t unicast_address){
|
||||
primary_element_address = unicast_address;
|
||||
}
|
||||
|
||||
uint16_t mesh_node_primary_element_address_get(void){
|
||||
uint16_t mesh_node_get_primary_element_address(void){
|
||||
return primary_element_address;
|
||||
}
|
||||
|
||||
void mesh_node_init(void){
|
||||
// dd Primary Element to list of elements
|
||||
mesh_element_add(&primary_element);
|
||||
mesh_node_add_element(&primary_element);
|
||||
}
|
||||
|
||||
void mesh_element_add(mesh_element_t * element){
|
||||
void mesh_node_add_element(mesh_element_t * element){
|
||||
element->element_index = mesh_element_index_next++;
|
||||
btstack_linked_list_add_tail(&mesh_elements, (void*) element);
|
||||
}
|
||||
|
||||
uint16_t mesh_element_count(void){
|
||||
uint16_t mesh_node_element_count(void){
|
||||
return (uint16_t) btstack_linked_list_count(&mesh_elements);
|
||||
}
|
||||
|
||||
mesh_element_t * mesh_primary_element(void){
|
||||
mesh_element_t * mesh_node_get_primary_element(void){
|
||||
return &primary_element;
|
||||
}
|
||||
|
||||
void mesh_access_set_primary_element_location(uint16_t location){
|
||||
void mesh_node_set_primary_element_location(uint16_t location){
|
||||
primary_element.loc = location;
|
||||
}
|
||||
|
||||
mesh_element_t * mesh_element_for_index(uint16_t element_index){
|
||||
mesh_element_t * mesh_node_element_for_index(uint16_t element_index){
|
||||
btstack_linked_list_iterator_t it;
|
||||
btstack_linked_list_iterator_init(&it, &mesh_elements);
|
||||
while (btstack_linked_list_iterator_has_next(&it)){
|
||||
@ -90,9 +90,9 @@ mesh_element_t * mesh_element_for_index(uint16_t element_index){
|
||||
return NULL;
|
||||
}
|
||||
|
||||
mesh_element_t * mesh_element_for_unicast_address(uint16_t unicast_address){
|
||||
uint16_t element_index = unicast_address - mesh_node_primary_element_address_get();
|
||||
return mesh_element_for_index(element_index);
|
||||
mesh_element_t * mesh_node_element_for_unicast_address(uint16_t unicast_address){
|
||||
uint16_t element_index = unicast_address - mesh_node_get_primary_element_address();
|
||||
return mesh_node_element_for_index(element_index);
|
||||
}
|
||||
|
||||
void mesh_element_iterator_init(mesh_element_iterator_t * iterator){
|
||||
|
@ -80,41 +80,42 @@ void mesh_node_primary_element_address_set(uint16_t unicast_address);
|
||||
* @note Returned by Configuration Server Composite Data
|
||||
* @param location
|
||||
*/
|
||||
void mesh_access_set_primary_element_location(uint16_t location);
|
||||
void mesh_node_set_primary_element_location(uint16_t location);
|
||||
|
||||
/**
|
||||
* @brief Get unicast address of primary element
|
||||
*/
|
||||
uint16_t mesh_node_primary_element_address_get(void);
|
||||
uint16_t mesh_node_get_primary_element_address(void);
|
||||
|
||||
/**
|
||||
* @brief Get Primary Element of this node
|
||||
*/
|
||||
mesh_element_t * mesh_primary_element(void);
|
||||
mesh_element_t * mesh_node_get_primary_element(void);
|
||||
|
||||
/**
|
||||
* @brief Add secondary element
|
||||
* @param element
|
||||
*/
|
||||
void mesh_element_add(mesh_element_t * element);
|
||||
void mesh_node_add_element(mesh_element_t * element);
|
||||
|
||||
/**
|
||||
* @brief Get number elements
|
||||
* @returns number of elements on this node
|
||||
*/
|
||||
uint16_t mesh_element_count(void);
|
||||
uint16_t mesh_node_element_count(void);
|
||||
|
||||
/**
|
||||
* @brief Get element for given unicast address
|
||||
* @param unicast_address
|
||||
*/
|
||||
mesh_element_t * mesh_element_for_unicast_address(uint16_t unicast_address);
|
||||
mesh_element_t * mesh_node_element_for_unicast_address(uint16_t unicast_address);
|
||||
|
||||
/**
|
||||
* @brief Get element by index
|
||||
* @param element_index
|
||||
*/
|
||||
mesh_element_t * mesh_element_for_index(uint16_t element_index);
|
||||
mesh_element_t * mesh_node_element_for_index(uint16_t element_index);
|
||||
|
||||
|
||||
// Mesh Element Iterator
|
||||
|
||||
|
@ -718,30 +718,33 @@ int btstack_main(void)
|
||||
|
||||
// Access layer
|
||||
mesh_access_init();
|
||||
|
||||
// Node Configuration
|
||||
|
||||
// Loc - bottom - https://www.bluetooth.com/specifications/assigned-numbers/gatt-namespace-descriptors
|
||||
mesh_access_set_primary_element_location(0x103);
|
||||
mesh_node_set_primary_element_location(0x103);
|
||||
|
||||
// Setup models
|
||||
mesh_configuration_server_model.model_identifier = mesh_model_get_model_identifier_bluetooth_sig(MESH_SIG_MODEL_ID_CONFIGURATION_SERVER);
|
||||
mesh_model_reset_appkeys(&mesh_configuration_server_model);
|
||||
mesh_configuration_server_model.model_data = &mesh_configuration_server_model_context;
|
||||
mesh_configuration_server_model.operations = mesh_configuration_server_get_operations();
|
||||
mesh_element_add_model(mesh_primary_element(), &mesh_configuration_server_model);
|
||||
mesh_element_add_model(mesh_node_get_primary_element(), &mesh_configuration_server_model);
|
||||
|
||||
mesh_health_server_model.model_identifier = mesh_model_get_model_identifier_bluetooth_sig(MESH_SIG_MODEL_ID_HEALTH_SERVER);
|
||||
mesh_model_reset_appkeys(&mesh_health_server_model);
|
||||
mesh_element_add_model(mesh_primary_element(), &mesh_health_server_model);
|
||||
mesh_element_add_model(mesh_node_get_primary_element(), &mesh_health_server_model);
|
||||
|
||||
mesh_generic_on_off_server_model.model_identifier = mesh_model_get_model_identifier_bluetooth_sig(MESH_SIG_MODEL_ID_GENERIC_ON_OFF_SERVER);
|
||||
mesh_model_reset_appkeys(&mesh_generic_on_off_server_model);
|
||||
mesh_generic_on_off_server_model.operations = mesh_generic_on_off_server_get_operations();
|
||||
mesh_element_add_model(mesh_primary_element(), &mesh_generic_on_off_server_model);
|
||||
mesh_element_add_model(mesh_node_get_primary_element(), &mesh_generic_on_off_server_model);
|
||||
mesh_generic_on_off_server_model.model_data = (void *) &mesh_generic_on_off_state;
|
||||
mesh_generic_on_off_server_register_packet_handler(&mesh_generic_on_off_server_model, &mesh_state_update_message_handler);
|
||||
|
||||
mesh_vendor_model.model_identifier = mesh_model_get_model_identifier(BLUETOOTH_COMPANY_ID_BLUEKITCHEN_GMBH, MESH_BLUEKITCHEN_MODEL_ID_TEST_SERVER);
|
||||
mesh_model_reset_appkeys(&mesh_vendor_model);
|
||||
mesh_element_add_model(mesh_primary_element(), &mesh_vendor_model);
|
||||
mesh_element_add_model(mesh_node_get_primary_element(), &mesh_vendor_model);
|
||||
|
||||
// Enable PROXY
|
||||
mesh_foundation_gatt_proxy_set(1);
|
||||
|
@ -167,7 +167,7 @@ static void mesh_access_acknowledged_run(btstack_timer_source_t * ts){
|
||||
// find correct model and emit error
|
||||
uint16_t src = mesh_pdu_src(pdu);
|
||||
uint16_t dst = mesh_pdu_dst(pdu);
|
||||
mesh_element_t * element = mesh_element_for_unicast_address(src);
|
||||
mesh_element_t * element = mesh_node_element_for_unicast_address(src);
|
||||
if (element){
|
||||
// find
|
||||
mesh_model_iterator_t model_it;
|
||||
@ -398,7 +398,7 @@ uint8_t mesh_access_get_element_index(mesh_model_t * mesh_model){
|
||||
}
|
||||
|
||||
uint16_t mesh_access_get_element_address(mesh_model_t * mesh_model){
|
||||
return mesh_node_primary_element_address_get() + mesh_model->element->element_index;
|
||||
return mesh_node_get_primary_element_address() + mesh_model->element->element_index;
|
||||
}
|
||||
|
||||
// Model Identifier utilities
|
||||
@ -424,7 +424,7 @@ int mesh_model_is_bluetooth_sig(uint32_t model_identifier){
|
||||
}
|
||||
|
||||
mesh_model_t * mesh_model_get_configuration_server(void){
|
||||
return mesh_model_get_by_identifier(mesh_primary_element(), mesh_model_get_model_identifier_bluetooth_sig(MESH_SIG_MODEL_ID_CONFIGURATION_SERVER));
|
||||
return mesh_model_get_by_identifier(mesh_node_get_primary_element(), mesh_model_get_model_identifier_bluetooth_sig(MESH_SIG_MODEL_ID_CONFIGURATION_SERVER));
|
||||
}
|
||||
|
||||
void mesh_element_add_model(mesh_element_t * element, mesh_model_t * mesh_model){
|
||||
@ -462,7 +462,7 @@ mesh_model_t * mesh_model_get_by_identifier(mesh_element_t * element, uint32_t m
|
||||
}
|
||||
|
||||
mesh_model_t * mesh_access_model_for_address_and_model_identifier(uint16_t element_address, uint32_t model_identifier, uint8_t * status){
|
||||
mesh_element_t * element = mesh_element_for_unicast_address(element_address);
|
||||
mesh_element_t * element = mesh_node_element_for_unicast_address(element_address);
|
||||
if (element == NULL){
|
||||
*status = MESH_FOUNDATION_STATUS_INVALID_ADDRESS;
|
||||
return NULL;
|
||||
@ -900,7 +900,7 @@ static void mesh_access_message_process_handler(mesh_pdu_t * 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);
|
||||
mesh_element_t * element = mesh_node_element_for_unicast_address(dst);
|
||||
if (element != NULL){
|
||||
// iterate over models, look for operation
|
||||
mesh_model_iterator_t model_it;
|
||||
@ -944,7 +944,7 @@ static void mesh_access_message_process_handler(mesh_pdu_t * pdu){
|
||||
}
|
||||
if (deliver_to_primary_element){
|
||||
mesh_model_iterator_t model_it;
|
||||
mesh_model_iterator_init(&model_it, mesh_primary_element());
|
||||
mesh_model_iterator_init(&model_it, mesh_node_get_primary_element());
|
||||
while (mesh_model_iterator_has_next(&model_it)){
|
||||
mesh_model_t * model = mesh_model_iterator_next(&model_it);
|
||||
// find opcode in table
|
||||
|
@ -43,6 +43,7 @@
|
||||
#include "mesh/mesh_lower_transport.h"
|
||||
#include "mesh_keys.h"
|
||||
#include "bluetooth_company_id.h"
|
||||
#include "mesh/mesh_node.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
|
@ -463,7 +463,7 @@ const mesh_access_message_t mesh_foundation_config_heartbeat_subscription_status
|
||||
static void config_server_send_message(uint16_t netkey_index, uint16_t dest, mesh_pdu_t *pdu){
|
||||
// Configuration Server is on primary element and can only use DeviceKey
|
||||
uint16_t appkey_index = MESH_DEVICE_KEY_INDEX;
|
||||
uint16_t src = mesh_node_primary_element_address_get();
|
||||
uint16_t src = mesh_node_get_primary_element_address();
|
||||
uint8_t ttl = mesh_foundation_default_ttl_get();
|
||||
mesh_upper_transport_setup_access_pdu_header(pdu, netkey_index, appkey_index, ttl, src, dest, 0);
|
||||
mesh_upper_transport_send_access_pdu(pdu);
|
||||
@ -1851,7 +1851,7 @@ static void config_heartbeat_publication_emit(mesh_heartbeat_publication_t * mes
|
||||
data[0] = mesh_heartbeat_publication->ttl;
|
||||
big_endian_store_16(data, 1, mesh_heartbeat_publication->active_features);
|
||||
mesh_upper_transport_setup_control_pdu((mesh_pdu_t *) network_pdu, mesh_heartbeat_publication->netkey_index,
|
||||
mesh_heartbeat_publication->ttl, mesh_node_primary_element_address_get(), mesh_heartbeat_publication->destination,
|
||||
mesh_heartbeat_publication->ttl, mesh_node_get_primary_element_address(), mesh_heartbeat_publication->destination,
|
||||
MESH_TRANSPORT_OPCODE_HEARTBEAT, data, sizeof(data));
|
||||
mesh_upper_transport_send_control_pdu((mesh_pdu_t *) network_pdu);
|
||||
}
|
||||
@ -2288,7 +2288,7 @@ void mesh_node_reset(void){
|
||||
void mesh_node_store_provisioning_data(void){
|
||||
// fill prov data
|
||||
mesh_provisioning_data_t provisioning_data;
|
||||
provisioning_data.unicast_address = mesh_node_primary_element_address_get();
|
||||
provisioning_data.unicast_address = mesh_node_get_primary_element_address();
|
||||
memcpy(provisioning_data.device_key, mesh_transport_key_get(MESH_DEVICE_KEY_INDEX), 16);
|
||||
|
||||
// store in tlv
|
||||
|
Loading…
x
Reference in New Issue
Block a user