mirror of
https://github.com/bluekitchen/btstack.git
synced 2025-04-16 08:42:28 +00:00
hfp: register for hci events in hfp.c instead of hfp_ag and hfp_hf
This commit is contained in:
parent
e9c22d4ea1
commit
520c92d527
@ -106,6 +106,8 @@ static btstack_packet_handler_t hfp_ag_callback;
|
|||||||
static btstack_packet_handler_t hfp_hf_rfcomm_packet_handler;
|
static btstack_packet_handler_t hfp_hf_rfcomm_packet_handler;
|
||||||
static btstack_packet_handler_t hfp_ag_rfcomm_packet_handler;
|
static btstack_packet_handler_t hfp_ag_rfcomm_packet_handler;
|
||||||
|
|
||||||
|
static btstack_packet_callback_registration_t hci_event_callback_registration;
|
||||||
|
|
||||||
static hfp_connection_t * sco_establishment_active;
|
static hfp_connection_t * sco_establishment_active;
|
||||||
|
|
||||||
void hfp_set_hf_callback(btstack_packet_handler_t callback){
|
void hfp_set_hf_callback(btstack_packet_handler_t callback){
|
||||||
@ -498,7 +500,18 @@ static void handle_query_rfcomm_event(uint8_t packet_type, uint16_t channel, uin
|
|||||||
if (hfp_connection->rfcomm_channel_nr > 0){
|
if (hfp_connection->rfcomm_channel_nr > 0){
|
||||||
hfp_connection->state = HFP_W4_RFCOMM_CONNECTED;
|
hfp_connection->state = HFP_W4_RFCOMM_CONNECTED;
|
||||||
log_info("HFP: SDP_EVENT_QUERY_COMPLETE context %p, addr %s, state %d", hfp_connection, bd_addr_to_str( hfp_connection->remote_addr), hfp_connection->state);
|
log_info("HFP: SDP_EVENT_QUERY_COMPLETE context %p, addr %s, state %d", hfp_connection, bd_addr_to_str( hfp_connection->remote_addr), hfp_connection->state);
|
||||||
btstack_packet_handler_t packet_handler = hfp_connection->local_role == HFP_ROLE_AG ? hfp_ag_rfcomm_packet_handler : hfp_hf_rfcomm_packet_handler;
|
btstack_packet_handler_t packet_handler;
|
||||||
|
switch (hfp_connection->local_role){
|
||||||
|
case HFP_ROLE_AG:
|
||||||
|
packet_handler = hfp_ag_rfcomm_packet_handler;
|
||||||
|
break;
|
||||||
|
case HFP_ROLE_HF:
|
||||||
|
packet_handler = hfp_hf_rfcomm_packet_handler;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
log_error("Role %x", hfp_connection->local_role);
|
||||||
|
return;
|
||||||
|
}
|
||||||
rfcomm_create_channel(packet_handler, hfp_connection->remote_addr, hfp_connection->rfcomm_channel_nr, NULL);
|
rfcomm_create_channel(packet_handler, hfp_connection->remote_addr, hfp_connection->rfcomm_channel_nr, NULL);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -583,6 +596,9 @@ void hfp_handle_hci_event(uint8_t packet_type, uint16_t channel, uint8_t *packet
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case RFCOMM_EVENT_INCOMING_CONNECTION:
|
case RFCOMM_EVENT_INCOMING_CONNECTION:
|
||||||
|
if (local_role > 1){
|
||||||
|
log_error("hfp_handle_hci_event role %x", local_role);
|
||||||
|
}
|
||||||
// data: event (8), len(8), address(48), channel (8), rfcomm_cid (16)
|
// data: event (8), len(8), address(48), channel (8), rfcomm_cid (16)
|
||||||
rfcomm_event_incoming_connection_get_bd_addr(packet, event_addr);
|
rfcomm_event_incoming_connection_get_bd_addr(packet, event_addr);
|
||||||
hfp_connection = provide_hfp_connection_context_for_bd_addr(event_addr, local_role);
|
hfp_connection = provide_hfp_connection_context_for_bd_addr(event_addr, local_role);
|
||||||
@ -707,6 +723,9 @@ void hfp_handle_hci_event(uint8_t packet_type, uint16_t channel, uint8_t *packet
|
|||||||
}
|
}
|
||||||
|
|
||||||
case RFCOMM_EVENT_CHANNEL_CLOSED:
|
case RFCOMM_EVENT_CHANNEL_CLOSED:
|
||||||
|
if (local_role > 1){
|
||||||
|
log_error("hfp_handle_hci_event role %x", local_role);
|
||||||
|
}
|
||||||
rfcomm_cid = little_endian_read_16(packet,2);
|
rfcomm_cid = little_endian_read_16(packet,2);
|
||||||
hfp_connection = get_hfp_connection_context_for_rfcomm_cid(rfcomm_cid);
|
hfp_connection = get_hfp_connection_context_for_rfcomm_cid(rfcomm_cid);
|
||||||
if (!hfp_connection) break;
|
if (!hfp_connection) break;
|
||||||
@ -1478,3 +1497,11 @@ void hfp_set_hf_rfcomm_packet_handler(btstack_packet_handler_t handler){
|
|||||||
hfp_hf_rfcomm_packet_handler = handler;
|
hfp_hf_rfcomm_packet_handler = handler;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void packet_handler(uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size){
|
||||||
|
hfp_handle_hci_event(packet_type, channel, packet, size, HFP_ROLE_INVALID);
|
||||||
|
}
|
||||||
|
|
||||||
|
void hfp_init(void){
|
||||||
|
hci_event_callback_registration.callback = &packet_handler;
|
||||||
|
hci_add_event_handler(&hci_event_callback_registration);
|
||||||
|
}
|
||||||
|
@ -155,7 +155,8 @@ extern "C" {
|
|||||||
#define HFP_CODEC_MSBC 0x02
|
#define HFP_CODEC_MSBC 0x02
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
HFP_ROLE_AG = 0,
|
HFP_ROLE_INVALID = 0,
|
||||||
|
HFP_ROLE_AG,
|
||||||
HFP_ROLE_HF,
|
HFP_ROLE_HF,
|
||||||
} hfp_role_t;
|
} hfp_role_t;
|
||||||
|
|
||||||
@ -647,6 +648,8 @@ void hfp_set_ag_rfcomm_packet_handler(btstack_packet_handler_t handler);
|
|||||||
void hfp_set_hf_callback(btstack_packet_handler_t callback);
|
void hfp_set_hf_callback(btstack_packet_handler_t callback);
|
||||||
void hfp_set_hf_rfcomm_packet_handler(btstack_packet_handler_t handler);
|
void hfp_set_hf_rfcomm_packet_handler(btstack_packet_handler_t handler);
|
||||||
|
|
||||||
|
void hfp_init(void);
|
||||||
|
|
||||||
void hfp_create_sdp_record(uint8_t * service, uint32_t service_record_handle, uint16_t service_uuid, int rfcomm_channel_nr, const char * name);
|
void hfp_create_sdp_record(uint8_t * service, uint32_t service_record_handle, uint16_t service_uuid, int rfcomm_channel_nr, const char * name);
|
||||||
void hfp_handle_hci_event(uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size, hfp_role_t local_role);
|
void hfp_handle_hci_event(uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size, hfp_role_t local_role);
|
||||||
void hfp_emit_event(hfp_connection_t * hfp_connection, uint8_t event_subtype, uint8_t value);
|
void hfp_emit_event(hfp_connection_t * hfp_connection, uint8_t event_subtype, uint8_t value);
|
||||||
|
@ -106,7 +106,6 @@ static int hfp_ag_response_and_hold_active = 0;
|
|||||||
static hfp_phone_number_t * subscriber_numbers = NULL;
|
static hfp_phone_number_t * subscriber_numbers = NULL;
|
||||||
static int subscriber_numbers_count = 0;
|
static int subscriber_numbers_count = 0;
|
||||||
|
|
||||||
static btstack_packet_callback_registration_t hci_event_callback_registration;
|
|
||||||
hfp_ag_indicator_t * hfp_ag_get_ag_indicators(hfp_connection_t * hfp_connection);
|
hfp_ag_indicator_t * hfp_ag_get_ag_indicators(hfp_connection_t * hfp_connection);
|
||||||
|
|
||||||
|
|
||||||
@ -2005,18 +2004,6 @@ static void hfp_run(void){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void hci_packet_handler(uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size){
|
|
||||||
switch (packet_type){
|
|
||||||
case HCI_EVENT_PACKET:
|
|
||||||
hfp_handle_hci_event(packet_type, channel, packet, size, HFP_ROLE_AG);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
hfp_run();
|
|
||||||
}
|
|
||||||
|
|
||||||
static void rfcomm_packet_handler(uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size){
|
static void rfcomm_packet_handler(uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size){
|
||||||
switch (packet_type){
|
switch (packet_type){
|
||||||
case RFCOMM_DATA_PACKET:
|
case RFCOMM_DATA_PACKET:
|
||||||
@ -2071,9 +2058,7 @@ void hfp_ag_init_call_hold_services(int call_hold_services_nr, const char * call
|
|||||||
|
|
||||||
|
|
||||||
void hfp_ag_init(uint16_t rfcomm_channel_nr){
|
void hfp_ag_init(uint16_t rfcomm_channel_nr){
|
||||||
// register for HCI events
|
hfp_init();
|
||||||
hci_event_callback_registration.callback = &hci_packet_handler;
|
|
||||||
hci_add_event_handler(&hci_event_callback_registration);
|
|
||||||
|
|
||||||
rfcomm_register_service(&rfcomm_packet_handler, rfcomm_channel_nr, 0xffff);
|
rfcomm_register_service(&rfcomm_packet_handler, rfcomm_channel_nr, 0xffff);
|
||||||
hfp_set_ag_rfcomm_packet_handler(&rfcomm_packet_handler);
|
hfp_set_ag_rfcomm_packet_handler(&rfcomm_packet_handler);
|
||||||
|
@ -85,8 +85,6 @@ static hfp_callheld_status_t hfp_callheld_status;
|
|||||||
|
|
||||||
static char phone_number[25];
|
static char phone_number[25];
|
||||||
|
|
||||||
static btstack_packet_callback_registration_t hci_event_callback_registration;
|
|
||||||
|
|
||||||
void hfp_hf_register_packet_handler(btstack_packet_handler_t callback){
|
void hfp_hf_register_packet_handler(btstack_packet_handler_t callback){
|
||||||
if (callback == NULL){
|
if (callback == NULL){
|
||||||
log_error("hfp_hf_register_packet_handler called with NULL callback");
|
log_error("hfp_hf_register_packet_handler called with NULL callback");
|
||||||
@ -1069,17 +1067,6 @@ static void hfp_run(void){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void hci_packet_handler(uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size){
|
|
||||||
switch (packet_type){
|
|
||||||
case HCI_EVENT_PACKET:
|
|
||||||
hfp_handle_hci_event(packet_type, channel, packet, size, HFP_ROLE_HF);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
hfp_run();
|
|
||||||
}
|
|
||||||
|
|
||||||
static void rfcomm_packet_handler(uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size){
|
static void rfcomm_packet_handler(uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size){
|
||||||
switch (packet_type){
|
switch (packet_type){
|
||||||
case RFCOMM_DATA_PACKET:
|
case RFCOMM_DATA_PACKET:
|
||||||
@ -1095,9 +1082,7 @@ static void rfcomm_packet_handler(uint8_t packet_type, uint16_t channel, uint8_t
|
|||||||
}
|
}
|
||||||
|
|
||||||
void hfp_hf_init(uint16_t rfcomm_channel_nr){
|
void hfp_hf_init(uint16_t rfcomm_channel_nr){
|
||||||
// register for HCI events
|
hfp_init();
|
||||||
hci_event_callback_registration.callback = &hci_packet_handler;
|
|
||||||
hci_add_event_handler(&hci_event_callback_registration);
|
|
||||||
|
|
||||||
rfcomm_register_service(rfcomm_packet_handler, rfcomm_channel_nr, 0xffff);
|
rfcomm_register_service(rfcomm_packet_handler, rfcomm_channel_nr, 0xffff);
|
||||||
hfp_set_hf_rfcomm_packet_handler(&rfcomm_packet_handler);
|
hfp_set_hf_rfcomm_packet_handler(&rfcomm_packet_handler);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user