mesh: single mesh_upper_transport_setup_control_pdu instead of segmented/unsegmented

This commit is contained in:
Matthias Ringwald 2019-04-22 22:24:45 +02:00
parent f804bd819f
commit dd5179955b
4 changed files with 22 additions and 14 deletions

View File

@ -1611,7 +1611,7 @@ static void config_heartbeat_publication_emit(btstack_timer_source_t * ts){
uint8_t data[3];
data[0] = mesh_heartbeat_publication.ttl;
big_endian_store_16(data, 1, mesh_heartbeat_publication.features);
mesh_upper_transport_setup_unsegmented_control_pdu(network_pdu, mesh_heartbeat_publication.netkey_index,
mesh_upper_transport_setup_control_pdu((mesh_pdu_t *) network_pdu, mesh_heartbeat_publication.netkey_index,
mesh_heartbeat_publication.ttl, 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);

View File

@ -343,17 +343,16 @@ void test_send_control_message(uint16_t netkey_index, uint8_t ttl, uint16_t src,
uint8_t opcode = transport_pdu_data[0];
mesh_pdu_t * pdu;
if (transport_pdu_len < 12){
// send as unsegmented control pdu
mesh_network_pdu_t * network_pdu = mesh_network_pdu_get();
mesh_upper_transport_setup_unsegmented_control_pdu(network_pdu, netkey_index, ttl, src, dest, opcode, transport_pdu_data+1, transport_pdu_len-1);
mesh_upper_transport_send_control_pdu((mesh_pdu_t*) network_pdu);
pdu = (mesh_pdu_t *) mesh_network_pdu_get();
} else {
// send as segmented control pdu
mesh_transport_pdu_t * transport_pdu = mesh_transport_pdu_get();
mesh_upper_transport_setup_segmented_control_pdu(transport_pdu, netkey_index, ttl, src, dest, opcode, transport_pdu_data+1, transport_pdu_len-1);
mesh_upper_transport_send_control_pdu((mesh_pdu_t*) transport_pdu);
pdu = (mesh_pdu_t *) mesh_transport_pdu_get();
}
mesh_upper_transport_setup_control_pdu(pdu, netkey_index, ttl, src, dest, opcode, transport_pdu_data+1, transport_pdu_len-1);
mesh_upper_transport_send_control_pdu(pdu);
// check for all network pdus
int i;

View File

@ -546,7 +546,7 @@ static void mesh_upper_transport_send_segmented_access_pdu_ccm(void * arg){
mesh_lower_transport_send_pdu((mesh_pdu_t*) transport_pdu);
}
uint8_t mesh_upper_transport_setup_unsegmented_control_pdu(mesh_network_pdu_t * network_pdu, uint16_t netkey_index, uint8_t ttl, uint16_t src, uint16_t dest, uint8_t opcode,
static uint8_t mesh_upper_transport_setup_unsegmented_control_pdu(mesh_network_pdu_t * network_pdu, uint16_t netkey_index, uint8_t ttl, uint16_t src, uint16_t dest, uint8_t opcode,
const uint8_t * control_pdu_data, uint16_t control_pdu_len){
printf("[+] Upper transport, setup unsegmented Control PDU (opcode %02x): \n", opcode);
@ -569,7 +569,7 @@ uint8_t mesh_upper_transport_setup_unsegmented_control_pdu(mesh_network_pdu_t *
return 0;
}
uint8_t mesh_upper_transport_setup_segmented_control_pdu(mesh_transport_pdu_t * transport_pdu, uint16_t netkey_index, uint8_t ttl, uint16_t src, uint16_t dest, uint8_t opcode,
static uint8_t mesh_upper_transport_setup_segmented_control_pdu(mesh_transport_pdu_t * transport_pdu, uint16_t netkey_index, uint8_t ttl, uint16_t src, uint16_t dest, uint8_t opcode,
const uint8_t * control_pdu_data, uint16_t control_pdu_len){
printf("[+] Upper transport, setup segmented Control PDU (opcode %02x): \n", opcode);
@ -596,6 +596,18 @@ uint8_t mesh_upper_transport_setup_segmented_control_pdu(mesh_transport_pdu_t *
return 0;
}
uint8_t mesh_upper_transport_setup_control_pdu(mesh_pdu_t * pdu, uint16_t netkey_index,
uint8_t ttl, uint16_t src, uint16_t dest, uint8_t opcode, const uint8_t * control_pdu_data, uint16_t control_pdu_len){
switch (pdu->pdu_type){
case MESH_PDU_TYPE_NETWORK:
return mesh_upper_transport_setup_unsegmented_control_pdu((mesh_network_pdu_t *) pdu, netkey_index, ttl, src, dest, opcode, control_pdu_data, control_pdu_len);
case MESH_PDU_TYPE_TRANSPORT:
return mesh_upper_transport_setup_segmented_control_pdu((mesh_transport_pdu_t *) pdu, netkey_index, ttl, src, dest, opcode, control_pdu_data, control_pdu_len);
default:
return 1;
}
}
uint8_t mesh_upper_transport_setup_unsegmented_access_pdu_header(mesh_network_pdu_t * network_pdu, uint16_t netkey_index,
uint16_t appkey_index, uint8_t ttl, uint16_t src, uint16_t dest){

View File

@ -63,11 +63,8 @@ void mesh_upper_transport_message_processed_by_higher_layer(mesh_pdu_t * pdu);
void mesh_upper_transport_register_control_message_handler(void (*callback)(mesh_pdu_t * pdu));
uint8_t mesh_upper_transport_setup_segmented_control_pdu(mesh_transport_pdu_t * transport_pdu, uint16_t netkey_index,
uint8_t ttl, uint16_t src, uint16_t dest, uint8_t opcode, const uint8_t * control_pdu_data, uint16_t control_pdu_len);
uint8_t mesh_upper_transport_setup_unsegmented_control_pdu(mesh_network_pdu_t * network_pdu, uint16_t netkey_index,
uint8_t ttl, uint16_t src, uint16_t dest, uint8_t opcode, const uint8_t * control_pdu_data, uint16_t control_pdu_len);
uint8_t mesh_upper_transport_setup_control_pdu(mesh_pdu_t * pdu, uint16_t netkey_index,
uint8_t ttl, uint16_t src, uint16_t dest, uint8_t opcode, const uint8_t * control_pdu_data, uint16_t control_pdu_len);
void mesh_upper_transport_send_control_pdu(mesh_pdu_t * pdu);