mirror of
https://github.com/bluekitchen/btstack.git
synced 2025-02-05 00:40:19 +00:00
mesh: support separate packet handlers for provisioner and device roles
This commit is contained in:
parent
18d0ae0600
commit
94d617e4bd
@ -97,7 +97,7 @@ static uint8_t pb_adv_provisioner_open_countdown;
|
||||
|
||||
static uint8_t pb_adv_msg_in_buffer[MESH_PB_ADV_MAX_PDU_SIZE]; // TODO: how large are prov messages?
|
||||
|
||||
// single adv link
|
||||
// single adv link, roles: provisioner = 1, device = 0
|
||||
static uint16_t pb_adv_cid = 1;
|
||||
static uint8_t pb_adv_provisioner_role;
|
||||
|
||||
@ -137,7 +137,8 @@ static uint8_t pb_adv_msg_out_seg;
|
||||
static uint32_t pb_adv_msg_out_start;
|
||||
static const uint8_t * pb_adv_msg_out_buffer;
|
||||
|
||||
static btstack_packet_handler_t pb_adv_packet_handler;
|
||||
static btstack_packet_handler_t pb_adv_device_packet_handler;
|
||||
static btstack_packet_handler_t pb_adv_provisioner_packet_handler;
|
||||
|
||||
// poor man's random number generator
|
||||
static uint32_t pb_adv_random(void){
|
||||
@ -145,6 +146,14 @@ static uint32_t pb_adv_random(void){
|
||||
return pb_adv_lfsr;
|
||||
}
|
||||
|
||||
static void pb_adv_packet_handler(uint8_t packet_type, uint16_t channel, uint8_t * packet, uint16_t size){
|
||||
if (pb_adv_provisioner_role == 0){
|
||||
(*pb_adv_device_packet_handler)(packet_type, channel, packet, size);
|
||||
} else {
|
||||
(*pb_adv_provisioner_packet_handler)(packet_type, channel, packet, size);
|
||||
}
|
||||
}
|
||||
|
||||
static void pb_adv_emit_pdu_sent(uint8_t status){
|
||||
uint8_t event[] = { HCI_EVENT_MESH_META, 2, MESH_SUBEVENT_PB_TRANSPORT_PDU_SENT, status};
|
||||
pb_adv_packet_handler(HCI_EVENT_PACKET, 0, event, sizeof(event));
|
||||
@ -614,8 +623,12 @@ void pb_adv_init(void){
|
||||
pb_adv_random();
|
||||
}
|
||||
|
||||
void pb_adv_register_packet_handler(btstack_packet_handler_t packet_handler){
|
||||
pb_adv_packet_handler = packet_handler;
|
||||
void pb_adv_register_device_packet_handler(btstack_packet_handler_t packet_handler){
|
||||
pb_adv_device_packet_handler = packet_handler;
|
||||
}
|
||||
|
||||
void pb_adv_register_provisioner_packet_handler(btstack_packet_handler_t packet_handler){
|
||||
pb_adv_provisioner_packet_handler = packet_handler;
|
||||
}
|
||||
|
||||
void pb_adv_send_pdu(uint16_t pb_transport_cid, const uint8_t * pdu, uint16_t size){
|
||||
|
@ -54,11 +54,16 @@ extern "C" {
|
||||
void pb_adv_init(void);
|
||||
|
||||
/**
|
||||
* Register listener for Provisioning PDUs and MESH_PBV_ADV_SEND_COMPLETE
|
||||
* Register provisioning device listener for Provisioning PDUs and MESH_PBV_ADV_SEND_COMPLETE
|
||||
*/
|
||||
void pb_adv_register_packet_handler(btstack_packet_handler_t packet_handler);
|
||||
void pb_adv_register_device_packet_handler(btstack_packet_handler_t packet_handler);
|
||||
|
||||
/**
|
||||
/**
|
||||
* Register provisioning provisioner listener for Provisioning PDUs and MESH_PBV_ADV_SEND_COMPLETE
|
||||
*/
|
||||
void pb_adv_register_provisioner_packet_handler(btstack_packet_handler_t packet_handler);
|
||||
|
||||
/**
|
||||
* Send Provisioning PDU
|
||||
* @param pb_adv_cid
|
||||
* @param pdu
|
||||
|
@ -843,7 +843,7 @@ void provisioning_device_init(void){
|
||||
#ifdef ENABLE_MESH_ADV_BEARER
|
||||
// setup PB ADV
|
||||
pb_adv_init();
|
||||
pb_adv_register_packet_handler(&provisioning_handle_pdu);
|
||||
pb_adv_register_device_packet_handler(&provisioning_handle_pdu);
|
||||
#endif
|
||||
#ifdef ENABLE_MESH_GATT_BEARER
|
||||
// setup PB GATT
|
||||
|
@ -734,7 +734,7 @@ static void prov_key_generated(void * arg){
|
||||
void provisioning_provisioner_init(void){
|
||||
pb_adv_cid = MESH_PB_TRANSPORT_INVALID_CID;
|
||||
pb_adv_init();
|
||||
pb_adv_register_packet_handler(&provisioning_handle_pdu);
|
||||
pb_adv_register_provisioner_packet_handler(&provisioning_handle_pdu);
|
||||
}
|
||||
|
||||
void provisioning_provisioner_register_packet_handler(btstack_packet_handler_t packet_handler){
|
||||
|
Loading…
x
Reference in New Issue
Block a user