mesh: add mesh_lower_transport_set_higher_layer_handler to avaoid calling upper transport directly

This commit is contained in:
Matthias Ringwald 2019-04-09 14:23:16 +02:00
parent bdcf830af3
commit 1d36037326
3 changed files with 12 additions and 17 deletions

View File

@ -41,18 +41,13 @@
#include <stdlib.h>
#include <string.h>
#include "ble/mesh/beacon.h"
#include "mesh_transport.h"
#include "btstack_util.h"
#include "btstack_memory.h"
#include "mesh_peer.h"
#include "mesh_lower_transport.h"
static uint16_t primary_element_address;
// temp prototypes upper transport
void mesh_upper_unsegmented_control_message_received(mesh_network_pdu_t * network_pdu);
void mesh_upper_transport_segmented_message_received(mesh_transport_pdu_t *transport_pdu);
void mesh_upper_transport_unsegmented_message_received(mesh_network_pdu_t * network_pdu);
static void (*higher_layer_handler)( mesh_pdu_t * pdu);
static void mesh_print_hex(const char * name, const uint8_t * data, uint16_t len){
printf("%-20s ", name);
@ -181,7 +176,7 @@ static void mesh_lower_transport_process_unsegmented_control_message(mesh_networ
mesh_network_message_processed_by_higher_layer(network_pdu);
break;
default:
mesh_upper_transport_unsegmented_message_received(network_pdu);
higher_layer_handler((mesh_pdu_t *) network_pdu);
break;
}
}
@ -425,7 +420,7 @@ static void mesh_lower_transport_process_segment( mesh_transport_pdu_t * transpo
mesh_lower_transport_send_ack_for_transport_pdu(transport_pdu);
// forward to upper transport
mesh_upper_transport_segmented_message_received(transport_pdu);
higher_layer_handler((mesh_pdu_t*) transport_pdu);
}
void mesh_lower_transport_message_processed_by_higher_layer(mesh_pdu_t * pdu){
@ -645,7 +640,7 @@ static void mesh_lower_transport_run(void){
mesh_lower_transport_process_unsegmented_control_message(network_pdu);
} else {
// unsegmented access message (encrypted)
mesh_upper_transport_unsegmented_message_received(network_pdu);
higher_layer_handler((mesh_pdu_t *) network_pdu);
}
}
}
@ -695,3 +690,6 @@ void mesh_lower_transport_init(){
mesh_network_set_higher_layer_handler(&mesh_lower_transport_received_message);
}
void mesh_lower_transport_set_higher_layer_handler(void (*pdu_handler)( mesh_pdu_t * pdu)){
higher_layer_handler = pdu_handler;
}

View File

@ -69,6 +69,7 @@ void mesh_transport_set_dest(mesh_transport_pdu_t * transport_pdu, uint16_t dest
void mesh_lower_transport_init();
void mesh_lower_transport_set_higher_layer_handler(void (*pdu_handler)( mesh_pdu_t * pdu));
void mesh_lower_transport_set_seq(uint32_t seq);
uint32_t mesh_lower_transport_next_seq(void);;

View File

@ -508,13 +508,8 @@ static void mesh_upper_transport_process_message(mesh_transport_pdu_t * transpor
mesh_upper_transport_validate_segmented_message(transport_pdu);
}
void mesh_upper_transport_segmented_message_received(mesh_transport_pdu_t *transport_pdu){
btstack_linked_list_add_tail(&upper_transport_incoming, (btstack_linked_item_t*) transport_pdu);
mesh_transport_run();
}
void mesh_upper_transport_unsegmented_message_received(mesh_network_pdu_t * network_pdu){
btstack_linked_list_add_tail(&upper_transport_incoming, (btstack_linked_item_t*) network_pdu);
void mesh_upper_transport_message_received(mesh_pdu_t * pdu){
btstack_linked_list_add_tail(&upper_transport_incoming, (btstack_linked_item_t*) pdu);
mesh_transport_run();
}
@ -789,6 +784,7 @@ void mesh_upper_transport_register_segemented_message_handler(void (*callback)(m
void mesh_transport_init(){
mesh_lower_transport_init();
mesh_lower_transport_set_higher_layer_handler(&mesh_upper_transport_message_received);
}
static void mesh_transport_run(void){
@ -851,4 +847,4 @@ mesh_transport_pdu_t * mesh_transport_pdu_get(void){
void mesh_transport_pdu_free(mesh_transport_pdu_t * transport_pdu){
btstack_memory_mesh_transport_pdu_free(transport_pdu);
}
}