hfp_hf: extract hfp_hf_handle_rfcomm_command

This commit is contained in:
Matthias Ringwald 2020-01-13 22:19:23 +01:00
parent 5dde773e0b
commit 426f998884

View File

@ -997,24 +997,7 @@ static int hfp_parser_is_end_of_line(uint8_t byte){
return (byte == '\n') || (byte == '\r');
}
static void hfp_hf_handle_rfcomm_event(uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size){
UNUSED(packet_type); // ok: only called with RFCOMM_DATA_PACKET
// assertion: size >= 1 as rfcomm.c does not deliver empty packets
if (size < 1) return;
hfp_connection_t * hfp_connection = get_hfp_connection_context_for_rfcomm_cid(channel);
if (!hfp_connection) return;
hfp_log_rfcomm_message("HFP_HF_RX", packet, size);
// process messages byte-wise
int pos;
for (pos = 0; pos < size; pos++){
hfp_parse(hfp_connection, packet[pos], 1);
// parse until end of line "\r\n"
if (!hfp_parser_is_end_of_line(packet[pos])) continue;
static void hfp_hf_handle_rfcomm_command(hfp_connection_t * hfp_connection){
int value;
int i;
switch (hfp_connection->command){
@ -1102,6 +1085,27 @@ static void hfp_hf_handle_rfcomm_event(uint8_t packet_type, uint16_t channel, ui
break;
}
}
static void hfp_hf_handle_rfcomm_data(uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size){
UNUSED(packet_type); // ok: only called with RFCOMM_DATA_PACKET
// assertion: size >= 1 as rfcomm.c does not deliver empty packets
if (size < 1) return;
hfp_connection_t * hfp_connection = get_hfp_connection_context_for_rfcomm_cid(channel);
if (!hfp_connection) return;
hfp_log_rfcomm_message("HFP_HF_RX", packet, size);
// process messages byte-wise
int pos;
for (pos = 0; pos < size; pos++){
hfp_parse(hfp_connection, packet[pos], 1);
// parse until end of line "\r\n"
if (!hfp_parser_is_end_of_line(packet[pos])) continue;
hfp_hf_handle_rfcomm_command(hfp_connection);
}
hfp_run_for_context(hfp_connection);
}
@ -1118,7 +1122,7 @@ static void hfp_run(void){
static void rfcomm_packet_handler(uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size){
switch (packet_type){
case RFCOMM_DATA_PACKET:
hfp_hf_handle_rfcomm_event(packet_type, channel, packet, size);
hfp_hf_handle_rfcomm_data(packet_type, channel, packet, size);
break;
case HCI_EVENT_PACKET:
if (packet[0] == RFCOMM_EVENT_CAN_SEND_NOW){