• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2020 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #pragma once
18 
19 #include <cstdint>
20 #include <string>
21 
22 #include "device/include/esco_parameters.h"
23 #include "stack/include/btm_api_types.h"
24 
25 constexpr uint16_t kMaxScoLinks = static_cast<uint16_t>(BTM_MAX_SCO_LINKS);
26 
27 /* Define the structures needed by sco
28  */
29 
30 typedef enum : uint16_t {
31   SCO_ST_UNUSED = 0,
32   SCO_ST_LISTENING = 1,
33   SCO_ST_W4_CONN_RSP = 2,
34   SCO_ST_CONNECTING = 3,
35   SCO_ST_CONNECTED = 4,
36   SCO_ST_DISCONNECTING = 5,
37   SCO_ST_PEND_UNPARK = 6,
38   SCO_ST_PEND_ROLECHANGE = 7,
39   SCO_ST_PEND_MODECHANGE = 8,
40 } tSCO_STATE;
41 
sco_state_text(const tSCO_STATE & state)42 inline std::string sco_state_text(const tSCO_STATE& state) {
43   switch (state) {
44     case SCO_ST_UNUSED:
45       return std::string("unused");
46     case SCO_ST_LISTENING:
47       return std::string("listening");
48     case SCO_ST_W4_CONN_RSP:
49       return std::string("connect_response");
50     case SCO_ST_CONNECTING:
51       return std::string("connecting");
52     case SCO_ST_CONNECTED:
53       return std::string("connected");
54     case SCO_ST_DISCONNECTING:
55       return std::string("disconnecting");
56     case SCO_ST_PEND_UNPARK:
57       return std::string("pending_unpark");
58     case SCO_ST_PEND_ROLECHANGE:
59       return std::string("pending_role_change");
60     case SCO_ST_PEND_MODECHANGE:
61       return std::string("pending_mode_change");
62   }
63 }
64 
65 typedef void(tBTM_SCO_IND_CBACK)(uint16_t sco_inx);
66 
67 /* Define the structure that contains (e)SCO data */
68 typedef struct {
69   tBTM_ESCO_CBACK* p_esco_cback; /* Callback for eSCO events     */
70   enh_esco_params_t setup;
71   tBTM_ESCO_DATA data; /* Connection complete information */
72   uint8_t hci_status;
73 } tBTM_ESCO_INFO;
74 
75 /* Define the structure used for SCO Management
76  */
77 typedef struct {
78   tBTM_ESCO_INFO esco;    /* Current settings             */
79   tBTM_SCO_CB* p_conn_cb; /* Callback for when connected  */
80   tBTM_SCO_CB* p_disc_cb; /* Callback for when disconnect */
81   tSCO_STATE state;       /* The state of the SCO link    */
82 
83   uint16_t hci_handle;    /* HCI Handle                   */
84  public:
is_active__anon83962073030885   bool is_active() const { return state != SCO_ST_UNUSED; }
Handle__anon83962073030886   uint16_t Handle() const { return hci_handle; }
87 
88   bool is_orig;           /* true if the originator       */
89   bool rem_bd_known;      /* true if remote BD addr known */
90 
91 } tSCO_CONN;
92 
93 /* SCO Management control block */
94 typedef struct {
95   tBTM_SCO_IND_CBACK* app_sco_ind_cb;
96   tSCO_CONN sco_db[BTM_MAX_SCO_LINKS];
97   enh_esco_params_t def_esco_parms;
98   bool esco_supported;        /* true if 1.2 cntlr AND supports eSCO links */
99   esco_data_path_t sco_route; /* HCI, PCM, or TEST */
100 
get_sco_connection_from_index__anon839620730408101   tSCO_CONN* get_sco_connection_from_index(uint16_t index) {
102     return (index < kMaxScoLinks) ? (&sco_db[index]) : nullptr;
103   }
104 
get_sco_connection_from_handle__anon839620730408105   tSCO_CONN* get_sco_connection_from_handle(uint16_t handle) {
106     tSCO_CONN* p_sco = sco_db;
107     for (uint16_t xx = 0; xx < kMaxScoLinks; xx++, p_sco++) {
108       if (p_sco->hci_handle == handle) {
109         return p_sco;
110       }
111     }
112     return nullptr;
113   }
114 
Init__anon839620730408115   void Init() {
116     def_esco_parms = esco_parameters_for_codec(ESCO_CODEC_CVSD_S3);
117     sco_route = ESCO_DATA_PATH_PCM;
118   }
119 
get_index__anon839620730408120   uint16_t get_index(const tSCO_CONN* p_sco) const {
121     CHECK(p_sco != nullptr);
122     const tSCO_CONN* p = sco_db;
123     for (uint16_t xx = 0; xx < kMaxScoLinks; xx++, p++) {
124       if (p_sco == p) {
125         return xx;
126       }
127     }
128     return 0xffff;
129   }
130 
131 } tSCO_CB;
132 
133 extern void btm_sco_chk_pend_rolechange(uint16_t hci_handle);
134 extern void btm_sco_disc_chk_pend_for_modechange(uint16_t hci_handle);
135