Home | History | Annotate | Download | only in include
      1 /******************************************************************************
      2  *
      3  *  Copyright (c) 2014 The Android Open Source Project
      4  *  Copyright 2003-2012 Broadcom Corporation
      5  *
      6  *  Licensed under the Apache License, Version 2.0 (the "License");
      7  *  you may not use this file except in compliance with the License.
      8  *  You may obtain a copy of the License at:
      9  *
     10  *  http://www.apache.org/licenses/LICENSE-2.0
     11  *
     12  *  Unless required by applicable law or agreed to in writing, software
     13  *  distributed under the License is distributed on an "AS IS" BASIS,
     14  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     15  *  See the License for the specific language governing permissions and
     16  *  limitations under the License.
     17  *
     18  ******************************************************************************/
     19 
     20 /******************************************************************************
     21  *
     22  *  This is the public interface file for the handsfree (HF role) subsystem
     23  *
     24  ******************************************************************************/
     25 #ifndef BTA_HF_CLIENT_API_H
     26 #define BTA_HF_CLIENT_API_H
     27 
     28 #include "bta_api.h"
     29 
     30 /*****************************************************************************
     31  *  Constants and data types
     32  ****************************************************************************/
     33 
     34 /* HFP peer (AG) features*/
     35 #define BTA_HF_CLIENT_PEER_FEAT_3WAY 0x00000001 /* Three-way calling */
     36 #define BTA_HF_CLIENT_PEER_FEAT_ECNR \
     37   0x00000002 /* Echo cancellation and/or noise reduction */
     38 #define BTA_HF_CLIENT_PEER_FEAT_VREC 0x00000004 /* Voice recognition */
     39 #define BTA_HF_CLIENT_PEER_INBAND 0x00000008    /* In-band ring tone */
     40 #define BTA_HF_CLIENT_PEER_VTAG \
     41   0x00000010 /* Attach a phone number to a voice tag */
     42 #define BTA_HF_CLIENT_PEER_REJECT \
     43   0x00000020                              /* Ability to reject incoming call */
     44 #define BTA_HF_CLIENT_PEER_ECS 0x00000040 /* Enhanced Call Status */
     45 #define BTA_HF_CLIENT_PEER_ECC 0x00000080 /* Enhanced Call Control */
     46 #define BTA_HF_CLIENT_PEER_EXTERR 0x00000100 /* Extended error codes */
     47 #define BTA_HF_CLIENT_PEER_CODEC 0x00000200  /* Codec Negotiation */
     48 
     49 typedef uint16_t tBTA_HF_CLIENT_PEER_FEAT;
     50 
     51 /* HFP HF features */
     52 #define BTA_HF_CLIENT_FEAT_ECNR \
     53   0x00000001 /* Echo cancellation and/or noise reduction */
     54 #define BTA_HF_CLIENT_FEAT_3WAY \
     55   0x00000002 /* Call waiting and three-way calling */
     56 #define BTA_HF_CLIENT_FEAT_CLI \
     57   0x00000004 /* Caller ID presentation capability */
     58 #define BTA_HF_CLIENT_FEAT_VREC 0x00000008  /* Voice recognition activation */
     59 #define BTA_HF_CLIENT_FEAT_VOL 0x00000010   /* Remote volume control */
     60 #define BTA_HF_CLIENT_FEAT_ECS 0x00000020   /* Enhanced Call Status */
     61 #define BTA_HF_CLIENT_FEAT_ECC 0x00000040   /* Enhanced Call Control */
     62 #define BTA_HF_CLIENT_FEAT_CODEC 0x00000080 /* Codec Negotiation */
     63 
     64 /* HFP HF extended call handling - masks not related to any spec */
     65 #define BTA_HF_CLIENT_CHLD_REL \
     66   0x00000001 /* 0  Release waiting call or held calls */
     67 #define BTA_HF_CLIENT_CHLD_REL_ACC                                             \
     68   0x00000002 /* 1  Release active calls and accept other (waiting or held) cal \
     69                 */
     70 #define BTA_HF_CLIENT_CHLD_REL_X 0x00000004 /* 1x Release x call*/
     71 #define BTA_HF_CLIENT_CHLD_HOLD_ACC \
     72   0x00000008 /* 2  Active calls on hold and accept other call */
     73 #define BTA_HF_CLIENT_CHLD_PRIV_X \
     74   0x00000010 /* 2x Active multiparty call on hold except call x */
     75 #define BTA_HF_CLIENT_CHLD_MERGE               \
     76   0x00000020 /* 3  Add held call to multiparty \
     77                 */
     78 #define BTA_HF_CLIENT_CHLD_MERGE_DETACH \
     79   0x00000040 /* 4  Add held call to multiparty */
     80 
     81 typedef uint16_t tBTA_HF_CLIENT_CHLD_FEAT;
     82 
     83 /* HFP AG errors ot OK sent to HF Unit */
     84 #define BTA_HF_CLIENT_AT_RESULT_OK 0
     85 #define BTA_HF_CLIENT_AT_RESULT_ERROR 1
     86 #define BTA_HF_CLIENT_AT_RESULT_NO_CARRIER 2
     87 #define BTA_HF_CLIENT_AT_RESULT_BUSY 3
     88 #define BTA_HF_CLIENT_AT_RESULT_NO_ANSWER 4
     89 #define BTA_HF_CLIENT_AT_RESULT_DELAY 5
     90 #define BTA_HF_CLIENT_AT_RESULT_BLACKLISTED 6
     91 #define BTA_HF_CLIENT_AT_RESULT_CME 7
     92 
     93 typedef uint8_t tBTA_HF_CLIENT_AT_RESULT_TYPE;
     94 
     95 /* HF Client callback events */
     96 #define BTA_HF_CLIENT_ENABLE_EVT 0     /* HF Client enabled */
     97 #define BTA_HF_CLIENT_REGISTER_EVT 1   /* HF Client registered */
     98 #define BTA_HF_CLIENT_OPEN_EVT 2       /* HF Client connection open */
     99 #define BTA_HF_CLIENT_CLOSE_EVT 3      /* HF Client connection closed */
    100 #define BTA_HF_CLIENT_CONN_EVT 4       /* Service level connection opened */
    101 #define BTA_HF_CLIENT_AUDIO_OPEN_EVT 5 /* Audio connection open */
    102 #define BTA_HF_CLIENT_AUDIO_MSBC_OPEN_EVT \
    103   6 /* Audio connection with mSBC codec open */
    104 #define BTA_HF_CLIENT_AUDIO_CLOSE_EVT 7 /* Audio connection closed */
    105 #define BTA_HF_CLIENT_SPK_EVT 8         /* Speaker volume changed */
    106 #define BTA_HF_CLIENT_MIC_EVT 9         /* Microphone volume changed */
    107 #define BTA_HF_CLIENT_IND_EVT 10        /* Indicator */
    108 #define BTA_HF_CLIENT_VOICE_REC_EVT \
    109   11 /* AG changed voice recognition setting */
    110 #define BTA_HF_CLIENT_OPERATOR_NAME_EVT 12 /* Operator name acquired */
    111 #define BTA_HF_CLIENT_CLIP_EVT 13      /* Calling line identification event */
    112 #define BTA_HF_CLIENT_CCWA_EVT 14      /* Call waiting notification */
    113 #define BTA_HF_CLIENT_AT_RESULT_EVT 15 /* Call waiting notification */
    114 #define BTA_HF_CLIENT_CLCC_EVT 16      /* current call event */
    115 #define BTA_HF_CLIENT_CNUM_EVT 17      /* subscriber information event */
    116 #define BTA_HF_CLIENT_BTRH_EVT 18      /* bluetooth response and hold event */
    117 #define BTA_HF_CLIENT_BSIR_EVT                                               \
    118   19                              /* in-band ring tone setting changed event \
    119                                      */
    120 #define BTA_HF_CLIENT_BINP_EVT 20 /* binp number event */
    121 #define BTA_HF_CLIENT_RING_INDICATION 21 /* HF Client ring indication */
    122 #define BTA_HF_CLIENT_DISABLE_EVT 30     /* HF Client disabled */
    123 
    124 typedef uint8_t tBTA_HF_CLIENT_EVT;
    125 
    126 /* HF Client open status */
    127 #define BTA_HF_CLIENT_SUCCESS 0        /* Connection successfully opened */
    128 #define BTA_HF_CLIENT_FAIL_SDP 1       /* Open failed due to SDP */
    129 #define BTA_HF_CLIENT_FAIL_RFCOMM 2    /* Open failed due to RFCOMM */
    130 #define BTA_HF_CLIENT_FAIL_RESOURCES 3 /* out of resources failure  */
    131 
    132 typedef uint8_t tBTA_HF_CLIENT_STATUS;
    133 
    134 /* indicator type */
    135 #define BTA_HF_CLIENT_IND_BATTCH 0    /* Battery charge indicator */
    136 #define BTA_HF_CLIENT_IND_SIGNAL 1    /* Signal Strength indicator */
    137 #define BTA_HF_CLIENT_IND_SERVICE 2   /* Service availability indicator */
    138 #define BTA_HF_CLIENT_IND_CALL 3      /* Standard call status indicator*/
    139 #define BTA_HF_CLIENT_IND_ROAM 4      /* Roaming status indicator */
    140 #define BTA_HF_CLIENT_IND_CALLSETUP 5 /* Call setup status indicator */
    141 #define BTA_HF_CLIENT_IND_CALLHELD 6  /* Call hold status indicator */
    142 
    143 typedef uint8_t tBTA_HF_CLIENT_IND_TYPE;
    144 
    145 /* AT commands */
    146 #define BTA_HF_CLIENT_AT_CMD_VTS 0
    147 #define BTA_HF_CLIENT_AT_CMD_BTRH 1
    148 #define BTA_HF_CLIENT_AT_CMD_CHUP 2
    149 #define BTA_HF_CLIENT_AT_CMD_CHLD 3
    150 #define BTA_HF_CLIENT_AT_CMD_BCC 4
    151 #define BTA_HF_CLIENT_AT_CMD_CNUM 5
    152 #define BTA_HF_CLIENT_AT_CMD_ATA 6
    153 #define BTA_HF_CLIENT_AT_CMD_COPS 7
    154 #define BTA_HF_CLIENT_AT_CMD_ATD 8
    155 #define BTA_HF_CLIENT_AT_CMD_VGM 9
    156 #define BTA_HF_CLIENT_AT_CMD_VGS 10
    157 #define BTA_HF_CLIENT_AT_CMD_BVRA 11
    158 #define BTA_HF_CLIENT_AT_CMD_CLCC 12
    159 #define BTA_HF_CLIENT_AT_CMD_BINP 13
    160 #define BTA_HF_CLIENT_AT_CMD_BLDN 14
    161 #define BTA_HF_CLIENT_AT_CMD_NREC 15
    162 
    163 typedef uint8_t tBTA_HF_CLIENT_AT_CMD_TYPE;
    164 
    165 /* data associated with BTA_HF_CLIENT_REGISTER_EVT */
    166 typedef struct {
    167   RawAddress bd_addr;
    168   tBTA_HF_CLIENT_STATUS status;
    169 } tBTA_HF_CLIENT_REGISTER;
    170 
    171 /* data associated with BTA_HF_CLIENT_OPEN_EVT */
    172 typedef struct {
    173   RawAddress bd_addr;
    174   uint16_t handle;  // Handle for client control block
    175   tBTA_HF_CLIENT_STATUS status;
    176 } tBTA_HF_CLIENT_OPEN;
    177 
    178 /* data associated with BTA_HF_CLIENT_CONN_EVT */
    179 typedef struct {
    180   RawAddress bd_addr;
    181   tBTA_HF_CLIENT_PEER_FEAT peer_feat;
    182   tBTA_HF_CLIENT_CHLD_FEAT chld_feat;
    183 } tBTA_HF_CLIENT_CONN;
    184 
    185 /* data associated with BTA_HF_CLIENT_IND_EVT event */
    186 typedef struct {
    187   RawAddress bd_addr;
    188   tBTA_HF_CLIENT_IND_TYPE type;
    189   uint16_t value;
    190 } tBTA_HF_CLIENT_IND;
    191 
    192 /* data associated with BTA_HF_CLIENT_OPERATOR_NAME_EVT */
    193 #define BTA_HF_CLIENT_OPERATOR_NAME_LEN 16
    194 typedef struct {
    195   RawAddress bd_addr;
    196   char name[BTA_HF_CLIENT_OPERATOR_NAME_LEN + 1];
    197 } tBTA_HF_CLIENT_OPERATOR_NAME;
    198 
    199 /* data associated with BTA_HF_CLIENT_CLIP_EVT  and BTA_HF_CLIENT_CCWA_EVT*/
    200 #define BTA_HF_CLIENT_NUMBER_LEN 32
    201 typedef struct {
    202   RawAddress bd_addr;
    203   char number[BTA_HF_CLIENT_NUMBER_LEN + 1];
    204 } tBTA_HF_CLIENT_NUMBER;
    205 
    206 /* data associated with BTA_HF_CLIENT_AT_RESULT_EVT event */
    207 typedef struct {
    208   RawAddress bd_addr;
    209   tBTA_HF_CLIENT_AT_RESULT_TYPE type;
    210   uint16_t cme;
    211 } tBTA_HF_CLIENT_AT_RESULT;
    212 
    213 /* data associated with BTA_HF_CLIENT_CLCC_EVT event */
    214 typedef struct {
    215   RawAddress bd_addr;
    216   uint32_t idx;
    217   bool inc;
    218   uint8_t status;
    219   bool mpty;
    220   bool number_present;
    221   char number[BTA_HF_CLIENT_NUMBER_LEN + 1];
    222 } tBTA_HF_CLIENT_CLCC;
    223 
    224 /* data associated with BTA_HF_CLIENT_CNUM_EVT event */
    225 typedef struct {
    226   RawAddress bd_addr;
    227   uint16_t service;
    228   char number[BTA_HF_CLIENT_NUMBER_LEN + 1];
    229 } tBTA_HF_CLIENT_CNUM;
    230 
    231 /* data associated with other events */
    232 typedef struct {
    233   RawAddress bd_addr;
    234   uint16_t value;
    235 } tBTA_HF_CLIENT_VAL;
    236 
    237 /* union of data associated with AG callback */
    238 typedef union {
    239   // Common BD ADDR field for all tyepdefs
    240   RawAddress bd_addr;
    241   tBTA_HF_CLIENT_REGISTER reg;
    242   tBTA_HF_CLIENT_OPEN open;
    243   tBTA_HF_CLIENT_CONN conn;
    244   tBTA_HF_CLIENT_IND ind;
    245   tBTA_HF_CLIENT_VAL val;
    246   tBTA_HF_CLIENT_OPERATOR_NAME operator_name;
    247   tBTA_HF_CLIENT_NUMBER number;
    248   tBTA_HF_CLIENT_AT_RESULT result;
    249   tBTA_HF_CLIENT_CLCC clcc;
    250   tBTA_HF_CLIENT_CNUM cnum;
    251 } tBTA_HF_CLIENT;
    252 
    253 typedef uint32_t tBTA_HF_CLIENT_FEAT;
    254 
    255 /* HF Client callback */
    256 typedef void(tBTA_HF_CLIENT_CBACK)(tBTA_HF_CLIENT_EVT event,
    257                                    tBTA_HF_CLIENT* p_data);
    258 
    259 /*****************************************************************************
    260  *  External Function Declarations
    261  ****************************************************************************/
    262 
    263 /*******************************************************************************
    264  *
    265  * Function         BTA_HfClientEnable
    266  *
    267  * Description      Enable the HF CLient service. When the enable
    268  *                  operation is complete the callback function will be
    269  *                  called with a BTA_HF_CLIENT_ENABLE_EVT. This function must
    270  *                  be called before other function in the HF CLient API are
    271  *                  called.
    272  *
    273  * Returns          BTA_SUCCESS if OK, BTA_FAILURE otherwise.
    274  *
    275  ******************************************************************************/
    276 tBTA_STATUS BTA_HfClientEnable(tBTA_HF_CLIENT_CBACK* p_cback, tBTA_SEC sec_mask,
    277                                tBTA_HF_CLIENT_FEAT features,
    278                                const char* p_service_name);
    279 
    280 /*******************************************************************************
    281  *
    282  * Function         BTA_HfClientDisable
    283  *
    284  * Description      Disable the HF Client service.
    285  *
    286  * Returns          void
    287  *
    288  ******************************************************************************/
    289 void BTA_HfClientDisable(void);
    290 
    291 /*******************************************************************************
    292  *
    293  * Function         BTA_HfClientOpen
    294  *
    295  * Description      Opens a connection to an audio gateway.
    296  *                  When connection is open callback function is called
    297  *                  with a BTA_HF_CLIENT_OPEN_EVT. Only the data connection is
    298  *                  opened. The audio connection is not opened. The handle
    299  *                  is stored in p_handle and should be used for subsequent
    300  *                  calls to do any AT operations
    301  *
    302  *
    303  * Returns          void
    304  *
    305  ******************************************************************************/
    306 void BTA_HfClientOpen(const RawAddress& bd_addr, tBTA_SEC sec_mask,
    307                       uint16_t* p_handle);
    308 
    309 /*******************************************************************************
    310  *
    311  * Function         BTA_HfClientClose
    312  *
    313  * Description      Close the current connection to an audio gateway.
    314  *                  Any current audio connection will also be closed
    315  *
    316  *
    317  * Returns          void
    318  *
    319  ******************************************************************************/
    320 void BTA_HfClientClose(uint16_t handle);
    321 
    322 /*******************************************************************************
    323  *
    324  * Function         BTA_HfCllientAudioOpen
    325  *
    326  * Description      Opens an audio connection to the currently connected
    327  *                 audio gateway
    328  *
    329  *
    330  * Returns          void
    331  *
    332  ******************************************************************************/
    333 void BTA_HfClientAudioOpen(uint16_t handle);
    334 
    335 /*******************************************************************************
    336  *
    337  * Function         BTA_HfClientAudioClose
    338  *
    339  * Description      Close the currently active audio connection to an audio
    340  *                  gateway. The data connection remains open
    341  *
    342  *
    343  * Returns          void
    344  *
    345  ******************************************************************************/
    346 void BTA_HfClientAudioClose(uint16_t handle);
    347 
    348 /*******************************************************************************
    349  *
    350  * Function         BTA_HfClientSendAT
    351  *
    352  * Description      send AT command
    353  *
    354  *
    355  * Returns          void
    356  *
    357  ******************************************************************************/
    358 void BTA_HfClientSendAT(uint16_t handle, tBTA_HF_CLIENT_AT_CMD_TYPE at,
    359                         uint32_t val1, uint32_t val2, const char* str);
    360 
    361 /*******************************************************************************
    362  *
    363  * Function         BTA_HfClientDumpStatistics
    364  *
    365  * Description      Dump statistics about the various control blocks
    366  *                  and other relevant connection statistics
    367  *
    368  * Returns          Void
    369  *
    370  ******************************************************************************/
    371 void BTA_HfClientDumpStatistics(int fd);
    372 
    373 #endif /* BTA_HF_CLIENT_API_H */
    374