diff --git a/src/classic/hfp.c b/src/classic/hfp.c index 6cda9a808..52318e052 100644 --- a/src/classic/hfp.c +++ b/src/classic/hfp.c @@ -409,10 +409,6 @@ void hfp_create_sdp_record(uint8_t * service, uint32_t service_record_handle, ui static hfp_connection_t * connection_doing_sdp_query = NULL; -static void handle_hci_event(uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size){ - hfp_handle_hci_event(packet_type, packet, size); -} - static void handle_query_rfcomm_event(uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size){ hfp_connection_t * hfp_connection = connection_doing_sdp_query; @@ -431,7 +427,7 @@ static void handle_query_rfcomm_event(uint8_t packet_type, uint16_t channel, uin if (hfp_connection->rfcomm_channel_nr > 0){ 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); - rfcomm_create_channel(handle_hci_event, hfp_connection->remote_addr, hfp_connection->rfcomm_channel_nr, NULL); + rfcomm_create_channel(&hfp_handle_hci_event, hfp_connection->remote_addr, hfp_connection->rfcomm_channel_nr, NULL); break; } log_info("rfcomm service not found, status %u.", sdp_event_query_complete_get_status(packet)); @@ -441,7 +437,7 @@ static void handle_query_rfcomm_event(uint8_t packet_type, uint16_t channel, uin } } -void hfp_handle_hci_event(uint8_t packet_type, uint8_t *packet, uint16_t size){ +void hfp_handle_hci_event(uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size){ bd_addr_t event_addr; uint16_t rfcomm_cid, handle; hfp_connection_t * hfp_connection = NULL; diff --git a/src/classic/hfp.h b/src/classic/hfp.h index 6d9b90501..754d60477 100644 --- a/src/classic/hfp.h +++ b/src/classic/hfp.h @@ -624,7 +624,7 @@ int store_bit(uint32_t bitmap, int position, uint8_t value); void hfp_set_callback(hfp_callback_t callback); 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, uint8_t *packet, uint16_t size); +void hfp_handle_hci_event(uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size); void hfp_emit_event(hfp_callback_t callback, uint8_t event_subtype, uint8_t value); void hfp_emit_simple_event(hfp_callback_t callback, uint8_t event_subtype); void hfp_emit_string_event(hfp_callback_t callback, uint8_t event_subtype, const char * value); diff --git a/src/classic/hfp_ag.c b/src/classic/hfp_ag.c index 880d1ea61..cc044689b 100644 --- a/src/classic/hfp_ag.c +++ b/src/classic/hfp_ag.c @@ -56,6 +56,7 @@ #include "hci_dump.h" #include "l2cap.h" #include "btstack_debug.h" +#include "btstack_event.h" #include "classic/core.h" #include "classic/hfp.h" #include "classic/hfp_ag.h" @@ -1610,8 +1611,11 @@ static void hfp_ag_send_call_status(hfp_connection_t * hfp_connection, int call_ static void hfp_run_for_context(hfp_connection_t *hfp_connection){ if (!hfp_connection) return; - if (!rfcomm_can_send_packet_now(hfp_connection->rfcomm_cid)) return; - + if (!rfcomm_can_send_packet_now(hfp_connection->rfcomm_cid)) { + rfcomm_request_can_send_now_event(hfp_connection->rfcomm_cid); + return; + } + if (hfp_connection->send_status_of_current_calls){ hfp_connection->ok_pending = 0; if (hfp_connection->next_call_index < hfp_gsm_get_number_of_calls()){ @@ -1978,7 +1982,12 @@ static void packet_handler(uint8_t packet_type, uint16_t channel, uint8_t *packe hfp_handle_rfcomm_data(packet_type, channel, packet, size); break; case HCI_EVENT_PACKET: - hfp_handle_hci_event(packet_type, packet, size); + if (packet[0] == RFCOMM_EVENT_CAN_SEND_NOW){ + uint16_t rfcomm_cid = rfcomm_event_can_send_now_get_rfcomm_cid(packet); + hfp_run_for_context(get_hfp_connection_context_for_rfcomm_cid(rfcomm_cid)); + return; + } + hfp_handle_hci_event(packet_type, channel, packet, size); break; default: break; diff --git a/src/classic/hfp_hf.c b/src/classic/hfp_hf.c index 6991c96e9..c584c5f41 100644 --- a/src/classic/hfp_hf.c +++ b/src/classic/hfp_hf.c @@ -1070,7 +1070,7 @@ static void packet_handler(uint8_t packet_type, uint16_t channel, uint8_t *packe hfp_handle_rfcomm_event(packet_type, channel, packet, size); break; case HCI_EVENT_PACKET: - hfp_handle_hci_event(packet_type, packet, size); + hfp_handle_hci_event(packet_type, channel, packet, size); default: break; } diff --git a/test/hfp/mock.c b/test/hfp/mock.c index d925136c1..e37f1220e 100644 --- a/test/hfp/mock.c +++ b/test/hfp/mock.c @@ -154,6 +154,10 @@ int rfcomm_send(uint16_t rfcomm_cid, uint8_t *data, uint16_t len){ return 0; } +void rfcomm_request_can_send_now_event(uint16_t rfcomm_cid){ + // TODO: emit event +} + int rfcomm_reserve_packet_buffer(void){ return 1; };