mesh: let network handle proxy configuration messages from gatt bearer

This commit is contained in:
Matthias Ringwald 2019-06-28 14:35:12 +02:00
parent d00dae02bc
commit f276878605
4 changed files with 40 additions and 32 deletions

View File

@ -785,13 +785,42 @@ static void mesh_network_gatt_bearer_handle_network_event(uint8_t packet_type, u
}
#endif
#ifdef ENABLE_MESH_GATT_BEARER
static void mesh_netework_gatt_bearer_handle_proxy_configuration(uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size){
switch (packet_type){
case MESH_PROXY_DATA_PACKET:
mesh_network_process_proxy_configuration_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:
// forward to higher layer
(*mesh_network_proxy_message_handler)(MESH_NETWORK_CAN_SEND_NOW, NULL);
break;
default:
break;
}
break;
default:
break;
}
break;
default:
break;
}
}
#endif
void mesh_network_init(void){
#ifdef ENABLE_MESH_ADV_BEARER
adv_bearer_register_for_network_pdu(&mesh_adv_bearer_handle_network_event);
#endif
#ifdef ENABLE_MESH_GATT_BEARER
gatt_bearer_register_for_network_pdu(&mesh_network_gatt_bearer_handle_network_event);
gatt_bearer_con_handle = HCI_CON_HANDLE_INVALID;
gatt_bearer_register_for_network_pdu(&mesh_network_gatt_bearer_handle_network_event);
gatt_bearer_register_for_mesh_proxy_configuration(&mesh_netework_gatt_bearer_handle_proxy_configuration);
#endif
}

View File

@ -60,6 +60,7 @@ extern "C" {
typedef enum {
MESH_NETWORK_PDU_RECEIVED,
MESH_NETWORK_PDU_SENT,
MESH_NETWORK_CAN_SEND_NOW,
} mesh_network_callback_type_t;
typedef enum {

View File

@ -848,36 +848,6 @@ static void request_can_send_now_proxy_configuration_callback_handler(mesh_netwo
gatt_bearer_request_can_send_now_for_mesh_proxy_configuration();
}
static void packet_handler_for_mesh_proxy_configuration(uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size){
printf("packet_handler_for_mesh_proxy_configuration\n");
switch (packet_type){
case MESH_PROXY_DATA_PACKET:
printf("Received proxy configuration\n");
printf_hexdump(packet, size);
mesh_network_process_proxy_configuration_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:
printf("MESH_SUBEVENT_CAN_SEND_NOW packet_handler_for_mesh_proxy_configuration len %d\n", encrypted_proxy_configuration_ready_to_send->len);
printf_hexdump(encrypted_proxy_configuration_ready_to_send->data, encrypted_proxy_configuration_ready_to_send->len);
gatt_bearer_send_mesh_proxy_configuration(encrypted_proxy_configuration_ready_to_send->data, encrypted_proxy_configuration_ready_to_send->len);
break;
default:
break;
}
break;
default:
break;
}
break;
default:
break;
}
}
static void proxy_configuration_message_handler(mesh_network_callback_type_t callback_type, mesh_network_pdu_t * received_network_pdu){
mesh_proxy_configuration_message_opcode_t opcode;
uint8_t data[4];
@ -928,6 +898,11 @@ static void proxy_configuration_message_handler(mesh_network_callback_type_t cal
break;
}
break;
case MESH_NETWORK_CAN_SEND_NOW:
printf("MESH_SUBEVENT_CAN_SEND_NOW mesh_netework_gatt_bearer_handle_proxy_configuration len %d\n", encrypted_proxy_configuration_ready_to_send->len);
printf_hexdump(encrypted_proxy_configuration_ready_to_send->data, encrypted_proxy_configuration_ready_to_send->len);
gatt_bearer_send_mesh_proxy_configuration(encrypted_proxy_configuration_ready_to_send->data, encrypted_proxy_configuration_ready_to_send->len);
break;
case MESH_NETWORK_PDU_SENT:
// printf("test MESH_PROXY_PDU_SENT\n");
// mesh_lower_transport_received_mesage(MESH_NETWORK_PDU_SENT, network_pdu);
@ -976,12 +951,13 @@ int btstack_main(void)
// Setup GATT bearer
gatt_bearer_init();
gatt_bearer_register_for_mesh_proxy_configuration(&packet_handler_for_mesh_proxy_configuration);
// mesh proxy configuration
mesh_network_set_proxy_message_handler(proxy_configuration_message_handler);
#ifdef ENABLE_MESH_ADV_BEARER
// Setup Unprovisioned Device Beacon
beacon_init();
// Register for Unprovisioned Device Beacons provisioner
beacon_register_for_unprovisioned_device_beacons(&mesh_unprovisioned_beacon_handler);
#endif

View File

@ -60,6 +60,8 @@ static btstack_packet_handler_t gatt_packet_handler;
void gatt_bearer_register_for_network_pdu(btstack_packet_handler_t packet_handler){
gatt_packet_handler = packet_handler;
}
void gatt_bearer_register_for_mesh_proxy_configuration(btstack_packet_handler_t packet_handler){
}
void gatt_bearer_request_can_send_now_for_network_pdu(void){
// simulate can send now
uint8_t event[3];