hfp: use full size line buffer to send enhanced VRA message

This commit is contained in:
Milanka Ringwald 2021-08-23 11:21:45 +02:00
parent a9e632e913
commit 51aa5d5a8f
4 changed files with 20 additions and 12 deletions

View File

@ -109,7 +109,7 @@ static hfp_generic_status_indicator_t hf_indicators[] = {
};
static hfp_voice_recognition_message_t msg = {
0xABCD, HFP_TEXT_TYPE_MESSAGE_FROM_AG, HFP_TEXT_OPERATION_REPLACE, "The temperature in Munich"
0xABCD, HFP_TEXT_TYPE_MESSAGE_FROM_AG, HFP_TEXT_OPERATION_REPLACE, "The temperature in Munich is 30 degrees."
};
#define INQUIRY_INTERVAL 5

View File

@ -1183,7 +1183,7 @@ static hfp_command_t parse_command(const char * line_buffer, int isHandsFree){
}
static void hfp_parser_store_byte(hfp_connection_t * hfp_connection, uint8_t byte){
if ((hfp_connection->line_size + 1 ) >= HFP_MAX_INDICATOR_DESC_SIZE) return;
if ((hfp_connection->line_size + 1) >= HFP_MAX_VR_TEXT_SIZE) return;
hfp_connection->line_buffer[hfp_connection->line_size++] = byte;
hfp_connection->line_buffer[hfp_connection->line_size] = 0;
}
@ -1197,6 +1197,7 @@ static int hfp_parser_is_end_of_line(uint8_t byte){
static void hfp_parser_reset_line_buffer(hfp_connection_t *hfp_connection) {
hfp_connection->line_size = 0;
// hfp_connection->line_buffer[0] = 0;
}
static void hfp_parser_store_if_token(hfp_connection_t * hfp_connection, uint8_t byte){
@ -1702,7 +1703,8 @@ static void parse_sequence(hfp_connection_t * hfp_connection){
hfp_connection->ag_msg.text_type = (hfp_text_type_t) btstack_atoi((char *)&hfp_connection->line_buffer[0]);
break;
case 5:
hfp_connection->ag_vra_msg_length = hfp_connection->line_size;
hfp_connection->line_buffer[hfp_connection->line_size] = 0;
hfp_connection->ag_vra_msg_length = hfp_connection->line_size + 1;
log_info("VRA message of length %d", hfp_connection->ag_vra_msg_length);
break;
default:

View File

@ -534,7 +534,7 @@ static int hfp_ag_send_voice_recognition_cmd(hfp_connection_t * hfp_connection,
}
static int hfp_ag_send_enhanced_voice_recognition_msg_cmd(hfp_connection_t * hfp_connection){
char buffer[100];
char buffer[HFP_MAX_VR_TEXT_SIZE + 30];
snprintf(buffer, sizeof(buffer), "\r\n%s: 1,%d,%X,%d,%d,\"%s\"\r\n", HFP_ACTIVATE_VOICE_RECOGNITION,
hfp_connection->ag_vra_state,
hfp_connection->ag_msg.text_id,
@ -2909,6 +2909,12 @@ uint8_t hfp_ag_enhanced_voice_recognition_send_message(hci_con_handle_t acl_hand
return ERROR_CODE_COMMAND_DISALLOWED;
}
uint16_t message_len = strlen(msg.text);
if ((message_len == 0) || ((message_len + 1) > HFP_MAX_VR_TEXT_SIZE)){
return ERROR_CODE_UNSUPPORTED_FEATURE_OR_PARAMETER_VALUE;
}
hfp_connection->command = HFP_CMD_AG_ACTIVATE_VOICE_RECOGNITION;
hfp_connection->vra_state_requested = HFP_VRA_W2_SEND_ENHANCED_VOICE_RECOGNITION_MSG;
hfp_connection->ag_msg = msg;

View File

@ -218,7 +218,7 @@ static void hfp_emit_network_operator_event(const hfp_connection_t * hfp_connect
static void hfp_hf_emit_enhanced_voice_recognition_text(hfp_connection_t * hfp_connection){
btstack_assert(hfp_connection != NULL);
uint8_t event[HFP_MAX_VR_TEXT_SIZE];
uint8_t event[HFP_MAX_VR_TEXT_SIZE + 11];
int pos = 0;
event[pos++] = HCI_EVENT_HFP_META;
event[pos++] = sizeof(event) - 2;
@ -230,15 +230,15 @@ static void hfp_hf_emit_enhanced_voice_recognition_text(hfp_connection_t * hfp_c
event[pos++] = hfp_connection->ag_msg.text_type;
event[pos++] = hfp_connection->ag_msg.text_operation;
// length, zero ending
uint16_t value_length = hfp_connection->ag_vra_msg_length;
// length, zero ending is already in message
uint8_t * value = &hfp_connection->line_buffer[0];
uint16_t size = btstack_min(value_length, sizeof(event) - pos - 2 - 1);
little_endian_store_16(event, pos, size+1);
uint16_t value_length = hfp_connection->ag_vra_msg_length;
little_endian_store_16(event, pos, value_length);
pos += 2;
memcpy(&event[pos], value, size);
event[pos + size] = 0;
pos += size + 1;
memcpy(&event[pos], value, value_length);
pos += value_length;
(*hfp_hf_callback)(HCI_EVENT_PACKET, 0, event, pos);
}