mirror of
https://github.com/bluekitchen/btstack.git
synced 2025-03-29 04:20:20 +00:00
hci: replace hci_register_packet_handler with hci_add_event_handler
This commit is contained in:
parent
1ef6bb52dc
commit
fb37a842ea
@ -52,12 +52,11 @@
|
|||||||
#include "btstack_memory.h"
|
#include "btstack_memory.h"
|
||||||
#include "hci_dump.h"
|
#include "hci_dump.h"
|
||||||
|
|
||||||
// static bd_addr_t remote = {0x04,0x0C,0xCE,0xE4,0x85,0xD3};
|
|
||||||
static bd_addr_t remote = {0x84, 0x38, 0x35, 0x65, 0xD1, 0x15};
|
static bd_addr_t remote = {0x84, 0x38, 0x35, 0x65, 0xD1, 0x15};
|
||||||
|
|
||||||
static void packet_handler (uint8_t packet_type, uint8_t *packet, uint16_t size){
|
static btstack_packet_callback_registration_t hci_event_callback_registration;
|
||||||
printf("packet_handler type %u, packet[0] %x\n", packet_type, packet[0]);
|
|
||||||
|
|
||||||
|
static void packet_handler(uint8_t packet_type, uint8_t *packet, uint16_t size){
|
||||||
if (packet_type != HCI_EVENT_PACKET) return;
|
if (packet_type != HCI_EVENT_PACKET) return;
|
||||||
|
|
||||||
switch (packet[0]) {
|
switch (packet[0]) {
|
||||||
@ -77,7 +76,9 @@ static void packet_handler (uint8_t packet_type, uint8_t *packet, uint16_t size)
|
|||||||
int btstack_main(int argc, const char * argv[]);
|
int btstack_main(int argc, const char * argv[]);
|
||||||
int btstack_main(int argc, const char * argv[]){
|
int btstack_main(int argc, const char * argv[]){
|
||||||
|
|
||||||
hci_register_packet_handler(packet_handler);
|
hci_event_callback_registration.callback = &packet_handler;
|
||||||
|
hci_add_event_handler(&hci_event_callback_registration);
|
||||||
|
|
||||||
// turn on!
|
// turn on!
|
||||||
hci_power_control(HCI_POWER_ON);
|
hci_power_control(HCI_POWER_ON);
|
||||||
|
|
||||||
|
@ -83,6 +83,7 @@ int deviceCount = 0;
|
|||||||
enum STATE {INIT, ACTIVE} ;
|
enum STATE {INIT, ACTIVE} ;
|
||||||
enum STATE state = INIT;
|
enum STATE state = INIT;
|
||||||
|
|
||||||
|
static btstack_packet_callback_registration_t hci_event_callback_registration;
|
||||||
|
|
||||||
static int getDeviceIndexForAddress( bd_addr_t addr){
|
static int getDeviceIndexForAddress( bd_addr_t addr){
|
||||||
int j;
|
int j;
|
||||||
@ -136,7 +137,7 @@ static void continue_remote_names(void){
|
|||||||
* INIT, and ACTIVE.
|
* INIT, and ACTIVE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static void packet_handler (uint8_t packet_type, uint8_t *packet, uint16_t size){
|
static void packet_handler(uint8_t packet_type, uint8_t *packet, uint16_t size){
|
||||||
bd_addr_t addr;
|
bd_addr_t addr;
|
||||||
int i;
|
int i;
|
||||||
int numResponses;
|
int numResponses;
|
||||||
@ -245,7 +246,9 @@ static void packet_handler (uint8_t packet_type, uint8_t *packet, uint16_t size)
|
|||||||
/* LISTING_START(MainConfiguration): Setup packet handler for GAP inquiry */
|
/* LISTING_START(MainConfiguration): Setup packet handler for GAP inquiry */
|
||||||
int btstack_main(int argc, const char * argv[]);
|
int btstack_main(int argc, const char * argv[]);
|
||||||
int btstack_main(int argc, const char * argv[]) {
|
int btstack_main(int argc, const char * argv[]) {
|
||||||
hci_register_packet_handler(packet_handler);
|
|
||||||
|
hci_event_callback_registration.callback = &packet_handler;
|
||||||
|
hci_add_event_handler(&hci_event_callback_registration);
|
||||||
|
|
||||||
// turn on!
|
// turn on!
|
||||||
hci_power_control(HCI_POWER_ON);
|
hci_power_control(HCI_POWER_ON);
|
||||||
|
@ -78,6 +78,7 @@ int deviceCount = 0;
|
|||||||
enum STATE {INIT, W4_INQUIRY_MODE_COMPLETE, ACTIVE} ;
|
enum STATE {INIT, W4_INQUIRY_MODE_COMPLETE, ACTIVE} ;
|
||||||
enum STATE state = INIT;
|
enum STATE state = INIT;
|
||||||
|
|
||||||
|
static btstack_packet_callback_registration_t hci_event_callback_registration;
|
||||||
|
|
||||||
static int getDeviceIndexForAddress( bd_addr_t addr){
|
static int getDeviceIndexForAddress( bd_addr_t addr){
|
||||||
int j;
|
int j;
|
||||||
@ -221,7 +222,8 @@ static void packet_handler (uint8_t packet_type, uint8_t *packet, uint16_t size)
|
|||||||
int btstack_main(int argc, const char * argv[]);
|
int btstack_main(int argc, const char * argv[]);
|
||||||
int btstack_main(int argc, const char * argv[]) {
|
int btstack_main(int argc, const char * argv[]) {
|
||||||
|
|
||||||
hci_register_packet_handler(packet_handler);
|
hci_event_callback_registration.callback = &packet_handler;
|
||||||
|
hci_add_event_handler(&hci_event_callback_registration);
|
||||||
|
|
||||||
// turn on!
|
// turn on!
|
||||||
hci_power_control(HCI_POWER_ON);
|
hci_power_control(HCI_POWER_ON);
|
||||||
|
@ -56,6 +56,8 @@
|
|||||||
#include "hci.h"
|
#include "hci.h"
|
||||||
#include "ble/ad_parser.h"
|
#include "ble/ad_parser.h"
|
||||||
|
|
||||||
|
static btstack_packet_callback_registration_t hci_event_callback_registration;
|
||||||
|
|
||||||
/* @section GAP LE setup for receiving advertisements
|
/* @section GAP LE setup for receiving advertisements
|
||||||
*
|
*
|
||||||
* @text GAP LE advertisements are received as custom HCI events of the
|
* @text GAP LE advertisements are received as custom HCI events of the
|
||||||
@ -64,10 +66,11 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
/* LISTING_START(GAPLEAdvSetup): Setting up GAP LE client for receiving advertisements */
|
/* LISTING_START(GAPLEAdvSetup): Setting up GAP LE client for receiving advertisements */
|
||||||
static void handle_hci_event(uint8_t packet_type, uint8_t *packet, uint16_t size);
|
static void packet_handler(uint8_t packet_type, uint8_t *packet, uint16_t size);
|
||||||
|
|
||||||
static void gap_le_advertisements_setup(void){
|
static void gap_le_advertisements_setup(void){
|
||||||
hci_register_packet_handler(handle_hci_event);
|
hci_event_callback_registration.callback = &packet_handler;
|
||||||
|
hci_add_event_handler(&hci_event_callback_registration);
|
||||||
}
|
}
|
||||||
/* LISTING_END */
|
/* LISTING_END */
|
||||||
|
|
||||||
@ -224,7 +227,7 @@ static void dump_advertisement_data(uint8_t * adv_data, uint8_t adv_size){
|
|||||||
|
|
||||||
/* LISTING_START(GAPLEAdvPacketHandler): Scanning and receiving advertisements */
|
/* LISTING_START(GAPLEAdvPacketHandler): Scanning and receiving advertisements */
|
||||||
|
|
||||||
static void handle_hci_event(uint8_t packet_type, uint8_t *packet, uint16_t size){
|
static void packet_handler(uint8_t packet_type, uint8_t *packet, uint16_t size){
|
||||||
if (packet_type != HCI_EVENT_PACKET) return;
|
if (packet_type != HCI_EVENT_PACKET) return;
|
||||||
|
|
||||||
switch (packet[0]) {
|
switch (packet[0]) {
|
||||||
|
19
src/hci.c
19
src/hci.c
@ -284,12 +284,6 @@ static int nr_hci_connections(void){
|
|||||||
return count;
|
return count;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Dummy handler called by HCI
|
|
||||||
*/
|
|
||||||
static void dummy_handler(uint8_t packet_type, uint8_t *packet, uint16_t size){
|
|
||||||
}
|
|
||||||
|
|
||||||
uint8_t hci_number_outgoing_packets(hci_con_handle_t handle){
|
uint8_t hci_number_outgoing_packets(hci_con_handle_t handle){
|
||||||
hci_connection_t * connection = hci_connection_for_handle(handle);
|
hci_connection_t * connection = hci_connection_for_handle(handle);
|
||||||
if (!connection) {
|
if (!connection) {
|
||||||
@ -1814,8 +1808,8 @@ void hci_add_event_handler(btstack_packet_callback_registration_t * callback_han
|
|||||||
|
|
||||||
|
|
||||||
/** Register HCI packet handlers */
|
/** Register HCI packet handlers */
|
||||||
void hci_register_packet_handler(void (*handler)(uint8_t packet_type, uint8_t *packet, uint16_t size)){
|
void hci_register_acl_packet_handler(void (*handler)(uint8_t packet_type, uint8_t *packet, uint16_t size)){
|
||||||
hci_stack->packet_handler = handler;
|
hci_stack->acl_packet_handler = handler;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -1877,9 +1871,6 @@ void hci_init(const hci_transport_t *transport, void *config, btstack_link_key_d
|
|||||||
// init used hardware control with NULL
|
// init used hardware control with NULL
|
||||||
// init used chipset with NULL
|
// init used chipset with NULL
|
||||||
|
|
||||||
// higher level handler
|
|
||||||
hci_stack->packet_handler = dummy_handler;
|
|
||||||
|
|
||||||
// store and open remote device db
|
// store and open remote device db
|
||||||
hci_stack->link_key_db = link_key_db;
|
hci_stack->link_key_db = link_key_db;
|
||||||
if (hci_stack->link_key_db) {
|
if (hci_stack->link_key_db) {
|
||||||
@ -2879,11 +2870,12 @@ int hci_send_cmd(const hci_cmd_t *cmd, ...){
|
|||||||
// TODO: generalize, use table similar to hci_create_command
|
// TODO: generalize, use table similar to hci_create_command
|
||||||
|
|
||||||
static void hci_emit_event(uint8_t * event, uint16_t size, int dump){
|
static void hci_emit_event(uint8_t * event, uint16_t size, int dump){
|
||||||
|
// dump packet
|
||||||
if (dump) {
|
if (dump) {
|
||||||
hci_dump_packet( HCI_EVENT_PACKET, 0, event, sizeof(event));
|
hci_dump_packet( HCI_EVENT_PACKET, 0, event, sizeof(event));
|
||||||
}
|
}
|
||||||
hci_stack->packet_handler(HCI_EVENT_PACKET, event, sizeof(event));
|
|
||||||
|
|
||||||
|
// dispatch to all event handlers
|
||||||
btstack_linked_list_iterator_t it;
|
btstack_linked_list_iterator_t it;
|
||||||
btstack_linked_list_iterator_init(&it, &hci_stack->event_handlers);
|
btstack_linked_list_iterator_init(&it, &hci_stack->event_handlers);
|
||||||
while (btstack_linked_list_iterator_has_next(&it)){
|
while (btstack_linked_list_iterator_has_next(&it)){
|
||||||
@ -2893,7 +2885,8 @@ static void hci_emit_event(uint8_t * event, uint16_t size, int dump){
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void hci_emit_acl_packet(uint8_t * packet, uint16_t size){
|
static void hci_emit_acl_packet(uint8_t * packet, uint16_t size){
|
||||||
hci_stack->packet_handler(HCI_ACL_DATA_PACKET, packet, size);
|
if (!hci_stack->acl_packet_handler) return;
|
||||||
|
hci_stack->acl_packet_handler(HCI_ACL_DATA_PACKET, packet, size);
|
||||||
}
|
}
|
||||||
|
|
||||||
void hci_emit_state(void){
|
void hci_emit_state(void){
|
||||||
|
@ -573,7 +573,7 @@ typedef struct {
|
|||||||
uint16_t packet_types;
|
uint16_t packet_types;
|
||||||
|
|
||||||
/* callback to L2CAP layer */
|
/* callback to L2CAP layer */
|
||||||
void (*packet_handler)(uint8_t packet_type, uint8_t *packet, uint16_t size);
|
void (*acl_packet_handler)(uint8_t packet_type, uint8_t *packet, uint16_t size);
|
||||||
|
|
||||||
/* callback for SCO data */
|
/* callback for SCO data */
|
||||||
void (*sco_packet_handler)(uint8_t packet_type, uint8_t *packet, uint16_t size);
|
void (*sco_packet_handler)(uint8_t packet_type, uint8_t *packet, uint16_t size);
|
||||||
@ -791,9 +791,9 @@ void hci_set_bd_addr(bd_addr_t addr);
|
|||||||
void hci_add_event_handler(btstack_packet_callback_registration_t * callback_handler);
|
void hci_add_event_handler(btstack_packet_callback_registration_t * callback_handler);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Registers a packet handler. Used if L2CAP is not used (rarely).
|
* @brief Registers a packet handler for ACL data. Used by L2CAP
|
||||||
*/
|
*/
|
||||||
void hci_register_packet_handler(void (*handler)(uint8_t packet_type, uint8_t *packet, uint16_t size));
|
void hci_register_acl_packet_handler(void (*handler)(uint8_t packet_type, uint8_t *packet, uint16_t size));
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Registers a packet handler for SCO data. Used for HSP and HFP profiles.
|
* @brief Registers a packet handler for SCO data. Used for HSP and HFP profiles.
|
||||||
|
@ -73,6 +73,8 @@ static void l2cap_packet_handler(uint8_t packet_type, uint8_t *packet, uint16_t
|
|||||||
static l2cap_signaling_response_t signaling_responses[NR_PENDING_SIGNALING_RESPONSES];
|
static l2cap_signaling_response_t signaling_responses[NR_PENDING_SIGNALING_RESPONSES];
|
||||||
static int signaling_responses_pending;
|
static int signaling_responses_pending;
|
||||||
|
|
||||||
|
static btstack_packet_callback_registration_t hci_event_callback_registration;
|
||||||
|
|
||||||
static btstack_linked_list_t l2cap_channels;
|
static btstack_linked_list_t l2cap_channels;
|
||||||
static btstack_linked_list_t l2cap_services;
|
static btstack_linked_list_t l2cap_services;
|
||||||
static btstack_linked_list_t l2cap_le_channels;
|
static btstack_linked_list_t l2cap_le_channels;
|
||||||
@ -111,7 +113,11 @@ void l2cap_init(void){
|
|||||||
//
|
//
|
||||||
// register callback with HCI
|
// register callback with HCI
|
||||||
//
|
//
|
||||||
hci_register_packet_handler(&l2cap_packet_handler);
|
hci_event_callback_registration.callback = &l2cap_packet_handler;
|
||||||
|
hci_add_event_handler(&hci_event_callback_registration);
|
||||||
|
|
||||||
|
hci_register_acl_packet_handler(&l2cap_packet_handler);
|
||||||
|
|
||||||
hci_connectable_control(0); // no services yet
|
hci_connectable_control(0); // no services yet
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user