• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /******************************************************************************
2  *
3  *  Copyright (C) 2003-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 is the private interface file for the BTA audio gateway.
22  *
23  ******************************************************************************/
24 #ifndef BTA_AG_INT_H
25 #define BTA_AG_INT_H
26 
27 #include "bta_sys.h"
28 #include "bta_api.h"
29 #include "bta_ag_api.h"
30 #include "bta_ag_at.h"
31 
32 /* Send RING & CLIP in one AT cmd */
33 #ifndef BTA_AG_MULTI_RESULT_INCLUDED
34 #define BTA_AG_MULTI_RESULT_INCLUDED      FALSE
35 #endif
36 
37 /* Replace : in VGS and VGM for HSP */
38 #ifndef BTA_HSP_RESULT_REPLACE_COLON
39 #define BTA_HSP_RESULT_REPLACE_COLON      TRUE
40 #endif
41 
42 /*****************************************************************************
43 **  Constants
44 *****************************************************************************/
45 #define HFP_VERSION_1_1         0x0101
46 #define HFP_VERSION_1_5         0x0105
47 #define HFP_VERSION_1_6         0x0106
48 
49 #define HSP_VERSION_1_0         0x0100
50 #define HSP_VERSION_1_2         0x0102
51 
52 /* Number of SCBs (AG service instances that can be registered) */
53 #ifndef BTA_AG_NUM_SCB
54 #define BTA_AG_NUM_SCB          2
55 #endif
56 
57 /* Timer to wait for retry in case of collision */
58 #ifndef BTA_AG_COLLISION_TIMER
59 #define BTA_AG_COLLISION_TIMER  2000
60 #endif
61 
62 /* RFCOMM MTU SIZE */
63 #define BTA_AG_MTU              256
64 
65 /* Internal profile indexes */
66 #define BTA_AG_HSP              0       /* index for HSP */
67 #define BTA_AG_HFP              1       /* index for HFP */
68 #define BTA_AG_NUM_IDX          2       /* number of profile indexes */
69 
70 /* profile role for connection */
71 #define BTA_AG_ACP              0       /* accepted connection */
72 #define BTA_AG_INT              1       /* initiating connection */
73 
74 /* feature mask that matches spec */
75 #define BTA_AG_BSRF_FEAT_SPEC        (BTA_AG_FEAT_3WAY | BTA_AG_FEAT_ECNR    | \
76                                       BTA_AG_FEAT_VREC | BTA_AG_FEAT_INBAND  | \
77                                       BTA_AG_FEAT_VTAG | BTA_AG_FEAT_REJECT  | \
78                                       BTA_AG_FEAT_ECS  | BTA_AG_FEAT_ECC     | \
79                                       BTA_AG_FEAT_EXTERR | BTA_AG_FEAT_CODEC | \
80                                       BTA_AG_FEAT_VOIP)
81 
82 #define BTA_AG_SDP_FEAT_SPEC         (BTA_AG_FEAT_3WAY | BTA_AG_FEAT_ECNR    | \
83                                       BTA_AG_FEAT_VREC | BTA_AG_FEAT_INBAND  | \
84                                       BTA_AG_FEAT_VTAG)
85 
86 enum
87 {
88     /* these events are handled by the state machine */
89     BTA_AG_API_REGISTER_EVT = BTA_SYS_EVT_START(BTA_ID_AG),
90     BTA_AG_API_DEREGISTER_EVT,
91     BTA_AG_API_OPEN_EVT,
92     BTA_AG_API_CLOSE_EVT,
93     BTA_AG_API_AUDIO_OPEN_EVT,
94     BTA_AG_API_AUDIO_CLOSE_EVT,
95     BTA_AG_API_RESULT_EVT,
96     BTA_AG_API_SETCODEC_EVT,
97     BTA_AG_RFC_OPEN_EVT,
98     BTA_AG_RFC_CLOSE_EVT,
99     BTA_AG_RFC_SRV_CLOSE_EVT,
100     BTA_AG_RFC_DATA_EVT,
101     BTA_AG_SCO_OPEN_EVT,
102     BTA_AG_SCO_CLOSE_EVT,
103     BTA_AG_DISC_ACP_RES_EVT,
104     BTA_AG_DISC_INT_RES_EVT,
105     BTA_AG_DISC_OK_EVT,
106     BTA_AG_DISC_FAIL_EVT,
107     BTA_AG_CI_RX_WRITE_EVT,
108     BTA_AG_RING_TOUT_EVT,
109     BTA_AG_SVC_TOUT_EVT,
110     BTA_AG_CI_SCO_DATA_EVT,
111     BTA_AG_CI_SLC_READY_EVT,
112     BTA_AG_MAX_EVT,
113 
114     /* these events are handled outside of the state machine */
115     BTA_AG_API_ENABLE_EVT,
116     BTA_AG_API_DISABLE_EVT
117 };
118 
119 /* Actions to perform after a SCO event */
120 enum
121 {
122     BTA_AG_POST_SCO_NONE,       /* no action */
123     BTA_AG_POST_SCO_CLOSE_RFC,  /* close RFCOMM channel after SCO closes */
124     BTA_AG_POST_SCO_RING,       /* send RING result code after SCO opens */
125     BTA_AG_POST_SCO_CALL_CONN,  /* send call indicators after SCO opens/closes */
126     BTA_AG_POST_SCO_CALL_ORIG,  /* send call indicators after SCO closes */
127     BTA_AG_POST_SCO_CALL_END,   /* send call indicators after SCO closes */
128     BTA_AG_POST_SCO_CALL_END_INCALL   /* send call indicators for end call & incoming call after SCO closes */
129 };
130 
131 /* sco states */
132 enum
133 {
134     BTA_AG_SCO_SHUTDOWN_ST,     /* no sco listening, all sco connections closed */
135     BTA_AG_SCO_LISTEN_ST,       /* sco listening */
136 #if (BTM_WBS_INCLUDED == TRUE )
137     BTA_AG_SCO_CODEC_ST,        /* sco codec negotiation */
138 #endif
139     BTA_AG_SCO_OPENING_ST,      /* sco connection opening */
140     BTA_AG_SCO_OPEN_CL_ST,      /* opening sco connection being closed */
141     BTA_AG_SCO_OPEN_XFER_ST,    /* opening sco connection being transferred */
142     BTA_AG_SCO_OPEN_ST,         /* sco open */
143     BTA_AG_SCO_CLOSING_ST,      /* sco closing */
144     BTA_AG_SCO_CLOSE_OP_ST,     /* closing sco being opened */
145     BTA_AG_SCO_CLOSE_XFER_ST,   /* closing sco being transferred */
146     BTA_AG_SCO_SHUTTING_ST      /* sco shutting down */
147 };
148 
149 /*****************************************************************************
150 **  Data types
151 *****************************************************************************/
152 
153 /* data type for BTA_AG_API_ENABLE_EVT */
154 typedef struct
155 {
156     BT_HDR              hdr;
157     tBTA_AG_PARSE_MODE  parse_mode;
158     tBTA_AG_CBACK      *p_cback;
159 } tBTA_AG_API_ENABLE;
160 
161 /* data type for BTA_AG_API_REGISTER_EVT */
162 typedef struct
163 {
164     BT_HDR              hdr;
165     char                p_name[2][BTA_SERVICE_NAME_LEN+1];
166     tBTA_SERVICE_MASK   services;
167     tBTA_SEC            sec_mask;
168     tBTA_AG_FEAT        features;
169     UINT8               app_id;
170 } tBTA_AG_API_REGISTER;
171 
172 /* data type for BTA_AG_API_OPEN_EVT */
173 typedef struct
174 {
175     BT_HDR              hdr;
176     BD_ADDR             bd_addr;
177     tBTA_SERVICE_MASK   services;
178     tBTA_SEC            sec_mask;
179 } tBTA_AG_API_OPEN;
180 
181 /* data type for BTA_AG_API_RESULT_EVT */
182 typedef struct
183 {
184     BT_HDR            hdr;
185     tBTA_AG_RES       result;
186     tBTA_AG_RES_DATA  data;
187 } tBTA_AG_API_RESULT;
188 
189 /* data type for BTA_AG_API_SETCODEC_EVT */
190 typedef struct
191 {
192     BT_HDR              hdr;
193     tBTA_AG_PEER_CODEC  codec;
194 } tBTA_AG_API_SETCODEC;
195 
196 /* data type for BTA_AG_DISC_RESULT_EVT */
197 typedef struct
198 {
199     BT_HDR          hdr;
200     UINT16          status;
201 } tBTA_AG_DISC_RESULT;
202 
203 /* data type for RFCOMM events */
204 typedef struct
205 {
206     BT_HDR          hdr;
207     UINT16          port_handle;
208 } tBTA_AG_RFC;
209 
210 /* data type for BTA_AG_CI_RX_WRITE_EVT */
211 typedef struct
212 {
213     BT_HDR          hdr;
214 //    char            p_data[BTA_AG_MTU+1];
215 } tBTA_AG_CI_RX_WRITE;
216 
217 /* union of all event datatypes */
218 typedef union
219 {
220     BT_HDR                  hdr;
221     tBTA_AG_API_ENABLE      api_enable;
222     tBTA_AG_API_REGISTER    api_register;
223     tBTA_AG_API_OPEN        api_open;
224     tBTA_AG_API_RESULT      api_result;
225 #if (BTM_WBS_INCLUDED == TRUE )
226     tBTA_AG_API_SETCODEC    api_setcodec;
227 #endif
228     tBTA_AG_DISC_RESULT     disc_result;
229     tBTA_AG_RFC             rfc;
230     tBTA_AG_CI_RX_WRITE     ci_rx_write;
231 } tBTA_AG_DATA;
232 
233 /* type for each profile */
234 typedef struct
235 {
236     UINT32          sdp_handle;
237     UINT8           scn;
238 } tBTA_AG_PROFILE;
239 
240 /* type for each service control block */
241 typedef struct
242 {
243     char                clip[BTA_AG_AT_MAX_LEN+1]; /* number string used for CLIP */
244     UINT16              serv_handle[BTA_AG_NUM_IDX]; /* RFCOMM server handles */
245     tBTA_AG_AT_CB       at_cb;          /* AT command interpreter */
246     TIMER_LIST_ENT      act_timer;     /* ring timer */
247     BD_ADDR             peer_addr;      /* peer bd address */
248     tSDP_DISCOVERY_DB   *p_disc_db;     /* pointer to discovery database */
249     tBTA_SERVICE_MASK   reg_services;   /* services specified in register API */
250     tBTA_SERVICE_MASK   open_services;  /* services specified in open API */
251     UINT16              conn_handle;    /* RFCOMM handle of connected service */
252     tBTA_SEC            serv_sec_mask;  /* server security mask */
253     tBTA_SEC            cli_sec_mask;   /* client security mask */
254     tBTA_AG_FEAT        features;       /* features registered by application */
255     tBTA_AG_PEER_FEAT   peer_features;  /* peer device features */
256     UINT16              peer_version;   /* profile version of peer device */
257     UINT16              hsp_version;    /* HSP profile version */
258 #if (BTM_WBS_INCLUDED == TRUE )
259     tBTA_AG_PEER_CODEC  peer_codecs;    /* codecs for eSCO supported by the peer */
260     tBTA_AG_PEER_CODEC  sco_codec;      /* codec to be used for eSCO connection */
261     tBTA_AG_PEER_CODEC  inuse_codec;    /* codec being used for the current SCO connection */
262     BOOLEAN             codec_updated;  /* set to TRUE whenever the app updates codec type */
263     BOOLEAN             codec_fallback; /* If sco nego fails for mSBC, fallback to CVSD */
264     TIMER_LIST_ENT      cn_timer;       /* codec negotiation timer */
265 #endif
266     UINT16              sco_idx;        /* SCO handle */
267     BOOLEAN             in_use;         /* scb in use */
268     BOOLEAN             dealloc;        /* TRUE if service shutting down */
269     BOOLEAN             clip_enabled;   /* set to TRUE if HF enables CLIP reporting */
270     BOOLEAN             ccwa_enabled;   /* set to TRUE if HF enables CCWA reporting */
271     BOOLEAN             cmer_enabled;   /* set to TRUE if HF enables CMER reporting */
272     BOOLEAN             cmee_enabled;   /* set to TRUE if HF enables CME ERROR reporting */
273     BOOLEAN             inband_enabled; /* set to TRUE if inband ring enabled */
274     BOOLEAN             svc_conn;       /* set to TRUE when service level connection up */
275     TIMER_LIST_ENT      colli_timer;    /* Collision timer */
276     BOOLEAN             colli_tmr_on;   /* TRUE if collision timer is active */
277     UINT8               state;          /* state machine state */
278     UINT8               conn_service;   /* connected service */
279     UINT8               peer_scn;       /* peer scn */
280     UINT8               app_id;         /* application id */
281     UINT8               role;           /* initiator/acceptor role */
282     UINT8               post_sco;       /* action to perform after sco event */
283     UINT8               call_ind;       /* CIEV call indicator value */
284     UINT8               callsetup_ind;  /* CIEV callsetup indicator value */
285     UINT8               service_ind;    /* CIEV service indicator value */
286     UINT8               signal_ind;     /* CIEV signal indicator value */
287     UINT8               roam_ind;       /* CIEV roam indicator value */
288     UINT8               battchg_ind;    /* CIEV battery charge indicator value */
289     UINT8               callheld_ind;   /* CIEV call held indicator value */
290     BOOLEAN             retry_with_sco_only; /* indicator to try with SCO only when eSCO fails */
291     UINT32              bia_masked_out; /* indicators HF does not want us to send */
292 } tBTA_AG_SCB;
293 
294 /* type for sco data */
295 typedef struct
296 {
297     tBTM_ESCO_CONN_REQ_EVT_DATA  conn_data;     /* SCO data for pending conn request */
298     tBTA_AG_SCB                 *p_curr_scb;    /* SCB associated with SCO connection */
299     tBTA_AG_SCB                 *p_xfer_scb;    /* SCB associated with SCO transfer */
300     UINT16                      cur_idx;        /* SCO handle */
301     UINT8                       state;          /* SCO state variable */
302     BOOLEAN                     param_updated;  /* if params were updated to non-default */
303     tBTM_ESCO_PARAMS            params;         /* ESCO parameters */
304 } tBTA_AG_SCO_CB;
305 
306 
307 /* type for AG control block */
308 typedef struct
309 {
310     tBTA_AG_SCB         scb[BTA_AG_NUM_SCB];        /* service control blocks */
311     tBTA_AG_PROFILE     profile[BTA_AG_NUM_IDX];    /* profile-specific data */
312     tBTA_AG_SCO_CB      sco;                        /* SCO data */
313     tBTA_AG_CBACK       *p_cback;                   /* application callback */
314     tBTA_AG_PARSE_MODE  parse_mode;                 /* parse/pass-through mode */
315 } tBTA_AG_CB;
316 
317 /*****************************************************************************
318 **  Global data
319 *****************************************************************************/
320 
321 /* constant lookup tables */
322 extern const UINT16 bta_ag_uuid[BTA_AG_NUM_IDX];
323 extern const UINT8 bta_ag_sec_id[BTA_AG_NUM_IDX];
324 extern const tBTA_AG_AT_CMD *bta_ag_at_tbl[BTA_AG_NUM_IDX];
325 
326 /* control block declaration */
327 #if BTA_DYNAMIC_MEMORY == FALSE
328 extern tBTA_AG_CB bta_ag_cb;
329 #else
330 extern tBTA_AG_CB *bta_ag_cb_ptr;
331 #define bta_ag_cb (*bta_ag_cb_ptr)
332 #endif
333 
334 /* config struct */
335 extern tBTA_AG_CFG *p_bta_ag_cfg;
336 
337 /*****************************************************************************
338 **  Function prototypes
339 *****************************************************************************/
340 
341 /* main functions */
342 extern void bta_ag_scb_dealloc(tBTA_AG_SCB *p_scb);
343 extern UINT16 bta_ag_scb_to_idx(tBTA_AG_SCB *p_scb);
344 extern tBTA_AG_SCB *bta_ag_scb_by_idx(UINT16 idx);
345 extern UINT8 bta_ag_service_to_idx(tBTA_SERVICE_MASK services);
346 extern UINT16 bta_ag_idx_by_bdaddr(BD_ADDR peer_addr);
347 extern BOOLEAN bta_ag_other_scb_open(tBTA_AG_SCB *p_curr_scb);
348 extern tBTA_AG_SCB *bta_ag_get_other_idle_scb (tBTA_AG_SCB *p_curr_scb);
349 extern void bta_ag_sm_execute(tBTA_AG_SCB *p_scb, UINT16 event, tBTA_AG_DATA *p_data);
350 extern BOOLEAN bta_ag_hdl_event(BT_HDR *p_msg);
351 extern void bta_ag_collision_cback (tBTA_SYS_CONN_STATUS status, UINT8 id,
352                                     UINT8 app_id, BD_ADDR peer_addr);
353 extern void bta_ag_resume_open (tBTA_AG_SCB *p_scb);
354 
355 /* SDP functions */
356 extern BOOLEAN bta_ag_add_record(UINT16 service_uuid, char *p_service_name, UINT8 scn,
357                                  tBTA_AG_FEAT features, UINT32 sdp_handle);
358 extern void bta_ag_create_records(tBTA_AG_SCB *p_scb, tBTA_AG_DATA *p_data);
359 extern void bta_ag_del_records(tBTA_AG_SCB *p_scb, tBTA_AG_DATA *p_data);
360 extern BOOLEAN bta_ag_sdp_find_attr(tBTA_AG_SCB *p_scb, tBTA_SERVICE_MASK service);
361 extern void bta_ag_do_disc(tBTA_AG_SCB *p_scb, tBTA_SERVICE_MASK service);
362 extern void bta_ag_free_db(tBTA_AG_SCB *p_scb, tBTA_AG_DATA *p_data);
363 
364 /* RFCOMM functions */
365 extern void bta_ag_start_servers(tBTA_AG_SCB *p_scb, tBTA_SERVICE_MASK services);
366 extern void bta_ag_close_servers(tBTA_AG_SCB *p_scb, tBTA_SERVICE_MASK services);
367 extern BOOLEAN bta_ag_is_server_closed (tBTA_AG_SCB *p_scb);
368 extern void bta_ag_rfc_do_close(tBTA_AG_SCB *p_scb, tBTA_AG_DATA *p_data);
369 extern void bta_ag_rfc_do_open(tBTA_AG_SCB *p_scb, tBTA_AG_DATA *p_data);
370 
371 /* SCO functions */
372 extern BOOLEAN bta_ag_sco_is_open(tBTA_AG_SCB *p_scb);
373 extern BOOLEAN bta_ag_sco_is_opening(tBTA_AG_SCB *p_scb);
374 extern void bta_ag_sco_conn_rsp(tBTA_AG_SCB *p_scb, tBTM_ESCO_CONN_REQ_EVT_DATA *p_data);
375 
376 /* AT command functions */
377 extern void bta_ag_at_hsp_cback(tBTA_AG_SCB *p_scb, UINT16 cmd, UINT8 arg_type,
378                                 char *p_arg, INT16 int_arg);
379 extern void bta_ag_at_hfp_cback(tBTA_AG_SCB *p_scb, UINT16 cmd, UINT8 arg_type,
380                                 char *p_arg, INT16 int_arg);
381 extern void bta_ag_at_err_cback(tBTA_AG_SCB *p_scb, BOOLEAN unknown, char *p_arg);
382 extern BOOLEAN bta_ag_inband_enabled(tBTA_AG_SCB *p_scb);
383 extern void bta_ag_send_call_inds(tBTA_AG_SCB *p_scb, tBTA_AG_RES result);
384 
385 /* Action functions */
386 extern void bta_ag_register(tBTA_AG_SCB *p_scb, tBTA_AG_DATA *p_data);
387 extern void bta_ag_deregister(tBTA_AG_SCB *p_scb, tBTA_AG_DATA *p_data);
388 extern void bta_ag_start_dereg(tBTA_AG_SCB *p_scb, tBTA_AG_DATA *p_data);
389 extern void bta_ag_start_close(tBTA_AG_SCB *p_scb, tBTA_AG_DATA *p_data);
390 extern void bta_ag_start_open(tBTA_AG_SCB *p_scb, tBTA_AG_DATA *p_data);
391 extern void bta_ag_disc_int_res(tBTA_AG_SCB *p_scb, tBTA_AG_DATA *p_data);
392 extern void bta_ag_disc_acp_res(tBTA_AG_SCB *p_scb, tBTA_AG_DATA *p_data);
393 extern void bta_ag_disc_fail(tBTA_AG_SCB *p_scb, tBTA_AG_DATA *p_data);
394 extern void bta_ag_open_fail(tBTA_AG_SCB *p_scb, tBTA_AG_DATA *p_data);
395 extern void bta_ag_rfc_fail(tBTA_AG_SCB *p_scb, tBTA_AG_DATA *p_data);
396 extern void bta_ag_rfc_close(tBTA_AG_SCB *p_scb, tBTA_AG_DATA *p_data);
397 extern void bta_ag_rfc_open(tBTA_AG_SCB *p_scb, tBTA_AG_DATA *p_data);
398 extern void bta_ag_rfc_acp_open(tBTA_AG_SCB *p_scb, tBTA_AG_DATA *p_data);
399 extern void bta_ag_rfc_data(tBTA_AG_SCB *p_scb, tBTA_AG_DATA *p_data);
400 extern void bta_ag_sco_listen(tBTA_AG_SCB *p_scb, tBTA_AG_DATA *p_data);
401 extern void bta_ag_sco_open(tBTA_AG_SCB *p_scb, tBTA_AG_DATA *p_data);
402 extern void bta_ag_sco_close(tBTA_AG_SCB *p_scb, tBTA_AG_DATA *p_data);
403 #if (BTM_WBS_INCLUDED == TRUE )
404 extern void bta_ag_sco_codec_nego(tBTA_AG_SCB *p_scb, BOOLEAN result);
405 extern void bta_ag_codec_negotiate (tBTA_AG_SCB *p_scb);
406 #endif
407 extern void bta_ag_sco_shutdown(tBTA_AG_SCB *p_scb, tBTA_AG_DATA *p_data);
408 extern void bta_ag_sco_conn_open(tBTA_AG_SCB *p_scb, tBTA_AG_DATA *p_data);
409 extern void bta_ag_sco_conn_close(tBTA_AG_SCB *p_scb, tBTA_AG_DATA *p_data);
410 extern void bta_ag_post_sco_open(tBTA_AG_SCB *p_scb, tBTA_AG_DATA *p_data);
411 extern void bta_ag_post_sco_close(tBTA_AG_SCB *p_scb, tBTA_AG_DATA *p_data);
412 extern void bta_ag_svc_conn_open(tBTA_AG_SCB *p_scb, tBTA_AG_DATA *p_data);
413 extern void bta_ag_result(tBTA_AG_SCB *p_scb, tBTA_AG_DATA *p_data);
414 extern void bta_ag_setcodec(tBTA_AG_SCB *p_scb, tBTA_AG_DATA *p_data);
415 #if (BTM_WBS_INCLUDED == TRUE )
416 extern void bta_ag_send_bcs(tBTA_AG_SCB *p_scb, tBTA_AG_DATA *p_data);
417 #endif
418 extern void bta_ag_send_ring(tBTA_AG_SCB *p_scb, tBTA_AG_DATA *p_data);
419 extern void bta_ag_ci_sco_data(tBTA_AG_SCB *p_scb, tBTA_AG_DATA *p_data);
420 extern void bta_ag_set_esco_param(BOOLEAN set_reset, tBTM_ESCO_PARAMS *param);
421 extern void bta_ag_ci_rx_data(tBTA_AG_SCB *p_scb, tBTA_AG_DATA *p_data);
422 extern void bta_ag_rcvd_slc_ready(tBTA_AG_SCB *p_scb, tBTA_AG_DATA *p_data);
423 #endif /* BTA_AG_INT_H */
424