OSDN Git Service

Remove always true BTM_PWR_MGR_INCLUDED
[android-x86/system-bt.git] / stack / btm / btm_sco.c
1 /******************************************************************************
2  *
3  *  Copyright (C) 2000-2012 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 /******************************************************************************
20  *
21  *  This file contains functions that handle SCO connections. This includes
22  *  operations such as connect, disconnect, change supported packet types.
23  *
24  ******************************************************************************/
25
26 #include <string.h>
27 #include "bt_types.h"
28 #include "bt_target.h"
29 #include "gki.h"
30 #include "bt_types.h"
31 #include "hcimsgs.h"
32 #include "btu.h"
33 #include "btm_api.h"
34 #include "btm_int.h"
35 #include "hcidefs.h"
36 #include "bt_utils.h"
37
38 #if BTM_SCO_INCLUDED == TRUE
39
40 /********************************************************************************/
41 /*                 L O C A L    D A T A    D E F I N I T I O N S                */
42 /********************************************************************************/
43
44 #define SCO_ST_UNUSED           0
45 #define SCO_ST_LISTENING        1
46 #define SCO_ST_W4_CONN_RSP      2
47 #define SCO_ST_CONNECTING       3
48 #define SCO_ST_CONNECTED        4
49 #define SCO_ST_DISCONNECTING    5
50 #define SCO_ST_PEND_UNPARK      6
51 #define SCO_ST_PEND_ROLECHANGE  7
52
53 /********************************************************************************/
54 /*              L O C A L    F U N C T I O N     P R O T O T Y P E S            */
55 /********************************************************************************/
56
57 static const tBTM_ESCO_PARAMS btm_esco_defaults =
58 {
59     BTM_64KBITS_RATE,               /* TX Bandwidth (64 kbits/sec)              */
60     BTM_64KBITS_RATE,               /* RX Bandwidth (64 kbits/sec)              */
61     0x000a,                         /* 10 ms (HS/HF can use EV3, 2-EV3, 3-EV3)  */
62     0x0060,                         /* Inp Linear, Air CVSD, 2s Comp, 16bit     */
63     (BTM_SCO_PKT_TYPES_MASK_HV1 +   /* Packet Types                             */
64      BTM_SCO_PKT_TYPES_MASK_HV2 +
65      BTM_SCO_PKT_TYPES_MASK_HV3 +
66      BTM_SCO_PKT_TYPES_MASK_EV3 +
67      BTM_SCO_PKT_TYPES_MASK_EV4 +
68      BTM_SCO_PKT_TYPES_MASK_EV5),
69      BTM_ESCO_RETRANS_POWER        /* Retransmission Effort (Power)   */
70 };
71
72 /*******************************************************************************
73 **
74 ** Function         btm_sco_flush_sco_data
75 **
76 ** Description      This function is called to flush the SCO data for this channel.
77 **
78 ** Returns          void
79 **
80 *******************************************************************************/
81 void btm_sco_flush_sco_data(UINT16 sco_inx)
82 {
83 #if BTM_SCO_HCI_INCLUDED == TRUE
84 #if (BTM_MAX_SCO_LINKS>0)
85     tSCO_CONN   *p ;
86     BT_HDR      *p_buf;
87
88     if (sco_inx < BTM_MAX_SCO_LINKS)
89     {
90         p = &btm_cb.sco_cb.sco_db[sco_inx];
91         while (p->xmit_data_q.p_first)
92         {
93             if ((p_buf = (BT_HDR *)GKI_dequeue (&p->xmit_data_q)) != NULL)
94                 GKI_freebuf (p_buf);
95         }
96     }
97 #else
98     UNUSED(sco_inx);
99 #endif
100 #else
101     UNUSED(sco_inx);
102 #endif
103 }
104 /*******************************************************************************
105 **
106 ** Function         btm_sco_init
107 **
108 ** Description      This function is called at BTM startup to initialize
109 **
110 ** Returns          void
111 **
112 *******************************************************************************/
113 void btm_sco_init (void)
114 {
115 #if 0  /* cleared in btm_init; put back in if called from anywhere else! */
116     memset (&btm_cb.sco_cb, 0, sizeof(tSCO_CB));
117 #endif
118     /* Initialize nonzero defaults */
119     btm_cb.sco_cb.sco_disc_reason  = BTM_INVALID_SCO_DISC_REASON;
120
121     btm_cb.sco_cb.def_esco_parms = btm_esco_defaults; /* Initialize with defaults */
122     btm_cb.sco_cb.desired_sco_mode = BTM_DEFAULT_SCO_MODE;
123 }
124
125 /*******************************************************************************
126 **
127 ** Function         btm_esco_conn_rsp
128 **
129 ** Description      This function is called upon receipt of an (e)SCO connection
130 **                  request event (BTM_ESCO_CONN_REQ_EVT) to accept or reject
131 **                  the request. Parameters used to negotiate eSCO links.
132 **                  If p_parms is NULL, then default values are used.
133 **                  If the link type of the incoming request is SCO, then only
134 **                  the tx_bw, max_latency, content format, and packet_types are
135 **                  valid.  The hci_status parameter should be
136 **                  ([0x0] to accept, [0x0d..0x0f] to reject)
137 **
138 ** Returns          void
139 **
140 *******************************************************************************/
141 static void btm_esco_conn_rsp (UINT16 sco_inx, UINT8 hci_status, BD_ADDR bda,
142                                tBTM_ESCO_PARAMS *p_parms)
143 {
144 #if (BTM_MAX_SCO_LINKS>0)
145     tSCO_CONN        *p_sco = NULL;
146     tBTM_ESCO_PARAMS *p_setup;
147     UINT16            temp_pkt_types;
148
149     if (sco_inx < BTM_MAX_SCO_LINKS)
150         p_sco = &btm_cb.sco_cb.sco_db[sco_inx];
151
152     /* Reject the connect request if refused by caller or wrong state */
153     if (hci_status != HCI_SUCCESS || p_sco == NULL)
154     {
155         if (p_sco)
156         {
157             p_sco->state = (p_sco->state == SCO_ST_W4_CONN_RSP) ? SCO_ST_LISTENING
158                                                                 : SCO_ST_UNUSED;
159         }
160
161         if (!btm_cb.sco_cb.esco_supported)
162         {
163             if (!btsnd_hcic_reject_conn (bda, hci_status))
164             {
165                 BTM_TRACE_ERROR("Could not reject (e)SCO conn: No Buffer!!!");
166             }
167         }
168         else
169         {
170             if (!btsnd_hcic_reject_esco_conn (bda, hci_status))
171             {
172                 BTM_TRACE_ERROR("Could not reject (e)SCO conn: No Buffer!!!");
173             }
174         }
175     }
176     else    /* Connection is being accepted */
177     {
178         p_sco->state = SCO_ST_CONNECTING;
179         p_setup = &p_sco->esco.setup;
180         /* If parameters not specified use the default */
181         if (p_parms)
182             *p_setup = *p_parms;
183         else /* Use the last setup passed thru BTM_SetEscoMode (or defaults) */
184         {
185             *p_setup = btm_cb.sco_cb.def_esco_parms;
186         }
187
188         temp_pkt_types = (p_setup->packet_types &
189                           BTM_SCO_SUPPORTED_PKTS_MASK &
190                           btm_cb.btm_sco_pkt_types_supported);
191
192         /* Make sure at least one eSCO packet type is sent, else might confuse peer */
193         /* Taking this out to confirm with BQB tests
194         ** Real application would like to include this though, as many devices
195         ** do not retry with SCO only if an eSCO connection fails.
196         if (!(temp_pkt_types & BTM_ESCO_LINK_ONLY_MASK))
197         {
198             temp_pkt_types |= BTM_SCO_PKT_TYPES_MASK_EV3;
199         }
200         */
201         /* If SCO request, remove eSCO packet types (conformance) */
202         if (p_sco->esco.data.link_type == BTM_LINK_TYPE_SCO)
203         {
204             temp_pkt_types &= BTM_SCO_LINK_ONLY_MASK;
205             temp_pkt_types |= BTM_SCO_EXCEPTION_PKTS_MASK;
206         }
207         else
208         {
209             /* OR in any exception packet types */
210             temp_pkt_types |= ((p_setup->packet_types & BTM_SCO_EXCEPTION_PKTS_MASK) |
211                 (btm_cb.btm_sco_pkt_types_supported & BTM_SCO_EXCEPTION_PKTS_MASK));
212         }
213
214         if (btsnd_hcic_accept_esco_conn (bda, p_setup->tx_bw, p_setup->rx_bw,
215                                      p_setup->max_latency, p_setup->voice_contfmt,
216                                          p_setup->retrans_effort, temp_pkt_types))
217         {
218             p_setup->packet_types = temp_pkt_types;
219         }
220         else
221         {
222             BTM_TRACE_ERROR("Could not accept SCO conn: No Buffer!!!");
223         }
224     }
225 #endif
226 }
227
228
229 #if BTM_SCO_HCI_INCLUDED == TRUE
230 /*******************************************************************************
231 **
232 ** Function         btm_sco_check_send_pkts
233 **
234 ** Description      This function is called to check if it can send packets
235 **                  to the Host Controller.
236 **
237 ** Returns          void
238 **
239 *******************************************************************************/
240 void btm_sco_check_send_pkts (UINT16 sco_inx)
241 {
242     BT_HDR  *p_buf;
243     tSCO_CB  *p_cb = &btm_cb.sco_cb;
244     tSCO_CONN   *p_ccb = &p_cb->sco_db[sco_inx];
245
246     /* If there is data to send, send it now */
247     while (p_ccb->xmit_data_q.p_first != NULL)
248     {
249         p_buf = NULL;
250
251 #if BTM_SCO_HCI_DEBUG
252         BTM_TRACE_DEBUG ("btm: [%d] buf in xmit_data_q", p_ccb->xmit_data_q.count );
253 #endif
254         p_buf = (BT_HDR *)GKI_dequeue (&p_ccb->xmit_data_q);
255
256         HCI_SCO_DATA_TO_LOWER (p_buf);
257     }
258 }
259 #endif /* BTM_SCO_HCI_INCLUDED == TRUE */
260
261 /*******************************************************************************
262 **
263 ** Function         btm_route_sco_data
264 **
265 ** Description      Route received SCO data.
266 **
267 ** Returns          void
268 **
269 *******************************************************************************/
270 void  btm_route_sco_data(BT_HDR *p_msg)
271 {
272 #if BTM_SCO_HCI_INCLUDED == TRUE
273     UINT16      sco_inx, handle;
274     UINT8       *p = (UINT8 *)(p_msg + 1) + p_msg->offset;
275     UINT8       pkt_size = 0;
276     UINT8       pkt_status = 0;
277
278     /* Extract Packet_Status_Flag and handle */
279     STREAM_TO_UINT16 (handle, p);
280     pkt_status = HCID_GET_EVENT(handle);
281     handle   = HCID_GET_HANDLE (handle);
282
283     STREAM_TO_UINT8 (pkt_size, p);
284
285     if ((sco_inx = btm_find_scb_by_handle(handle)) != BTM_MAX_SCO_LINKS )
286     {
287         /* send data callback */
288         if (!btm_cb.sco_cb.p_data_cb )
289             /* if no data callback registered,  just free the buffer  */
290             GKI_freebuf (p_msg);
291         else
292         {
293             (*btm_cb.sco_cb.p_data_cb)(sco_inx, p_msg, (tBTM_SCO_DATA_FLAG) pkt_status);
294         }
295     }
296     else /* no mapping handle SCO connection is active, free the buffer */
297     {
298         GKI_freebuf (p_msg);
299     }
300 #else
301     GKI_freebuf(p_msg);
302 #endif
303 }
304
305 /*******************************************************************************
306 **
307 ** Function         BTM_WriteScoData
308 **
309 ** Description      This function write SCO data to a specified instance. The data
310 **                  to be written p_buf needs to carry an offset of
311 **                  HCI_SCO_PREAMBLE_SIZE bytes, and the data length can not
312 **                  exceed BTM_SCO_DATA_SIZE_MAX bytes, whose default value is set
313 **                  to 60 and is configurable. Data longer than the maximum bytes
314 **                  will be truncated.
315 **
316 ** Returns          BTM_SUCCESS: data write is successful
317 **                  BTM_ILLEGAL_VALUE: SCO data contains illegal offset value.
318 **                  BTM_SCO_BAD_LENGTH: SCO data length exceeds the max SCO packet
319 **                                      size.
320 **                  BTM_NO_RESOURCES: no resources.
321 **                  BTM_UNKNOWN_ADDR: unknown SCO connection handle, or SCO is not
322 **                                    routed via HCI.
323 **
324 **
325 *******************************************************************************/
326 tBTM_STATUS BTM_WriteScoData (UINT16 sco_inx, BT_HDR *p_buf)
327 {
328 #if (BTM_SCO_HCI_INCLUDED == TRUE) && (BTM_MAX_SCO_LINKS>0)
329     tSCO_CONN   *p_ccb = &btm_cb.sco_cb.sco_db[sco_inx];
330     UINT8   *p;
331     tBTM_STATUS     status = BTM_SUCCESS;
332
333     if (sco_inx < BTM_MAX_SCO_LINKS && btm_cb.sco_cb.p_data_cb &&
334         p_ccb->state == SCO_ST_CONNECTED)
335     {
336         /* Ensure we have enough space in the buffer for the SCO and HCI headers */
337         if (p_buf->offset < HCI_SCO_PREAMBLE_SIZE)
338         {
339             BTM_TRACE_ERROR ("BTM SCO - cannot send buffer, offset: %d", p_buf->offset);
340             GKI_freebuf (p_buf);
341             status = BTM_ILLEGAL_VALUE;
342         }
343         else    /* write HCI header */
344         {
345             /* Step back 3 bytes to add the headers */
346             p_buf->offset -= HCI_SCO_PREAMBLE_SIZE;
347             /* Set the pointer to the beginning of the data */
348             p = (UINT8 *)(p_buf + 1) + p_buf->offset;
349             /* add HCI handle */
350             UINT16_TO_STREAM (p, p_ccb->hci_handle);
351             /* only sent the first BTM_SCO_DATA_SIZE_MAX bytes data if more than max,
352                and set warning status */
353             if (p_buf->len > BTM_SCO_DATA_SIZE_MAX)
354             {
355                 p_buf->len = BTM_SCO_DATA_SIZE_MAX;
356                 status = BTM_SCO_BAD_LENGTH;
357             }
358
359             UINT8_TO_STREAM (p, (UINT8)p_buf->len);
360             p_buf->len += HCI_SCO_PREAMBLE_SIZE;
361
362             GKI_enqueue (&p_ccb->xmit_data_q, p_buf);
363
364             btm_sco_check_send_pkts (sco_inx);
365         }
366     }
367     else
368     {
369         GKI_freebuf(p_buf);
370
371         BTM_TRACE_WARNING ("BTM_WriteScoData, invalid sco index: %d at state [%d]",
372             sco_inx, btm_cb.sco_cb.sco_db[sco_inx].state);
373         status = BTM_UNKNOWN_ADDR;
374     }
375
376     return (status);
377
378 #else
379     UNUSED(sco_inx);
380     UNUSED(p_buf);
381     return (BTM_NO_RESOURCES);
382 #endif
383 }
384
385 #if (BTM_MAX_SCO_LINKS>0)
386 /*******************************************************************************
387 **
388 ** Function         btm_send_connect_request
389 **
390 ** Description      This function is called to respond to SCO connect indications
391 **
392 ** Returns          void
393 **
394 *******************************************************************************/
395 static tBTM_STATUS btm_send_connect_request(UINT16 acl_handle,
396                                             tBTM_ESCO_PARAMS *p_setup)
397 {
398     UINT16 temp_pkt_types;
399     UINT8 xx;
400     tACL_CONN *p_acl;
401
402     /* Send connect request depending on version of spec */
403     if (!btm_cb.sco_cb.esco_supported)
404     {
405         if (!btsnd_hcic_add_SCO_conn (acl_handle, BTM_ESCO_2_SCO(p_setup->packet_types)))
406             return (BTM_NO_RESOURCES);
407     }
408     else
409     {
410         temp_pkt_types = (p_setup->packet_types & BTM_SCO_SUPPORTED_PKTS_MASK &
411                              btm_cb.btm_sco_pkt_types_supported);
412
413         /* OR in any exception packet types */
414         temp_pkt_types |= ((p_setup->packet_types & BTM_SCO_EXCEPTION_PKTS_MASK) |
415             (btm_cb.btm_sco_pkt_types_supported & BTM_SCO_EXCEPTION_PKTS_MASK));
416
417         /* Finally, remove EDR eSCO if the remote device doesn't support it */
418         /* UPF25:  Only SCO was brought up in this case */
419         btm_handle_to_acl_index(acl_handle);
420         if ((xx = btm_handle_to_acl_index(acl_handle)) < MAX_L2CAP_LINKS)
421         {
422             p_acl = &btm_cb.acl_db[xx];
423             if (!HCI_EDR_ESCO_2MPS_SUPPORTED(p_acl->peer_lmp_features[HCI_EXT_FEATURES_PAGE_0]))
424             {
425
426                 BTM_TRACE_WARNING("BTM Remote does not support 2-EDR eSCO");
427                 temp_pkt_types |= (HCI_ESCO_PKT_TYPES_MASK_NO_2_EV3 |
428                                    HCI_ESCO_PKT_TYPES_MASK_NO_2_EV5);
429             }
430             if (!HCI_EDR_ESCO_3MPS_SUPPORTED(p_acl->peer_lmp_features[HCI_EXT_FEATURES_PAGE_0]))
431             {
432
433                 BTM_TRACE_WARNING("BTM Remote does not support 3-EDR eSCO");
434                 temp_pkt_types |= (HCI_ESCO_PKT_TYPES_MASK_NO_3_EV3 |
435                                    HCI_ESCO_PKT_TYPES_MASK_NO_3_EV5);
436             }
437         }
438
439
440         BTM_TRACE_API("      txbw 0x%x, rxbw 0x%x, lat 0x%x, voice 0x%x, retrans 0x%02x, pkt 0x%04x",
441             p_setup->tx_bw, p_setup->rx_bw,
442             p_setup->max_latency, p_setup->voice_contfmt,
443             p_setup->retrans_effort, temp_pkt_types);
444
445         if (!btsnd_hcic_setup_esco_conn(acl_handle,
446                                         p_setup->tx_bw,
447                                         p_setup->rx_bw,
448                                         p_setup->max_latency,
449                                         p_setup->voice_contfmt,
450                                         p_setup->retrans_effort,
451                                         temp_pkt_types))
452             return (BTM_NO_RESOURCES);
453         else
454             p_setup->packet_types = temp_pkt_types;
455     }
456
457     return (BTM_CMD_STARTED);
458 }
459 #endif
460
461 /*******************************************************************************
462 **
463 ** Function         btm_set_sco_ind_cback
464 **
465 ** Description      This function is called to register for TCS SCO connect
466 **                  indications.
467 **
468 ** Returns          void
469 **
470 *******************************************************************************/
471 void btm_set_sco_ind_cback( tBTM_SCO_IND_CBACK *sco_ind_cb )
472 {
473     btm_cb.sco_cb.app_sco_ind_cb = sco_ind_cb;
474 }
475
476 /*******************************************************************************
477 **
478 ** Function         btm_accept_sco_link
479 **
480 ** Description      This function is called to respond to TCS SCO connect
481 **                  indications
482 **
483 ** Returns          void
484 **
485 *******************************************************************************/
486 void btm_accept_sco_link(UINT16 sco_inx, tBTM_ESCO_PARAMS *p_setup,
487                          tBTM_SCO_CB *p_conn_cb, tBTM_SCO_CB *p_disc_cb)
488 {
489 #if (BTM_MAX_SCO_LINKS>0)
490     tSCO_CONN        *p_sco;
491
492     if (sco_inx >= BTM_MAX_SCO_LINKS)
493     {
494         BTM_TRACE_ERROR("btm_accept_sco_link: Invalid sco_inx(%d)", sco_inx);
495         return;
496     }
497
498     /* Link role is ignored in for this message */
499     p_sco = &btm_cb.sco_cb.sco_db[sco_inx];
500     p_sco->p_conn_cb = p_conn_cb;
501     p_sco->p_disc_cb = p_disc_cb;
502     p_sco->esco.data.link_type = BTM_LINK_TYPE_ESCO; /* Accept with all supported types */
503
504     BTM_TRACE_DEBUG("TCS accept SCO: Packet Types 0x%04x", p_setup->packet_types);
505
506     btm_esco_conn_rsp(sco_inx, HCI_SUCCESS, p_sco->esco.data.bd_addr, p_setup);
507 #else
508     btm_reject_sco_link(sco_inx);
509 #endif
510 }
511
512 /*******************************************************************************
513 **
514 ** Function         btm_reject_sco_link
515 **
516 ** Description      This function is called to respond to SCO connect indications
517 **
518 ** Returns          void
519 **
520 *******************************************************************************/
521 void btm_reject_sco_link( UINT16 sco_inx )
522 {
523     btm_esco_conn_rsp(sco_inx, HCI_ERR_HOST_REJECT_RESOURCES,
524                       btm_cb.sco_cb.sco_db[sco_inx].esco.data.bd_addr, NULL);
525 }
526
527 /*******************************************************************************
528 **
529 ** Function         BTM_CreateSco
530 **
531 ** Description      This function is called to create an SCO connection. If the
532 **                  "is_orig" flag is TRUE, the connection will be originated,
533 **                  otherwise BTM will wait for the other side to connect.
534 **
535 **                  NOTE:  If BTM_IGNORE_SCO_PKT_TYPE is passed in the pkt_types
536 **                      parameter the default packet types is used.
537 **
538 ** Returns          BTM_UNKNOWN_ADDR if the ACL connection is not up
539 **                  BTM_BUSY         if another SCO being set up to
540 **                                   the same BD address
541 **                  BTM_NO_RESOURCES if the max SCO limit has been reached
542 **                  BTM_CMD_STARTED  if the connection establishment is started.
543 **                                   In this case, "*p_sco_inx" is filled in
544 **                                   with the sco index used for the connection.
545 **
546 *******************************************************************************/
547 tBTM_STATUS BTM_CreateSco (BD_ADDR remote_bda, BOOLEAN is_orig, UINT16 pkt_types,
548                            UINT16 *p_sco_inx, tBTM_SCO_CB *p_conn_cb,
549                            tBTM_SCO_CB *p_disc_cb)
550 {
551 #if (BTM_MAX_SCO_LINKS > 0)
552     tBTM_ESCO_PARAMS *p_setup;
553     tSCO_CONN        *p = &btm_cb.sco_cb.sco_db[0];
554     UINT16            xx;
555     UINT16            acl_handle = 0;
556     UINT16            temp_pkt_types;
557     tACL_CONN        *p_acl;
558
559 #if (BTM_SCO_WAKE_PARKED_LINK == TRUE)
560     tBTM_PM_MODE      md;
561     tBTM_PM_PWR_MD    pm;
562 #else  // BTM_SCO_WAKE_PARKED_LINK
563     UINT8             mode;
564 #endif  // BTM_SCO_WAKE_PARKED_LINK
565
566     *p_sco_inx = BTM_INVALID_SCO_INDEX;
567
568     /* If originating, ensure that there is an ACL connection to the BD Address */
569     if (is_orig)
570     {
571         if ((!remote_bda) || ((acl_handle = BTM_GetHCIConnHandle (remote_bda, BT_TRANSPORT_BR_EDR)) == 0xFFFF))
572             return (BTM_UNKNOWN_ADDR);
573     }
574
575     if (remote_bda)
576     {
577         /* If any SCO is being established to the remote BD address, refuse this */
578         for (xx = 0; xx < BTM_MAX_SCO_LINKS; xx++, p++)
579         {
580             if (((p->state == SCO_ST_CONNECTING) || (p->state == SCO_ST_LISTENING)
581                 || (p->state == SCO_ST_PEND_UNPARK))
582                 && (!memcmp (p->esco.data.bd_addr, remote_bda, BD_ADDR_LEN)))
583             {
584                 return (BTM_BUSY);
585             }
586         }
587     }
588     else
589     {
590         /* Support only 1 wildcard BD address at a time */
591         for (xx = 0; xx < BTM_MAX_SCO_LINKS; xx++, p++)
592         {
593             if ((p->state == SCO_ST_LISTENING) && (!p->rem_bd_known))
594                 return (BTM_BUSY);
595         }
596     }
597
598     /* Now, try to find an unused control block, and kick off the SCO establishment */
599     for (xx = 0, p = &btm_cb.sco_cb.sco_db[0]; xx < BTM_MAX_SCO_LINKS; xx++, p++)
600     {
601         if (p->state == SCO_ST_UNUSED)
602         {
603             if (remote_bda)
604             {
605                 if (is_orig)
606                 {
607                     /* can not create SCO link if in park mode */
608 #if BTM_SCO_WAKE_PARKED_LINK == TRUE
609                     if(BTM_ReadPowerMode(remote_bda, &md) == BTM_SUCCESS)
610                     {
611                         if (md == BTM_PM_MD_PARK || md == BTM_PM_MD_SNIFF)
612                         {
613                             memset( (void*)&pm, 0, sizeof(pm));
614                             pm.mode = BTM_PM_MD_ACTIVE;
615                             BTM_SetPowerMode(BTM_PM_SET_ONLY_ID, remote_bda, &pm);
616                             p->state = SCO_ST_PEND_UNPARK;
617                         }
618                     }
619 #else  // BTM_SCO_WAKE_PARKED_LINK
620                     if( (BTM_ReadPowerMode(remote_bda, &mode) == BTM_SUCCESS) && (mode == BTM_PM_MD_PARK) )
621                         return (BTM_WRONG_MODE);
622 #endif  // BTM_SCO_WAKE_PARKED_LINK
623                 }
624                 memcpy (p->esco.data.bd_addr, remote_bda, BD_ADDR_LEN);
625                 p->rem_bd_known = TRUE;
626             }
627             else
628                 p->rem_bd_known = FALSE;
629
630             /* Link role is ignored in for this message */
631             if (pkt_types == BTM_IGNORE_SCO_PKT_TYPE)
632                 pkt_types = btm_cb.sco_cb.def_esco_parms.packet_types;
633
634             p_setup = &p->esco.setup;
635             *p_setup = btm_cb.sco_cb.def_esco_parms;
636             p_setup->packet_types = (btm_cb.sco_cb.desired_sco_mode == BTM_LINK_TYPE_SCO)
637                 ? (pkt_types & BTM_SCO_LINK_ONLY_MASK) : pkt_types;
638
639             temp_pkt_types = (p_setup->packet_types & BTM_SCO_SUPPORTED_PKTS_MASK &
640                              btm_cb.btm_sco_pkt_types_supported);
641
642             /* OR in any exception packet types */
643             if (btm_cb.sco_cb.desired_sco_mode == HCI_LINK_TYPE_ESCO)
644             {
645                 temp_pkt_types |= ((p_setup->packet_types & BTM_SCO_EXCEPTION_PKTS_MASK) |
646                     (btm_cb.btm_sco_pkt_types_supported & BTM_SCO_EXCEPTION_PKTS_MASK));
647             }
648             else    /* Only using SCO packet types; turn off EDR also */
649             {
650                 temp_pkt_types |= BTM_SCO_EXCEPTION_PKTS_MASK;
651             }
652
653             p_setup->packet_types = temp_pkt_types;
654             p->p_conn_cb  = p_conn_cb;
655             p->p_disc_cb  = p_disc_cb;
656             p->hci_handle = BTM_INVALID_HCI_HANDLE;
657             p->is_orig = is_orig;
658
659             if( p->state != SCO_ST_PEND_UNPARK )
660             {
661                 if (is_orig)
662                 {
663                     /* If role change is in progress, do not proceed with SCO setup
664                      * Wait till role change is complete */
665                     p_acl = btm_bda_to_acl(remote_bda, BT_TRANSPORT_BR_EDR);
666                     if (p_acl && p_acl->switch_role_state != BTM_ACL_SWKEY_STATE_IDLE)
667                     {
668                         BTM_TRACE_API("Role Change is in progress for ACL handle 0x%04x",acl_handle);
669                         p->state = SCO_ST_PEND_ROLECHANGE;
670
671                     }
672                 }
673             }
674
675             if( p->state != SCO_ST_PEND_UNPARK && p->state != SCO_ST_PEND_ROLECHANGE )
676             {
677                 if (is_orig)
678                 {
679                     BTM_TRACE_API("BTM_CreateSco -> (e)SCO Link for ACL handle 0x%04x, Desired Type %d",
680                                     acl_handle, btm_cb.sco_cb.desired_sco_mode);
681
682                     if ((btm_send_connect_request(acl_handle, p_setup)) != BTM_CMD_STARTED)
683                         return (BTM_NO_RESOURCES);
684
685                     p->state = SCO_ST_CONNECTING;
686                 }
687                 else
688                     p->state = SCO_ST_LISTENING;
689             }
690
691             *p_sco_inx = xx;
692
693             return (BTM_CMD_STARTED);
694         }
695     }
696
697 #endif
698     /* If here, all SCO blocks in use */
699     return (BTM_NO_RESOURCES);
700 }
701
702 #if (BTM_SCO_WAKE_PARKED_LINK == TRUE)
703 /*******************************************************************************
704 **
705 ** Function         btm_sco_chk_pend_unpark
706 **
707 ** Description      This function is called by BTIF when there is a mode change
708 **                  event to see if there are SCO commands waiting for the unpark.
709 **
710 ** Returns          void
711 **
712 *******************************************************************************/
713 void btm_sco_chk_pend_unpark (UINT8 hci_status, UINT16 hci_handle)
714 {
715 #if (BTM_MAX_SCO_LINKS>0)
716     UINT16      xx;
717     UINT16      acl_handle;
718     tSCO_CONN   *p = &btm_cb.sco_cb.sco_db[0];
719
720     for (xx = 0; xx < BTM_MAX_SCO_LINKS; xx++, p++)
721     {
722         if ((p->state == SCO_ST_PEND_UNPARK) &&
723             ((acl_handle = BTM_GetHCIConnHandle (p->esco.data.bd_addr, BT_TRANSPORT_BR_EDR)) == hci_handle))
724
725         {
726             BTM_TRACE_API("btm_sco_chk_pend_unpark -> (e)SCO Link for ACL handle 0x%04x, Desired Type %d, hci_status 0x%02x",
727                                     acl_handle, btm_cb.sco_cb.desired_sco_mode, hci_status);
728
729             if ((btm_send_connect_request(acl_handle, &p->esco.setup)) == BTM_CMD_STARTED)
730                 p->state = SCO_ST_CONNECTING;
731         }
732     }
733 #endif  // BTM_MAX_SCO_LINKS
734 }
735 #endif  // BTM_SCO_WAKE_PARKED_LINK
736
737 /*******************************************************************************
738 **
739 ** Function         btm_sco_chk_pend_rolechange
740 **
741 ** Description      This function is called by BTIF when there is a role change
742 **                  event to see if there are SCO commands waiting for the role change.
743 **
744 ** Returns          void
745 **
746 *******************************************************************************/
747 void btm_sco_chk_pend_rolechange (UINT16 hci_handle)
748 {
749 #if (BTM_MAX_SCO_LINKS>0)
750     UINT16      xx;
751     UINT16      acl_handle;
752     tSCO_CONN   *p = &btm_cb.sco_cb.sco_db[0];
753
754     for (xx = 0; xx < BTM_MAX_SCO_LINKS; xx++, p++)
755     {
756         if ((p->state == SCO_ST_PEND_ROLECHANGE) &&
757             ((acl_handle = BTM_GetHCIConnHandle (p->esco.data.bd_addr, BT_TRANSPORT_BR_EDR)) == hci_handle))
758
759         {
760             BTM_TRACE_API("btm_sco_chk_pend_rolechange -> (e)SCO Link for ACL handle 0x%04x", acl_handle);
761
762             if ((btm_send_connect_request(acl_handle, &p->esco.setup)) == BTM_CMD_STARTED)
763                 p->state = SCO_ST_CONNECTING;
764         }
765     }
766 #endif
767 }
768
769 /*******************************************************************************
770 **
771 ** Function         btm_sco_conn_req
772 **
773 ** Description      This function is called by BTIF when an SCO connection
774 **                  request is received from a remote.
775 **
776 ** Returns          void
777 **
778 *******************************************************************************/
779 void btm_sco_conn_req (BD_ADDR bda,  DEV_CLASS dev_class, UINT8 link_type)
780 {
781 #if (BTM_MAX_SCO_LINKS>0)
782     tSCO_CB     *p_sco = &btm_cb.sco_cb;
783     tSCO_CONN   *p = &p_sco->sco_db[0];
784     UINT16      xx;
785     tBTM_ESCO_CONN_REQ_EVT_DATA evt_data;
786
787     for (xx = 0; xx < BTM_MAX_SCO_LINKS; xx++, p++)
788     {
789         /*
790          * If the sco state is in the SCO_ST_CONNECTING state, we still need
791          * to return accept sco to avoid race conditon for sco creation
792          */
793         int rem_bd_matches = p->rem_bd_known &&
794           !memcmp (p->esco.data.bd_addr, bda, BD_ADDR_LEN);
795         if (((p->state == SCO_ST_CONNECTING) && rem_bd_matches) ||
796             ((p->state == SCO_ST_LISTENING) && (rem_bd_matches || !p->rem_bd_known)))
797         {
798             /* If this guy was a wildcard, he is not one any more */
799             p->rem_bd_known = TRUE;
800             p->esco.data.link_type = link_type;
801             p->state = SCO_ST_W4_CONN_RSP;
802             memcpy (p->esco.data.bd_addr, bda, BD_ADDR_LEN);
803
804             /* If no callback, auto-accept the connection if packet types match */
805             if (!p->esco.p_esco_cback)
806             {
807                 /* If requesting eSCO reject if default parameters are SCO only */
808                 if ((link_type == BTM_LINK_TYPE_ESCO
809                     && !(p_sco->def_esco_parms.packet_types & BTM_ESCO_LINK_ONLY_MASK)
810                     && ((p_sco->def_esco_parms.packet_types & BTM_SCO_EXCEPTION_PKTS_MASK)
811                        == BTM_SCO_EXCEPTION_PKTS_MASK))
812
813                     /* Reject request if SCO is desired but no SCO packets delected */
814                     || (link_type == BTM_LINK_TYPE_SCO
815                     && !(p_sco->def_esco_parms.packet_types & BTM_SCO_LINK_ONLY_MASK)))
816                 {
817                     btm_esco_conn_rsp(xx, HCI_ERR_HOST_REJECT_RESOURCES, bda, NULL);
818                 }
819                 else    /* Accept the request */
820                 {
821                     btm_esco_conn_rsp(xx, HCI_SUCCESS, bda, NULL);
822                 }
823             }
824             else    /* Notify upper layer of connect indication */
825             {
826                 memcpy(evt_data.bd_addr, bda, BD_ADDR_LEN);
827                 memcpy(evt_data.dev_class, dev_class, DEV_CLASS_LEN);
828                 evt_data.link_type = link_type;
829                 evt_data.sco_inx = xx;
830                 p->esco.p_esco_cback(BTM_ESCO_CONN_REQ_EVT, (tBTM_ESCO_EVT_DATA *)&evt_data);
831             }
832
833             return;
834         }
835     }
836
837     /* TCS usage */
838     if (btm_cb.sco_cb.app_sco_ind_cb)
839     {
840         /* Now, try to find an unused control block */
841         for (xx = 0, p = &btm_cb.sco_cb.sco_db[0]; xx < BTM_MAX_SCO_LINKS; xx++, p++)
842         {
843             if (p->state == SCO_ST_UNUSED)
844             {
845                 p->is_orig = FALSE;
846                 p->state = SCO_ST_LISTENING;
847
848                 p->esco.data.link_type = link_type;
849                 memcpy (p->esco.data.bd_addr, bda, BD_ADDR_LEN);
850                 p->rem_bd_known = TRUE;
851                 break;
852             }
853         }
854         if( xx < BTM_MAX_SCO_LINKS)
855         {
856             btm_cb.sco_cb.app_sco_ind_cb(xx);
857             return;
858         }
859     }
860
861 #endif
862     /* If here, no one wants the SCO connection. Reject it */
863     BTM_TRACE_WARNING("btm_sco_conn_req: No one wants this SCO connection; rejecting it");
864     btm_esco_conn_rsp(BTM_MAX_SCO_LINKS, HCI_ERR_HOST_REJECT_RESOURCES, bda, NULL);
865 }
866
867 /*******************************************************************************
868 **
869 ** Function         btm_sco_connected
870 **
871 ** Description      This function is called by BTIF when an (e)SCO connection
872 **                  is connected.
873 **
874 ** Returns          void
875 **
876 *******************************************************************************/
877 void btm_sco_connected (UINT8 hci_status, BD_ADDR bda, UINT16 hci_handle,
878                         tBTM_ESCO_DATA *p_esco_data)
879 {
880 #if (BTM_MAX_SCO_LINKS>0)
881     tSCO_CONN   *p = &btm_cb.sco_cb.sco_db[0];
882     UINT16      xx;
883     BOOLEAN     spt = FALSE;
884     tBTM_CHG_ESCO_PARAMS parms;
885 #endif
886
887     btm_cb.sco_cb.sco_disc_reason = hci_status;
888
889 #if (BTM_MAX_SCO_LINKS>0)
890     for (xx = 0; xx < BTM_MAX_SCO_LINKS; xx++, p++)
891     {
892         if (((p->state == SCO_ST_CONNECTING) ||
893              (p->state == SCO_ST_LISTENING)  ||
894              (p->state == SCO_ST_W4_CONN_RSP))
895          && (p->rem_bd_known)
896          && (!bda || !memcmp (p->esco.data.bd_addr, bda, BD_ADDR_LEN)))
897         {
898             if (hci_status != HCI_SUCCESS)
899             {
900                 /* Report the error if originator, otherwise remain in Listen mode */
901                 if (p->is_orig)
902                 {
903                     /* If role switch is pending, we need try again after role switch is complete */
904                     if(hci_status == HCI_ERR_ROLE_SWITCH_PENDING)
905                     {
906                         BTM_TRACE_API("Role Change pending for HCI handle 0x%04x",hci_handle);
907                         p->state = SCO_ST_PEND_ROLECHANGE;
908                     }
909                     /* avoid calling disconnect callback because of sco creation race */
910                     else if (hci_status != HCI_ERR_LMP_ERR_TRANS_COLLISION)
911                     {
912                         p->state = SCO_ST_UNUSED;
913                         (*p->p_disc_cb)(xx);
914                     }
915                 }
916                 else
917                 {
918                     /* Notify the upper layer that incoming sco connection has failed. */
919                     if (p->state == SCO_ST_CONNECTING)
920                     {
921                         p->state = SCO_ST_UNUSED;
922                         (*p->p_disc_cb)(xx);
923                     }
924                     else
925                         p->state = SCO_ST_LISTENING;
926                 }
927
928                 return;
929             }
930
931             if (p->state == SCO_ST_LISTENING)
932                 spt = TRUE;
933
934             p->state = SCO_ST_CONNECTED;
935             p->hci_handle = hci_handle;
936
937             if (!btm_cb.sco_cb.esco_supported)
938             {
939                 p->esco.data.link_type = BTM_LINK_TYPE_SCO;
940                 if (spt)
941                 {
942                     parms.packet_types = p->esco.setup.packet_types;
943                     /* Keep the other parameters the same for SCO */
944                     parms.max_latency = p->esco.setup.max_latency;
945                     parms.retrans_effort = p->esco.setup.retrans_effort;
946
947                     BTM_ChangeEScoLinkParms(xx, &parms);
948                 }
949             }
950             else
951             {
952                 if (p_esco_data)
953                     p->esco.data = *p_esco_data;
954             }
955
956             (*p->p_conn_cb)(xx);
957
958             return;
959         }
960     }
961 #endif
962 }
963
964
965 /*******************************************************************************
966 **
967 ** Function         btm_find_scb_by_handle
968 **
969 ** Description      Look through all active SCO connection for a match based on the
970 **                  HCI handle.
971 **
972 ** Returns          index to matched SCO connection CB, or BTM_MAX_SCO_LINKS if
973 **                  no match.
974 **
975 *******************************************************************************/
976 UINT16  btm_find_scb_by_handle (UINT16 handle)
977 {
978     int         xx;
979     tSCO_CONN    *p = &btm_cb.sco_cb.sco_db[0];
980
981     for (xx = 0; xx < BTM_MAX_SCO_LINKS; xx++, p++)
982     {
983         if ((p->state == SCO_ST_CONNECTED) && (p->hci_handle == handle))
984         {
985             return (xx);
986         }
987     }
988
989     /* If here, no match found */
990     return (xx);
991 }
992
993 /*******************************************************************************
994 **
995 ** Function         BTM_RemoveSco
996 **
997 ** Description      This function is called to remove a specific SCO connection.
998 **
999 ** Returns          status of the operation
1000 **
1001 *******************************************************************************/
1002 tBTM_STATUS BTM_RemoveSco (UINT16 sco_inx)
1003 {
1004 #if (BTM_MAX_SCO_LINKS>0)
1005     tSCO_CONN   *p = &btm_cb.sco_cb.sco_db[sco_inx];
1006     UINT16       tempstate;
1007
1008     /* Validity check */
1009     if ((sco_inx >= BTM_MAX_SCO_LINKS) || (p->state == SCO_ST_UNUSED))
1010         return (BTM_UNKNOWN_ADDR);
1011
1012     /* If no HCI handle, simply drop the connection and return */
1013     if (p->hci_handle == BTM_INVALID_HCI_HANDLE || p->state == SCO_ST_PEND_UNPARK)
1014     {
1015         p->hci_handle = BTM_INVALID_HCI_HANDLE;
1016         p->state = SCO_ST_UNUSED;
1017         p->esco.p_esco_cback = NULL;    /* Deregister the eSCO event callback */
1018         return (BTM_SUCCESS);
1019     }
1020
1021     tempstate = p->state;
1022     p->state = SCO_ST_DISCONNECTING;
1023
1024     if (!btsnd_hcic_disconnect (p->hci_handle, HCI_ERR_PEER_USER))
1025     {
1026         p->state = tempstate;
1027         return (BTM_NO_RESOURCES);
1028     }
1029
1030     return (BTM_CMD_STARTED);
1031 #else
1032     return (BTM_NO_RESOURCES);
1033 #endif
1034 }
1035
1036 /*******************************************************************************
1037 **
1038 ** Function         btm_remove_sco_links
1039 **
1040 ** Description      This function is called to remove all sco links for an ACL link.
1041 **
1042 ** Returns          void
1043 **
1044 *******************************************************************************/
1045 void btm_remove_sco_links (BD_ADDR bda)
1046 {
1047 #if (BTM_MAX_SCO_LINKS>0)
1048     tSCO_CONN   *p = &btm_cb.sco_cb.sco_db[0];
1049     UINT16       xx;
1050
1051     for (xx = 0; xx < BTM_MAX_SCO_LINKS; xx++, p++)
1052     {
1053         if (p->rem_bd_known && (!memcmp (p->esco.data.bd_addr, bda, BD_ADDR_LEN)))
1054         {
1055             BTM_RemoveSco(xx);
1056         }
1057     }
1058 #endif
1059 }
1060
1061 /*******************************************************************************
1062 **
1063 ** Function         btm_sco_removed
1064 **
1065 ** Description      This function is called by BTIF when an SCO connection
1066 **                  is removed.
1067 **
1068 ** Returns          void
1069 **
1070 *******************************************************************************/
1071 void btm_sco_removed (UINT16 hci_handle, UINT8 reason)
1072 {
1073 #if (BTM_MAX_SCO_LINKS>0)
1074     tSCO_CONN   *p = &btm_cb.sco_cb.sco_db[0];
1075     UINT16      xx;
1076 #endif
1077
1078     btm_cb.sco_cb.sco_disc_reason = reason;
1079
1080 #if (BTM_MAX_SCO_LINKS>0)
1081     p = &btm_cb.sco_cb.sco_db[0];
1082     for (xx = 0; xx < BTM_MAX_SCO_LINKS; xx++, p++)
1083     {
1084         if ((p->state != SCO_ST_UNUSED) && (p->state != SCO_ST_LISTENING) && (p->hci_handle == hci_handle))
1085         {
1086             btm_sco_flush_sco_data(xx);
1087
1088             p->state = SCO_ST_UNUSED;
1089             p->hci_handle = BTM_INVALID_HCI_HANDLE;
1090             p->rem_bd_known = FALSE;
1091             p->esco.p_esco_cback = NULL;    /* Deregister eSCO callback */
1092             (*p->p_disc_cb)(xx);
1093
1094             return;
1095         }
1096     }
1097 #endif
1098 }
1099
1100
1101 /*******************************************************************************
1102 **
1103 ** Function         btm_sco_acl_removed
1104 **
1105 ** Description      This function is called when an ACL connection is
1106 **                  removed. If the BD address is NULL, it is assumed that
1107 **                  the local device is down, and all SCO links are removed.
1108 **                  If a specific BD address is passed, only SCO connections
1109 **                  to that BD address are removed.
1110 **
1111 ** Returns          void
1112 **
1113 *******************************************************************************/
1114 void btm_sco_acl_removed (BD_ADDR bda)
1115 {
1116 #if (BTM_MAX_SCO_LINKS>0)
1117     tSCO_CONN   *p = &btm_cb.sco_cb.sco_db[0];
1118     UINT16      xx;
1119
1120     for (xx = 0; xx < BTM_MAX_SCO_LINKS; xx++, p++)
1121     {
1122         if (p->state != SCO_ST_UNUSED)
1123         {
1124             if ((!bda) || (!memcmp (p->esco.data.bd_addr, bda, BD_ADDR_LEN) && p->rem_bd_known))
1125             {
1126                 btm_sco_flush_sco_data(xx);
1127
1128                 p->state = SCO_ST_UNUSED;
1129                 p->esco.p_esco_cback = NULL;    /* Deregister eSCO callback */
1130                 (*p->p_disc_cb)(xx);
1131             }
1132         }
1133     }
1134 #endif
1135 }
1136
1137
1138 /*******************************************************************************
1139 **
1140 ** Function         BTM_SetScoPacketTypes
1141 **
1142 ** Description      This function is called to set the packet types used for
1143 **                  a specific SCO connection,
1144 **
1145 ** Parameters       pkt_types - One or more of the following
1146 **                  BTM_SCO_PKT_TYPES_MASK_HV1
1147 **                  BTM_SCO_PKT_TYPES_MASK_HV2
1148 **                  BTM_SCO_PKT_TYPES_MASK_HV3
1149 **                  BTM_SCO_PKT_TYPES_MASK_EV3
1150 **                  BTM_SCO_PKT_TYPES_MASK_EV4
1151 **                  BTM_SCO_PKT_TYPES_MASK_EV5
1152 **                  BTM_SCO_PKT_TYPES_MASK_NO_2_EV3
1153 **                  BTM_SCO_PKT_TYPES_MASK_NO_3_EV3
1154 **                  BTM_SCO_PKT_TYPES_MASK_NO_2_EV5
1155 **                  BTM_SCO_PKT_TYPES_MASK_NO_3_EV5
1156 **
1157 **                  BTM_SCO_LINK_ALL_MASK   - enables all supported types
1158 **
1159 ** Returns          status of the operation
1160 **
1161 *******************************************************************************/
1162 tBTM_STATUS BTM_SetScoPacketTypes (UINT16 sco_inx, UINT16 pkt_types)
1163 {
1164 #if (BTM_MAX_SCO_LINKS>0)
1165     tBTM_CHG_ESCO_PARAMS parms;
1166     tSCO_CONN           *p;
1167
1168     /* Validity check */
1169     if (sco_inx >= BTM_MAX_SCO_LINKS)
1170         return (BTM_UNKNOWN_ADDR);
1171
1172     p = &btm_cb.sco_cb.sco_db[sco_inx];
1173     parms.packet_types = pkt_types;
1174
1175     /* Keep the other parameters the same for SCO */
1176     parms.max_latency = p->esco.setup.max_latency;
1177     parms.retrans_effort = p->esco.setup.retrans_effort;
1178
1179     return (BTM_ChangeEScoLinkParms(sco_inx, &parms));
1180 #else
1181     return (BTM_UNKNOWN_ADDR);
1182 #endif
1183 }
1184
1185
1186 /*******************************************************************************
1187 **
1188 ** Function         BTM_ReadScoPacketTypes
1189 **
1190 ** Description      This function is read the packet types used for a specific
1191 **                  SCO connection.
1192 **
1193 ** Returns          Packet types supported for the connection
1194 **                  One or more of the following (bitmask):
1195 **                  BTM_SCO_PKT_TYPES_MASK_HV1
1196 **                  BTM_SCO_PKT_TYPES_MASK_HV2
1197 **                  BTM_SCO_PKT_TYPES_MASK_HV3
1198 **                  BTM_SCO_PKT_TYPES_MASK_EV3
1199 **                  BTM_SCO_PKT_TYPES_MASK_EV4
1200 **                  BTM_SCO_PKT_TYPES_MASK_EV5
1201 **                  BTM_SCO_PKT_TYPES_MASK_NO_2_EV3
1202 **                  BTM_SCO_PKT_TYPES_MASK_NO_3_EV3
1203 **                  BTM_SCO_PKT_TYPES_MASK_NO_2_EV5
1204 **                  BTM_SCO_PKT_TYPES_MASK_NO_3_EV5
1205 **
1206 *******************************************************************************/
1207 UINT16 BTM_ReadScoPacketTypes (UINT16 sco_inx)
1208 {
1209 #if (BTM_MAX_SCO_LINKS>0)
1210     tSCO_CONN *p = &btm_cb.sco_cb.sco_db[sco_inx];
1211
1212     /* Validity check */
1213     if ((sco_inx < BTM_MAX_SCO_LINKS) && (p->state == SCO_ST_CONNECTED))
1214         return (p->esco.setup.packet_types);
1215     else
1216         return (0);
1217 #else
1218     return (0);
1219 #endif
1220 }
1221
1222 /*******************************************************************************
1223 **
1224 ** Function         BTM_ReadScoDiscReason
1225 **
1226 ** Description      This function is returns the reason why an (e)SCO connection
1227 **                  has been removed. It contains the value until read, or until
1228 **                  another (e)SCO connection has disconnected.
1229 **
1230 ** Returns          HCI reason or BTM_INVALID_SCO_DISC_REASON if not set.
1231 **
1232 *******************************************************************************/
1233 UINT16 BTM_ReadScoDiscReason (void)
1234 {
1235     UINT16 res = btm_cb.sco_cb.sco_disc_reason;
1236     btm_cb.sco_cb.sco_disc_reason = BTM_INVALID_SCO_DISC_REASON;
1237     return (res);
1238 }
1239
1240 /*******************************************************************************
1241 **
1242 ** Function         BTM_ReadDeviceScoPacketTypes
1243 **
1244 ** Description      This function is read the SCO packet types that
1245 **                  the device supports.
1246 **
1247 ** Returns          Packet types supported by the device.
1248 **                  One or more of the following (bitmask):
1249 **                  BTM_SCO_PKT_TYPES_MASK_HV1
1250 **                  BTM_SCO_PKT_TYPES_MASK_HV2
1251 **                  BTM_SCO_PKT_TYPES_MASK_HV3
1252 **                  BTM_SCO_PKT_TYPES_MASK_EV3
1253 **                  BTM_SCO_PKT_TYPES_MASK_EV4
1254 **                  BTM_SCO_PKT_TYPES_MASK_EV5
1255 **                  BTM_SCO_PKT_TYPES_MASK_NO_2_EV3
1256 **                  BTM_SCO_PKT_TYPES_MASK_NO_3_EV3
1257 **                  BTM_SCO_PKT_TYPES_MASK_NO_2_EV5
1258 **                  BTM_SCO_PKT_TYPES_MASK_NO_3_EV5
1259 **
1260 *******************************************************************************/
1261 UINT16 BTM_ReadDeviceScoPacketTypes (void)
1262 {
1263     return (btm_cb.btm_sco_pkt_types_supported);
1264 }
1265
1266 /*******************************************************************************
1267 **
1268 ** Function         BTM_ReadScoHandle
1269 **
1270 ** Description      This function is used to read the HCI handle used for a specific
1271 **                  SCO connection,
1272 **
1273 ** Returns          handle for the connection, or 0xFFFF if invalid SCO index.
1274 **
1275 *******************************************************************************/
1276 UINT16 BTM_ReadScoHandle (UINT16 sco_inx)
1277 {
1278 #if (BTM_MAX_SCO_LINKS>0)
1279     tSCO_CONN   *p = &btm_cb.sco_cb.sco_db[sco_inx];
1280
1281     /* Validity check */
1282     if ((sco_inx < BTM_MAX_SCO_LINKS) && (p->state == SCO_ST_CONNECTED))
1283         return (p->hci_handle);
1284     else
1285         return (BTM_INVALID_HCI_HANDLE);
1286 #else
1287     return (BTM_INVALID_HCI_HANDLE);
1288 #endif
1289 }
1290
1291 /*******************************************************************************
1292 **
1293 ** Function         BTM_ReadScoBdAddr
1294 **
1295 ** Description      This function is read the remote BD Address for a specific
1296 **                  SCO connection,
1297 **
1298 ** Returns          pointer to BD address or NULL if not known
1299 **
1300 *******************************************************************************/
1301 UINT8 *BTM_ReadScoBdAddr (UINT16 sco_inx)
1302 {
1303 #if (BTM_MAX_SCO_LINKS>0)
1304     tSCO_CONN   *p = &btm_cb.sco_cb.sco_db[sco_inx];
1305
1306     /* Validity check */
1307     if ((sco_inx < BTM_MAX_SCO_LINKS) && (p->rem_bd_known))
1308         return (p->esco.data.bd_addr);
1309     else
1310         return (NULL);
1311 #else
1312     return (NULL);
1313 #endif
1314 }
1315
1316 /*******************************************************************************
1317 **
1318 ** Function         BTM_SetEScoMode
1319 **
1320 ** Description      This function sets up the negotiated parameters for SCO or
1321 **                  eSCO, and sets as the default mode used for outgoing calls to
1322 **                  BTM_CreateSco.  It does not change any currently active (e)SCO links.
1323 **                  Note:  Incoming (e)SCO connections will always use packet types
1324 **                      supported by the controller.  If eSCO is not desired the
1325 **                      feature should be disabled in the controller's feature mask.
1326 **
1327 ** Returns          BTM_SUCCESS if the successful.
1328 **                  BTM_BUSY if there are one or more active (e)SCO links.
1329 **
1330 *******************************************************************************/
1331 tBTM_STATUS BTM_SetEScoMode (tBTM_SCO_TYPE sco_mode, tBTM_ESCO_PARAMS *p_parms)
1332 {
1333     tSCO_CB          *p_esco = &btm_cb.sco_cb;
1334     tBTM_ESCO_PARAMS *p_def = &p_esco->def_esco_parms;
1335
1336     if (p_esco->esco_supported)
1337     {
1338         if (p_parms)
1339         {
1340             if (sco_mode == BTM_LINK_TYPE_ESCO)
1341                 *p_def = *p_parms;  /* Save as the default parameters */
1342             else    /* Load only the SCO packet types */
1343             {
1344                 p_def->packet_types = p_parms->packet_types;
1345                 p_def->tx_bw            = BTM_64KBITS_RATE;
1346                 p_def->rx_bw            = BTM_64KBITS_RATE;
1347                 p_def->max_latency      = 0x000a;
1348                 p_def->voice_contfmt    = 0x0060;
1349                 p_def->retrans_effort   = 0;
1350
1351                 /* OR in any exception packet types */
1352                 p_def->packet_types |= BTM_SCO_EXCEPTION_PKTS_MASK;
1353             }
1354         }
1355         p_esco->desired_sco_mode = sco_mode;
1356         BTM_TRACE_API("BTM_SetEScoMode -> mode %d",  sco_mode);
1357     }
1358     else
1359     {
1360         p_esco->desired_sco_mode = BTM_LINK_TYPE_SCO;
1361         p_def->packet_types &= BTM_SCO_LINK_ONLY_MASK;
1362         p_def->retrans_effort = 0;
1363         BTM_TRACE_API("BTM_SetEScoMode -> mode SCO (eSCO not supported)");
1364     }
1365
1366     BTM_TRACE_DEBUG("    txbw 0x%08x, rxbw 0x%08x, max_lat 0x%04x, voice 0x%04x, pkt 0x%04x, rtx effort 0x%02x",
1367                      p_def->tx_bw, p_def->rx_bw, p_def->max_latency,
1368                      p_def->voice_contfmt, p_def->packet_types,
1369                      p_def->retrans_effort);
1370
1371     return (BTM_SUCCESS);
1372 }
1373
1374
1375
1376 /*******************************************************************************
1377 **
1378 ** Function         BTM_RegForEScoEvts
1379 **
1380 ** Description      This function registers a SCO event callback with the
1381 **                  specified instance.  It should be used to received
1382 **                  connection indication events and change of link parameter
1383 **                  events.
1384 **
1385 ** Returns          BTM_SUCCESS if the successful.
1386 **                  BTM_ILLEGAL_VALUE if there is an illegal sco_inx
1387 **                  BTM_MODE_UNSUPPORTED if controller version is not BT1.2 or
1388 **                          later or does not support eSCO.
1389 **
1390 *******************************************************************************/
1391 tBTM_STATUS BTM_RegForEScoEvts (UINT16 sco_inx, tBTM_ESCO_CBACK *p_esco_cback)
1392 {
1393 #if (BTM_MAX_SCO_LINKS>0)
1394     if (!btm_cb.sco_cb.esco_supported)
1395     {
1396         btm_cb.sco_cb.sco_db[sco_inx].esco.p_esco_cback = NULL;
1397         return (BTM_MODE_UNSUPPORTED);
1398     }
1399
1400     if (sco_inx < BTM_MAX_SCO_LINKS &&
1401         btm_cb.sco_cb.sco_db[sco_inx].state != SCO_ST_UNUSED)
1402     {
1403         btm_cb.sco_cb.sco_db[sco_inx].esco.p_esco_cback = p_esco_cback;
1404         return (BTM_SUCCESS);
1405     }
1406     return (BTM_ILLEGAL_VALUE);
1407 #else
1408     return (BTM_MODE_UNSUPPORTED);
1409 #endif
1410 }
1411
1412 /*******************************************************************************
1413 **
1414 ** Function         BTM_ReadEScoLinkParms
1415 **
1416 ** Description      This function returns the current eSCO link parameters for
1417 **                  the specified handle.  This can be called anytime a connection
1418 **                  is active, but is typically called after receiving the SCO
1419 **                  opened callback.
1420 **
1421 **                  Note: If called over a 1.1 controller, only the packet types
1422 **                        field has meaning.
1423 **
1424 ** Returns          BTM_SUCCESS if returned data is valid connection.
1425 **                  BTM_WRONG_MODE if no connection with a peer device or bad sco_inx.
1426 **
1427 *******************************************************************************/
1428 tBTM_STATUS BTM_ReadEScoLinkParms (UINT16 sco_inx, tBTM_ESCO_DATA *p_parms)
1429 {
1430 #if (BTM_MAX_SCO_LINKS>0)
1431     UINT8 index;
1432
1433     BTM_TRACE_API("BTM_ReadEScoLinkParms -> sco_inx 0x%04x", sco_inx);
1434
1435     if (sco_inx < BTM_MAX_SCO_LINKS &&
1436         btm_cb.sco_cb.sco_db[sco_inx].state >= SCO_ST_CONNECTED)
1437     {
1438         *p_parms = btm_cb.sco_cb.sco_db[sco_inx].esco.data;
1439         return (BTM_SUCCESS);
1440     }
1441
1442     if (sco_inx == BTM_FIRST_ACTIVE_SCO_INDEX)
1443     {
1444         for (index = 0; index < BTM_MAX_SCO_LINKS; index++)
1445         {
1446             if (btm_cb.sco_cb.sco_db[index].state >= SCO_ST_CONNECTED)
1447             {
1448                 BTM_TRACE_API("BTM_ReadEScoLinkParms the first active SCO index is %d",index);
1449                 *p_parms = btm_cb.sco_cb.sco_db[index].esco.data;
1450                 return (BTM_SUCCESS);
1451             }
1452         }
1453     }
1454
1455 #endif
1456
1457     BTM_TRACE_API("BTM_ReadEScoLinkParms cannot find the SCO index!");
1458     memset(p_parms, 0, sizeof(tBTM_ESCO_DATA));
1459     return (BTM_WRONG_MODE);
1460 }
1461
1462 /*******************************************************************************
1463 **
1464 ** Function         BTM_ChangeEScoLinkParms
1465 **
1466 ** Description      This function requests renegotiation of the parameters on
1467 **                  the current eSCO Link.  If any of the changes are accepted
1468 **                  by the controllers, the BTM_ESCO_CHG_EVT event is sent in
1469 **                  the tBTM_ESCO_CBACK function with the current settings of
1470 **                  the link. The callback is registered through the call to
1471 **                  BTM_SetEScoMode.
1472 **
1473 **                  Note: If called over a SCO link (including 1.1 controller),
1474 **                        a change packet type request is sent out instead.
1475 **
1476 ** Returns          BTM_CMD_STARTED if command is successfully initiated.
1477 **                  BTM_NO_RESOURCES - not enough resources to initiate command.
1478 **                  BTM_WRONG_MODE if no connection with a peer device or bad sco_inx.
1479 **
1480 *******************************************************************************/
1481 tBTM_STATUS BTM_ChangeEScoLinkParms (UINT16 sco_inx, tBTM_CHG_ESCO_PARAMS *p_parms)
1482 {
1483 #if (BTM_MAX_SCO_LINKS>0)
1484     tBTM_ESCO_PARAMS *p_setup;
1485     tSCO_CONN        *p_sco;
1486     UINT16            temp_pkt_types;
1487
1488     /* Make sure sco handle is valid and on an active link */
1489     if (sco_inx >= BTM_MAX_SCO_LINKS ||
1490         btm_cb.sco_cb.sco_db[sco_inx].state != SCO_ST_CONNECTED)
1491         return (BTM_WRONG_MODE);
1492
1493     p_sco = &btm_cb.sco_cb.sco_db[sco_inx];
1494     p_setup = &p_sco->esco.setup;
1495
1496     /* If SCO connection OR eSCO not supported just send change packet types */
1497     if (p_sco->esco.data.link_type == BTM_LINK_TYPE_SCO ||
1498         !btm_cb.sco_cb.esco_supported)
1499     {
1500         p_setup->packet_types = p_parms->packet_types &
1501             (btm_cb.btm_sco_pkt_types_supported & BTM_SCO_LINK_ONLY_MASK);
1502
1503
1504         BTM_TRACE_API("BTM_ChangeEScoLinkParms -> SCO Link for handle 0x%04x, pkt 0x%04x",
1505                          p_sco->hci_handle, p_setup->packet_types);
1506
1507         if (!btsnd_hcic_change_conn_type (p_sco->hci_handle,
1508                                      BTM_ESCO_2_SCO(p_setup->packet_types)))
1509             return (BTM_NO_RESOURCES);
1510     }
1511     else
1512     {
1513         temp_pkt_types = (p_parms->packet_types & BTM_SCO_SUPPORTED_PKTS_MASK &
1514                              btm_cb.btm_sco_pkt_types_supported);
1515
1516         /* OR in any exception packet types */
1517         temp_pkt_types |= ((p_parms->packet_types & BTM_SCO_EXCEPTION_PKTS_MASK) |
1518             (btm_cb.btm_sco_pkt_types_supported & BTM_SCO_EXCEPTION_PKTS_MASK));
1519
1520         BTM_TRACE_API("BTM_ChangeEScoLinkParms -> eSCO Link for handle 0x%04x", p_sco->hci_handle);
1521         BTM_TRACE_API("      txbw 0x%x, rxbw 0x%x, lat 0x%x, voice 0x%x, retrans 0x%02x, pkt 0x%04x",
1522                          p_setup->tx_bw, p_setup->rx_bw, p_parms->max_latency,
1523                          p_setup->voice_contfmt, p_parms->retrans_effort, temp_pkt_types);
1524
1525         /* When changing an existing link, only change latency, retrans, and pkts */
1526         if (!btsnd_hcic_setup_esco_conn(p_sco->hci_handle, p_setup->tx_bw,
1527                                         p_setup->rx_bw, p_parms->max_latency,
1528                                         p_setup->voice_contfmt,
1529                                         p_parms->retrans_effort,
1530                                         temp_pkt_types))
1531             return (BTM_NO_RESOURCES);
1532         else
1533             p_parms->packet_types = temp_pkt_types;
1534     }
1535
1536     return (BTM_CMD_STARTED);
1537 #else
1538     return (BTM_WRONG_MODE);
1539 #endif
1540 }
1541
1542 /*******************************************************************************
1543 **
1544 ** Function         BTM_EScoConnRsp
1545 **
1546 ** Description      This function is called upon receipt of an (e)SCO connection
1547 **                  request event (BTM_ESCO_CONN_REQ_EVT) to accept or reject
1548 **                  the request. Parameters used to negotiate eSCO links.
1549 **                  If p_parms is NULL, then values set through BTM_SetEScoMode
1550 **                  are used.
1551 **                  If the link type of the incoming request is SCO, then only
1552 **                  the tx_bw, max_latency, content format, and packet_types are
1553 **                  valid.  The hci_status parameter should be
1554 **                  ([0x0] to accept, [0x0d..0x0f] to reject)
1555 **
1556 **
1557 ** Returns          void
1558 **
1559 *******************************************************************************/
1560 void BTM_EScoConnRsp (UINT16 sco_inx, UINT8 hci_status, tBTM_ESCO_PARAMS *p_parms)
1561 {
1562 #if (BTM_MAX_SCO_LINKS>0)
1563     if (sco_inx < BTM_MAX_SCO_LINKS &&
1564         btm_cb.sco_cb.sco_db[sco_inx].state == SCO_ST_W4_CONN_RSP)
1565     {
1566         btm_esco_conn_rsp(sco_inx, hci_status,
1567                           btm_cb.sco_cb.sco_db[sco_inx].esco.data.bd_addr,
1568                           p_parms);
1569     }
1570 #endif
1571 }
1572
1573 /*******************************************************************************
1574 **
1575 ** Function         btm_read_def_esco_mode
1576 **
1577 ** Description      This function copies the current default esco settings into
1578 **                  the return buffer.
1579 **
1580 ** Returns          tBTM_SCO_TYPE
1581 **
1582 *******************************************************************************/
1583 tBTM_SCO_TYPE btm_read_def_esco_mode (tBTM_ESCO_PARAMS *p_parms)
1584 {
1585 #if (BTM_MAX_SCO_LINKS>0)
1586     *p_parms = btm_cb.sco_cb.def_esco_parms;
1587     return btm_cb.sco_cb.desired_sco_mode;
1588 #else
1589     return BTM_LINK_TYPE_SCO;
1590 #endif
1591 }
1592
1593 /*******************************************************************************
1594 **
1595 ** Function         btm_esco_proc_conn_chg
1596 **
1597 ** Description      This function is called by BTIF when an SCO connection
1598 **                  is changed.
1599 **
1600 ** Returns          void
1601 **
1602 *******************************************************************************/
1603 void btm_esco_proc_conn_chg (UINT8 status, UINT16 handle, UINT8 tx_interval,
1604                              UINT8 retrans_window, UINT16 rx_pkt_len,
1605                              UINT16 tx_pkt_len)
1606 {
1607 #if (BTM_MAX_SCO_LINKS>0)
1608     tSCO_CONN               *p = &btm_cb.sco_cb.sco_db[0];
1609     tBTM_CHG_ESCO_EVT_DATA   data;
1610     UINT16                   xx;
1611
1612     BTM_TRACE_EVENT("btm_esco_proc_conn_chg -> handle 0x%04x, status 0x%02x",
1613                       handle, status);
1614
1615     for (xx = 0; xx < BTM_MAX_SCO_LINKS; xx++, p++)
1616     {
1617         if (p->state == SCO_ST_CONNECTED && handle == p->hci_handle)
1618         {
1619             /* If upper layer wants notification */
1620             if (p->esco.p_esco_cback)
1621             {
1622                 memcpy(data.bd_addr, p->esco.data.bd_addr, BD_ADDR_LEN);
1623                 data.hci_status = status;
1624                 data.sco_inx = xx;
1625                 data.rx_pkt_len = p->esco.data.rx_pkt_len = rx_pkt_len;
1626                 data.tx_pkt_len = p->esco.data.tx_pkt_len = tx_pkt_len;
1627                 data.tx_interval = p->esco.data.tx_interval = tx_interval;
1628                 data.retrans_window = p->esco.data.retrans_window = retrans_window;
1629
1630                 (*p->esco.p_esco_cback)(BTM_ESCO_CHG_EVT,
1631                                         (tBTM_ESCO_EVT_DATA *)&data);
1632             }
1633             return;
1634         }
1635     }
1636 #endif
1637 }
1638
1639 /*******************************************************************************
1640 **
1641 ** Function         btm_is_sco_active
1642 **
1643 ** Description      This function is called to see if a SCO handle is already in
1644 **                  use.
1645 **
1646 ** Returns          BOOLEAN
1647 **
1648 *******************************************************************************/
1649 BOOLEAN btm_is_sco_active (UINT16 handle)
1650 {
1651 #if (BTM_MAX_SCO_LINKS>0)
1652     UINT16     xx;
1653     tSCO_CONN *p = &btm_cb.sco_cb.sco_db[0];
1654
1655     for (xx = 0; xx < BTM_MAX_SCO_LINKS; xx++, p++)
1656     {
1657         if (handle == p->hci_handle && p->state == SCO_ST_CONNECTED)
1658             return (TRUE);
1659     }
1660 #endif
1661     return (FALSE);
1662 }
1663
1664 /*******************************************************************************
1665 **
1666 ** Function         BTM_GetNumScoLinks
1667 **
1668 ** Description      This function returns the number of active sco links.
1669 **
1670 ** Returns          UINT8
1671 **
1672 *******************************************************************************/
1673 UINT8 BTM_GetNumScoLinks (void)
1674 {
1675 #if (BTM_MAX_SCO_LINKS>0)
1676     tSCO_CONN *p = &btm_cb.sco_cb.sco_db[0];
1677     UINT16     xx;
1678     UINT8      num_scos = 0;
1679
1680     for (xx = 0; xx < BTM_MAX_SCO_LINKS; xx++, p++)
1681     {
1682         switch (p->state)
1683         {
1684         case SCO_ST_W4_CONN_RSP:
1685         case SCO_ST_CONNECTING:
1686         case SCO_ST_CONNECTED:
1687         case SCO_ST_DISCONNECTING:
1688         case SCO_ST_PEND_UNPARK:
1689             num_scos++;
1690         }
1691     }
1692     return (num_scos);
1693 #else
1694     return (0);
1695 #endif
1696 }
1697
1698
1699 /*******************************************************************************
1700 **
1701 ** Function         btm_is_sco_active_by_bdaddr
1702 **
1703 ** Description      This function is called to see if a SCO active to a bd address.
1704 **
1705 ** Returns          BOOLEAN
1706 **
1707 *******************************************************************************/
1708 BOOLEAN btm_is_sco_active_by_bdaddr (BD_ADDR remote_bda)
1709 {
1710 #if (BTM_MAX_SCO_LINKS>0)
1711     UINT8 xx;
1712     tSCO_CONN *p = &btm_cb.sco_cb.sco_db[0];
1713
1714     /* If any SCO is being established to the remote BD address, refuse this */
1715     for (xx = 0; xx < BTM_MAX_SCO_LINKS; xx++, p++)
1716     {
1717         if ((!memcmp (p->esco.data.bd_addr, remote_bda, BD_ADDR_LEN)) && (p->state == SCO_ST_CONNECTED))
1718         {
1719             return (TRUE);
1720         }
1721     }
1722 #endif
1723     return (FALSE);
1724 }
1725 #else   /* SCO_EXCLUDED == TRUE (Link in stubs) */
1726
1727 tBTM_STATUS BTM_CreateSco (BD_ADDR remote_bda, BOOLEAN is_orig,
1728                            UINT16 pkt_types, UINT16 *p_sco_inx,
1729                            tBTM_SCO_CB *p_conn_cb,
1730                            tBTM_SCO_CB *p_disc_cb) {return (BTM_NO_RESOURCES);}
1731 tBTM_STATUS BTM_RemoveSco (UINT16 sco_inx) {return (BTM_NO_RESOURCES);}
1732 tBTM_STATUS BTM_SetScoPacketTypes (UINT16 sco_inx, UINT16 pkt_types) {return (BTM_NO_RESOURCES);}
1733 UINT16 BTM_ReadScoPacketTypes (UINT16 sco_inx) {return (0);}
1734 UINT16 BTM_ReadDeviceScoPacketTypes (void) {return (0);}
1735 UINT16 BTM_ReadScoHandle (UINT16 sco_inx) {return (BTM_INVALID_HCI_HANDLE);}
1736 UINT8 *BTM_ReadScoBdAddr(UINT16 sco_inx) {return((UINT8 *) NULL);}
1737 UINT16 BTM_ReadScoDiscReason (void) {return (BTM_INVALID_SCO_DISC_REASON);}
1738 tBTM_STATUS BTM_SetEScoMode (tBTM_SCO_TYPE sco_mode, tBTM_ESCO_PARAMS *p_parms) {return (BTM_MODE_UNSUPPORTED);}
1739 tBTM_STATUS BTM_RegForEScoEvts (UINT16 sco_inx, tBTM_ESCO_CBACK *p_esco_cback) { return (BTM_ILLEGAL_VALUE);}
1740 tBTM_STATUS BTM_ReadEScoLinkParms (UINT16 sco_inx, tBTM_ESCO_DATA *p_parms) { return (BTM_MODE_UNSUPPORTED);}
1741 tBTM_STATUS BTM_ChangeEScoLinkParms (UINT16 sco_inx, tBTM_CHG_ESCO_PARAMS *p_parms) { return (BTM_MODE_UNSUPPORTED);}
1742 void BTM_EScoConnRsp (UINT16 sco_inx, UINT8 hci_status, tBTM_ESCO_PARAMS *p_parms) {}
1743 UINT8 BTM_GetNumScoLinks (void)  {return (0);}
1744
1745 #endif /* If SCO is being used */