mesh: introduce mesh_upper_transport_builder

This commit is contained in:
Matthias Ringwald 2020-03-30 15:03:46 +02:00
parent 923523a338
commit f12194469a
6 changed files with 132 additions and 155 deletions

View File

@ -617,61 +617,62 @@ static int mesh_access_setup_opcode(uint8_t * buffer, uint32_t opcode){
}
// mesh_message_t builder
void mesh_access_message_add_data(mesh_upper_transport_pdu_t * pdu, const uint8_t * data, uint16_t data_len){
mesh_upper_transport_message_add_data(pdu, data, data_len);
}
mesh_upper_transport_pdu_t * mesh_access_message_init(uint32_t opcode) {
mesh_upper_transport_pdu_t * pdu = mesh_upper_transport_message_init(MESH_PDU_TYPE_UPPER_UNSEGMENTED_ACCESS);
if (!pdu) return NULL;
void mesh_access_message_init(mesh_upper_transport_builder_t * builder, uint32_t opcode) {
mesh_upper_transport_message_init(builder, MESH_PDU_TYPE_UPPER_UNSEGMENTED_ACCESS);
// add opcode
uint8_t opcode_buffer[3];
uint8_t opcode_len = mesh_access_setup_opcode(opcode_buffer, opcode);
mesh_access_message_add_data(pdu, opcode_buffer, opcode_len);
return pdu;
mesh_access_message_add_data(builder, opcode_buffer, opcode_len);
}
void mesh_access_message_add_uint8(mesh_upper_transport_pdu_t * pdu, uint8_t value){
mesh_upper_transport_message_add_uint8(pdu, value);
void mesh_access_message_add_data(mesh_upper_transport_builder_t * pdu, const uint8_t * data, uint16_t data_len){
mesh_upper_transport_message_add_data(pdu, data, data_len);
}
void mesh_access_message_add_uint16(mesh_upper_transport_pdu_t * pdu, uint16_t value){
mesh_upper_transport_message_add_uint16(pdu, value);
void mesh_access_message_add_uint8(mesh_upper_transport_builder_t * builder, uint8_t value){
mesh_upper_transport_message_add_uint8(builder, value);
}
void mesh_access_message_add_uint24(mesh_upper_transport_pdu_t * pdu, uint16_t value){
mesh_upper_transport_message_add_uint24(pdu, value);
void mesh_access_message_add_uint16(mesh_upper_transport_builder_t * builder, uint16_t value){
mesh_upper_transport_message_add_uint16(builder, value);
}
void mesh_access_message_add_uint32(mesh_upper_transport_pdu_t * pdu, uint16_t value){
mesh_upper_transport_message_add_uint32(pdu, value);
void mesh_access_message_add_uint24(mesh_upper_transport_builder_t * builder, uint16_t value){
mesh_upper_transport_message_add_uint24(builder, value);
}
void mesh_access_message_add_model_identifier(mesh_upper_transport_pdu_t * pdu, uint32_t model_identifier){
void mesh_access_message_add_uint32(mesh_upper_transport_builder_t * builder, uint16_t value){
mesh_upper_transport_message_add_uint32(builder, value);
}
void mesh_access_message_add_model_identifier(mesh_upper_transport_builder_t * builder, uint32_t model_identifier){
if (mesh_model_is_bluetooth_sig(model_identifier)){
return mesh_access_message_add_uint16( pdu, mesh_model_get_model_id(model_identifier) );
return mesh_access_message_add_uint16(builder, mesh_model_get_model_id(model_identifier) );
} else {
return mesh_access_message_add_uint32( pdu, model_identifier );
return mesh_access_message_add_uint32(builder, model_identifier );
}
}
bool mesh_access_message_finalize(mesh_upper_transport_pdu_t * pdu){
mesh_upper_transport_pdu_t * mesh_access_message_finalize(mesh_upper_transport_builder_t * builder){
mesh_upper_transport_pdu_t * upper_pdu = mesh_upper_transport_message_finalize(builder);
if (upper_pdu == NULL) return NULL;
// upgrade to segmented if needed
if (pdu->pdu_header.pdu_type == MESH_PDU_TYPE_UPPER_UNSEGMENTED_ACCESS) {
if ((pdu->transmic_len == 8 ) || (pdu->len > 11)){
pdu->pdu_header.pdu_type = MESH_PDU_TYPE_UPPER_SEGMENTED_ACCESS;
if (upper_pdu->pdu_header.pdu_type == MESH_PDU_TYPE_UPPER_UNSEGMENTED_ACCESS) {
if ((upper_pdu->transmic_len == 8 ) || (upper_pdu->len > 11)){
upper_pdu->pdu_header.pdu_type = MESH_PDU_TYPE_UPPER_SEGMENTED_ACCESS;
}
}
return mesh_upper_transport_message_finalize(pdu);
return upper_pdu;
}
// access message template
mesh_upper_transport_pdu_t * mesh_access_setup_message(const mesh_access_message_t *message_template, ...){
mesh_upper_transport_pdu_t * upper_pdu = mesh_access_message_init(message_template->opcode);
if (!upper_pdu) return NULL;
mesh_upper_transport_builder_t builder;
mesh_access_message_init(&builder, message_template->opcode);
va_list argptr;
va_start(argptr, message_template);
@ -684,23 +685,23 @@ mesh_upper_transport_pdu_t * mesh_access_setup_message(const mesh_access_message
switch (*format){
case '1':
word = va_arg(argptr, int); // minimal va_arg is int: 2 bytes on 8+16 bit CPUs
mesh_access_message_add_uint8(upper_pdu, word);
mesh_access_message_add_uint8(&builder, word);
break;
case '2':
word = va_arg(argptr, int); // minimal va_arg is int: 2 bytes on 8+16 bit CPUs
mesh_access_message_add_uint16(upper_pdu, word);
mesh_access_message_add_uint16(&builder, word);
break;
case '3':
longword = va_arg(argptr, uint32_t);
mesh_access_message_add_uint24(upper_pdu, longword);
mesh_access_message_add_uint24(&builder, longword);
break;
case '4':
longword = va_arg(argptr, uint32_t);
mesh_access_message_add_uint32(upper_pdu, longword);
mesh_access_message_add_uint32(&builder, longword);
break;
case 'm':
longword = va_arg(argptr, uint32_t);
mesh_access_message_add_model_identifier(upper_pdu, longword);
mesh_access_message_add_model_identifier(&builder, longword);
break;
default:
btstack_assert(false);
@ -711,15 +712,7 @@ mesh_upper_transport_pdu_t * mesh_access_setup_message(const mesh_access_message
va_end(argptr);
bool ok = mesh_access_message_finalize(upper_pdu);
if (!ok){
// memory alloc failed
mesh_upper_transport_pdu_free((mesh_pdu_t *) upper_pdu);
upper_pdu = NULL;
}
return upper_pdu;
return mesh_access_message_finalize(&builder);
}
static const mesh_operation_t * mesh_model_lookup_operation_by_opcode(mesh_model_t * model, uint32_t opcode){

View File

@ -48,6 +48,7 @@
#include "mesh/mesh_lower_transport.h"
#include "mesh/mesh_keys.h"
#include "mesh/mesh_node.h"
#include "mesh_upper_transport.h"
#ifdef __cplusplus
extern "C"
@ -247,14 +248,14 @@ uint32_t mesh_access_parser_get_sig_model_identifier(mesh_access_parser_state_t
uint32_t mesh_access_parser_get_vendor_model_identifier(mesh_access_parser_state_t * parser);
uint32_t mesh_access_parser_get_model_identifier(mesh_access_parser_state_t * parser);
mesh_upper_transport_pdu_t * mesh_access_message_init(uint32_t opcode);
void mesh_access_message_add_data(mesh_upper_transport_pdu_t * pdu, const uint8_t * data, uint16_t data_len);
void mesh_access_message_add_uint8(mesh_upper_transport_pdu_t * pdu, uint8_t value);
void mesh_access_message_add_uint16(mesh_upper_transport_pdu_t * pdu, uint16_t value);
void mesh_access_message_add_uint24(mesh_upper_transport_pdu_t * pdu, uint16_t value);
void mesh_access_message_add_uint32(mesh_upper_transport_pdu_t * pdu, uint16_t value);
void mesh_access_message_add_model_identifier(mesh_upper_transport_pdu_t * pdu, uint32_t model_identifier);
bool mesh_access_message_finalize(mesh_upper_transport_pdu_t * pdu);
void mesh_access_message_init(mesh_upper_transport_builder_t * builder, uint32_t opcode);
void mesh_access_message_add_data(mesh_upper_transport_builder_t * builder, const uint8_t * data, uint16_t data_len);
void mesh_access_message_add_uint8(mesh_upper_transport_builder_t * builder, uint8_t value);
void mesh_access_message_add_uint16(mesh_upper_transport_builder_t * builder, uint16_t value);
void mesh_access_message_add_uint24(mesh_upper_transport_builder_t * builder, uint16_t value);
void mesh_access_message_add_uint32(mesh_upper_transport_builder_t * builder, uint16_t value);
void mesh_access_message_add_model_identifier(mesh_upper_transport_builder_t * builder, uint32_t model_identifier);
mesh_upper_transport_pdu_t * mesh_access_message_finalize(mesh_upper_transport_builder_t * builder);
// message builder using template
mesh_upper_transport_pdu_t * mesh_access_setup_message(const mesh_access_message_t *message_template, ...);

View File

@ -245,21 +245,20 @@ static void config_composition_data_status(uint16_t netkey_index, uint16_t dest)
printf("Received Config Composition Data Get -> send Config Composition Data Status\n");
mesh_upper_transport_pdu_t * upper_pdu = mesh_access_message_init(
MESH_FOUNDATION_OPERATION_COMPOSITION_DATA_STATUS);
if (!upper_pdu) return;
mesh_upper_transport_builder_t builder;
mesh_access_message_init(&builder, MESH_FOUNDATION_OPERATION_COMPOSITION_DATA_STATUS);
// page 0
mesh_access_message_add_uint8(upper_pdu, 0);
mesh_access_message_add_uint8(&builder, 0);
// CID
mesh_access_message_add_uint16(upper_pdu, mesh_node_get_company_id());
mesh_access_message_add_uint16(&builder, mesh_node_get_company_id());
// PID
mesh_access_message_add_uint16(upper_pdu, mesh_node_get_product_id());
mesh_access_message_add_uint16(&builder, mesh_node_get_product_id());
// VID
mesh_access_message_add_uint16(upper_pdu, mesh_node_get_product_version_id());
mesh_access_message_add_uint16(&builder, mesh_node_get_product_version_id());
// CRPL - number of protection list entries
mesh_access_message_add_uint16(upper_pdu, 1);
mesh_access_message_add_uint16(&builder, 1);
// Features - Relay, Proxy, Friend, Lower Power, ...
uint16_t features = 0;
#ifdef ENABLE_MESH_RELAY
@ -268,7 +267,7 @@ static void config_composition_data_status(uint16_t netkey_index, uint16_t dest)
#ifdef ENABLE_MESH_PROXY_SERVER
features |= 2;
#endif
mesh_access_message_add_uint16(upper_pdu, features);
mesh_access_message_add_uint16(&builder, features);
mesh_element_iterator_t element_it;
mesh_element_iterator_init(&element_it);
@ -276,11 +275,11 @@ static void config_composition_data_status(uint16_t netkey_index, uint16_t dest)
mesh_element_t * element = mesh_element_iterator_next(&element_it);
// Loc
mesh_access_message_add_uint16(upper_pdu, element->loc);
mesh_access_message_add_uint16(&builder, element->loc);
// NumS
mesh_access_message_add_uint8(upper_pdu, element->models_count_sig);
mesh_access_message_add_uint8(&builder, element->models_count_sig);
// NumV
mesh_access_message_add_uint8(upper_pdu, element->models_count_vendor);
mesh_access_message_add_uint8(&builder, element->models_count_vendor);
mesh_model_iterator_t model_it;
@ -289,22 +288,18 @@ static void config_composition_data_status(uint16_t netkey_index, uint16_t dest)
while (mesh_model_iterator_has_next(&model_it)){
mesh_model_t * model = mesh_model_iterator_next(&model_it);
if (!mesh_model_is_bluetooth_sig(model->model_identifier)) continue;
mesh_access_message_add_model_identifier(upper_pdu, model->model_identifier);
mesh_access_message_add_model_identifier(&builder, model->model_identifier);
}
// Vendor Models
mesh_model_iterator_init(&model_it, element);
while (mesh_model_iterator_has_next(&model_it)){
mesh_model_t * model = mesh_model_iterator_next(&model_it);
if (mesh_model_is_bluetooth_sig(model->model_identifier)) continue;
mesh_access_message_add_model_identifier(upper_pdu, model->model_identifier);
mesh_access_message_add_model_identifier(&builder, model->model_identifier);
}
}
bool ok = mesh_access_message_finalize(upper_pdu);
if (!ok){
mesh_upper_transport_pdu_free((mesh_pdu_t*) upper_pdu);
return;
}
mesh_upper_transport_pdu_t * upper_pdu = mesh_access_message_finalize(&builder);
// send as segmented access pdu
config_server_send_message(netkey_index, dest, (mesh_pdu_t *) upper_pdu);
@ -570,22 +565,18 @@ static void config_netkey_status(mesh_model_t * mesh_model, uint16_t netkey_inde
static void config_netkey_list(mesh_model_t * mesh_model, uint16_t netkey_index, uint16_t dest) {
UNUSED(mesh_model);
mesh_upper_transport_pdu_t * upper_pdu = mesh_access_message_init(MESH_FOUNDATION_OPERATION_NETKEY_LIST);
if (!upper_pdu) return;
mesh_upper_transport_builder_t builder;
mesh_access_message_init(&builder, MESH_FOUNDATION_OPERATION_NETKEY_LIST);
// add list of netkey indexes
mesh_network_key_iterator_t it;
mesh_network_key_iterator_init(&it);
while (mesh_network_key_iterator_has_more(&it)){
mesh_network_key_t * network_key = mesh_network_key_iterator_get_next(&it);
mesh_access_message_add_uint16(upper_pdu, network_key->netkey_index);
mesh_access_message_add_uint16(&builder, network_key->netkey_index);
}
bool ok = mesh_access_message_finalize(upper_pdu);
if (!ok){
mesh_upper_transport_pdu_free((mesh_pdu_t*) upper_pdu);
return;
}
mesh_upper_transport_pdu_t * upper_pdu = mesh_access_message_finalize(&builder);
// send as segmented access pdu
config_server_send_message(netkey_index, dest, (mesh_pdu_t *) upper_pdu);
@ -813,8 +804,8 @@ static void config_appkey_status(mesh_model_t * mesh_model, uint16_t netkey_inde
static void config_appkey_list(mesh_model_t * mesh_model, uint16_t netkey_index, uint16_t dest, uint32_t netkey_index_of_list){
UNUSED(mesh_model);
mesh_upper_transport_pdu_t * upper_pdu = mesh_access_message_init(MESH_FOUNDATION_OPERATION_APPKEY_LIST);
if (!upper_pdu) return;
mesh_upper_transport_builder_t builder;
mesh_access_message_init(&builder, MESH_FOUNDATION_OPERATION_APPKEY_LIST);
// check netkey_index is valid
mesh_network_key_t * network_key = mesh_network_key_list_get(netkey_index_of_list);
@ -824,25 +815,21 @@ static void config_appkey_list(mesh_model_t * mesh_model, uint16_t netkey_index,
} else {
status = MESH_FOUNDATION_STATUS_SUCCESS;
}
mesh_access_message_add_uint8(upper_pdu, status);
mesh_access_message_add_uint16(upper_pdu, netkey_index_of_list);
mesh_access_message_add_uint8(&builder, status);
mesh_access_message_add_uint16(&builder, netkey_index_of_list);
// add list of appkey indexes
mesh_transport_key_iterator_t it;
mesh_transport_key_iterator_init(&it, netkey_index_of_list);
while (mesh_transport_key_iterator_has_more(&it)){
mesh_transport_key_t * transport_key = mesh_transport_key_iterator_get_next(&it);
mesh_access_message_add_uint16(upper_pdu, transport_key->appkey_index);
mesh_access_message_add_uint16(&builder, transport_key->appkey_index);
}
bool ok = mesh_access_message_finalize(upper_pdu);
if (!ok){
mesh_upper_transport_pdu_free((mesh_pdu_t*) upper_pdu);
return;
}
mesh_upper_transport_pdu_t * upper_pdu = mesh_access_message_finalize(&builder);
// send as segmented access pdu
config_server_send_message(netkey_index, dest, (mesh_pdu_t *) upper_pdu);
config_server_send_message(netkey_index, dest, (mesh_pdu_t *) &builder);
}
static void config_appkey_add_or_update_aid(void *arg){
@ -1053,13 +1040,13 @@ static void config_model_subscription_list(mesh_model_t * mesh_model, uint16_t n
opcode = MESH_FOUNDATION_OPERATION_VENDOR_MODEL_SUBSCRIPTION_LIST;
}
mesh_upper_transport_pdu_t * upper_pdu = mesh_access_message_init(opcode);
if (!upper_pdu) return;
mesh_upper_transport_builder_t builder;
mesh_access_message_init(&builder, opcode);
// setup segmented message
mesh_access_message_add_uint8(upper_pdu, status);
mesh_access_message_add_uint16(upper_pdu, element_address);
mesh_access_message_add_model_identifier(upper_pdu, model_identifier);
mesh_access_message_add_uint8(&builder, status);
mesh_access_message_add_uint16(&builder, element_address);
mesh_access_message_add_model_identifier(&builder, model_identifier);
if (target_model != NULL){
uint16_t i;
@ -1071,17 +1058,13 @@ static void config_model_subscription_list(mesh_model_t * mesh_model, uint16_t n
if (virtual_address == NULL) continue;
address = virtual_address->hash;
}
mesh_access_message_add_uint16(upper_pdu, address);
mesh_access_message_add_uint16(&builder, address);
}
}
bool ok = mesh_access_message_finalize(upper_pdu);
if (!ok){
mesh_upper_transport_pdu_free((mesh_pdu_t*) upper_pdu);
return;
}
mesh_upper_transport_pdu_t * upper_pdu = mesh_access_message_finalize(&builder);
config_server_send_message(netkey_index, dest, (mesh_pdu_t *) upper_pdu);
config_server_send_message(netkey_index, dest, (mesh_pdu_t *) &builder);
}
static void config_model_subscription_get_handler(mesh_model_t *mesh_model, mesh_pdu_t * pdu){
@ -1371,15 +1354,15 @@ static void config_model_app_list(mesh_model_t * config_server_model, uint16_t n
opcode = MESH_FOUNDATION_OPERATION_VENDOR_MODEL_APP_LIST;
}
mesh_upper_transport_pdu_t * upper_pdu = mesh_access_message_init(opcode);
if (!upper_pdu) return;
mesh_upper_transport_builder_t builder;
mesh_access_message_init(&builder, opcode);
mesh_access_message_add_uint8(upper_pdu, status);
mesh_access_message_add_uint16(upper_pdu, element_address);
mesh_access_message_add_uint8(&builder, status);
mesh_access_message_add_uint16(&builder, element_address);
if (mesh_model_is_bluetooth_sig(model_identifier)) {
mesh_access_message_add_uint16(upper_pdu, mesh_model_get_model_id(model_identifier));
mesh_access_message_add_uint16(&builder, mesh_model_get_model_id(model_identifier));
} else {
mesh_access_message_add_uint32(upper_pdu, model_identifier);
mesh_access_message_add_uint32(&builder, model_identifier);
}
// add list of appkey indexes
@ -1388,15 +1371,11 @@ static void config_model_app_list(mesh_model_t * config_server_model, uint16_t n
for (i=0;i<MAX_NR_MESH_APPKEYS_PER_MODEL;i++){
uint16_t appkey_index = mesh_model->appkey_indices[i];
if (appkey_index == MESH_APPKEY_INVALID) continue;
mesh_access_message_add_uint16(upper_pdu, appkey_index);
mesh_access_message_add_uint16(&builder, appkey_index);
}
}
bool ok = mesh_access_message_finalize(upper_pdu);
if (!ok){
mesh_upper_transport_pdu_free((mesh_pdu_t*) upper_pdu);
return;
}
mesh_upper_transport_pdu_t * upper_pdu = mesh_access_message_finalize(&builder);
// send as segmented access pdu
config_server_send_message(netkey_index, dest, (mesh_pdu_t *) upper_pdu);

View File

@ -120,34 +120,30 @@ static mesh_pdu_t * health_attention_status(void){
// report fault status - used for both current as well as registered faults, see registered_faults param
static mesh_pdu_t * health_fault_status(mesh_model_t * mesh_model, uint32_t opcode, uint16_t company_id, bool registered_faults){
mesh_upper_transport_pdu_t * upper_pdu = mesh_access_message_init(opcode);
if (!upper_pdu) return NULL;
mesh_upper_transport_builder_t builder;
mesh_access_message_init(&builder, opcode);
mesh_health_fault_t * fault = mesh_health_server_fault_for_company_id(mesh_model, company_id);
if (fault == NULL){
// no fault state with company_id found
mesh_access_message_add_uint8(upper_pdu, 0);
mesh_access_message_add_uint16(upper_pdu, company_id);
mesh_access_message_add_uint8(&builder, 0);
mesh_access_message_add_uint16(&builder, company_id);
} else {
mesh_access_message_add_uint8(upper_pdu, fault->test_id);
mesh_access_message_add_uint16(upper_pdu, fault->company_id);
mesh_access_message_add_uint8(&builder, fault->test_id);
mesh_access_message_add_uint16(&builder, fault->company_id);
int i;
if (registered_faults){
for (i = 0; i < fault->num_registered_faults; i++){
mesh_access_message_add_uint8(upper_pdu, fault->registered_faults[i]);
mesh_access_message_add_uint8(&builder, fault->registered_faults[i]);
}
} else {
for (i = 0; i < fault->num_current_faults; i++){
mesh_access_message_add_uint8(upper_pdu, fault->current_faults[i]);
mesh_access_message_add_uint8(&builder, fault->current_faults[i]);
}
}
}
bool ok = mesh_access_message_finalize(upper_pdu);
if (!ok){
mesh_upper_transport_pdu_free((mesh_pdu_t*)upper_pdu);
return NULL;
}
mesh_upper_transport_pdu_t * upper_pdu = mesh_access_message_finalize(&builder);
return (mesh_pdu_t *) upper_pdu;
}

View File

@ -1231,23 +1231,25 @@ void mesh_upper_transport_init(){
}
mesh_upper_transport_pdu_t * mesh_upper_transport_message_init(mesh_pdu_type_t pdu_type) {
mesh_upper_transport_pdu_t * pdu = btstack_memory_mesh_upper_transport_pdu_get();
if (!pdu) return NULL;
void mesh_upper_transport_message_init(mesh_upper_transport_builder_t * builder, mesh_pdu_type_t pdu_type) {
btstack_assert(builder != NULL);
pdu->pdu_header.pdu_type = pdu_type;
pdu->transmic_len = 4;
pdu->ack_opcode = MESH_ACCESS_OPCODE_NOT_SET;
builder->pdu = btstack_memory_mesh_upper_transport_pdu_get();
if (!builder->pdu) return;
return pdu;
builder->pdu->pdu_header.pdu_type = pdu_type;
builder->pdu->transmic_len = 4;
builder->pdu->ack_opcode = MESH_ACCESS_OPCODE_NOT_SET;
}
void mesh_upper_transport_message_add_data(mesh_upper_transport_pdu_t * pdu, const uint8_t * data, uint16_t data_len){
if (pdu->pdu_header.pdu_type == MESH_PDU_TYPE_INVALID) return;
void mesh_upper_transport_message_add_data(mesh_upper_transport_builder_t * builder, const uint8_t * data, uint16_t data_len){
btstack_assert(builder != NULL);
if (builder->pdu == NULL) return;
uint16_t bytes_current_segment = 0;
mesh_network_pdu_t * network_pdu = (mesh_network_pdu_t *) btstack_linked_list_get_last_item(&pdu->segments);
mesh_network_pdu_t * network_pdu = (mesh_network_pdu_t *) btstack_linked_list_get_last_item(&builder->pdu->segments);
if (network_pdu){
bytes_current_segment = MESH_NETWORK_PAYLOAD_MAX - network_pdu->len;
}
@ -1255,10 +1257,11 @@ void mesh_upper_transport_message_add_data(mesh_upper_transport_pdu_t * pdu, con
if (bytes_current_segment == 0){
network_pdu = (mesh_network_pdu_t *) mesh_network_pdu_get();
if (network_pdu == NULL) {
pdu->pdu_header.pdu_type = MESH_PDU_TYPE_INVALID;
mesh_upper_transport_pdu_free((mesh_pdu_t *) builder->pdu);
builder->pdu = NULL;
return;
}
btstack_linked_list_add_tail(&pdu->segments, (btstack_linked_item_t *) network_pdu);
btstack_linked_list_add_tail(&builder->pdu->segments, (btstack_linked_item_t *) network_pdu);
bytes_current_segment = MESH_NETWORK_PAYLOAD_MAX;
}
uint16_t bytes_to_copy = btstack_min(bytes_current_segment, data_len);
@ -1270,28 +1273,28 @@ void mesh_upper_transport_message_add_data(mesh_upper_transport_pdu_t * pdu, con
}
}
void mesh_upper_transport_message_add_uint8(mesh_upper_transport_pdu_t * pdu, uint8_t value){
mesh_upper_transport_message_add_data(pdu, &value, 1);
void mesh_upper_transport_message_add_uint8(mesh_upper_transport_builder_t * builder, uint8_t value){
mesh_upper_transport_message_add_data(builder, &value, 1);
}
void mesh_upper_transport_message_add_uint16(mesh_upper_transport_pdu_t * pdu, uint16_t value){
void mesh_upper_transport_message_add_uint16(mesh_upper_transport_builder_t * builder, uint16_t value){
uint8_t buffer[2];
little_endian_store_16(buffer, 0, value);
mesh_upper_transport_message_add_data(pdu, buffer, sizeof(buffer));
mesh_upper_transport_message_add_data(builder, buffer, sizeof(buffer));
}
void mesh_upper_transport_message_add_uint24(mesh_upper_transport_pdu_t * pdu, uint16_t value){
void mesh_upper_transport_message_add_uint24(mesh_upper_transport_builder_t * builder, uint16_t value){
uint8_t buffer[3];
little_endian_store_24(buffer, 0, value);
mesh_upper_transport_message_add_data(pdu, buffer, sizeof(buffer));
mesh_upper_transport_message_add_data(builder, buffer, sizeof(buffer));
}
void mesh_upper_transport_message_add_uint32(mesh_upper_transport_pdu_t * pdu, uint16_t value){
void mesh_upper_transport_message_add_uint32(mesh_upper_transport_builder_t * builder, uint16_t value){
uint8_t buffer[4];
little_endian_store_32(buffer, 0, value);
mesh_upper_transport_message_add_data(pdu, buffer, sizeof(buffer));
mesh_upper_transport_message_add_data(builder, buffer, sizeof(buffer));
}
bool mesh_upper_transport_message_finalize(mesh_upper_transport_pdu_t * pdu){
return pdu->pdu_header.pdu_type != MESH_PDU_TYPE_INVALID;
mesh_upper_transport_pdu_t * mesh_upper_transport_message_finalize(mesh_upper_transport_builder_t * builder){
return builder->pdu;
}

View File

@ -48,6 +48,20 @@ extern "C"
{
#endif
// upper transport message builder
typedef struct {
mesh_upper_transport_pdu_t * pdu;
} mesh_upper_transport_builder_t;
void mesh_upper_transport_message_init(mesh_upper_transport_builder_t * builder, mesh_pdu_type_t pdu_type);
void mesh_upper_transport_message_add_data(mesh_upper_transport_builder_t * builder, const uint8_t * data, uint16_t data_len);
void mesh_upper_transport_message_add_uint8(mesh_upper_transport_builder_t * builder, uint8_t value);
void mesh_upper_transport_message_add_uint16(mesh_upper_transport_builder_t * builder, uint16_t value);
void mesh_upper_transport_message_add_uint24(mesh_upper_transport_builder_t * builder, uint16_t value);
void mesh_upper_transport_message_add_uint32(mesh_upper_transport_builder_t * builder, uint16_t value);
mesh_upper_transport_pdu_t * mesh_upper_transport_message_finalize(mesh_upper_transport_builder_t * builder);
void mesh_upper_transport_init(void);
void mesh_upper_transport_message_processed_by_higher_layer(mesh_pdu_t * pdu);
@ -77,15 +91,6 @@ void mesh_upper_transport_send_access_pdu(mesh_pdu_t * pdu);
void mesh_upper_transport_pdu_free(mesh_pdu_t * pdu);
// upper transport message builder
mesh_upper_transport_pdu_t * mesh_upper_transport_message_init(mesh_pdu_type_t pdu_type);
void mesh_upper_transport_message_add_data(mesh_upper_transport_pdu_t * pdu, const uint8_t * data, uint16_t data_len);
void mesh_upper_transport_message_add_uint8(mesh_upper_transport_pdu_t * pdu, uint8_t value);
void mesh_upper_transport_message_add_uint16(mesh_upper_transport_pdu_t * pdu, uint16_t value);
void mesh_upper_transport_message_add_uint24(mesh_upper_transport_pdu_t * pdu, uint16_t value);
void mesh_upper_transport_message_add_uint32(mesh_upper_transport_pdu_t * pdu, uint16_t value);
bool mesh_upper_transport_message_finalize(mesh_upper_transport_pdu_t * pdu);
// test
void mesh_upper_transport_dump(void);
void mesh_upper_transport_reset(void);