mesh: use single access builder

This commit is contained in:
Matthias Ringwald 2020-03-28 23:30:29 +01:00
parent 039cbf1d6c
commit 6f13b0f4dc
10 changed files with 93 additions and 184 deletions

View File

@ -615,54 +615,6 @@ static int mesh_access_setup_opcode(uint8_t * buffer, uint32_t opcode){
return 3;
}
mesh_upper_transport_pdu_t * mesh_access_transport_init(uint32_t opcode){
mesh_upper_transport_pdu_t * pdu = btstack_memory_mesh_upper_transport_pdu_get();
if (!pdu) return NULL;
btstack_assert(false);
// TODO: new types
// pdu->len = mesh_access_setup_opcode(pdu->data, opcode);
// pdu->ack_opcode = MESH_ACCESS_OPCODE_NOT_SET;
return pdu;
}
void mesh_access_transport_add_uint8(mesh_upper_transport_pdu_t * pdu, uint8_t value){
btstack_assert(false);
// pdu->data[pdu->len++] = value;
}
void mesh_access_transport_add_uint16(mesh_upper_transport_pdu_t * pdu, uint16_t value){
btstack_assert(false);
// little_endian_store_16(pdu->data, pdu->len, value);
// pdu->len += 2;
}
void mesh_access_transport_add_uint24(mesh_upper_transport_pdu_t * pdu, uint32_t value){
btstack_assert(false);
// little_endian_store_24(pdu->data, pdu->len, value);
// pdu->len += 3;
}
void mesh_access_transport_add_uint32(mesh_upper_transport_pdu_t * pdu, uint32_t value){
btstack_assert(false);
// little_endian_store_32(pdu->data, pdu->len, value);
// pdu->len += 4;
}
void mesh_access_transport_add_label_uuid(mesh_upper_transport_pdu_t * pdu, uint8_t * value){
btstack_assert(false);
// (void)memcpy(value, pdu->data, 16);
// pdu->len += 16;
}
void mesh_access_transport_add_model_identifier(mesh_upper_transport_pdu_t * pdu, uint32_t model_identifier){
if (!mesh_model_is_bluetooth_sig(model_identifier)){
mesh_access_transport_add_uint16( pdu, mesh_model_get_vendor_id(model_identifier) );
}
mesh_access_transport_add_uint16( pdu, mesh_model_get_model_id(model_identifier) );
}
// mesh_message_t builder
mesh_upper_transport_pdu_t * mesh_access_message_init(uint32_t opcode, bool segmented, uint8_t num_segments){
btstack_assert(num_segments > 0);
@ -776,55 +728,6 @@ mesh_upper_transport_pdu_t * mesh_access_setup_message(bool segmented, const mes
return message_pdu;
}
mesh_upper_transport_pdu_t * mesh_access_setup_segmented_message(const mesh_access_message_t *message_template, ...){
mesh_upper_transport_pdu_t * transport_pdu = mesh_access_transport_init(message_template->opcode);
if (!transport_pdu) return NULL;
va_list argptr;
va_start(argptr, message_template);
// add params
const char * format = message_template->format;
uint16_t word;
uint32_t longword;
uint8_t * ptr;
while (*format){
switch (*format++){
case '1':
word = va_arg(argptr, int); // minimal va_arg is int: 2 bytes on 8+16 bit CPUs
mesh_access_transport_add_uint8( transport_pdu, word);
break;
case '2':
word = va_arg(argptr, int); // minimal va_arg is int: 2 bytes on 8+16 bit CPUs
mesh_access_transport_add_uint16( transport_pdu, word);
break;
case '3':
longword = va_arg(argptr, uint32_t);
mesh_access_transport_add_uint24( transport_pdu, longword);
break;
case '4':
longword = va_arg(argptr, uint32_t);
mesh_access_transport_add_uint32( transport_pdu, longword);
break;
case 'P': // 16 byte, eg LabelUUID, in network endianess
ptr = va_arg(argptr, uint8_t *);
mesh_access_transport_add_label_uuid( transport_pdu, ptr);
break;
case 'm':
longword = va_arg(argptr, uint32_t);
mesh_access_transport_add_model_identifier( transport_pdu, longword);
break;
default:
break;
}
}
va_end(argptr);
return transport_pdu;
}
static const mesh_operation_t * mesh_model_lookup_operation_by_opcode(mesh_model_t * model, uint32_t opcode){
// find opcode in table
const mesh_operation_t * operation = model->operations;

View File

@ -247,15 +247,7 @@ uint32_t mesh_access_parser_get_model_identifier(mesh_access_parser_state_t * pa
uint32_t mesh_access_parser_get_sig_model_identifier(mesh_access_parser_state_t * parser);
uint32_t mesh_access_parser_get_vendor_model_identifier(mesh_access_parser_state_t * parser);
// message builder transport
mesh_upper_transport_pdu_t * mesh_access_transport_init(uint32_t opcode);
void mesh_access_transport_add_uint8(mesh_upper_transport_pdu_t * pdu, uint8_t value);
void mesh_access_transport_add_uint16(mesh_upper_transport_pdu_t * pdu, uint16_t value);
void mesh_access_transport_add_uint24(mesh_upper_transport_pdu_t * pdu, uint32_t value);
void mesh_access_transport_add_uint32(mesh_upper_transport_pdu_t * pdu, uint32_t value);
void mesh_access_transport_add_model_identifier(mesh_upper_transport_pdu_t * pdu, uint32_t model_identifier);
void mesh_access_transport_add_label_uuid(mesh_upper_transport_pdu_t * pdu, uint8_t * value);
// message builder
mesh_upper_transport_pdu_t * mesh_access_message_init(uint32_t opcode, bool segmented, uint8_t num_segments);
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);
@ -264,7 +256,6 @@ void mesh_access_message_add_uint32(mesh_upper_transport_pdu_t * pdu, uint16_t v
void mesh_access_message_add_model_identifier(mesh_upper_transport_pdu_t * pdu, uint32_t model_identifier);
// message builder using template
mesh_upper_transport_pdu_t * mesh_access_setup_segmented_message(const mesh_access_message_t *message_template, ...);
mesh_upper_transport_pdu_t * mesh_access_setup_message(bool segmented, const mesh_access_message_t *message_template, ...);
#ifdef __cplusplus

View File

@ -499,7 +499,7 @@ uint8_t mesh_configuration_client_send_model_publication_virtual_address_set(mes
return ERROR_CODE_PARAMETER_OUT_OF_MANDATORY_RANGE;
}
mesh_upper_transport_pdu_t * transport_pdu = mesh_access_setup_segmented_message(&mesh_configuration_client_model_publication_virtual_address_set,
mesh_upper_transport_pdu_t * transport_pdu = mesh_access_setup_message(true, &mesh_configuration_client_model_publication_virtual_address_set,
dest,
publication_config->publish_address_virtual,
(publication_config->credential_flag << 12) | publication_config->appkey_index,
@ -529,7 +529,7 @@ uint8_t mesh_configuration_client_send_model_subscription_virtual_address_add(me
uint8_t status = mesh_access_validate_envelop_params(mesh_model, dest, netkey_index, appkey_index);
if (status != ERROR_CODE_SUCCESS) return status;
mesh_upper_transport_pdu_t * transport_pdu = mesh_access_setup_segmented_message(&mesh_configuration_client_model_subscription_virtual_address_add, dest, address, model_id);
mesh_upper_transport_pdu_t * transport_pdu = mesh_access_setup_message(true, &mesh_configuration_client_model_subscription_virtual_address_add, dest, address, model_id);
if (!transport_pdu) return BTSTACK_MEMORY_ALLOC_FAILED;
mesh_configuration_client_send_acknowledged(mesh_access_get_element_address(mesh_model), dest, netkey_index, appkey_index, (mesh_pdu_t *) transport_pdu, MESH_FOUNDATION_OPERATION_MODEL_SUBSCRIPTION_STATUS);
@ -551,7 +551,7 @@ uint8_t mesh_configuration_client_send_model_subscription_virtual_address_delete
uint8_t status = mesh_access_validate_envelop_params(mesh_model, dest, netkey_index, appkey_index);
if (status != ERROR_CODE_SUCCESS) return status;
mesh_upper_transport_pdu_t * transport_pdu = mesh_access_setup_segmented_message(&mesh_configuration_client_model_subscription_virtual_address_delete, dest, address, model_id);
mesh_upper_transport_pdu_t * transport_pdu = mesh_access_setup_message(true, &mesh_configuration_client_model_subscription_virtual_address_delete, dest, address, model_id);
if (!transport_pdu) return BTSTACK_MEMORY_ALLOC_FAILED;
mesh_configuration_client_send_acknowledged(mesh_access_get_element_address(mesh_model), dest, netkey_index, appkey_index, (mesh_pdu_t *) transport_pdu, MESH_FOUNDATION_OPERATION_MODEL_SUBSCRIPTION_STATUS);
@ -573,7 +573,7 @@ uint8_t mesh_configuration_client_send_model_subscription_virtual_address_overwr
uint8_t status = mesh_access_validate_envelop_params(mesh_model, dest, netkey_index, appkey_index);
if (status != ERROR_CODE_SUCCESS) return status;
mesh_upper_transport_pdu_t * transport_pdu = mesh_access_setup_segmented_message(&mesh_configuration_client_model_subscription_virtual_address_overwrite, dest, address, model_id);
mesh_upper_transport_pdu_t * transport_pdu = mesh_access_setup_message(true, &mesh_configuration_client_model_subscription_virtual_address_overwrite, dest, address, model_id);
if (!transport_pdu) return BTSTACK_MEMORY_ALLOC_FAILED;
mesh_configuration_client_send_acknowledged(mesh_access_get_element_address(mesh_model), dest, netkey_index, appkey_index, (mesh_pdu_t *) transport_pdu, MESH_FOUNDATION_OPERATION_MODEL_SUBSCRIPTION_STATUS);
@ -615,7 +615,7 @@ uint8_t mesh_configuration_client_send_netkey_add(mesh_model_t * mesh_model, uin
uint8_t status = mesh_access_validate_envelop_params(mesh_model, dest, netkey_index, appkey_index);
if (status != ERROR_CODE_SUCCESS) return status;
mesh_upper_transport_pdu_t * transport_pdu = mesh_access_setup_segmented_message(&mesh_configuration_client_netkey_add, index, netkey);
mesh_upper_transport_pdu_t * transport_pdu = mesh_access_setup_message(true, &mesh_configuration_client_netkey_add, index, netkey);
if (!transport_pdu) return BTSTACK_MEMORY_ALLOC_FAILED;
mesh_configuration_client_send_acknowledged(mesh_access_get_element_address(mesh_model), dest, netkey_index, appkey_index, (mesh_pdu_t *) transport_pdu, MESH_FOUNDATION_OPERATION_NETKEY_STATUS);
@ -626,7 +626,7 @@ uint8_t mesh_configuration_client_send_netkey_update(mesh_model_t * mesh_model,
uint8_t status = mesh_access_validate_envelop_params(mesh_model, dest, netkey_index, appkey_index);
if (status != ERROR_CODE_SUCCESS) return status;
mesh_upper_transport_pdu_t * transport_pdu = mesh_access_setup_segmented_message(&mesh_configuration_client_netkey_update, index, netkey);
mesh_upper_transport_pdu_t * transport_pdu = mesh_access_setup_message(true, &mesh_configuration_client_netkey_update, index, netkey);
if (!transport_pdu) return BTSTACK_MEMORY_ALLOC_FAILED;
mesh_configuration_client_send_acknowledged(mesh_access_get_element_address(mesh_model), dest, netkey_index, appkey_index, (mesh_pdu_t *) transport_pdu, MESH_FOUNDATION_OPERATION_NETKEY_STATUS);
@ -637,7 +637,7 @@ uint8_t mesh_configuration_client_send_netkey_delete(mesh_model_t * mesh_model,
uint8_t status = mesh_access_validate_envelop_params(mesh_model, dest, netkey_index, appkey_index);
if (status != ERROR_CODE_SUCCESS) return status;
mesh_upper_transport_pdu_t * transport_pdu = mesh_access_setup_segmented_message(&mesh_configuration_client_netkey_delete, index);
mesh_upper_transport_pdu_t * transport_pdu = mesh_access_setup_message(true, &mesh_configuration_client_netkey_delete, index);
if (!transport_pdu) return BTSTACK_MEMORY_ALLOC_FAILED;
mesh_configuration_client_send_acknowledged(mesh_access_get_element_address(mesh_model), dest, netkey_index, appkey_index, (mesh_pdu_t *) transport_pdu, MESH_FOUNDATION_OPERATION_NETKEY_STATUS);
@ -648,7 +648,7 @@ uint8_t mesh_configuration_client_send_netkey_get(mesh_model_t * mesh_model, uin
uint8_t status = mesh_access_validate_envelop_params(mesh_model, dest, netkey_index, appkey_index);
if (status != ERROR_CODE_SUCCESS) return status;
mesh_upper_transport_pdu_t * transport_pdu = mesh_access_setup_segmented_message(&mesh_configuration_client_netkey_get);
mesh_upper_transport_pdu_t * transport_pdu = mesh_access_setup_message(true, &mesh_configuration_client_netkey_get);
if (!transport_pdu) return BTSTACK_MEMORY_ALLOC_FAILED;
mesh_configuration_client_send_acknowledged(mesh_access_get_element_address(mesh_model), dest, netkey_index, appkey_index, (mesh_pdu_t *) transport_pdu, MESH_FOUNDATION_OPERATION_NETKEY_LIST);
@ -659,7 +659,7 @@ uint8_t mesh_configuration_client_send_appkey_add(mesh_model_t * mesh_model, uin
uint8_t status = mesh_access_validate_envelop_params(mesh_model, dest, netkey_index, appkey_index);
if (status != ERROR_CODE_SUCCESS) return status;
mesh_upper_transport_pdu_t * transport_pdu = mesh_access_setup_segmented_message(&mesh_configuration_client_appkey_add, netk_index << 12 | appk_index, appkey);
mesh_upper_transport_pdu_t * transport_pdu = mesh_access_setup_message(true, &mesh_configuration_client_appkey_add, netk_index << 12 | appk_index, appkey);
if (!transport_pdu) return BTSTACK_MEMORY_ALLOC_FAILED;
mesh_configuration_client_send_acknowledged(mesh_access_get_element_address(mesh_model), dest, netkey_index, appkey_index, (mesh_pdu_t *) transport_pdu, MESH_FOUNDATION_OPERATION_APPKEY_STATUS);
@ -670,7 +670,7 @@ uint8_t mesh_configuration_client_send_appkey_update(mesh_model_t * mesh_model,
uint8_t status = mesh_access_validate_envelop_params(mesh_model, dest, netkey_index, appkey_index);
if (status != ERROR_CODE_SUCCESS) return status;
mesh_upper_transport_pdu_t * transport_pdu = mesh_access_setup_segmented_message(&mesh_configuration_client_appkey_update, netk_index << 12 | appk_index, appkey);
mesh_upper_transport_pdu_t * transport_pdu = mesh_access_setup_message(true, &mesh_configuration_client_appkey_update, netk_index << 12 | appk_index, appkey);
if (!transport_pdu) return BTSTACK_MEMORY_ALLOC_FAILED;
mesh_configuration_client_send_acknowledged(mesh_access_get_element_address(mesh_model), dest, netkey_index, appkey_index, (mesh_pdu_t *) transport_pdu, MESH_FOUNDATION_OPERATION_APPKEY_STATUS);
@ -681,7 +681,7 @@ uint8_t mesh_configuration_client_send_appkey_delete(mesh_model_t * mesh_model,
uint8_t status = mesh_access_validate_envelop_params(mesh_model, dest, netkey_index, appkey_index);
if (status != ERROR_CODE_SUCCESS) return status;
mesh_upper_transport_pdu_t * transport_pdu = mesh_access_setup_segmented_message(&mesh_configuration_client_appkey_delete, netk_index << 12 | appk_index);
mesh_upper_transport_pdu_t * transport_pdu = mesh_access_setup_message(true, &mesh_configuration_client_appkey_delete, netk_index << 12 | appk_index);
if (!transport_pdu) return BTSTACK_MEMORY_ALLOC_FAILED;
mesh_configuration_client_send_acknowledged(mesh_access_get_element_address(mesh_model), dest, netkey_index, appkey_index, (mesh_pdu_t *) transport_pdu, MESH_FOUNDATION_OPERATION_APPKEY_STATUS);
@ -692,7 +692,7 @@ uint8_t mesh_configuration_client_send_appkey_get(mesh_model_t * mesh_model, uin
uint8_t status = mesh_access_validate_envelop_params(mesh_model, dest, netkey_index, appkey_index);
if (status != ERROR_CODE_SUCCESS) return status;
mesh_upper_transport_pdu_t * transport_pdu = mesh_access_setup_segmented_message(&mesh_configuration_client_appkey_get, netk_index);
mesh_upper_transport_pdu_t * transport_pdu = mesh_access_setup_message(true, &mesh_configuration_client_appkey_get, netk_index);
if (!transport_pdu) return BTSTACK_MEMORY_ALLOC_FAILED;
mesh_configuration_client_send_acknowledged(mesh_access_get_element_address(mesh_model), dest, netkey_index, appkey_index, (mesh_pdu_t *) transport_pdu, MESH_FOUNDATION_OPERATION_APPKEY_LIST);
@ -703,7 +703,7 @@ uint8_t mesh_configuration_client_send_node_identity_get(mesh_model_t * mesh_mod
uint8_t status = mesh_access_validate_envelop_params(mesh_model, dest, netkey_index, appkey_index);
if (status != ERROR_CODE_SUCCESS) return status;
mesh_upper_transport_pdu_t * transport_pdu = mesh_access_setup_segmented_message(&mesh_configuration_client_node_identity_get, netk_index);
mesh_upper_transport_pdu_t * transport_pdu = mesh_access_setup_message(true, &mesh_configuration_client_node_identity_get, netk_index);
if (!transport_pdu) return BTSTACK_MEMORY_ALLOC_FAILED;
mesh_configuration_client_send_acknowledged(mesh_access_get_element_address(mesh_model), dest, netkey_index, appkey_index, (mesh_pdu_t *) transport_pdu, MESH_FOUNDATION_OPERATION_NODE_IDENTITY_STATUS);
@ -714,7 +714,7 @@ uint8_t mesh_configuration_client_send_node_identity_set(mesh_model_t * mesh_mod
uint8_t status = mesh_access_validate_envelop_params(mesh_model, dest, netkey_index, appkey_index);
if (status != ERROR_CODE_SUCCESS) return status;
mesh_upper_transport_pdu_t * transport_pdu = mesh_access_setup_segmented_message(&mesh_configuration_client_node_identity_set, netk_index, node_identity_state);
mesh_upper_transport_pdu_t * transport_pdu = mesh_access_setup_message(true, &mesh_configuration_client_node_identity_set, netk_index, node_identity_state);
if (!transport_pdu) return BTSTACK_MEMORY_ALLOC_FAILED;
mesh_configuration_client_send_acknowledged(mesh_access_get_element_address(mesh_model), dest, netkey_index, appkey_index, (mesh_pdu_t *) transport_pdu, MESH_FOUNDATION_OPERATION_NODE_IDENTITY_STATUS);
@ -725,7 +725,7 @@ uint8_t mesh_configuration_client_send_model_app_bind_get(mesh_model_t * mesh_mo
uint8_t status = mesh_access_validate_envelop_params(mesh_model, dest, netkey_index, appkey_index);
if (status != ERROR_CODE_SUCCESS) return status;
mesh_upper_transport_pdu_t * transport_pdu = mesh_access_setup_segmented_message(&mesh_configuration_client_model_app_bind, dest, appk_index, model_identifier);
mesh_upper_transport_pdu_t * transport_pdu = mesh_access_setup_message(true, &mesh_configuration_client_model_app_bind, dest, appk_index, model_identifier);
if (!transport_pdu) return BTSTACK_MEMORY_ALLOC_FAILED;
mesh_configuration_client_send_acknowledged(mesh_access_get_element_address(mesh_model), dest, netkey_index, appkey_index, (mesh_pdu_t *) transport_pdu, MESH_FOUNDATION_OPERATION_MODEL_APP_STATUS);

View File

@ -245,20 +245,22 @@ 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 * transport_pdu = mesh_access_transport_init(MESH_FOUNDATION_OPERATION_COMPOSITION_DATA_STATUS);
btstack_assert(false);
// TODO: figure out num segments
mesh_upper_transport_pdu_t * transport_pdu = mesh_access_message_init(MESH_FOUNDATION_OPERATION_COMPOSITION_DATA_STATUS, true, 1);
if (!transport_pdu) return;
// page 0
mesh_access_transport_add_uint8(transport_pdu, 0);
mesh_access_message_add_uint8(transport_pdu, 0);
// CID
mesh_access_transport_add_uint16(transport_pdu, mesh_node_get_company_id());
mesh_access_message_add_uint16(transport_pdu, mesh_node_get_company_id());
// PID
mesh_access_transport_add_uint16(transport_pdu, mesh_node_get_product_id());
mesh_access_message_add_uint16(transport_pdu, mesh_node_get_product_id());
// VID
mesh_access_transport_add_uint16(transport_pdu, mesh_node_get_product_version_id());
mesh_access_message_add_uint16(transport_pdu, mesh_node_get_product_version_id());
// CRPL - number of protection list entries
mesh_access_transport_add_uint16(transport_pdu, 1);
mesh_access_message_add_uint16(transport_pdu, 1);
// Features - Relay, Proxy, Friend, Lower Power, ...
uint16_t features = 0;
#ifdef ENABLE_MESH_RELAY
@ -267,7 +269,7 @@ static void config_composition_data_status(uint16_t netkey_index, uint16_t dest)
#ifdef ENABLE_MESH_PROXY_SERVER
features |= 2;
#endif
mesh_access_transport_add_uint16(transport_pdu, features);
mesh_access_message_add_uint16(transport_pdu, features);
mesh_element_iterator_t element_it;
mesh_element_iterator_init(&element_it);
@ -275,11 +277,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_transport_add_uint16(transport_pdu, element->loc);
mesh_access_message_add_uint16(transport_pdu, element->loc);
// NumS
mesh_access_transport_add_uint8( transport_pdu, element->models_count_sig);
mesh_access_message_add_uint8( transport_pdu, element->models_count_sig);
// NumV
mesh_access_transport_add_uint8( transport_pdu, element->models_count_vendor);
mesh_access_message_add_uint8( transport_pdu, element->models_count_vendor);
mesh_model_iterator_t model_it;
@ -288,14 +290,14 @@ 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_transport_add_model_identifier(transport_pdu, model->model_identifier);
mesh_access_message_add_model_identifier(transport_pdu, 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_transport_add_model_identifier(transport_pdu, model->model_identifier);
mesh_access_message_add_model_identifier(transport_pdu, model->model_identifier);
}
}
@ -313,7 +315,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){
UNUSED(mesh_model);
// setup message
mesh_upper_transport_pdu_t * transport_pdu = mesh_access_setup_segmented_message(&mesh_foundation_config_beacon_status,
mesh_upper_transport_pdu_t * transport_pdu = mesh_access_setup_message(true,&mesh_foundation_config_beacon_status,
mesh_foundation_beacon_get());
if (!transport_pdu) return;
@ -349,7 +351,7 @@ static void config_beacon_set_handler(mesh_model_t *mesh_model, mesh_pdu_t * pdu
static void config_model_default_ttl_status(mesh_model_t * mesh_model, uint16_t netkey_index, uint16_t dest){
UNUSED(mesh_model);
// setup message
mesh_upper_transport_pdu_t * transport_pdu = mesh_access_setup_segmented_message(
mesh_upper_transport_pdu_t * transport_pdu = mesh_access_setup_message(true,
&mesh_foundation_config_default_ttl_status, mesh_foundation_default_ttl_get());
if (!transport_pdu) return;
@ -387,7 +389,7 @@ static void config_friend_status(mesh_model_t * mesh_model, uint16_t netkey_inde
UNUSED(mesh_model);
// setup message
mesh_upper_transport_pdu_t * transport_pdu = mesh_access_setup_segmented_message(
mesh_upper_transport_pdu_t * transport_pdu = mesh_access_setup_message(true,
&mesh_foundation_config_friend_status, mesh_foundation_friend_get());
if (!transport_pdu) return;
@ -426,7 +428,7 @@ static void config_friend_set_handler(mesh_model_t *mesh_model, mesh_pdu_t * pdu
static void config_model_gatt_proxy_status(mesh_model_t * mesh_model, uint16_t netkey_index, uint16_t dest){
UNUSED(mesh_model);
// setup message
mesh_upper_transport_pdu_t * transport_pdu = mesh_access_setup_segmented_message(&mesh_foundation_config_gatt_proxy_status, mesh_foundation_gatt_proxy_get());
mesh_upper_transport_pdu_t * transport_pdu = mesh_access_setup_message(true,&mesh_foundation_config_gatt_proxy_status, mesh_foundation_gatt_proxy_get());
if (!transport_pdu) return;
// send as segmented access pdu
@ -465,7 +467,7 @@ static void config_model_relay_status(mesh_model_t * mesh_model, uint16_t netkey
UNUSED(mesh_model);
// setup message
mesh_upper_transport_pdu_t * transport_pdu = mesh_access_setup_segmented_message(&mesh_foundation_config_relay_status,
mesh_upper_transport_pdu_t * transport_pdu = mesh_access_setup_message(true,&mesh_foundation_config_relay_status,
mesh_foundation_relay_get(),
mesh_foundation_relay_retransmit_get());
if (!transport_pdu) return;
@ -512,7 +514,7 @@ static void config_model_network_transmit_status(mesh_model_t * mesh_model, uint
UNUSED(mesh_model);
// setup message
mesh_upper_transport_pdu_t * transport_pdu = mesh_access_setup_segmented_message(
mesh_upper_transport_pdu_t * transport_pdu = mesh_access_setup_message(true,
&mesh_foundation_config_network_transmit_status, mesh_foundation_network_transmit_get());
if (!transport_pdu) return;
@ -552,7 +554,7 @@ static void config_netkey_status(mesh_model_t * mesh_model, uint16_t netkey_inde
UNUSED(mesh_model);
// setup message
mesh_upper_transport_pdu_t * transport_pdu = mesh_access_setup_segmented_message(
mesh_upper_transport_pdu_t * transport_pdu = mesh_access_setup_message(true,
&mesh_foundation_config_netkey_status, status, new_netkey_index);
if (!transport_pdu) return;
@ -563,7 +565,10 @@ 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 * transport_pdu = mesh_access_transport_init(MESH_FOUNDATION_OPERATION_NETKEY_LIST);
btstack_assert(false);
// TODO: find num segments
mesh_upper_transport_pdu_t * transport_pdu = mesh_access_message_init(MESH_FOUNDATION_OPERATION_NETKEY_LIST, true, 1);
if (!transport_pdu) return;
// add list of netkey indexes
@ -571,7 +576,7 @@ static void config_netkey_list(mesh_model_t * mesh_model, uint16_t netkey_index,
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_transport_add_uint16(transport_pdu, network_key->netkey_index);
mesh_access_message_add_uint16(transport_pdu, network_key->netkey_index);
}
// send as segmented access pdu
@ -789,7 +794,7 @@ static void config_appkey_status(mesh_model_t * mesh_model, uint16_t netkey_inde
UNUSED(mesh_model);
// setup message
mesh_upper_transport_pdu_t * transport_pdu = mesh_access_setup_segmented_message(&mesh_foundation_config_appkey_status,
mesh_upper_transport_pdu_t * transport_pdu = mesh_access_setup_message(true,&mesh_foundation_config_appkey_status,
status, netkey_and_appkey_index);
if (!transport_pdu) return;
@ -800,7 +805,10 @@ 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 * transport_pdu = mesh_access_transport_init(MESH_FOUNDATION_OPERATION_APPKEY_LIST);
btstack_assert(false);
// TODO: find num segments
mesh_upper_transport_pdu_t * transport_pdu = mesh_access_message_init(MESH_FOUNDATION_OPERATION_APPKEY_LIST, true, 1);
if (!transport_pdu) return;
// check netkey_index is valid
@ -811,15 +819,15 @@ static void config_appkey_list(mesh_model_t * mesh_model, uint16_t netkey_index,
} else {
status = MESH_FOUNDATION_STATUS_SUCCESS;
}
mesh_access_transport_add_uint8(transport_pdu, status);
mesh_access_transport_add_uint16(transport_pdu, netkey_index_of_list);
mesh_access_message_add_uint8(transport_pdu, status);
mesh_access_message_add_uint16(transport_pdu, 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_transport_add_uint16(transport_pdu, transport_key->appkey_index);
mesh_access_message_add_uint16(transport_pdu, transport_key->appkey_index);
}
// send as segmented access pdu
@ -1034,13 +1042,16 @@ 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 * transport_pdu = mesh_access_transport_init(opcode);
btstack_assert(false);
// TODO: find num segments
mesh_upper_transport_pdu_t * transport_pdu = mesh_access_message_init(opcode, true, 1);
if (!transport_pdu) return;
// setup segmented message
mesh_access_transport_add_uint8(transport_pdu, status);
mesh_access_transport_add_uint16(transport_pdu, element_address);
mesh_access_transport_add_model_identifier(transport_pdu, model_identifier);
mesh_access_message_add_uint8(transport_pdu, status);
mesh_access_message_add_uint16(transport_pdu, element_address);
mesh_access_message_add_model_identifier(transport_pdu, model_identifier);
if (target_model != NULL){
uint16_t i;
@ -1052,7 +1063,7 @@ 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_transport_add_uint16(transport_pdu, address);
mesh_access_message_add_uint16(transport_pdu, address);
}
}
config_server_send_message(netkey_index, dest, (mesh_pdu_t *) transport_pdu);
@ -1076,7 +1087,7 @@ static void config_model_subscription_status(mesh_model_t * mesh_model, uint16_t
UNUSED(mesh_model);
// setup message
mesh_upper_transport_pdu_t * transport_pdu = mesh_access_setup_segmented_message(&mesh_foundation_config_model_subscription_status,
mesh_upper_transport_pdu_t * transport_pdu = mesh_access_setup_message(true,&mesh_foundation_config_model_subscription_status,
status, element_address, address, model_identifier);
if (!transport_pdu) return;
// send as segmented access pdu
@ -1327,7 +1338,7 @@ static void config_model_app_status(mesh_model_t * mesh_model, uint16_t netkey_i
UNUSED(mesh_model);
// setup message
mesh_upper_transport_pdu_t * transport_pdu = mesh_access_setup_segmented_message(&mesh_foundation_config_model_app_status,
mesh_upper_transport_pdu_t * transport_pdu = mesh_access_setup_message(true,&mesh_foundation_config_model_app_status,
status, element_address, appkey_index, model_identifier);
if (!transport_pdu) return;
@ -1344,15 +1355,19 @@ static void config_model_app_list(mesh_model_t * config_server_model, uint16_t n
} else {
opcode = MESH_FOUNDATION_OPERATION_VENDOR_MODEL_APP_LIST;
}
mesh_upper_transport_pdu_t * transport_pdu = mesh_access_transport_init(opcode);
btstack_assert(false);
// TODO: find num segments
mesh_upper_transport_pdu_t * transport_pdu = mesh_access_message_init(opcode, true, 1);
if (!transport_pdu) return;
mesh_access_transport_add_uint8(transport_pdu, status);
mesh_access_transport_add_uint16(transport_pdu, element_address);
mesh_access_message_add_uint8(transport_pdu, status);
mesh_access_message_add_uint16(transport_pdu, element_address);
if (mesh_model_is_bluetooth_sig(model_identifier)) {
mesh_access_transport_add_uint16(transport_pdu, mesh_model_get_model_id(model_identifier));
mesh_access_message_add_uint16(transport_pdu, mesh_model_get_model_id(model_identifier));
} else {
mesh_access_transport_add_uint32(transport_pdu, model_identifier);
mesh_access_message_add_uint32(transport_pdu, model_identifier);
}
// add list of appkey indexes
@ -1361,7 +1376,7 @@ 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_transport_add_uint16(transport_pdu, appkey_index);
mesh_access_message_add_uint16(transport_pdu, appkey_index);
}
}
@ -1511,7 +1526,7 @@ config_model_publication_status(mesh_model_t *mesh_model, uint16_t netkey_index,
}
}
mesh_upper_transport_pdu_t * transport_pdu = mesh_access_setup_segmented_message(
mesh_upper_transport_pdu_t * transport_pdu = mesh_access_setup_message(true,
&mesh_foundation_config_model_publication_status, status, element_address, publish_address,
app_key_index_and_credential_flag, ttl, period, retransmit, model_identifier);
if (!transport_pdu) return;
@ -1787,7 +1802,7 @@ static void config_heartbeat_publication_status(mesh_model_t *mesh_model, uint16
// setup message
uint8_t count_log = mesh_heartbeat_count_log(mesh_heartbeat_publication->count);
mesh_upper_transport_pdu_t * transport_pdu = mesh_access_setup_segmented_message(
mesh_upper_transport_pdu_t * transport_pdu = mesh_access_setup_message(true,
&mesh_foundation_config_heartbeat_publication_status,
status,
mesh_heartbeat_publication->destination,
@ -1886,7 +1901,7 @@ static void config_heartbeat_subscription_status(mesh_model_t *mesh_model, uint1
// setup message
uint8_t count_log = mesh_heartbeat_count_log(mesh_heartbeat_subscription->count);
mesh_upper_transport_pdu_t * transport_pdu = mesh_access_setup_segmented_message(
mesh_upper_transport_pdu_t * transport_pdu = mesh_access_setup_message(true,
&mesh_foundation_config_heartbeat_subscription_status,
status,
mesh_heartbeat_subscription->source,
@ -2030,7 +2045,7 @@ static void config_key_refresh_phase_status(mesh_model_t *mesh_model, uint16_t n
UNUSED(mesh_model);
// setup message
mesh_upper_transport_pdu_t * transport_pdu = mesh_access_setup_segmented_message(
mesh_upper_transport_pdu_t * transport_pdu = mesh_access_setup_message(true,
&mesh_key_refresh_phase_status,
status,
netkey_index,
@ -2109,7 +2124,7 @@ static void config_node_reset_status(mesh_model_t *mesh_model, uint16_t netkey_i
UNUSED(mesh_model);
// setup message
mesh_upper_transport_pdu_t * transport_pdu = mesh_access_setup_segmented_message(&mesh_foundation_node_reset_status);
mesh_upper_transport_pdu_t * transport_pdu = mesh_access_setup_message(true,&mesh_foundation_node_reset_status);
if (!transport_pdu) return;
// send as segmented access pdu
@ -2125,7 +2140,7 @@ static void config_node_reset_handler(mesh_model_t *mesh_model, mesh_pdu_t * pdu
static void low_power_node_poll_timeout_status(mesh_model_t *mesh_model, uint16_t netkey_index_dest, uint16_t dest, uint8_t status){
UNUSED(mesh_model);
mesh_upper_transport_pdu_t * transport_pdu = mesh_access_setup_segmented_message(
mesh_upper_transport_pdu_t * transport_pdu = mesh_access_setup_message(true,
&mesh_foundation_low_power_node_poll_timeout_status,
status,
0, // The unicast address of the Low Power node
@ -2150,7 +2165,7 @@ static void config_node_identity_status(mesh_model_t *mesh_model, uint16_t netke
UNUSED(mesh_model);
// setup message
mesh_upper_transport_pdu_t * transport_pdu = mesh_access_setup_segmented_message(
mesh_upper_transport_pdu_t * transport_pdu = mesh_access_setup_message(true,
&mesh_foundation_node_identity_status,
status,
netkey_index,

View File

@ -85,7 +85,7 @@ static void generic_client_send_message_acknowledged(uint16_t src, uint16_t dest
uint8_t mesh_generic_default_transition_time_client_get(mesh_model_t *mesh_model, uint16_t dest, uint16_t netkey_index, uint16_t appkey_index){
// setup message
mesh_upper_transport_pdu_t * transport_pdu = mesh_access_setup_segmented_message(&mesh_generic_default_transition_time_get);
mesh_upper_transport_pdu_t * transport_pdu = mesh_access_setup_message(true, &mesh_generic_default_transition_time_get);
if (!transport_pdu) return BTSTACK_MEMORY_ALLOC_FAILED;
// send as segmented access pdu
generic_client_send_message_acknowledged(mesh_access_get_element_address(mesh_model), dest, netkey_index, appkey_index, (mesh_pdu_t *) transport_pdu, MESH_GENERIC_DEFAULT_TRANSITION_TIME_STATUS);
@ -97,7 +97,7 @@ uint8_t mesh_generic_default_transition_time_client_set(mesh_model_t * mesh_mode
mesh_upper_transport_pdu_t * transport_pdu;
transport_pdu = mesh_access_setup_segmented_message(&mesh_generic_default_transition_time_set, transition_time_gdtt);
transport_pdu = mesh_access_setup_message(true, &mesh_generic_default_transition_time_set, transition_time_gdtt);
if (!transport_pdu) return BTSTACK_MEMORY_ALLOC_FAILED;
@ -108,7 +108,7 @@ uint8_t mesh_generic_default_transition_time_client_set(mesh_model_t * mesh_mode
uint8_t mesh_generic_default_transition_time_client_set_unacknowledged(mesh_model_t * mesh_model, uint16_t dest, uint16_t netkey_index, uint16_t appkey_index,
uint8_t transition_time_gdtt){
mesh_upper_transport_pdu_t * transport_pdu;
transport_pdu = mesh_access_setup_segmented_message(&mesh_generic_default_transition_time_set_unacknowledged, transition_time_gdtt);
transport_pdu = mesh_access_setup_message(true, &mesh_generic_default_transition_time_set_unacknowledged, transition_time_gdtt);
if (!transport_pdu) return BTSTACK_MEMORY_ALLOC_FAILED;
generic_client_send_message_unacknowledged(mesh_access_get_element_address(mesh_model), dest, netkey_index, appkey_index, (mesh_pdu_t *) transport_pdu);

View File

@ -74,7 +74,7 @@ static mesh_pdu_t * mesh_generic_default_transition_time_status_message(mesh_mod
mesh_upper_transport_pdu_t * transport_pdu = NULL;
log_info("Default transition time status: value %u", state->value);
transport_pdu = mesh_access_setup_segmented_message(&mesh_generic_default_transition_time_status, state->value);
transport_pdu = mesh_access_setup_message(true, &mesh_generic_default_transition_time_status, state->value);
return (mesh_pdu_t *) transport_pdu;
}

View File

@ -133,9 +133,9 @@ static inline uint8_t mesh_generic_level_client_set_value(mesh_model_t * mesh_mo
mesh_upper_transport_pdu_t * transport_pdu;
if (transition_time_gdtt != 0) {
transport_pdu = mesh_access_setup_segmented_message(message_template_with_transition, value, transaction_id, transition_time_gdtt, delay_time_gdtt);
transport_pdu = mesh_access_setup_message(true, message_template_with_transition, value, transaction_id, transition_time_gdtt, delay_time_gdtt);
} else {
transport_pdu = mesh_access_setup_segmented_message(message_template_instantaneous, value, transaction_id);
transport_pdu = mesh_access_setup_message(true, message_template_instantaneous, value, transaction_id);
}
if (!transport_pdu) return BTSTACK_MEMORY_ALLOC_FAILED;
@ -151,7 +151,7 @@ static inline uint8_t mesh_generic_level_client_set_value(mesh_model_t * mesh_mo
uint8_t mesh_generic_level_client_level_get(mesh_model_t *mesh_model, uint16_t dest, uint16_t netkey_index, uint16_t appkey_index){
// setup message
mesh_upper_transport_pdu_t * transport_pdu = mesh_access_setup_segmented_message(&mesh_generic_level_get);
mesh_upper_transport_pdu_t * transport_pdu = mesh_access_setup_message(true, &mesh_generic_level_get);
if (!transport_pdu) return BTSTACK_MEMORY_ALLOC_FAILED;
// send as segmented access pdu
generic_client_send_message_acknowledged(mesh_access_get_element_address(mesh_model), dest, netkey_index, appkey_index, (mesh_pdu_t *) transport_pdu, MESH_GENERIC_LEVEL_STATUS);

View File

@ -144,10 +144,10 @@ static mesh_pdu_t * mesh_generic_level_status_message(mesh_model_t *generic_leve
mesh_upper_transport_pdu_t * transport_pdu = NULL;
if (state->transition_data.base_transition.num_steps > 0) {
uint8_t remaining_time = (((uint8_t)state->transition_data.base_transition.step_resolution) << 6) | (state->transition_data.base_transition.num_steps);
transport_pdu = mesh_access_setup_segmented_message(&mesh_generic_level_status_transition, state->transition_data.current_value,
transport_pdu = mesh_access_setup_message(true, &mesh_generic_level_status_transition, state->transition_data.current_value,
state->transition_data.target_value, remaining_time);
} else {
transport_pdu = mesh_access_setup_segmented_message(&mesh_generic_level_status_instantaneous, state->transition_data.current_value);
transport_pdu = mesh_access_setup_message(true, &mesh_generic_level_status_instantaneous, state->transition_data.current_value);
}
return (mesh_pdu_t *)transport_pdu;
}

View File

@ -93,7 +93,7 @@ static void generic_client_send_message_acknowledged(uint16_t src, uint16_t dest
uint8_t mesh_generic_on_off_client_get(mesh_model_t *mesh_model, uint16_t dest, uint16_t netkey_index, uint16_t appkey_index){
// setup message
mesh_upper_transport_pdu_t * transport_pdu = mesh_access_setup_segmented_message(&mesh_generic_on_off_get);
mesh_upper_transport_pdu_t * transport_pdu = mesh_access_setup_message(true, &mesh_generic_on_off_get);
if (!transport_pdu) return BTSTACK_MEMORY_ALLOC_FAILED;
// send as segmented access pdu
generic_client_send_message_acknowledged(mesh_access_get_element_address(mesh_model), dest, netkey_index, appkey_index, (mesh_pdu_t *) transport_pdu, MESH_GENERIC_ON_OFF_STATUS);
@ -105,9 +105,9 @@ uint8_t mesh_generic_on_off_client_set(mesh_model_t * mesh_model, uint16_t dest,
mesh_upper_transport_pdu_t * transport_pdu;
if (transition_time_gdtt != 0) {
transport_pdu = mesh_access_setup_segmented_message(&mesh_generic_on_off_set_with_transition, on_off_value, transaction_id, transition_time_gdtt, delay_time_gdtt);
transport_pdu = mesh_access_setup_message(true, &mesh_generic_on_off_set_with_transition, on_off_value, transaction_id, transition_time_gdtt, delay_time_gdtt);
} else {
transport_pdu = mesh_access_setup_segmented_message(&mesh_generic_on_off_set_instantaneous, on_off_value, transaction_id);
transport_pdu = mesh_access_setup_message(true, &mesh_generic_on_off_set_instantaneous, on_off_value, transaction_id);
}
if (!transport_pdu) return BTSTACK_MEMORY_ALLOC_FAILED;
@ -119,9 +119,9 @@ uint8_t mesh_generic_on_off_client_set_unacknowledged(mesh_model_t * mesh_model,
uint8_t on_off_value, uint8_t transition_time_gdtt, uint8_t delay_time_gdtt, uint8_t transaction_id){
mesh_upper_transport_pdu_t * transport_pdu;
if (transition_time_gdtt != 0) {
transport_pdu = mesh_access_setup_segmented_message(&mesh_generic_on_off_set_unacknowledged_with_transition, on_off_value, transaction_id, transition_time_gdtt, delay_time_gdtt);
transport_pdu = mesh_access_setup_message(true, &mesh_generic_on_off_set_unacknowledged_with_transition, on_off_value, transaction_id, transition_time_gdtt, delay_time_gdtt);
} else {
transport_pdu = mesh_access_setup_segmented_message(&mesh_generic_on_off_set_unacknowledged_instantaneous, on_off_value, transaction_id);
transport_pdu = mesh_access_setup_message(true, &mesh_generic_on_off_set_unacknowledged_instantaneous, on_off_value, transaction_id);
}
if (!transport_pdu) return BTSTACK_MEMORY_ALLOC_FAILED;
generic_client_send_message_unacknowledged(mesh_access_get_element_address(mesh_model), dest, netkey_index, appkey_index, (mesh_pdu_t *) transport_pdu);

View File

@ -125,11 +125,11 @@ static mesh_pdu_t * mesh_generic_on_off_status_message(mesh_model_t *generic_on_
mesh_upper_transport_pdu_t * transport_pdu = NULL;
if (state->transition_data.base_transition.num_steps > 0) {
uint8_t remaining_time = (((uint8_t)state->transition_data.base_transition.step_resolution) << 6) | (state->transition_data.base_transition.num_steps);
transport_pdu = mesh_access_setup_segmented_message(&mesh_generic_on_off_status_transition, state->transition_data.current_value,
transport_pdu = mesh_access_setup_message(true, &mesh_generic_on_off_status_transition, state->transition_data.current_value,
state->transition_data.target_value, remaining_time);
} else {
log_info("On/Off Status: value %u, no transition active", state->transition_data.current_value);
transport_pdu = mesh_access_setup_segmented_message(&mesh_generic_on_off_status_instantaneous, state->transition_data.current_value);
transport_pdu = mesh_access_setup_message(true, &mesh_generic_on_off_status_instantaneous, state->transition_data.current_value);
}
return (mesh_pdu_t *) transport_pdu;
}