hfp.c (13ea5944fda42b197e733750a46b71daff1e7d82) | hfp.c (3ad75286b369b7c8fa8d48d87c7750c3b8b4b6c4) |
---|---|
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 --- 107 unchanged lines hidden (view full) --- 116 {0x0005, 0xff, SCO_PACKET_TYPES_HV3, false, CODEC_MASK_CVSD }, // HFP_LINK_SETTINGS_D1 117 {0x0007, 0x01, SCO_PACKET_TYPES_EV3, true, CODEC_MASK_CVSD }, // HFP_LINK_SETTINGS_S1 118 {0x0007, 0x01, SCO_PACKET_TYPES_2EV3, true, CODEC_MASK_CVSD }, // HFP_LINK_SETTINGS_S2 119 {0x000a, 0x01, SCO_PACKET_TYPES_2EV3, true, CODEC_MASK_CVSD }, // HFP_LINK_SETTINGS_S3 120 {0x000c, 0x02, SCO_PACKET_TYPES_2EV3, true, CODEC_MASK_CVSD }, // HFP_LINK_SETTINGS_S4 121 {0x0008, 0x02, SCO_PACKET_TYPES_EV3, true, CODEC_MASK_OTHER}, // HFP_LINK_SETTINGS_T1 122 {0x000d, 0x02, SCO_PACKET_TYPES_2EV3, true, CODEC_MASK_OTHER} // HFP_LINK_SETTINGS_T2 123}; | 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 --- 107 unchanged lines hidden (view full) --- 116 {0x0005, 0xff, SCO_PACKET_TYPES_HV3, false, CODEC_MASK_CVSD }, // HFP_LINK_SETTINGS_D1 117 {0x0007, 0x01, SCO_PACKET_TYPES_EV3, true, CODEC_MASK_CVSD }, // HFP_LINK_SETTINGS_S1 118 {0x0007, 0x01, SCO_PACKET_TYPES_2EV3, true, CODEC_MASK_CVSD }, // HFP_LINK_SETTINGS_S2 119 {0x000a, 0x01, SCO_PACKET_TYPES_2EV3, true, CODEC_MASK_CVSD }, // HFP_LINK_SETTINGS_S3 120 {0x000c, 0x02, SCO_PACKET_TYPES_2EV3, true, CODEC_MASK_CVSD }, // HFP_LINK_SETTINGS_S4 121 {0x0008, 0x02, SCO_PACKET_TYPES_EV3, true, CODEC_MASK_OTHER}, // HFP_LINK_SETTINGS_T1 122 {0x000d, 0x02, SCO_PACKET_TYPES_2EV3, true, 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}, |
|
124}; 125 126static const char * hfp_hf_features[] = { 127 "EC and/or NR function", 128 "Three-way calling", 129 "CLI presentation capability", 130 "Voice recognition activation", 131 "Remote volume control", --- 1772 unchanged lines hidden (view full) --- 1904 hfp_connection->packet_types = packet_types; 1905 1906 // get packet types - bits 6-9 are 'don't allow' 1907 uint16_t packet_types_flipped = packet_types ^ 0x03c0; 1908 hci_send_cmd(&hci_setup_synchronous_connection, hfp_connection->acl_handle, 8000, 8000, hfp_link_settings[setting].max_latency, 1909 sco_voice_setting, hfp_link_settings[setting].retransmission_effort, packet_types_flipped); 1910} 1911 | 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", --- 1772 unchanged lines hidden (view full) --- 1917 hfp_connection->packet_types = packet_types; 1918 1919 // get packet types - bits 6-9 are 'don't allow' 1920 uint16_t packet_types_flipped = packet_types ^ 0x03c0; 1921 hci_send_cmd(&hci_setup_synchronous_connection, hfp_connection->acl_handle, 8000, 8000, hfp_link_settings[setting].max_latency, 1922 sco_voice_setting, hfp_link_settings[setting].retransmission_effort, packet_types_flipped); 1923} 1924 |
1912void hfp_accept_synchronous_connection(hfp_connection_t * hfp_connection, bool incoming_eSCO){ | 1925hfp_link_settings_t hfp_safe_settings_for_context(bool use_eSCO, uint8_t negotiated_codec, bool secure_connection_in_use){ 1926 uint8_t i; 1927 hfp_link_settings_t link_setting = HFP_LINK_SETTINGS_NONE; 1928 for (i=0 ; i < ( sizeof(hfp_mandatory_safe_settings) / sizeof(struct hfp_mandatory_safe_setting) ) ; i++){ 1929 if (hfp_link_settings[(uint8_t)(hfp_mandatory_safe_settings[i].link_setting)].eSCO != use_eSCO) continue; 1930 if ((hfp_mandatory_safe_settings[i].codec_mask & (1 << negotiated_codec)) == 0) continue; 1931 if (hfp_mandatory_safe_settings[i].secure_connection_in_use != secure_connection_in_use) continue; 1932 link_setting = hfp_mandatory_safe_settings[i].link_setting; 1933 break; 1934 } 1935 return link_setting; 1936} |
1913 | 1937 |
1914 // remote supported feature eSCO is set if link type is eSCO 1915 // eSCO: S4 - max latency == transmission interval = 0x000c == 12 ms, 1916 uint16_t max_latency; 1917 uint8_t retransmission_effort; 1918 uint16_t packet_types; | 1938void hfp_accept_synchronous_connection(hfp_connection_t * hfp_connection, bool use_eSCO){ |
1919 | 1939 |
1920 if (incoming_eSCO && hci_extended_sco_link_supported() && hci_remote_esco_supported(hfp_connection->acl_handle)){ 1921 max_latency = 0x000c; 1922 retransmission_effort = 0x02; 1923 // eSCO: EV3 and 2-EV3 1924 packet_types = 0x0048; 1925 } else { 1926 max_latency = 0xffff; 1927 retransmission_effort = 0xff; 1928 // sco: HV1 and HV3 1929 packet_types = 0x005; 1930 } | 1940 bool secure_connection_in_use = gap_secure_connection(hfp_connection->acl_handle); |
1931 | 1941 |
1932 // mSBC only allows for transparent data | 1942 // lookup safe settings based on SCO type, SC use and Codec type 1943 hfp_link_settings_t link_setting = hfp_safe_settings_for_context(use_eSCO, hfp_connection->negotiated_codec, secure_connection_in_use); 1944 btstack_assert(link_setting != HFP_LINK_SETTINGS_NONE); 1945 1946 uint16_t max_latency = hfp_link_settings[(uint8_t) link_setting].max_latency; 1947 uint16_t retransmission_effort = hfp_link_settings[(uint8_t) link_setting].retransmission_effort; 1948 1949 // safer to allow more packet types: 1950 uint16_t packet_types = use_eSCO ? (SCO_PACKET_TYPES_EV3 | SCO_PACKET_TYPES_2EV3) : (SCO_PACKET_TYPES_HV1 | SCO_PACKET_TYPES_HV3); 1951 1952 // transparent data for non-CVSD connections or if codec provided by Controller |
1933 uint16_t sco_voice_setting = hci_get_sco_voice_setting(); 1934 if (hfp_connection->negotiated_codec != HFP_CODEC_CVSD){ 1935#ifdef ENABLE_BCM_PCM_WBS 1936 sco_voice_setting = 0x0063; // Transparent data, 16-bit for BCM controllers 1937#else 1938 sco_voice_setting = 0x0043; // Transparent data, 8-bit otherwise 1939#endif 1940 } --- 273 unchanged lines hidden --- | 1953 uint16_t sco_voice_setting = hci_get_sco_voice_setting(); 1954 if (hfp_connection->negotiated_codec != HFP_CODEC_CVSD){ 1955#ifdef ENABLE_BCM_PCM_WBS 1956 sco_voice_setting = 0x0063; // Transparent data, 16-bit for BCM controllers 1957#else 1958 sco_voice_setting = 0x0043; // Transparent data, 8-bit otherwise 1959#endif 1960 } --- 273 unchanged lines hidden --- |