1 /******************************************************************************
2  *
3  *  Copyright 2015 Broadcom Corporation
4  *
5  *  Licensed under the Apache License, Version 2.0 (the "License");
6  *  you may not use this file except in compliance with the License.
7  *  You may obtain a copy of the License at:
8  *
9  *  http://www.apache.org/licenses/LICENSE-2.0
10  *
11  *  Unless required by applicable law or agreed to in writing, software
12  *  distributed under the License is distributed on an "AS IS" BASIS,
13  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  *  See the License for the specific language governing permissions and
15  *  limitations under the License.
16  *
17  ******************************************************************************/
18 
19 #pragma once
20 
21 #include <stdint.h>
22 
23 /*******************
24  * SCO Codec Types
25  *******************/
26 typedef enum {
27   SCO_CODEC_NONE = 0x0000,
28   SCO_CODEC_CVSD = 0x0001,
29   SCO_CODEC_MSBC = 0x0002,
30   SCO_CODEC_LC3 = 0x0003,
31 } sco_codec_t;
32 
33 typedef enum {
34   SCO_CODEC_CVSD_D1 = 0,
35   ESCO_CODEC_CVSD_S1,
36   ESCO_CODEC_CVSD_S3,
37   ESCO_CODEC_CVSD_S4,
38   ESCO_CODEC_MSBC_T1,
39   ESCO_CODEC_MSBC_T2,
40   ESCO_CODEC_LC3_T1,
41   ESCO_CODEC_LC3_T2,
42   ESCO_CODEC_SWB_Q0,
43   ESCO_CODEC_SWB_Q1,
44   ESCO_CODEC_SWB_Q2,
45   ESCO_CODEC_SWB_Q3,
46   ESCO_CODEC_UNKNOWN,  // For testing
47 } esco_codec_t;
48 
49 #define ESCO_LEGACY_NUM_CODECS 8
50 #define ESCO_NUM_CODECS 12
51 
52 // Coding Formats (BT 4.1 or later Assigned numbers)
53 #define ESCO_CODING_FORMAT_ULAW ((uint8_t)0x00)     /* u-Law log    */
54 #define ESCO_CODING_FORMAT_ALAW ((uint8_t)0x01)     /* A-Law log    */
55 #define ESCO_CODING_FORMAT_CVSD ((uint8_t)0x02)     /* CVSD         */
56 #define ESCO_CODING_FORMAT_TRANSPNT ((uint8_t)0x03) /* Transparent  */
57 #define ESCO_CODING_FORMAT_LINEAR ((uint8_t)0x04)   /* Linear PCM   */
58 #define ESCO_CODING_FORMAT_MSBC ((uint8_t)0x05)     /* MSBC PCM   */
59 #define ESCO_CODING_FORMAT_LC3 ((uint8_t)0x06)      /* LC3 PCM   */
60 #define ESCO_CODING_FORMAT_VS ((uint8_t)0xFF)       /* Specifies VSC used */
61 typedef uint8_t esco_coding_format_t;
62 
63 // PCM Data Formats (BT 4.1 or later Assigned numbers)
64 #define ESCO_PCM_DATA_FORMAT_NA ((uint8_t)0x00)     /* N/A to coding format in use */
65 #define ESCO_PCM_DATA_FORMAT_1_COMP ((uint8_t)0x01) /* 1's complement   */
66 #define ESCO_PCM_DATA_FORMAT_2_COMP ((uint8_t)0x02) /* 2's complement   */
67 #define ESCO_PCM_DATA_FORMAT_SIGN ((uint8_t)0x03)   /* Sign-magnitude   */
68 #define ESCO_PCM_DATA_FORMAT_UNSIGN ((uint8_t)0x04) /* Unsigned         */
69 typedef uint8_t esco_pcm_data_format_t;
70 
71 // SCO Data Path
72 #define ESCO_DATA_PATH_PCM 1 /* 0x01-0xFE (PCM Chan) */
73 #define ESCO_DATA_PATH_HCI 0 /* HCI-0, 0x01-0xFE (PCM Chan) */
74 typedef uint8_t esco_data_path_t;
75 
76 // eSCO constants
77 #define TXRX_64KBITS_RATE 0x00001f40  /* 64 kbits/sec data rate */
78 #define TXRX_128KBITS_RATE 0x00003E80 /* 128 kbits/sec data rate */
79 typedef uint32_t esco_txrx_bandwidth_t;
80 
81 #define INPUT_OUTPUT_64K_RATE 0x00003E80  /* 16000 Bytes/sec over transport */
82 #define INPUT_OUTPUT_128K_RATE 0x00007D00 /* 32000 Bytes/sec over transport */
83 #define INPUT_OUTPUT_256K_RATE 0x0000FA00 /* 64000 Bytes/sec over transport */
84 typedef uint32_t esco_io_bandwidth_t;
85 
86 // Retransmission effort
87 #define ESCO_RETRANSMISSION_OFF 0
88 #define ESCO_RETRANSMISSION_POWER 1
89 #define ESCO_RETRANSMISSION_QUALITY 2
90 #define ESCO_RETRANSMISSION_DONTCARE 0xff
91 typedef uint8_t esco_retransmission_effort_t;
92 
93 // Definitions for eSCO packet type masks (BT1.2 and BT2.0 definitions)
94 #define ESCO_PKT_TYPES_MASK_HV1 0x0001
95 #define ESCO_PKT_TYPES_MASK_HV2 0x0002
96 #define ESCO_PKT_TYPES_MASK_HV3 0x0004
97 #define ESCO_PKT_TYPES_MASK_EV3 0x0008
98 #define ESCO_PKT_TYPES_MASK_EV4 0x0010
99 #define ESCO_PKT_TYPES_MASK_EV5 0x0020
100 #define ESCO_PKT_TYPES_MASK_NO_2_EV3 0x0040
101 #define ESCO_PKT_TYPES_MASK_NO_3_EV3 0x0080
102 #define ESCO_PKT_TYPES_MASK_NO_2_EV5 0x0100
103 #define ESCO_PKT_TYPES_MASK_NO_3_EV5 0x0200
104 typedef uint16_t esco_packet_types_t;
105 
106 // type definition
107 typedef struct {
108   esco_coding_format_t coding_format; /* Coding Format*/
109   uint16_t company_id;                /* Company ID from BT SIG Assigned Numbers */
110   uint16_t vendor_specific_codec_id;  /* Vendor Specific Codec ID */
111 } esco_coding_id_format_t;
112 
113 // Enhanced setup/accept synchronous connection See BT 4.1 or later HCI spec for
114 // details
115 typedef struct {
116   esco_txrx_bandwidth_t transmit_bandwidth;           /* Transmit Bandwidth (in octets/second) */
117   esco_txrx_bandwidth_t receive_bandwidth;            /* RX BW (# of octets/second) */
118   esco_coding_id_format_t transmit_coding_format;     /* TX coding format */
119   esco_coding_id_format_t receive_coding_format;      /* RX coding format */
120   uint16_t transmit_codec_frame_size;                 /* TX CODEC frame size (OTA frame size) */
121   uint16_t receive_codec_frame_size;                  /* RX CODEC frame size (OTA frame size) */
122   esco_io_bandwidth_t input_bandwidth;                /* Input BW (nominal rate octets/sec) */
123   esco_io_bandwidth_t output_bandwidth;               /* Output BW (nominal rate octets/sec) */
124   esco_coding_id_format_t input_coding_format;        /* Input coding format */
125   esco_coding_id_format_t output_coding_format;       /* Output coding format */
126   uint16_t input_coded_data_size;                     /* Input coded data size (in bits) */
127   uint16_t output_coded_data_size;                    /* Output coded data size (in bits) */
128   esco_pcm_data_format_t input_pcm_data_format;       /* Input PCM data format (see hcidefs.h) */
129   esco_pcm_data_format_t output_pcm_data_format;      /* Output PCM data format (see hcidefs.h) */
130   uint8_t input_pcm_payload_msb_position;             /* Input PCM sample payload MSB
131                                                          position */
132   uint8_t output_pcm_payload_msb_position;            /* Output PCM sample payload MSB
133                                                          position */
134   esco_data_path_t input_data_path;                   /* 0x00 - HCI, or 0x01-0xFE for VS) */
135   esco_data_path_t output_data_path;                  /* 0x00 - HCI, or 0x01-0xFE for VS) */
136   uint8_t input_transport_unit_size;                  /* Input transport unit size */
137   uint8_t output_transport_unit_size;                 /* Output transport unit size */
138   uint16_t max_latency_ms;                            /* Maximum latency (0x4-0xFFFE in msecs) */
139   esco_packet_types_t packet_types;                   /* Packet Types */
140   esco_retransmission_effort_t retransmission_effort; /* 0x00-0x02, 0xFF don't care */
141   esco_coding_format_t coding_format; /* Extra field to store codec when TX/RX is transparent */
142 } enh_esco_params_t;
143 
144 // Get the enhanced eSCO configuration parameters for the provided |codec|
145 enh_esco_params_t esco_parameters_for_codec(esco_codec_t codec, bool offload);
146