mesh: avoid redirect of mesh network messages via mesh.c

This commit is contained in:
Matthias Ringwald 2019-06-27 11:19:00 +02:00
parent 452750bf56
commit a59b27450e
4 changed files with 45 additions and 44 deletions

View File

@ -47,6 +47,7 @@
#include "mesh_keys.h"
#include "btstack_util.h"
#include "btstack_memory.h"
#include "btstack_event.h"
#ifdef ENABLE_MESH_ADV_BEARER
#include "mesh/adv_bearer.h"
@ -656,8 +657,8 @@ static void mesh_adv_message_handler(uint8_t packet_type, uint16_t channel, uint
}
#endif
void mesh_gatt_handle_event(uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size){
#ifdef ENABLE_MESH_GATT_BEARER
void mesh_gatt_handle_event(uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size){
mesh_network_pdu_t * network_pdu;
switch (packet_type){
case HCI_EVENT_PACKET:
@ -695,13 +696,50 @@ void mesh_gatt_handle_event(uint8_t packet_type, uint16_t channel, uint8_t *pack
}
break;
}
#endif
}
static void mesh_proxy_packet_handler_network_pdu(uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size){
switch (packet_type){
case MESH_PROXY_DATA_PACKET:
printf("mesh: Received network PDU (proxy)\n");
printf_hexdump(packet, size);
mesh_network_received_message(packet, size);
break;
case HCI_EVENT_PACKET:
switch (hci_event_packet_get_type(packet)){
case HCI_EVENT_MESH_META:
switch (hci_event_mesh_meta_get_subevent_code(packet)){
case MESH_SUBEVENT_CAN_SEND_NOW:
mesh_gatt_handle_event(packet_type, channel, packet, size);
break;
case MESH_SUBEVENT_MESSAGE_SENT:
mesh_gatt_handle_event(packet_type, channel, packet, size);
break;
case MESH_SUBEVENT_PROXY_CONNECTED:
printf("mesh: MESH_PROXY_CONNECTED\n");
break;
default:
break;
}
break;
default:
break;
}
break;
default:
break;
}
}
#endif
void mesh_network_init(void){
#ifdef ENABLE_MESH_ADV_BEARER
adv_bearer_register_for_mesh_message(&mesh_adv_message_handler);
#endif
#ifdef ENABLE_MESH_GATT_BEARER
gatt_bearer_register_for_mesh_network_pdu(&mesh_proxy_packet_handler_network_pdu);
#endif
}
void mesh_network_set_higher_layer_handler(void (*packet_handler)(mesh_network_callback_type_t callback_type, mesh_network_pdu_t * network_pdu)){

View File

@ -269,8 +269,6 @@ void mesh_network_encrypt_proxy_message(mesh_network_pdu_t * network_pdu, void (
void mesh_network_dump(void);
void mesh_network_reset(void);
void mesh_gatt_handle_event(uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size);
#if defined __cplusplus
}
#endif

View File

@ -833,39 +833,6 @@ static void mesh_proxy_packet_handler_beacon(uint8_t packet_type, uint16_t chann
}
}
static void mesh_proxy_packet_handler_network_pdu(uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size){
switch (packet_type){
case MESH_PROXY_DATA_PACKET:
printf("mesh: Received network PDU (proxy)\n");
printf_hexdump(packet, size);
mesh_network_received_message(packet, size);
break;
case HCI_EVENT_PACKET:
switch (hci_event_packet_get_type(packet)){
case HCI_EVENT_MESH_META:
switch (hci_event_mesh_meta_get_subevent_code(packet)){
case MESH_SUBEVENT_CAN_SEND_NOW:
mesh_gatt_handle_event(packet_type, channel, packet, size);
break;
case MESH_SUBEVENT_MESSAGE_SENT:
mesh_gatt_handle_event(packet_type, channel, packet, size);
break;
case MESH_SUBEVENT_PROXY_CONNECTED:
printf("mesh: MESH_PROXY_CONNECTED\n");
break;
default:
break;
}
break;
default:
break;
}
break;
default:
break;
}
}
static mesh_network_pdu_t * encrypted_proxy_configuration_ready_to_send;
static void request_can_send_now_proxy_configuration_callback_handler(mesh_network_pdu_t * network_pdu){
@ -1017,8 +984,6 @@ int btstack_main(void)
// Setup GATT bearer
gatt_bearer_init();
gatt_bearer_register_for_mesh_network_pdu(&mesh_proxy_packet_handler_network_pdu);
gatt_bearer_register_for_mesh_beacon(&mesh_proxy_packet_handler_network_pdu);
gatt_bearer_register_for_mesh_proxy_configuration(&packet_handler_for_mesh_proxy_configuration);
mesh_network_set_proxy_message_handler(proxy_configuration_message_handler);

View File

@ -57,9 +57,9 @@ void adv_bearer_emit_sent(void){
#endif
#ifdef ENABLE_MESH_GATT_BEARER
// static btstack_packet_handler_t gatt_packet_handler;
void adv_bearer_register_for_mesh_message(btstack_packet_handler_t packet_handler){
// gatt_packet_handler = packet_handler;
static btstack_packet_handler_t gatt_packet_handler;
void gatt_bearer_register_for_mesh_network_pdu(btstack_packet_handler_t packet_handler){
gatt_packet_handler = packet_handler;
}
void gatt_bearer_request_can_send_now_for_mesh_network_pdu(void){
printf("gatt_bearer_request_can_send_now_for_mesh_network_pdu\n");
@ -68,7 +68,7 @@ void gatt_bearer_request_can_send_now_for_mesh_network_pdu(void){
event[0] = HCI_EVENT_MESH_META;
event[1] = 1;
event[2] = MESH_SUBEVENT_CAN_SEND_NOW;
mesh_gatt_handle_event(HCI_EVENT_PACKET, 0, &event[0], sizeof(event));
(*gatt_packet_handler)(HCI_EVENT_PACKET, 0, &event[0], sizeof(event));
}
void gatt_bearer_send_mesh_network_pdu(const uint8_t * network_pdu, uint16_t size){
printf("gatt_bearer_send_mesh_network_pdu: \n");
@ -81,7 +81,7 @@ void gatt_bearer_emit_sent(void){
event[0] = HCI_EVENT_MESH_META;
event[1] = 1;
event[2] = MESH_SUBEVENT_MESSAGE_SENT;
mesh_gatt_handle_event(HCI_EVENT_PACKET, 0, &event[0], sizeof(event));
(*gatt_packet_handler)(HCI_EVENT_PACKET, 0, &event[0], sizeof(event));
}
#endif