hfp.c (4e01e8028394eb272a798dd786320dc0e7751048) | hfp.c (090c81feb660788a282ef81cee7bdb8ae8d35677) |
---|---|
1/* 2 * Copyright (C) 2014 BlueKitchen GmbH 3 * 4 * Redistribution and use in source and binary forms, with or without 5 * modification, are permitted provided that the following conditions 6 * are met: 7 * 8 * 1. Redistributions of source code must retain the above copyright --- 454 unchanged lines hidden (view full) --- 463 event[pos++] = HFP_SUBEVENT_AUDIO_CONNECTION_RELEASED; 464 little_endian_store_16(event, pos, hfp_connection->acl_handle); 465 pos += 2; 466 little_endian_store_16(event, pos, sco_handle); 467 pos += 2; 468 hfp_emit_event_for_context(hfp_connection, event, sizeof(event)); 469} 470 | 1/* 2 * Copyright (C) 2014 BlueKitchen GmbH 3 * 4 * Redistribution and use in source and binary forms, with or without 5 * modification, are permitted provided that the following conditions 6 * are met: 7 * 8 * 1. Redistributions of source code must retain the above copyright --- 454 unchanged lines hidden (view full) --- 463 event[pos++] = HFP_SUBEVENT_AUDIO_CONNECTION_RELEASED; 464 little_endian_store_16(event, pos, hfp_connection->acl_handle); 465 pos += 2; 466 little_endian_store_16(event, pos, sco_handle); 467 pos += 2; 468 hfp_emit_event_for_context(hfp_connection, event, sizeof(event)); 469} 470 |
471void hfp_emit_sco_event(hfp_connection_t * hfp_connection, uint8_t status, hci_con_handle_t sco_handle, bd_addr_t addr, uint8_t negotiated_codec){ | 471void hfp_emit_sco_connection_established(hfp_connection_t *hfp_connection, uint8_t status, hci_con_handle_t sco_handle, bd_addr_t addr, 472 uint8_t negotiated_codec, uint16_t packet_types) { |
472 btstack_assert(hfp_connection != NULL); | 473 btstack_assert(hfp_connection != NULL); |
473 uint8_t event[15]; | 474 uint8_t event[17]; |
474 int pos = 0; 475 event[pos++] = HCI_EVENT_HFP_META; 476 event[pos++] = sizeof(event) - 2; 477 event[pos++] = HFP_SUBEVENT_AUDIO_CONNECTION_ESTABLISHED; 478 little_endian_store_16(event, pos, hfp_connection->acl_handle); 479 pos += 2; 480 event[pos++] = status; // status 0 == OK 481 little_endian_store_16(event, pos, sco_handle); 482 pos += 2; 483 reverse_bd_addr(addr,&event[pos]); 484 pos += 6; 485 event[pos++] = negotiated_codec; | 475 int pos = 0; 476 event[pos++] = HCI_EVENT_HFP_META; 477 event[pos++] = sizeof(event) - 2; 478 event[pos++] = HFP_SUBEVENT_AUDIO_CONNECTION_ESTABLISHED; 479 little_endian_store_16(event, pos, hfp_connection->acl_handle); 480 pos += 2; 481 event[pos++] = status; // status 0 == OK 482 little_endian_store_16(event, pos, sco_handle); 483 pos += 2; 484 reverse_bd_addr(addr,&event[pos]); 485 pos += 6; 486 event[pos++] = negotiated_codec; |
487 little_endian_store_16(event, pos, packet_types); |
|
486 hfp_emit_event_for_context(hfp_connection, event, sizeof(event)); 487} 488 489void hfp_emit_string_event(hfp_connection_t * hfp_connection, uint8_t event_subtype, const char * value){ 490 btstack_assert(hfp_connection != NULL); 491#ifdef ENABLE_HFP_AT_MESSAGES 492 uint8_t event[256]; 493#else --- 384 unchanged lines hidden (view full) --- 878 if (hfp_sco_establishment_active == NULL) break; 879 status = hci_event_command_status_get_status(packet); 880 if (status == ERROR_CODE_SUCCESS) break; 881 882 hfp_connection = hfp_sco_establishment_active; 883 if (hfp_handle_failed_sco_connection(status)) break; 884 hfp_connection->establish_audio_connection = 0; 885 hfp_connection->state = HFP_SERVICE_LEVEL_CONNECTION_ESTABLISHED; | 488 hfp_emit_event_for_context(hfp_connection, event, sizeof(event)); 489} 490 491void hfp_emit_string_event(hfp_connection_t * hfp_connection, uint8_t event_subtype, const char * value){ 492 btstack_assert(hfp_connection != NULL); 493#ifdef ENABLE_HFP_AT_MESSAGES 494 uint8_t event[256]; 495#else --- 384 unchanged lines hidden (view full) --- 880 if (hfp_sco_establishment_active == NULL) break; 881 status = hci_event_command_status_get_status(packet); 882 if (status == ERROR_CODE_SUCCESS) break; 883 884 hfp_connection = hfp_sco_establishment_active; 885 if (hfp_handle_failed_sco_connection(status)) break; 886 hfp_connection->establish_audio_connection = 0; 887 hfp_connection->state = HFP_SERVICE_LEVEL_CONNECTION_ESTABLISHED; |
886 hfp_emit_sco_event(hfp_connection, status, 0, hfp_connection->remote_addr, hfp_connection->negotiated_codec); | 888 hfp_emit_sco_connection_established(hfp_connection, status, 0, hfp_connection->remote_addr, 889 hfp_connection->negotiated_codec, 0); |
887 } 888 break; 889 890 case HCI_EVENT_SYNCHRONOUS_CONNECTION_COMPLETE:{ 891 if (hfp_sco_establishment_active == NULL) break; 892 hci_event_synchronous_connection_complete_get_bd_addr(packet, event_addr); 893 hfp_connection = get_hfp_connection_context_for_bd_addr(event_addr, local_role); 894 if (!hfp_connection) { 895 log_error("HFP: connection does not exist for remote with addr %s.", bd_addr_to_str(event_addr)); 896 return; 897 } 898 899 status = hci_event_synchronous_connection_complete_get_status(packet); 900 if (status != ERROR_CODE_SUCCESS){ 901 hfp_connection->accept_sco = 0; 902 if (hfp_handle_failed_sco_connection(status)) break; 903 904 hfp_connection->establish_audio_connection = 0; 905 hfp_connection->state = HFP_SERVICE_LEVEL_CONNECTION_ESTABLISHED; | 890 } 891 break; 892 893 case HCI_EVENT_SYNCHRONOUS_CONNECTION_COMPLETE:{ 894 if (hfp_sco_establishment_active == NULL) break; 895 hci_event_synchronous_connection_complete_get_bd_addr(packet, event_addr); 896 hfp_connection = get_hfp_connection_context_for_bd_addr(event_addr, local_role); 897 if (!hfp_connection) { 898 log_error("HFP: connection does not exist for remote with addr %s.", bd_addr_to_str(event_addr)); 899 return; 900 } 901 902 status = hci_event_synchronous_connection_complete_get_status(packet); 903 if (status != ERROR_CODE_SUCCESS){ 904 hfp_connection->accept_sco = 0; 905 if (hfp_handle_failed_sco_connection(status)) break; 906 907 hfp_connection->establish_audio_connection = 0; 908 hfp_connection->state = HFP_SERVICE_LEVEL_CONNECTION_ESTABLISHED; |
906 hfp_emit_sco_event(hfp_connection, status, 0, event_addr, hfp_connection->negotiated_codec); | 909 hfp_emit_sco_connection_established(hfp_connection, status, 0, event_addr, 910 hfp_connection->negotiated_codec, 911 0); |
907 break; 908 } 909 910 uint16_t sco_handle = hci_event_synchronous_connection_complete_get_handle(packet); 911 uint8_t link_type = hci_event_synchronous_connection_complete_get_link_type(packet); 912 uint8_t transmission_interval = hci_event_synchronous_connection_complete_get_transmission_interval(packet); // measured in slots 913 uint8_t retransmission_interval = hci_event_synchronous_connection_complete_get_retransmission_interval(packet);// measured in slots 914 uint16_t rx_packet_length = hci_event_synchronous_connection_complete_get_rx_packet_length(packet); // measured in bytes 915 uint16_t tx_packet_length = hci_event_synchronous_connection_complete_get_tx_packet_length(packet); // measured in bytes | 912 break; 913 } 914 915 uint16_t sco_handle = hci_event_synchronous_connection_complete_get_handle(packet); 916 uint8_t link_type = hci_event_synchronous_connection_complete_get_link_type(packet); 917 uint8_t transmission_interval = hci_event_synchronous_connection_complete_get_transmission_interval(packet); // measured in slots 918 uint8_t retransmission_interval = hci_event_synchronous_connection_complete_get_retransmission_interval(packet);// measured in slots 919 uint16_t rx_packet_length = hci_event_synchronous_connection_complete_get_rx_packet_length(packet); // measured in bytes 920 uint16_t tx_packet_length = hci_event_synchronous_connection_complete_get_tx_packet_length(packet); // measured in bytes |
921 uint16_t packet_types = hfp_link_settings[hfp_sco_establishment_active->link_setting].packet_types; |
|
916 917 switch (link_type){ 918 case 0x00: 919 log_info("SCO Connection established."); 920 if (transmission_interval != 0) log_error("SCO Connection: transmission_interval not zero: %d.", transmission_interval); 921 if (retransmission_interval != 0) log_error("SCO Connection: retransmission_interval not zero: %d.", retransmission_interval); 922 if (rx_packet_length != 0) log_error("SCO Connection: rx_packet_length not zero: %d.", rx_packet_length); 923 if (tx_packet_length != 0) log_error("SCO Connection: tx_packet_length not zero: %d.", tx_packet_length); --- 24 unchanged lines hidden (view full) --- 948 switch (hfp_connection->vra_state){ 949 case HFP_VRA_VOICE_RECOGNITION_ACTIVATED: 950 hfp_connection->ag_audio_connection_opened_before_vra = false; 951 break; 952 default: 953 hfp_connection->ag_audio_connection_opened_before_vra = true; 954 break; 955 } | 922 923 switch (link_type){ 924 case 0x00: 925 log_info("SCO Connection established."); 926 if (transmission_interval != 0) log_error("SCO Connection: transmission_interval not zero: %d.", transmission_interval); 927 if (retransmission_interval != 0) log_error("SCO Connection: retransmission_interval not zero: %d.", retransmission_interval); 928 if (rx_packet_length != 0) log_error("SCO Connection: rx_packet_length not zero: %d.", rx_packet_length); 929 if (tx_packet_length != 0) log_error("SCO Connection: tx_packet_length not zero: %d.", tx_packet_length); --- 24 unchanged lines hidden (view full) --- 954 switch (hfp_connection->vra_state){ 955 case HFP_VRA_VOICE_RECOGNITION_ACTIVATED: 956 hfp_connection->ag_audio_connection_opened_before_vra = false; 957 break; 958 default: 959 hfp_connection->ag_audio_connection_opened_before_vra = true; 960 break; 961 } |
956 hfp_emit_sco_event(hfp_connection, status, sco_handle, event_addr, hfp_connection->negotiated_codec); | 962 hfp_emit_sco_connection_established(hfp_connection, status, sco_handle, event_addr, 963 hfp_connection->negotiated_codec, 964 packet_types); |
957 break; 958 } 959 960 case HCI_EVENT_DISCONNECTION_COMPLETE: 961 handle = little_endian_read_16(packet,3); 962 hfp_connection = get_hfp_connection_context_for_sco_handle(handle, local_role); 963 964 if (!hfp_connection) break; --- 1129 unchanged lines hidden --- | 965 break; 966 } 967 968 case HCI_EVENT_DISCONNECTION_COMPLETE: 969 handle = little_endian_read_16(packet,3); 970 hfp_connection = get_hfp_connection_context_for_sco_handle(handle, local_role); 971 972 if (!hfp_connection) break; --- 1129 unchanged lines hidden --- |