mesh: use gatt/adv bearer only if enabled

This commit is contained in:
Matthias Ringwald 2019-09-06 21:46:57 +02:00
parent 47a0820c04
commit 5127fa8aeb
4 changed files with 43 additions and 2 deletions

View File

@ -62,6 +62,7 @@ static char gap_name_prefix[] = "Mesh ";
static btstack_packet_callback_registration_t hci_event_callback_registration;
#ifdef ENABLE_MESH_GATT_BEARER
static void packet_handler (uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size){
UNUSED(channel);
UNUSED(size);
@ -90,6 +91,7 @@ static uint16_t att_read_callback(hci_con_handle_t connection_handle, uint16_t a
}
return 0;
}
#endif
static void mesh_provisioning_message_handler (uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size){
UNUSED(packet_type);
@ -180,12 +182,15 @@ static void stdin_process(char cmd){
int btstack_main(void);
int btstack_main(void)
{
#ifdef HAVE_BTSTACK_STDIN
// console
btstack_stdin_setup(stdin_process);
#endif
// crypto
btstack_crypto_init();
#ifdef ENABLE_GATT_BEARER
// l2cap
l2cap_init();
@ -197,14 +202,18 @@ int btstack_main(void)
//
sm_init();
#endif
#ifdef ENABLE_MESH_GATT_BEARER
// register for HCI events
hci_event_callback_registration.callback = &packet_handler;
hci_add_event_handler(&hci_event_callback_registration);
#endif
// mesh
mesh_init();
#ifdef ENABLE_GATT_BEARER
// setup connectable advertisments
bd_addr_t null_addr;
memset(null_addr, 0, 6);
@ -212,6 +221,7 @@ int btstack_main(void)
uint16_t adv_int_min = 0x0030;
uint16_t adv_int_max = 0x0030;
adv_bearer_advertisements_set_params(adv_int_min, adv_int_max, adv_type, 0, null_addr, 0x07, 0x00);
#endif
// Track Provisioning as device role
mesh_register_provisioning_device_packet_handler(&mesh_provisioning_message_handler);

View File

@ -2168,7 +2168,10 @@ static void config_node_identity_get_handler(mesh_model_t *mesh_model, mesh_pdu_
uint16_t netkey_index = mesh_access_parser_get_u16(&parser);
mesh_node_identity_state_t node_identity_state = MESH_NODE_IDENTITY_STATE_ADVERTISING_NOT_SUPPORTED;
uint8_t status = mesh_proxy_get_advertising_with_node_id_status(netkey_index, &node_identity_state);
uint8_t status = MESH_FOUNDATION_STATUS_SUCCESS;
#ifdef ENABLE_MESH_PROXY_SERVER
status = mesh_proxy_get_advertising_with_node_id_status(netkey_index, &node_identity_state);
#endif
config_node_identity_status(mesh_model, mesh_pdu_netkey_index(pdu), mesh_pdu_src(pdu), status, netkey_index, node_identity_state);
mesh_access_message_processed(pdu);

View File

@ -1133,24 +1133,33 @@ void mesh_network_dump(void){
mesh_network_dump_network_pdu(outgoing_pdu);
printf("incoming_pdu_raw: \n");
mesh_network_dump_network_pdu(incoming_pdu_raw);
#ifdef ENABLE_MESH_GATT_BEARER
printf("gatt_bearer_network_pdu: \n");
mesh_network_dump_network_pdu(gatt_bearer_network_pdu);
#endif
#ifdef ENABLE_MESH_ADV_BEARER
printf("adv_bearer_network_pdu: \n");
mesh_network_dump_network_pdu(adv_bearer_network_pdu);
#endif
}
void mesh_network_reset(void){
mesh_network_reset_network_pdus(&network_pdus_received);
mesh_network_reset_network_pdus(&network_pdus_queued);
mesh_network_reset_network_pdus(&network_pdus_outgoing_gatt);
mesh_network_reset_network_pdus(&network_pdus_outgoing_adv);
#ifdef ENABLE_MESH_ADV_BEARER
if (adv_bearer_network_pdu){
mesh_network_pdu_free(adv_bearer_network_pdu);
adv_bearer_network_pdu = NULL;
}
#endif
#ifdef ENABLE_MESH_GATT_BEARER
if (gatt_bearer_network_pdu){
mesh_network_pdu_free(gatt_bearer_network_pdu);
gatt_bearer_network_pdu = NULL;
}
#endif
if (outgoing_pdu){
mesh_network_pdu_free(outgoing_pdu);
outgoing_pdu = NULL;

View File

@ -46,8 +46,12 @@
#include "btstack_memory.h"
#include "mesh/mesh_crypto.h"
#ifdef ENABLE_MESH_ADV_BEARER
#include "mesh/pb_adv.h"
#endif
#ifdef ENABLE_MESH_GATT_BEARER
#include "mesh/pb_gatt.h"
#endif
#include "mesh/provisioning.h"
static void prov_key_generated(void * arg);
@ -150,23 +154,34 @@ static pb_type_t pb_type;
static void pb_send_pdu(uint16_t transport_cid, const uint8_t * buffer, uint16_t buffer_size){
switch (pb_type){
#ifdef ENABLE_MESH_ADV_BEARER
case PB_TYPE_ADV:
pb_adv_send_pdu(transport_cid, buffer, buffer_size);
break;
#endif
#ifdef ENABLE_MESH_GATT_BEARER
case PB_TYPE_GATT:
pb_gatt_send_pdu(transport_cid, buffer, buffer_size);
break;
}
#endif
default:
break;
}
}
static void pb_close_link(uint16_t transport_cid, uint8_t reason){
switch (pb_type){
#ifdef ENABLE_MESH_ADV_BEARER
case PB_TYPE_ADV:
pb_adv_close_link(transport_cid, reason);
break;
#endif
#ifdef ENABLE_MESH_GATT_BEARER
case PB_TYPE_GATT:
pb_gatt_close_link(transport_cid, reason);
break;
#endif
default:
}
}
@ -819,12 +834,16 @@ static void prov_key_generated(void * arg){
}
void provisioning_device_init(void){
#ifdef ENABLE_MESH_ADV_BEARER
// setup PB ADV
pb_adv_init();
pb_adv_register_packet_handler(&provisioning_handle_pdu);
#endif
#ifdef ENABLE_MESH_GATT_BEARER
// setup PB GATT
pb_gatt_init();
pb_gatt_register_packet_handler(&provisioning_handle_pdu);
#endif
pb_transport_cid = MESH_PB_TRANSPORT_INVALID_CID;