From 892f58a83a213fab3f45eea69c0642f7ee3bc9b0 Mon Sep 17 00:00:00 2001 From: Matthias Ringwald Date: Fri, 26 May 2023 16:44:38 +0200 Subject: [PATCH] hfp_hf: emit event for custom at commands --- src/classic/hfp_hf.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/classic/hfp_hf.c b/src/classic/hfp_hf.c index 197800fb1..82095b049 100644 --- a/src/classic/hfp_hf.c +++ b/src/classic/hfp_hf.c @@ -275,6 +275,20 @@ static void hfp_hf_emit_enhanced_voice_recognition_text(hfp_connection_t * hfp_c (*hfp_hf_callback)(HCI_EVENT_PACKET, 0, event, pos); } +static void hfp_hf_emit_custom_command_event(hfp_connection_t * hfp_connection){ + btstack_assert(sizeof(hfp_connection->line_buffer) < (255-5)); + + uint16_t line_len = strlen((const char*)hfp_connection->line_buffer) + 1; + uint8_t event[7 + sizeof(hfp_connection->line_buffer)]; + event[0] = HCI_EVENT_HFP_META; + event[1] = 5 + line_len; + event[2] = HFP_SUBEVENT_CUSTOM_AT_COMMAND; + little_endian_store_16(event, 3, hfp_connection->acl_handle); + little_endian_store_16(event, 5, hfp_connection->custom_at_command_id); + memcpy(&event[7], hfp_connection->line_buffer, line_len); + (*hfp_hf_callback)(HCI_EVENT_PACKET, 0, event, 7 + line_len); +} + /* send commands */ static inline int hfp_hf_send_cmd(uint16_t cid, const char * cmd){ @@ -1412,6 +1426,12 @@ static void hfp_hf_handle_rfcomm_command(hfp_connection_t * hfp_connection){ break; case HFP_CMD_CHANGE_IN_BAND_RING_TONE_SETTING: hfp_emit_event(hfp_connection, HFP_SUBEVENT_IN_BAND_RING_TONE, get_bit(hfp_connection->remote_supported_features, HFP_AGSF_IN_BAND_RING_TONE)); + case HFP_CMD_CUSTOM_MESSAGE: + hfp_connection->command = HFP_CMD_NONE; + hfp_parser_reset_line_buffer(hfp_connection); + log_info("Custom AT Command ID 0x%04x", hfp_connection->custom_at_command_id); + hfp_hf_emit_custom_command_event(hfp_connection); + break; default: break; }