mirror of
https://github.com/bluekitchen/btstack.git
synced 2025-04-17 20:42:47 +00:00
mesh: forward validated network pdu to transport layer before relaying
This commit is contained in:
parent
233d8706eb
commit
cb4abe7572
@ -112,6 +112,7 @@ static int mesh_network_cache_index;
|
|||||||
|
|
||||||
static void mesh_network_run(void);
|
static void mesh_network_run(void);
|
||||||
static void process_network_pdu_validate(mesh_network_pdu_t * network_pdu);
|
static void process_network_pdu_validate(mesh_network_pdu_t * network_pdu);
|
||||||
|
static void mesh_network_message_processed_by_upper_layer(mesh_network_pdu_t * network_pdu);
|
||||||
|
|
||||||
// network caching
|
// network caching
|
||||||
static uint32_t mesh_network_cache_hash(mesh_network_pdu_t * network_pdu){
|
static uint32_t mesh_network_cache_hash(mesh_network_pdu_t * network_pdu){
|
||||||
@ -191,6 +192,19 @@ static const mesh_network_key_t * mesh_network_key_iterator_get_next(mesh_networ
|
|||||||
return &mesh_network_primary_key;
|
return &mesh_network_primary_key;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// stub lower transport
|
||||||
|
static void transport_received_message(mesh_network_pdu_t * network_pdu){
|
||||||
|
uint8_t ctl_ttl = network_pdu->data[1];
|
||||||
|
uint8_t net_mic_len = (ctl_ttl & 0x80) ? 8 : 4;
|
||||||
|
|
||||||
|
//
|
||||||
|
printf("Lower Transport network_pdu: ");
|
||||||
|
printf_hexdump(&network_pdu->data[9], network_pdu->len - 9 - net_mic_len);
|
||||||
|
|
||||||
|
// done
|
||||||
|
mesh_network_message_processed_by_upper_layer(network_pdu);
|
||||||
|
}
|
||||||
|
|
||||||
// common helper
|
// common helper
|
||||||
|
|
||||||
int mesh_network_addresses_valid(uint8_t ctl, uint16_t src, uint16_t dst){
|
int mesh_network_addresses_valid(uint8_t ctl, uint16_t src, uint16_t dst){
|
||||||
@ -340,8 +354,6 @@ static void process_network_pdu_validate_d(void * arg){
|
|||||||
// compare nic to nic in data
|
// compare nic to nic in data
|
||||||
if (memcmp(net_mic, &network_pdu_in_validation->data[network_pdu->len-net_mic_len], net_mic_len) == 0){
|
if (memcmp(net_mic, &network_pdu_in_validation->data[network_pdu->len-net_mic_len], net_mic_len) == 0){
|
||||||
|
|
||||||
int free_pdu = 1;
|
|
||||||
|
|
||||||
// match
|
// match
|
||||||
printf("NetMIC matches\n");
|
printf("NetMIC matches\n");
|
||||||
|
|
||||||
@ -358,31 +370,13 @@ static void process_network_pdu_validate_d(void * arg){
|
|||||||
uint32_t hash = mesh_network_cache_hash(network_pdu);
|
uint32_t hash = mesh_network_cache_hash(network_pdu);
|
||||||
mesh_network_cache_add(hash);
|
mesh_network_cache_add(hash);
|
||||||
|
|
||||||
#if 0
|
// forward to lower transport layer. message is freed by call to mesh_network_message_processed_by_upper_layer
|
||||||
// TODO: forward to lower transport layer
|
transport_received_message(network_pdu);
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef ENABLE_MESH_RELAY
|
} else {
|
||||||
uint8_t ttl = ctl_ttl & 0x7f;
|
|
||||||
|
|
||||||
// check if address matches elements on our node and TTL >= 2
|
|
||||||
if (((src < mesh_network_primary_address) || (src > (mesh_network_primary_address + mesh_network_num_elements))) && (ttl >= 2)){
|
|
||||||
// prepare pdu for resending
|
|
||||||
network_pdu->len -= net_mic_len;
|
|
||||||
network_pdu->data[1] = (ctl << 7) | (ttl - 1);
|
|
||||||
|
|
||||||
// queue up
|
|
||||||
btstack_linked_list_add_tail(&network_pdus_queued, (btstack_linked_item_t *) network_pdu);
|
|
||||||
|
|
||||||
// go
|
|
||||||
mesh_network_run();
|
|
||||||
|
|
||||||
free_pdu = 0;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
if (free_pdu){
|
|
||||||
btstack_memory_mesh_network_pdu_free(network_pdu);
|
btstack_memory_mesh_network_pdu_free(network_pdu);
|
||||||
|
|
||||||
}
|
}
|
||||||
process_network_pdu_done();
|
process_network_pdu_done();
|
||||||
} else {
|
} else {
|
||||||
@ -392,6 +386,32 @@ static void process_network_pdu_validate_d(void * arg){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void mesh_network_message_processed_by_upper_layer(mesh_network_pdu_t * network_pdu){
|
||||||
|
#ifdef ENABLE_MESH_RELAY
|
||||||
|
uint8_t ctl_ttl = network_pdu->data[1];
|
||||||
|
uint8_t ctl = ctl_ttl >> 7;
|
||||||
|
uint8_t ttl = ctl_ttl & 0x7f;
|
||||||
|
uint8_t net_mic_len = (ctl_ttl & 0x80) ? 8 : 4;
|
||||||
|
uint16_t src = big_endian_read_16(network_pdu->data, 5);
|
||||||
|
|
||||||
|
// check if address matches elements on our node and TTL >= 2
|
||||||
|
if (((src < mesh_network_primary_address) || (src > (mesh_network_primary_address + mesh_network_num_elements))) && (ttl >= 2)){
|
||||||
|
// prepare pdu for resending
|
||||||
|
network_pdu->len -= net_mic_len;
|
||||||
|
network_pdu->data[1] = (ctl << 7) | (ttl - 1);
|
||||||
|
|
||||||
|
// queue up
|
||||||
|
btstack_linked_list_add_tail(&network_pdus_queued, (btstack_linked_item_t *) network_pdu);
|
||||||
|
|
||||||
|
// go
|
||||||
|
mesh_network_run();
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
btstack_memory_mesh_network_pdu_free(network_pdu);
|
||||||
|
}
|
||||||
|
|
||||||
static void process_network_pdu_validate_b(void * arg){
|
static void process_network_pdu_validate_b(void * arg){
|
||||||
mesh_network_pdu_t * network_pdu = (mesh_network_pdu_t *) arg;
|
mesh_network_pdu_t * network_pdu = (mesh_network_pdu_t *) arg;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user