hfp.c (b4320e7fd03a9a6c1d049a2558585051dddaebe5) | hfp.c (c528139d1e19587a03c0c7e035f7df390c0372fb) |
---|---|
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 --- 108 unchanged lines hidden (view full) --- 117 {0x0007, 0x01, SCO_PACKET_TYPES_EV3, CODEC_MASK_CVSD }, // HFP_LINK_SETTINGS_S1 118 {0x0007, 0x01, SCO_PACKET_TYPES_2EV3, CODEC_MASK_CVSD }, // HFP_LINK_SETTINGS_S2 119 {0x000a, 0x01, SCO_PACKET_TYPES_2EV3, CODEC_MASK_CVSD }, // HFP_LINK_SETTINGS_S3 120 {0x000c, 0x02, SCO_PACKET_TYPES_2EV3, CODEC_MASK_CVSD }, // HFP_LINK_SETTINGS_S4 121 {0x0008, 0x02, SCO_PACKET_TYPES_EV3, CODEC_MASK_OTHER}, // HFP_LINK_SETTINGS_T1 122 {0x000d, 0x02, SCO_PACKET_TYPES_2EV3, CODEC_MASK_OTHER} // HFP_LINK_SETTINGS_T2 123}; 124 | 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 --- 108 unchanged lines hidden (view full) --- 117 {0x0007, 0x01, SCO_PACKET_TYPES_EV3, CODEC_MASK_CVSD }, // HFP_LINK_SETTINGS_S1 118 {0x0007, 0x01, SCO_PACKET_TYPES_2EV3, CODEC_MASK_CVSD }, // HFP_LINK_SETTINGS_S2 119 {0x000a, 0x01, SCO_PACKET_TYPES_2EV3, CODEC_MASK_CVSD }, // HFP_LINK_SETTINGS_S3 120 {0x000c, 0x02, SCO_PACKET_TYPES_2EV3, CODEC_MASK_CVSD }, // HFP_LINK_SETTINGS_S4 121 {0x0008, 0x02, SCO_PACKET_TYPES_EV3, CODEC_MASK_OTHER}, // HFP_LINK_SETTINGS_T1 122 {0x000d, 0x02, SCO_PACKET_TYPES_2EV3, CODEC_MASK_OTHER} // HFP_LINK_SETTINGS_T2 123}; 124 |
125// table 5.8 'mandatory safe settings' for eSCO + similar entries for SCO 126static const struct hfp_mandatory_safe_setting { 127 const uint8_t codec_mask; 128 const bool secure_connection_in_use; 129 hfp_link_settings_t link_setting; 130} hfp_mandatory_safe_settings[] = { 131 { CODEC_MASK_CVSD, false, HFP_LINK_SETTINGS_D1}, 132 { CODEC_MASK_CVSD, true, HFP_LINK_SETTINGS_D1}, 133 { CODEC_MASK_CVSD, false, HFP_LINK_SETTINGS_S1}, 134 { CODEC_MASK_CVSD, true, HFP_LINK_SETTINGS_S4}, 135 { CODEC_MASK_OTHER, false, HFP_LINK_SETTINGS_T1}, 136 { CODEC_MASK_OTHER, true, HFP_LINK_SETTINGS_T2}, 137}; 138 | |
139static const char * hfp_hf_features[] = { 140 "EC and/or NR function", 141 "Three-way calling", 142 "CLI presentation capability", 143 "Voice recognition activation", 144 "Remote volume control", 145 146 "Enhanced call status", --- 1787 unchanged lines hidden (view full) --- 1934 hfp_connection->packet_types = packet_types; 1935 1936 // get packet types - bits 6-9 are 'don't allow' 1937 uint16_t packet_types_flipped = packet_types ^ 0x03c0; 1938 hci_send_cmd(&hci_setup_synchronous_connection, hfp_connection->acl_handle, 8000, 8000, hfp_link_settings[setting].max_latency, 1939 sco_voice_setting, hfp_link_settings[setting].retransmission_effort, packet_types_flipped); 1940} 1941 | 125static const char * hfp_hf_features[] = { 126 "EC and/or NR function", 127 "Three-way calling", 128 "CLI presentation capability", 129 "Voice recognition activation", 130 "Remote volume control", 131 132 "Enhanced call status", --- 1787 unchanged lines hidden (view full) --- 1920 hfp_connection->packet_types = packet_types; 1921 1922 // get packet types - bits 6-9 are 'don't allow' 1923 uint16_t packet_types_flipped = packet_types ^ 0x03c0; 1924 hci_send_cmd(&hci_setup_synchronous_connection, hfp_connection->acl_handle, 8000, 8000, hfp_link_settings[setting].max_latency, 1925 sco_voice_setting, hfp_link_settings[setting].retransmission_effort, packet_types_flipped); 1926} 1927 |
1942hfp_link_settings_t hfp_safe_settings_for_context(bool use_eSCO, uint8_t negotiated_codec, bool secure_connection_in_use){ 1943 uint8_t i; 1944 hfp_link_settings_t link_setting = HFP_LINK_SETTINGS_NONE; 1945 for (i=0 ; i < (sizeof(hfp_mandatory_safe_settings) / sizeof(struct hfp_mandatory_safe_setting)) ; i++){ 1946 uint16_t packet_types = hfp_link_settings[(uint8_t)(hfp_mandatory_safe_settings[i].link_setting)].packet_types; 1947 bool is_eSCO_setting = (packet_types & SCO_PACKET_TYPES_ESCO) != 0; 1948 if (is_eSCO_setting != use_eSCO) continue; 1949 if ((hfp_mandatory_safe_settings[i].codec_mask & (1 << negotiated_codec)) == 0) continue; 1950 if (hfp_mandatory_safe_settings[i].secure_connection_in_use != secure_connection_in_use) continue; 1951 link_setting = hfp_mandatory_safe_settings[i].link_setting; 1952 break; 1953 } 1954 return link_setting; 1955} 1956 | |
1957void hfp_accept_synchronous_connection(hfp_connection_t * hfp_connection, bool use_eSCO){ 1958 | 1928void hfp_accept_synchronous_connection(hfp_connection_t * hfp_connection, bool use_eSCO){ 1929 |
1959 bool secure_connection_in_use = gap_secure_connection(hfp_connection->acl_handle); | 1930 // use "don't care" where possible 1931 uint16_t max_latency = 0xffff; 1932 uint16_t retransmission_effort = 0xff; |
1960 | 1933 |
1961 // lookup safe settings based on SCO type, SC use and Codec type 1962 hfp_link_settings_t link_setting = hfp_safe_settings_for_context(use_eSCO, hfp_connection->negotiated_codec, secure_connection_in_use); 1963 btstack_assert(link_setting != HFP_LINK_SETTINGS_NONE); 1964 1965 uint16_t max_latency = hfp_link_settings[(uint8_t) link_setting].max_latency; 1966 uint16_t retransmission_effort = hfp_link_settings[(uint8_t) link_setting].retransmission_effort; 1967 1968 // safer to allow more packet types: 1969 uint16_t packet_types = use_eSCO ? (SCO_PACKET_TYPES_EV3 | SCO_PACKET_TYPES_2EV3) : (SCO_PACKET_TYPES_HV1 | SCO_PACKET_TYPES_HV3); 1970 | |
1971 // transparent data for non-CVSD connections or if codec provided by Controller 1972 uint16_t sco_voice_setting = hci_get_sco_voice_setting(); 1973 if (hfp_connection->negotiated_codec != HFP_CODEC_CVSD){ 1974#ifdef ENABLE_BCM_PCM_WBS 1975 sco_voice_setting = 0x0063; // Transparent data, 16-bit for BCM controllers 1976#else 1977 sco_voice_setting = 0x0043; // Transparent data, 8-bit otherwise 1978#endif 1979 } 1980 1981 // filter packet types | 1934 // transparent data for non-CVSD connections or if codec provided by Controller 1935 uint16_t sco_voice_setting = hci_get_sco_voice_setting(); 1936 if (hfp_connection->negotiated_codec != HFP_CODEC_CVSD){ 1937#ifdef ENABLE_BCM_PCM_WBS 1938 sco_voice_setting = 0x0063; // Transparent data, 16-bit for BCM controllers 1939#else 1940 sco_voice_setting = 0x0043; // Transparent data, 8-bit otherwise 1941#endif 1942 } 1943 1944 // filter packet types |
1982 packet_types &= hfp_get_sco_packet_types(); 1983 | 1945 uint16_t packet_types = hfp_get_sco_packet_types(); |
1984 hfp_connection->packet_types = packet_types; 1985 1986 // bits 6-9 are 'don't allow' 1987 uint16_t packet_types_flipped = packet_types ^ 0x3c0; 1988 1989 log_info("HFP: sending hci_accept_connection_request, packet types 0x%04x, sco_voice_setting 0x%02x", packet_types, sco_voice_setting); 1990 hci_send_cmd(&hci_accept_synchronous_connection, hfp_connection->remote_addr, 8000, 8000, max_latency, 1991 sco_voice_setting, retransmission_effort, packet_types_flipped); --- 266 unchanged lines hidden --- | 1946 hfp_connection->packet_types = packet_types; 1947 1948 // bits 6-9 are 'don't allow' 1949 uint16_t packet_types_flipped = packet_types ^ 0x3c0; 1950 1951 log_info("HFP: sending hci_accept_connection_request, packet types 0x%04x, sco_voice_setting 0x%02x", packet_types, sco_voice_setting); 1952 hci_send_cmd(&hci_accept_synchronous_connection, hfp_connection->remote_addr, 8000, 8000, max_latency, 1953 sco_voice_setting, retransmission_effort, packet_types_flipped); --- 266 unchanged lines hidden --- |