"ag/bta_ag_api.cc",
"ag/bta_ag_at.cc",
"ag/bta_ag_cfg.cc",
- "ag/bta_ag_ci.cc",
"ag/bta_ag_cmd.cc",
"ag/bta_ag_main.cc",
"ag/bta_ag_rfc.cc",
*
******************************************************************************/
-#include <string.h>
+#include <cstring>
#include "bta_ag_api.h"
#include "bta_ag_co.h"
******************************************************************************/
static void bta_ag_cback_open(tBTA_AG_SCB* p_scb, tBTA_AG_DATA* p_data,
tBTA_AG_STATUS status) {
- tBTA_AG_OPEN open;
+ tBTA_AG_OPEN open = {};
/* call app callback with open event */
open.hdr.handle = bta_ag_scb_to_idx(p_scb);
*
******************************************************************************/
void bta_ag_register(tBTA_AG_SCB* p_scb, tBTA_AG_DATA* p_data) {
- tBTA_AG_REGISTER reg;
+ tBTA_AG_REGISTER reg = {};
/* initialize control block */
p_scb->reg_services = p_data->api_register.services;
*
******************************************************************************/
void bta_ag_start_open(tBTA_AG_SCB* p_scb, tBTA_AG_DATA* p_data) {
- RawAddress pending_bd_addr;
+ RawAddress pending_bd_addr = {};
/* store parameters */
if (p_data) {
p_scb->peer_addr = RawAddress::kEmpty;
/* call open cback w. failure */
- bta_ag_cback_open(p_scb, NULL, BTA_AG_FAIL_SDP);
+ bta_ag_cback_open(p_scb, nullptr, BTA_AG_FAIL_SDP);
}
/*******************************************************************************
bta_ag_start_servers(p_scb, p_scb->reg_services);
/* call open cback w. failure */
- bta_ag_cback_open(p_scb, NULL, BTA_AG_FAIL_RFCOMM);
+ bta_ag_cback_open(p_scb, nullptr, BTA_AG_FAIL_RFCOMM);
}
/*******************************************************************************
*
******************************************************************************/
void bta_ag_rfc_close(tBTA_AG_SCB* p_scb, UNUSED_ATTR tBTA_AG_DATA* p_data) {
- tBTA_AG_CLOSE close;
+ tBTA_AG_CLOSE close = {};
tBTA_SERVICE_MASK services;
int i, num_active_conn = 0;
p_scb->hsp_version = HSP_VERSION_1_2;
bta_ag_at_reinit(&p_scb->at_cb);
- memset(&(p_scb->peer_hf_indicators), 0, sizeof(p_scb->peer_hf_indicators));
- memset(&(p_scb->local_hf_indicators), 0, sizeof(p_scb->local_hf_indicators));
+ for (auto& peer_hf_indicator : p_scb->peer_hf_indicators) {
+ peer_hf_indicator = {};
+ }
+ for (auto& local_hf_indicator : p_scb->local_hf_indicators) {
+ local_hf_indicator = {};
+ }
/* stop timers */
alarm_cancel(p_scb->ring_timer);
p_scb->conn_handle = 0;
/* Make sure SCO state is BTA_AG_SCO_SHUTDOWN_ST */
- bta_ag_sco_shutdown(p_scb, NULL);
+ bta_ag_sco_shutdown(p_scb, nullptr);
/* Check if all the SLCs are down */
for (i = 0; i < BTA_AG_NUM_SCB; i++) {
bta_sys_conn_open(BTA_ID_AG, p_scb->app_id, p_scb->peer_addr);
- bta_ag_cback_open(p_scb, NULL, BTA_AG_SUCCESS);
+ bta_ag_cback_open(p_scb, nullptr, BTA_AG_SUCCESS);
if (p_scb->conn_service == BTA_AG_HFP) {
/* if hfp start timer for service level conn */
uint16_t lcid;
int i;
tBTA_AG_SCB *ag_scb, *other_scb;
- RawAddress dev_addr;
+ RawAddress dev_addr = {};
int status;
/* set role */
******************************************************************************/
void bta_ag_rfc_data(tBTA_AG_SCB* p_scb, UNUSED_ATTR tBTA_AG_DATA* p_data) {
uint16_t len;
- char buf[BTA_AG_RFC_READ_MAX];
-
- memset(buf, 0, BTA_AG_RFC_READ_MAX);
+ char buf[BTA_AG_RFC_READ_MAX] = "";
APPL_TRACE_DEBUG("%s", __func__);
******************************************************************************/
void bta_ag_svc_conn_open(tBTA_AG_SCB* p_scb,
UNUSED_ATTR tBTA_AG_DATA* p_data) {
- tBTA_AG_CONN evt;
+ tBTA_AG_CONN evt = {};
if (!p_scb->svc_conn) {
/* set state variable */
if (bta_ag_cb.parse_mode == BTA_AG_PASS_THROUGH) {
/* In pass-through mode, BTA knows that SLC is ready only through call-in.
*/
- bta_ag_svc_conn_open(p_scb, NULL);
+ bta_ag_svc_conn_open(p_scb, nullptr);
}
}
******************************************************************************/
void bta_ag_setcodec(tBTA_AG_SCB* p_scb, tBTA_AG_DATA* p_data) {
tBTA_AG_PEER_CODEC codec_type = p_data->api_setcodec.codec;
- tBTA_AG_VAL val;
+ tBTA_AG_VAL val = {};
/* Check if the requested codec type is valid */
if ((codec_type != BTA_AG_CODEC_NONE) && (codec_type != BTA_AG_CODEC_CVSD) &&
******************************************************************************/
#include "bta_ag_api.h"
-#include <string.h>
+#include <cstring>
#include "bt_common.h"
#include "bta_ag_int.h"
#include "bta_api.h"
tBTA_STATUS BTA_AgEnable(tBTA_AG_PARSE_MODE parse_mode,
tBTA_AG_CBACK* p_cback) {
/* Error if AG is already enabled, or AG is in the middle of disabling. */
- for (int idx = 0; idx < BTA_AG_NUM_SCB; idx++) {
- if (bta_ag_cb.scb[idx].in_use) {
+ for (const tBTA_AG_SCB& scb : bta_ag_cb.scb) {
+ if (scb.in_use) {
APPL_TRACE_ERROR("BTA_AgEnable: FAILED, AG already enabled.");
return BTA_FAILURE;
}
* Returns void
*
******************************************************************************/
-void BTA_AgDisable(void) {
+void BTA_AgDisable() {
BT_HDR* p_buf = (BT_HDR*)osi_malloc(sizeof(BT_HDR));
p_buf->event = BTA_AG_API_DISABLE_EVT;
*
******************************************************************************/
-#include <string.h>
+#include <cstring>
#include "bt_common.h"
#include "bta_ag_at.h"
*
*****************************************************************************/
void bta_ag_at_init(tBTA_AG_AT_CB* p_cb) {
- p_cb->p_cmd_buf = NULL;
+ p_cb->p_cmd_buf = nullptr;
p_cb->cmd_pos = 0;
}
if (int_arg < (int16_t)p_cb->p_at_tbl[idx].min ||
int_arg > (int16_t)p_cb->p_at_tbl[idx].max) {
/* arg out of range; error */
- (*p_cb->p_err_cback)((tBTA_AG_SCB*)p_cb->p_user, false, NULL);
+ (*p_cb->p_err_cback)((tBTA_AG_SCB*)p_cb->p_user, false, nullptr);
} else {
(*p_cb->p_cmd_cback)((tBTA_AG_SCB*)p_cb->p_user,
p_cb->p_at_tbl[idx].command_id, arg_type, p_arg,
}
/* else error */
else {
- (*p_cb->p_err_cback)((tBTA_AG_SCB*)p_cb->p_user, false, NULL);
+ (*p_cb->p_err_cback)((tBTA_AG_SCB*)p_cb->p_user, false, nullptr);
}
}
/* else no match call error callback */
int i = 0;
char* p_save;
- if (p_cb->p_cmd_buf == NULL) {
+ if (p_cb->p_cmd_buf == nullptr) {
p_cb->p_cmd_buf = (char*)osi_malloc(p_cb->cmd_max_len);
p_cb->cmd_pos = 0;
}
const tBTA_AG_HF_IND bta_ag_local_hf_ind_cfg[] = {
/* The first row contains the number of indicators. Need to be updated
accordingly */
- {BTA_AG_NUM_LOCAL_HF_IND, 0, 0, 0, 0},
+ {BTA_AG_NUM_LOCAL_HF_IND, false, false, 0, 0},
- {1, 1, 1, 0,
+ {1, true, true, 0,
1}, /* Enhanced Driver Status, supported, enabled, range 0 ~ 1 */
- {2, 1, 1, 0,
+ {2, true, true, 0,
100} /* Battery Level Status, supported, enabled, range 0 ~ 100 */
};
+++ /dev/null
-/******************************************************************************
- *
- * Copyright 2003-2012 Broadcom Corporation
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at:
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- ******************************************************************************/
-
-/******************************************************************************
- *
- * This is the implementation file for audio gateway call-in functions.
- *
- ******************************************************************************/
-
-#include <string.h>
-
-#include "bt_common.h"
-#include "bta_ag_api.h"
-#include "bta_ag_ci.h"
-#include "bta_ag_int.h"
-#include "bta_api.h"
-
-/******************************************************************************
- *
- * Function bta_ag_ci_rx_write
- *
- * Description This function is called to send data to the AG when the AG
- * is configured for AT command pass-through. The function
- * copies data to an event buffer and sends it.
- *
- * Returns void
- *
- *****************************************************************************/
-void bta_ag_ci_rx_write(uint16_t handle, char* p_data, uint16_t len) {
- uint16_t len_remaining = len;
- char* p_data_area;
-
- if (len > (RFCOMM_DATA_BUF_SIZE - sizeof(tBTA_AG_CI_RX_WRITE) - 1))
- len = RFCOMM_DATA_BUF_SIZE - sizeof(tBTA_AG_CI_RX_WRITE) - 1;
-
- while (len_remaining) {
- if (len_remaining < len) len = len_remaining;
-
- tBTA_AG_CI_RX_WRITE* p_buf =
- (tBTA_AG_CI_RX_WRITE*)osi_malloc(sizeof(tBTA_AG_CI_RX_WRITE) + len + 1);
- p_buf->hdr.event = BTA_AG_CI_RX_WRITE_EVT;
- p_buf->hdr.layer_specific = handle;
-
- p_data_area = (char*)(p_buf + 1); /* Point to data area after header */
- strncpy(p_data_area, p_data, len);
- p_data_area[len] = 0;
-
- bta_sys_sendmsg(p_buf);
-
- len_remaining -= len;
- p_data += len;
- }
-}
-
-/******************************************************************************
- *
- * Function bta_ag_ci_slc_ready
- *
- * Description This function is called to notify AG that SLC is up at
- * the application. This funcion is only used when the app
- * is running in pass-through mode.
- *
- * Returns void
- *
- *****************************************************************************/
-void bta_ag_ci_slc_ready(uint16_t handle) {
- tBTA_AG_DATA* p_buf = (tBTA_AG_DATA*)osi_malloc(sizeof(tBTA_AG_DATA));
-
- p_buf->hdr.event = BTA_AG_CI_SLC_READY_EVT;
- p_buf->hdr.layer_specific = handle;
-
- bta_sys_sendmsg(p_buf);
-}
#define LOG_TAG "bta_ag_cmd"
-#include <ctype.h>
-#include <stdio.h>
-#include <string.h>
+#include <cctype>
+#include <cstdio>
+#include <cstring>
#include "bt_common.h"
#include "bt_target.h"
i != sizeof(bta_ag_result_tbl) / sizeof(bta_ag_result_tbl[0]); ++i) {
if (code == bta_ag_result_tbl[i].result_id) return &bta_ag_result_tbl[i];
}
- return 0;
+ return nullptr;
}
const tBTA_AG_AT_CMD* bta_ag_at_tbl[BTA_AG_NUM_IDX] = {bta_ag_hsp_cmd,
static void bta_ag_send_result(tBTA_AG_SCB* p_scb, size_t code,
const char* p_arg, int16_t int_arg) {
const tBTA_AG_RESULT* result = bta_ag_result_by_code(code);
- if (result == 0) {
+ if (result == nullptr) {
LOG_ERROR(LOG_TAG, "%s Unable to lookup result for code %zu", __func__,
code);
return;
}
- char buf[BTA_AG_AT_MAX_LEN + 16];
+ char buf[BTA_AG_AT_MAX_LEN + 16] = "";
char* p = buf;
- memset(buf, 0, sizeof(buf));
/* init with \r\n */
*p++ = '\r';
*
******************************************************************************/
static void bta_ag_send_ok(tBTA_AG_SCB* p_scb) {
- bta_ag_send_result(p_scb, BTA_AG_LOCAL_RES_OK, NULL, 0);
+ bta_ag_send_result(p_scb, BTA_AG_LOCAL_RES_OK, nullptr, 0);
}
/*******************************************************************************
static void bta_ag_send_error(tBTA_AG_SCB* p_scb, int16_t errcode) {
/* If HFP and extended audio gateway error codes are enabled */
if (p_scb->conn_service == BTA_AG_HFP && p_scb->cmee_enabled)
- bta_ag_send_result(p_scb, BTA_AG_LOCAL_RES_CMEE, NULL, errcode);
+ bta_ag_send_result(p_scb, BTA_AG_LOCAL_RES_CMEE, nullptr, errcode);
else
- bta_ag_send_result(p_scb, BTA_AG_LOCAL_RES_ERROR, NULL, 0);
+ bta_ag_send_result(p_scb, BTA_AG_LOCAL_RES_ERROR, nullptr, 0);
}
/*******************************************************************************
*p = 0;
n[i] = utl_str2int(p_s);
p_s = p + 1;
- if (p_s == 0) {
+ if (p_s == nullptr) {
break;
}
}
******************************************************************************/
static uint8_t bta_ag_parse_chld(UNUSED_ATTR tBTA_AG_SCB* p_scb, char* p_s) {
uint8_t retval = 0;
- int16_t idx = -1;
if (!isdigit(p_s[0])) {
return BTA_AG_INVALID_CHLD;
if (p_s[1] != 0) {
/* p_idxstr++; point to beginning of call number */
- idx = utl_str2int(&p_s[1]);
+ int16_t idx = utl_str2int(&p_s[1]);
if (idx != -1 && idx < 255) {
retval = (uint8_t)idx;
} else {
static tBTA_AG_PEER_CODEC bta_ag_parse_bac(tBTA_AG_SCB* p_scb, char* p_s) {
tBTA_AG_PEER_CODEC retval = BTA_AG_CODEC_NONE;
uint16_t uuid_codec;
- bool cont = false; /* Continue processing */
char* p;
while (p_s) {
for (p = p_s; *p != ',' && *p != 0; p++)
;
- /* get integre value */
+ /* get integer value */
+ bool cont = false; // Continue processing
if (*p != 0) {
*p = 0;
cont = true;
- } else
- cont = false;
-
+ }
uuid_codec = utl_str2int(p_s);
switch (uuid_codec) {
case UUID_CODEC_CVSD:
******************************************************************************/
static void bta_ag_process_unat_res(char* unat_result) {
- uint8_t str_leng;
- uint8_t i = 0;
uint8_t j = 0;
uint8_t pairs_of_nl_cr;
char trim_data[BTA_AG_AT_MAX_LEN];
- str_leng = strlen(unat_result);
+ uint8_t str_leng = strlen(unat_result);
/* If no extra CR and LF, just return */
if (str_leng < 4) return;
unat_result[str_leng - 2] == '\r' &&
unat_result[str_leng - 1] == '\n') {
pairs_of_nl_cr = 1;
- for (i = 0; i < (str_leng - 4 * pairs_of_nl_cr); i++) {
+ for (int i = 0; i < (str_leng - 4 * pairs_of_nl_cr); i++) {
trim_data[j++] = unat_result[i + pairs_of_nl_cr * 2];
}
/* Add EOF */
trim_data[j] = '\0';
str_leng = str_leng - 4;
strlcpy(unat_result, trim_data, str_leng + 1);
- i = 0;
j = 0;
if (str_leng < 4) return;
}
- return;
}
/*******************************************************************************
******************************************************************************/
bool bta_ag_inband_enabled(tBTA_AG_SCB* p_scb) {
/* if feature is enabled and no other scbs connected */
- if (p_scb->inband_enabled && !bta_ag_other_scb_open(p_scb)) {
- return true;
- } else {
- return false;
- }
+ return p_scb->inband_enabled && !bta_ag_other_scb_open(p_scb);
}
/*******************************************************************************
*
******************************************************************************/
void bta_ag_send_call_inds(tBTA_AG_SCB* p_scb, tBTA_AG_RES result) {
- uint8_t call = p_scb->call_ind;
+ uint8_t call;
/* set new call and callsetup values based on BTA_AgResult */
size_t callsetup = bta_ag_indicator_by_result_code(result);
bta_ag_send_ok(p_scb);
- tBTA_AG_VAL val;
+ tBTA_AG_VAL val = {};
val.hdr.handle = bta_ag_scb_to_idx(p_scb);
val.hdr.app_id = p_scb->app_id;
val.num = (uint16_t)int_arg;
******************************************************************************/
static bool bta_ag_parse_bind_set(tBTA_AG_SCB* p_scb, tBTA_AG_VAL val) {
char* p_token = strtok(val.str, ",");
- if (p_token == NULL) return false;
+ if (p_token == nullptr) return false;
- while (p_token != NULL) {
+ while (p_token != nullptr) {
uint16_t rcv_ind_id = atoi(p_token);
int index = bta_ag_find_empty_hf_ind(p_scb);
if (index == -1) {
p_scb->peer_hf_indicators[index].ind_id = rcv_ind_id;
APPL_TRACE_DEBUG("%s peer_hf_ind[%d] = %d", __func__, index, rcv_ind_id);
- p_token = strtok(NULL, ",");
+ p_token = strtok(nullptr, ",");
}
return true;
*
******************************************************************************/
static void bta_ag_bind_response(tBTA_AG_SCB* p_scb, uint8_t arg_type) {
- char buffer[BTA_AG_AT_MAX_LEN];
- memset(buffer, 0, BTA_AG_AT_MAX_LEN);
+ char buffer[BTA_AG_AT_MAX_LEN] = "";
if (arg_type == BTA_AG_AT_TEST) {
int index = 0;
p += utl_itoa((uint16_t)p_scb->local_hf_indicators[i].is_enable, p);
bta_ag_send_result(p_scb, BTA_AG_BIND_RES, buffer, 0);
-
+ // have to use memset here because assigning to "" will not zero
+ // initialize the rest of the buffer
memset(buffer, 0, sizeof(buffer));
p = buffer;
} else {
bta_ag_send_ok(p_scb);
/* If the service level connection wan't already open, now it's open */
- if (!p_scb->svc_conn) bta_ag_svc_conn_open(p_scb, NULL);
+ if (!p_scb->svc_conn) bta_ag_svc_conn_open(p_scb, nullptr);
}
}
char* p_token = strtok(val->str, ",");
uint16_t rcv_ind_id = atoi(p_token);
- p_token = strtok(NULL, ",");
+ p_token = strtok(nullptr, ",");
uint16_t rcv_ind_val = atoi(p_token);
APPL_TRACE_DEBUG("%s BIEV indicator id %d, value %d", __func__, rcv_ind_id,
int local_index = bta_ag_find_hf_ind_by_id(
p_scb->local_hf_indicators, BTA_AG_MAX_NUM_LOCAL_HF_IND, rcv_ind_id);
if (local_index == -1 ||
- p_scb->local_hf_indicators[local_index].is_supported != true ||
- p_scb->local_hf_indicators[local_index].is_enable != true) {
+ !p_scb->local_hf_indicators[local_index].is_supported ||
+ !p_scb->local_hf_indicators[local_index].is_enable) {
APPL_TRACE_WARNING("%s indicator id %d not supported or disabled", __func__,
rcv_ind_id);
return false;
******************************************************************************/
void bta_ag_at_hfp_cback(tBTA_AG_SCB* p_scb, uint16_t cmd, uint8_t arg_type,
char* p_arg, int16_t int_arg) {
- tBTA_AG_VAL val;
+ tBTA_AG_VAL val = {};
tBTA_AG_SCB* ag_scb;
uint32_t i, ind_id;
uint32_t bia_masked_out;
- if (p_arg == NULL) {
+ if (p_arg == nullptr) {
APPL_TRACE_ERROR("%s: p_arg is null, send error and return", __func__);
bta_ag_send_error(p_scb, BTA_AG_ERR_INV_CHAR_IN_TSTR);
return;
APPL_TRACE_DEBUG("%s: AT command %d, arg_type %d, int_arg %d, arg %s",
__func__, cmd, arg_type, int_arg, p_arg);
- memset(&val, 0, sizeof(tBTA_AG_VAL));
val.hdr.handle = bta_ag_scb_to_idx(p_scb);
val.hdr.app_id = p_scb->app_id;
val.hdr.status = BTA_AG_SUCCESS;
bta_ag_send_ok(p_scb);
/* if service level conn. not already open, now it's open */
- bta_ag_svc_conn_open(p_scb, NULL);
+ bta_ag_svc_conn_open(p_scb, nullptr);
} else {
val.idx = bta_ag_parse_chld(p_scb, val.str);
if (!p_scb->svc_conn &&
!((p_scb->features & BTA_AG_FEAT_3WAY) &&
(p_scb->peer_features & BTA_AG_PEER_FEAT_3WAY))) {
- bta_ag_svc_conn_open(p_scb, NULL);
+ bta_ag_svc_conn_open(p_scb, nullptr);
}
} else {
bta_ag_send_error(p_scb, BTA_AG_ERR_INV_CHAR_IN_TSTR);
p_scb->peer_features, features);
/* send BRSF, send OK */
- bta_ag_send_result(p_scb, BTA_AG_LOCAL_RES_BRSF, NULL, (int16_t)features);
+ bta_ag_send_result(p_scb, BTA_AG_LOCAL_RES_BRSF, nullptr,
+ (int16_t)features);
bta_ag_send_ok(p_scb);
break;
}
for (i = 0, ag_scb = &bta_ag_cb.scb[0]; i < BTA_AG_NUM_SCB;
i++, ag_scb++) {
if (ag_scb->in_use) {
- bta_ag_send_result(ag_scb, BTA_AG_BTRH_RES, NULL, int_arg);
+ bta_ag_send_result(ag_scb, BTA_AG_BTRH_RES, nullptr, int_arg);
}
}
bta_ag_send_ok(p_scb);
else
codec_sent = p_scb->sco_codec;
- if (codec_type == codec_sent)
- bta_ag_sco_codec_nego(p_scb, true);
- else
- bta_ag_sco_codec_nego(p_scb, false);
+ bta_ag_sco_codec_nego(p_scb, codec_type == codec_sent);
/* send final codec info to callback */
val.num = codec_sent;
}
case BTA_AG_LOCAL_EVT_BCC:
bta_ag_send_ok(p_scb);
- bta_ag_sco_open(p_scb, NULL);
+ bta_ag_sco_open(p_scb, nullptr);
break;
default:
*
******************************************************************************/
void bta_ag_at_err_cback(tBTA_AG_SCB* p_scb, bool unknown, char* p_arg) {
- tBTA_AG_VAL val;
-
if (unknown && (!strlen(p_arg))) {
APPL_TRACE_DEBUG("Empty AT cmd string received");
bta_ag_send_ok(p_scb);
return;
}
+ tBTA_AG_VAL val = {};
/* if unknown AT command and configured to pass these to app */
if (unknown && (p_scb->features & BTA_AG_FEAT_UNAT)) {
val.hdr.handle = bta_ag_scb_to_idx(p_scb);
switch (p_result->result) {
case BTA_AG_SPK_RES:
case BTA_AG_MIC_RES:
- bta_ag_send_result(p_scb, p_result->result, NULL, p_result->data.num);
+ bta_ag_send_result(p_scb, p_result->result, nullptr, p_result->data.num);
break;
case BTA_AG_IN_CALL_RES:
switch (p_result->result) {
case BTA_AG_SPK_RES:
case BTA_AG_MIC_RES:
- bta_ag_send_result(p_scb, p_result->result, NULL, p_result->data.num);
+ bta_ag_send_result(p_scb, p_result->result, nullptr, p_result->data.num);
break;
case BTA_AG_IN_CALL_RES:
case BTA_AG_INBAND_RING_RES:
p_scb->inband_enabled = p_result->data.state;
APPL_TRACE_DEBUG("inband_enabled set to %d", p_scb->inband_enabled);
- bta_ag_send_result(p_scb, p_result->result, NULL, p_result->data.state);
+ bta_ag_send_result(p_scb, p_result->result, nullptr,
+ p_result->data.state);
break;
case BTA_AG_CIND_RES:
break;
case BTA_AG_BVRA_RES:
- bta_ag_send_result(p_scb, p_result->result, NULL, p_result->data.state);
+ bta_ag_send_result(p_scb, p_result->result, nullptr,
+ p_result->data.state);
break;
case BTA_AG_BTRH_RES:
if (p_result->data.ok_flag != BTA_AG_OK_ERROR) {
/* Don't respond to read if not in response & hold state */
if (p_result->data.num != BTA_AG_BTRH_NO_RESP) {
- bta_ag_send_result(p_scb, p_result->result, NULL, p_result->data.num);
+ bta_ag_send_result(p_scb, p_result->result, nullptr,
+ p_result->data.num);
}
/* In case of a response to a read request we need to send OK */
/* send +BCS */
APPL_TRACE_DEBUG("send +BCS codec is %d", codec_uuid);
- bta_ag_send_result(p_scb, BTA_AG_LOCAL_RES_BCS, NULL, codec_uuid);
+ bta_ag_send_result(p_scb, BTA_AG_LOCAL_RES_BCS, nullptr, codec_uuid);
}
/*******************************************************************************
return;
}
/* send RING */
- bta_ag_send_result(p_scb, BTA_AG_LOCAL_RES_RING, NULL, 0);
+ bta_ag_send_result(p_scb, BTA_AG_LOCAL_RES_RING, nullptr, 0);
/* if HFP and clip enabled and clip data send CLIP */
if (p_scb->conn_service == BTA_AG_HFP && p_scb->clip_enabled &&
#define BTA_AG_ACP 0 /* accepted connection */
#define BTA_AG_INT 1 /* initiating connection */
-/* feature mask that matches spec */
-#define BTA_AG_BSRF_FEAT_SPEC \
- (BTA_AG_FEAT_3WAY | BTA_AG_FEAT_ECNR | BTA_AG_FEAT_VREC | \
- BTA_AG_FEAT_INBAND | BTA_AG_FEAT_VTAG | BTA_AG_FEAT_REJECT | \
- BTA_AG_FEAT_ECS | BTA_AG_FEAT_ECC | BTA_AG_FEAT_EXTERR | \
- BTA_AG_FEAT_CODEC | BTA_AG_FEAT_HF_IND | BTA_AG_FEAT_ESCO | \
- BTA_AG_FEAT_VOIP)
-
#define BTA_AG_SDP_FEAT_SPEC \
(BTA_AG_FEAT_3WAY | BTA_AG_FEAT_ECNR | BTA_AG_FEAT_VREC | \
BTA_AG_FEAT_INBAND | BTA_AG_FEAT_VTAG)
if (i == BTA_AG_NUM_SCB) {
/* out of scbs */
- p_scb = NULL;
+ p_scb = nullptr;
APPL_TRACE_WARNING("%s: Out of scbs", __func__);
}
return p_scb;
alarm_free(p_scb->collision_timer);
/* initialize control block */
- memset(p_scb, 0, sizeof(tBTA_AG_SCB));
+ *p_scb = {};
p_scb->sco_idx = BTM_INVALID_SCO_INDEX;
/* If all scbs are deallocated, callback with disable event */
}
if (!allocated) {
- (*bta_ag_cb.p_cback)(BTA_AG_DISABLE_EVT, NULL);
+ (*bta_ag_cb.p_cback)(BTA_AG_DISABLE_EVT, nullptr);
}
}
}
if (idx > 0 && idx <= BTA_AG_NUM_SCB) {
p_scb = &bta_ag_cb.scb[idx - 1];
if (!p_scb->in_use) {
- p_scb = NULL;
+ p_scb = nullptr;
APPL_TRACE_WARNING("ag scb idx %d not allocated", idx);
}
} else {
- p_scb = NULL;
+ p_scb = nullptr;
APPL_TRACE_DEBUG("ag scb idx %d out of range", idx);
}
return p_scb;
******************************************************************************/
uint16_t bta_ag_idx_by_bdaddr(const RawAddress* peer_addr) {
tBTA_AG_SCB* p_scb = &bta_ag_cb.scb[0];
- uint16_t i;
-
- if (peer_addr != NULL) {
- for (i = 0; i < BTA_AG_NUM_SCB; i++, p_scb++) {
+ if (peer_addr != nullptr) {
+ for (uint16_t i = 0; i < BTA_AG_NUM_SCB; i++, p_scb++) {
if (p_scb->in_use && *peer_addr == p_scb->peer_addr) {
return (i + 1);
}
******************************************************************************/
bool bta_ag_other_scb_open(tBTA_AG_SCB* p_curr_scb) {
tBTA_AG_SCB* p_scb = &bta_ag_cb.scb[0];
- int i;
-
- for (i = 0; i < BTA_AG_NUM_SCB; i++, p_scb++) {
+ for (int i = 0; i < BTA_AG_NUM_SCB; i++, p_scb++) {
if (p_scb->in_use && p_scb != p_curr_scb &&
p_scb->state == BTA_AG_OPEN_ST) {
return true;
}
}
-
/* no other scb found */
APPL_TRACE_DEBUG("No other ag scb open");
return false;
*
******************************************************************************/
bool bta_ag_scb_open(tBTA_AG_SCB* p_curr_scb) {
- if (p_curr_scb && p_curr_scb->in_use && p_curr_scb->state == BTA_AG_OPEN_ST) {
- return true;
- }
-
- return false;
+ return p_curr_scb && p_curr_scb->in_use &&
+ p_curr_scb->state == BTA_AG_OPEN_ST;
}
/*******************************************************************************
/* no other scb found */
APPL_TRACE_DEBUG("bta_ag_get_other_idle_scb: No idle AG scb");
- return NULL;
+ return nullptr;
}
/*******************************************************************************
p_scb = bta_ag_scb_by_idx(handle);
if (p_scb && (p_scb->state == BTA_AG_OPENING_ST)) {
- if (id == BTA_ID_SYS) /* ACL collision */
- {
+ if (id == BTA_ID_SYS) {
+ /* ACL collision */
APPL_TRACE_WARNING("AG found collision (ACL) ...");
- } else if (id == BTA_ID_AG) /* RFCOMM collision */
- {
+ } else if (id == BTA_ID_AG) {
+ /* RFCOMM collision */
APPL_TRACE_WARNING("AG found collision (RFCOMM) ...");
} else {
APPL_TRACE_WARNING("AG found collision (\?\?\?) ...");
/* Cancel SDP if it had been started. */
if (p_scb->p_disc_db) {
(void)SDP_CancelServiceSearch(p_scb->p_disc_db);
- bta_ag_free_db(p_scb, NULL);
+ bta_ag_free_db(p_scb, nullptr);
}
/* reopen registered servers */
/* resume opening process. */
if (p_scb->state == BTA_AG_INIT_ST) {
p_scb->state = BTA_AG_OPENING_ST;
- bta_ag_start_open(p_scb, NULL);
+ bta_ag_start_open(p_scb, nullptr);
}
} else {
APPL_TRACE_ERROR("bta_ag_resume_open, Null p_scb");
******************************************************************************/
static void bta_ag_api_enable(tBTA_AG_DATA* p_data) {
/* initialize control block */
- for (size_t i = 0; i < BTA_AG_NUM_SCB; i++) {
- alarm_free(bta_ag_cb.scb[i].ring_timer);
- alarm_free(bta_ag_cb.scb[i].codec_negotiation_timer);
- alarm_free(bta_ag_cb.scb[i].collision_timer);
+ for (tBTA_AG_SCB& scb : bta_ag_cb.scb) {
+ alarm_free(scb.ring_timer);
+ alarm_free(scb.codec_negotiation_timer);
+ alarm_free(scb.collision_timer);
+ scb = {};
}
- memset(&bta_ag_cb, 0, sizeof(tBTA_AG_CB));
/* store callback function */
bta_ag_cb.p_cback = p_data->api_enable.p_cback;
bta_sys_collision_register(BTA_ID_AG, bta_ag_collision_cback);
/* call callback with enable event */
- (*bta_ag_cb.p_cback)(BTA_AG_ENABLE_EVT, NULL);
+ (*bta_ag_cb.p_cback)(BTA_AG_ENABLE_EVT, nullptr);
}
/*******************************************************************************
if (!do_dereg) {
/* Done, send callback evt to app */
- (*bta_ag_cb.p_cback)(BTA_AG_DISABLE_EVT, NULL);
+ (*bta_ag_cb.p_cback)(BTA_AG_DISABLE_EVT, nullptr);
}
- bta_sys_collision_register(BTA_ID_AG, NULL);
+ bta_sys_collision_register(BTA_ID_AG, nullptr);
}
/*******************************************************************************
/* allocate an scb */
p_scb = bta_ag_scb_alloc();
- if (p_scb != NULL) {
+ if (p_scb != nullptr) {
APPL_TRACE_DEBUG("bta_ag_api_register: p_scb 0x%08x ", p_scb);
bta_ag_sm_execute(p_scb, p_data->hdr.event, p_data);
} else {
- tBTA_AG bta_ag;
+ tBTA_AG bta_ag = {};
bta_ag.reg.status = BTA_AG_FAIL_RESOURCES;
(*bta_ag_cb.p_cback)(BTA_AG_REGISTER_EVT, &bta_ag);
}
if (p_data->hdr.layer_specific != BTA_AG_HANDLE_ALL) {
p_scb = bta_ag_scb_by_idx(p_data->hdr.layer_specific);
- if (p_scb != NULL) {
+ if (p_scb != nullptr) {
APPL_TRACE_DEBUG("bta_ag_api_result: p_scb 0x%08x ", p_scb);
bta_ag_sm_execute(p_scb, BTA_AG_API_RESULT_EVT, p_data);
}
/* all others reference scb by handle */
default:
p_scb = bta_ag_scb_by_idx(p_msg->layer_specific);
- if (p_scb != NULL) {
+ if (p_scb != nullptr) {
APPL_TRACE_DEBUG("bta_ag_hdl_event: p_scb 0x%08x ", p_scb);
bta_ag_sm_execute(p_scb, p_msg->event, (tBTA_AG_DATA*)p_msg);
}
*
******************************************************************************/
-#include <string.h>
+#include <cstring>
#include "bt_common.h"
#include "bta_ag_api.h"
tBTA_AG_SCB* p_scb;
p_scb = bta_ag_scb_by_idx(handle);
- if (p_scb != NULL) {
+ if (p_scb != nullptr) {
/* ignore port events for port handles other than connected handle */
if (port_handle != p_scb->conn_handle) {
APPL_TRACE_DEBUG(
code, port_handle, handle);
p_scb = bta_ag_scb_by_idx(handle);
- if (p_scb != NULL) {
+ if (p_scb != nullptr) {
/* ignore close event for port handles other than connected handle */
if ((code != PORT_SUCCESS) && (port_handle != p_scb->conn_handle)) {
APPL_TRACE_DEBUG("ag_mgmt_cback ignoring handle:%d", port_handle);
static bool sco_allowed = true;
-#define BTA_AG_NO_EDR_ESCO \
- (ESCO_PKT_TYPES_MASK_NO_2_EV3 | ESCO_PKT_TYPES_MASK_NO_3_EV3 | \
- ESCO_PKT_TYPES_MASK_NO_2_EV5 | ESCO_PKT_TYPES_MASK_NO_3_EV5)
-
/* sco events */
enum {
BTA_AG_SCO_LISTEN_E, /* listen request */
tBTA_AG_SCB* p_scb;
/* match callback to scb; first check current sco scb */
- if (bta_ag_cb.sco.p_curr_scb != NULL && bta_ag_cb.sco.p_curr_scb->in_use) {
+ if (bta_ag_cb.sco.p_curr_scb != nullptr && bta_ag_cb.sco.p_curr_scb->in_use) {
handle = bta_ag_scb_to_idx(bta_ag_cb.sco.p_curr_scb);
}
/* then check for scb connected to this peer */
bta_sys_sendmsg(p_buf);
} else {
/* no match found; disconnect sco, init sco variables */
- bta_ag_cb.sco.p_curr_scb = NULL;
+ bta_ag_cb.sco.p_curr_scb = nullptr;
bta_ag_cb.sco.state = BTA_AG_SCO_SHUTDOWN_ST;
BTM_RemoveSco(sco_idx);
}
bta_ag_cb.scb[1].state);
/* match callback to scb */
- if (bta_ag_cb.sco.p_curr_scb != NULL && bta_ag_cb.sco.p_curr_scb->in_use) {
+ if (bta_ag_cb.sco.p_curr_scb != nullptr && bta_ag_cb.sco.p_curr_scb->in_use) {
/* We only care about callbacks for the active SCO */
if (bta_ag_cb.sco.p_curr_scb->sco_idx != sco_idx) {
if (bta_ag_cb.sco.p_curr_scb->sco_idx != 0xFFFF) return;
APPL_TRACE_DEBUG("no scb for ag_sco_disc_cback");
/* sco could be closed after scb dealloc'ed */
- if (bta_ag_cb.sco.p_curr_scb != NULL) {
+ if (bta_ag_cb.sco.p_curr_scb != nullptr) {
bta_ag_cb.sco.p_curr_scb->sco_idx = BTM_INVALID_SCO_INDEX;
- bta_ag_cb.sco.p_curr_scb = NULL;
+ bta_ag_cb.sco.p_curr_scb = nullptr;
bta_ag_cb.sco.state = BTA_AG_SCO_SHUTDOWN_ST;
}
}
/* Only process connection requests */
if (event == BTM_ESCO_CONN_REQ_EVT) {
if ((handle = bta_ag_idx_by_bdaddr(BTM_ReadScoBdAddr(sco_inx))) != 0 &&
- ((p_scb = bta_ag_scb_by_idx(handle)) != NULL) && p_scb->svc_conn) {
+ ((p_scb = bta_ag_scb_by_idx(handle)) != nullptr) && p_scb->svc_conn) {
p_scb->sco_idx = sco_inx;
/* If no other SCO active, allow this one */
APPL_TRACE_ERROR(
"%s: Nothing to remove,so accept Conn Request(sco_inx 0x%04x)",
__func__, sco_inx);
- bta_ag_cb.sco.p_xfer_scb = NULL;
+ bta_ag_cb.sco.p_xfer_scb = nullptr;
bta_ag_cb.sco.state = BTA_AG_SCO_LISTEN_ST;
bta_ag_sco_conn_rsp(p_scb, &p_data->conn_evt);
APPL_TRACE_WARNING(
"no scb for bta_ag_esco_connreq_cback or no resources");
BTM_EScoConnRsp(p_data->conn_evt.sco_inx, HCI_ERR_HOST_REJECT_RESOURCES,
- (enh_esco_params_t*)NULL);
+ (enh_esco_params_t*)nullptr);
}
} else if (event == BTM_ESCO_CHG_EVT) {
/* Received a change in the esco link */
*
******************************************************************************/
static void bta_ag_cback_sco(tBTA_AG_SCB* p_scb, uint8_t event) {
- tBTA_AG_HDR sco;
-
+ tBTA_AG_HDR sco = {};
sco.handle = bta_ag_scb_to_idx(p_scb);
sco.app_id = p_scb->app_id;
-
/* call close cback */
(*bta_ag_cb.p_cback)(event, (tBTA_AG*)&sco);
}
******************************************************************************/
static void bta_ag_create_pending_sco(tBTA_AG_SCB* p_scb, bool is_local) {
tBTA_AG_PEER_CODEC esco_codec = p_scb->inuse_codec;
- enh_esco_params_t params;
+ enh_esco_params_t params = {};
bta_ag_cb.sco.p_curr_scb = p_scb;
bta_ag_cb.sco.cur_idx = p_scb->sco_idx;
bta_sys_busy(BTA_ID_AG, p_scb->app_id, p_scb->peer_addr);
/* Send +BCS to the peer */
- bta_ag_send_bcs(p_scb, NULL);
+ bta_ag_send_bcs(p_scb, nullptr);
/* Start timer to handle timeout */
alarm_set_on_mloop(p_scb->codec_negotiation_timer,
/* remove listening connection */
bta_ag_remove_sco(p_scb, false);
- if (p_scb == p_sco->p_curr_scb) p_sco->p_curr_scb = NULL;
+ if (p_scb == p_sco->p_curr_scb) p_sco->p_curr_scb = nullptr;
/* If last SCO instance then finish shutting down */
if (!bta_ag_other_scb_open(p_scb)) {
/* remove listening connection */
bta_ag_remove_sco(p_scb, false);
- if (p_scb == p_sco->p_curr_scb) p_sco->p_curr_scb = NULL;
+ if (p_scb == p_sco->p_curr_scb) p_sco->p_curr_scb = nullptr;
/* If last SCO instance then finish shutting down */
if (!bta_ag_other_scb_open(p_scb)) {
p_sco->state = BTA_AG_SCO_OPENING_ST;
p_sco->p_curr_scb = p_sco->p_xfer_scb;
p_sco->cur_idx = p_sco->p_xfer_scb->sco_idx;
- p_sco->p_xfer_scb = NULL;
+ p_sco->p_xfer_scb = nullptr;
break;
default:
case BTA_AG_SCO_CLOSE_E:
/* clear xfer scb */
- p_sco->p_xfer_scb = NULL;
+ p_sco->p_xfer_scb = nullptr;
p_sco->state = BTA_AG_SCO_CLOSING_ST;
break;
case BTA_AG_SCO_SHUTDOWN_E:
/* clear xfer scb */
- p_sco->p_xfer_scb = NULL;
+ p_sco->p_xfer_scb = nullptr;
p_sco->state = BTA_AG_SCO_SHUTTING_ST;
break;
/* start codec negotiation */
p_sco->state = BTA_AG_SCO_CODEC_ST;
tBTA_AG_SCB* p_cn_scb = p_sco->p_xfer_scb;
- p_sco->p_xfer_scb = NULL;
+ p_sco->p_xfer_scb = nullptr;
bta_ag_codec_negotiate(p_cn_scb);
break;
}
if (p_scb == p_sco->p_curr_scb) {
p_sco->p_curr_scb->sco_idx = BTM_INVALID_SCO_INDEX;
- p_sco->p_curr_scb = NULL;
+ p_sco->p_curr_scb = nullptr;
}
break;
if (p_scb == p_sco->p_curr_scb) {
p_sco->p_curr_scb->sco_idx = BTM_INVALID_SCO_INDEX;
- p_sco->p_curr_scb = NULL;
+ p_sco->p_curr_scb = nullptr;
}
break;
}
/* if another scb using sco, this is a transfer */
- if (bta_ag_cb.sco.p_curr_scb != NULL && bta_ag_cb.sco.p_curr_scb != p_scb) {
+ if (bta_ag_cb.sco.p_curr_scb != nullptr &&
+ bta_ag_cb.sco.p_curr_scb != p_scb) {
event = BTA_AG_SCO_XFER_E;
}
/* else it is an open */
void bta_ag_sco_conn_close(tBTA_AG_SCB* p_scb,
UNUSED_ATTR tBTA_AG_DATA* p_data) {
/* clear current scb */
- bta_ag_cb.sco.p_curr_scb = NULL;
+ bta_ag_cb.sco.p_curr_scb = nullptr;
p_scb->sco_idx = BTM_INVALID_SCO_INDEX;
/* codec_fallback is set when AG is initiator and connection failed for mSBC.
*
******************************************************************************/
-#include <string.h>
+#include <cstring>
#include "bt_common.h"
#include "bta_ag_api.h"
APPL_TRACE_DEBUG("%s status:0x%x", __func__, status);
p_scb = bta_ag_scb_by_idx(idx);
- if (p_scb != NULL) {
+ if (p_scb != nullptr) {
/* set event according to int/acp */
if (p_scb->role == BTA_AG_ACP) {
event = BTA_AG_DISC_ACP_RES_EVT;
APPL_TRACE_DEBUG("%s uuid: %x", __func__, service_uuid);
- memset(proto_elem_list, 0,
- BTA_AG_NUM_PROTO_ELEMS * sizeof(tSDP_PROTOCOL_ELEM));
+ for (auto& proto_element : proto_elem_list) {
+ proto_element = {};
+ }
/* add the protocol element sequence */
proto_elem_list[0].protocol_uuid = UUID_PROTOCOL_L2CAP;
result &= SDP_AddProfileDescriptorList(sdp_handle, profile_uuid, version);
/* add service name */
- if (p_service_name != NULL && p_service_name[0] != 0) {
+ if (p_service_name != nullptr && p_service_name[0] != 0) {
result &= SDP_AddAttribute(
sdp_handle, ATTR_ID_SERVICE_NAME, TEXT_STR_DESC_TYPE,
(uint32_t)(strlen(p_service_name) + 1), (uint8_t*)p_service_name);
*
******************************************************************************/
bool bta_ag_sdp_find_attr(tBTA_AG_SCB* p_scb, tBTA_SERVICE_MASK service) {
- tSDP_DISC_REC* p_rec = NULL;
+ tSDP_DISC_REC* p_rec = nullptr;
tSDP_DISC_ATTR* p_attr;
tSDP_PROTOCOL_ELEM pe;
uint16_t uuid;
while (true) {
/* get next record; if none found, we're done */
p_rec = SDP_FindServiceInDb(p_scb->p_disc_db, uuid, p_rec);
- if (p_rec == NULL) {
+ if (p_rec == nullptr) {
if (uuid == UUID_SERVCLASS_HEADSET_HS) {
/* Search again in case the peer device uses the old HSP UUID */
uuid = UUID_SERVCLASS_HEADSET;
p_scb->peer_version = HSP_VERSION_1_0;
p_rec = SDP_FindServiceInDb(p_scb->p_disc_db, uuid, p_rec);
- if (p_rec == NULL) {
+ if (p_rec == nullptr) {
break;
}
} else
/* get features if HFP */
if (service & BTA_HFP_SERVICE_MASK) {
p_attr = SDP_FindAttributeInRec(p_rec, ATTR_ID_SUPPORTED_FEATURES);
- if (p_attr != NULL) {
+ if (p_attr != nullptr) {
/* Found attribute. Get value. */
/* There might be race condition between SDP and BRSF. */
/* Do not update if we already received BRSF. */
{
p_attr =
SDP_FindAttributeInRec(p_rec, ATTR_ID_REMOTE_AUDIO_VOLUME_CONTROL);
- if (p_attr != NULL) {
+ if (p_attr != nullptr) {
/* Remote volume control of HSP */
if (p_attr->attr_value.v.u8)
p_scb->peer_features |= BTA_AG_PEER_FEAT_VOL;
uint16_t num_uuid = 1;
uint16_t attr_list[4];
uint8_t num_attr;
- bool db_inited = false;
/* HFP initiator; get proto list and features */
if (service & BTA_HFP_SERVICE_MASK && p_scb->role == BTA_AG_INT) {
/* allocate buffer for sdp database */
p_scb->p_disc_db = (tSDP_DISCOVERY_DB*)osi_malloc(BTA_AG_DISC_BUF_SIZE);
/* set up service discovery database; attr happens to be attr_list len */
- db_inited = SDP_InitDiscoveryDb(p_scb->p_disc_db, BTA_AG_DISC_BUF_SIZE,
- num_uuid, uuid_list, num_attr, attr_list);
+ bool db_inited =
+ SDP_InitDiscoveryDb(p_scb->p_disc_db, BTA_AG_DISC_BUF_SIZE, num_uuid,
+ uuid_list, num_attr, attr_list);
if (db_inited) {
/*Service discovery not initiated */
if (!db_inited) {
/*free discover db */
- bta_ag_free_db(p_scb, NULL);
+ bta_ag_free_db(p_scb, nullptr);
/* sent failed event */
- bta_ag_sm_execute(p_scb, BTA_AG_DISC_FAIL_EVT, NULL);
+ bta_ag_sm_execute(p_scb, BTA_AG_DISC_FAIL_EVT, nullptr);
}
}
* Returns void
*
******************************************************************************/
-void BTA_AgDisable(void);
+void BTA_AgDisable();
/*******************************************************************************
*
+++ /dev/null
-/******************************************************************************
- *
- * Copyright 2003-2012 Broadcom Corporation
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at:
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- ******************************************************************************/
-
-/******************************************************************************
- *
- * This is the interface file for audio gateway call-in functions.
- *
- ******************************************************************************/
-#ifndef BTA_AG_CI_H
-#define BTA_AG_CI_H
-
-#include "bta_ag_api.h"
-
-/*****************************************************************************
- * Function Declarations
- ****************************************************************************/
-/*******************************************************************************
- *
- * Function bta_ag_ci_rx_write
- *
- * Description This function is called to send data to the AG when the AG
- * is configured for AT command pass-through. The function
- * copies data to an event buffer and sends it.
- *
- * Returns void
- *
- ******************************************************************************/
-extern void bta_ag_ci_rx_write(uint16_t handle, char* p_data, uint16_t len);
-
-/******************************************************************************
- *
- * Function bta_ag_ci_slc_ready
- *
- * Description This function is called to notify AG that SLC is up at
- * the application. This funcion is only used when the app
- * is running in pass-through mode.
- *
- * Returns void
- *
- *****************************************************************************/
-extern void bta_ag_ci_slc_ready(uint16_t handle);
-
-/******************************************************************************
- *
- * Function bta_ag_ci_wbs_command
- *
- * Description This function is called to notify AG that a WBS command is
- * received
- *
- * Returns void
- *
- *****************************************************************************/
-extern void bta_ag_ci_wbs_command(uint16_t handle, char* p_data, uint16_t len);
-
-#endif /* BTA_AG_CI_H */
#include "bta/include/bta_ag_co.h"
#include "bta/ag/bta_ag_int.h"
#include "bta/include/bta_ag_api.h"
-#include "bta/include/bta_ag_ci.h"
#include "osi/include/osi.h"
/*******************************************************************************
#define LOG_TAG "bt_btif_hf"
-#include <stdlib.h>
-#include <string.h>
-#include <time.h>
+#include <cstdlib>
+#include <cstring>
+#include <ctime>
#include <hardware/bluetooth.h>
#include <hardware/bt_hf.h>
/* HF features supported at runtime */
static uint32_t btif_hf_features = BTIF_HF_FEATURES;
-#define BTIF_HF_CALL_END_TIMEOUT 6
-
#define BTIF_HF_INVALID_IDX (-1)
/* Number of BTIF-HF control blocks */
#define BTIF_HF_NUM_CB 2
/* Max HF clients supported from App */
-uint16_t btif_max_hf_clients = 1;
+int btif_max_hf_clients = 1;
/* HF app ids for service registration */
typedef enum {
/*******************************************************************************
* Static variables
******************************************************************************/
-static bthf_callbacks_t* bt_hf_callbacks = NULL;
+static bthf_callbacks_t* bt_hf_callbacks = nullptr;
static int hf_idx = BTIF_HF_INVALID_IDX;
#define CHECK_BTHF_INIT() \
do { \
- if (bt_hf_callbacks == NULL) { \
+ if (bt_hf_callbacks == nullptr) { \
BTIF_TRACE_WARNING("BTHF: %s: BTHF not initialized", __func__); \
return BT_STATUS_NOT_READY; \
} else { \
uint16_t handle;
RawAddress connected_bda;
bthf_connection_state_t state;
- bthf_vr_state_t vr_state;
tBTA_AG_PEER_FEAT peer_feat;
int num_active;
int num_held;
*
******************************************************************************/
static void send_at_result(uint8_t ok_flag, uint16_t errcode, int idx) {
- tBTA_AG_RES_DATA ag_res;
- memset(&ag_res, 0, sizeof(ag_res));
-
+ tBTA_AG_RES_DATA ag_res = {};
ag_res.ok_flag = ok_flag;
if (ok_flag == BTA_AG_OK_ERROR) {
ag_res.errcode = errcode;
}
-
BTA_AgResult(btif_hf_cb[idx].handle, BTA_AG_UNAT_RES, &ag_res);
}
*
******************************************************************************/
static void send_indicator_update(uint16_t indicator, uint16_t value) {
- tBTA_AG_RES_DATA ag_res;
-
- memset(&ag_res, 0, sizeof(tBTA_AG_RES_DATA));
+ tBTA_AG_RES_DATA ag_res = {};
ag_res.ind.id = indicator;
ag_res.ind.value = value;
-
BTA_AgResult(BTA_AG_HANDLE_ALL, BTA_AG_IND_RES, &ag_res);
}
*
*******************************************************************************/
static void send_call_status_forcibly(uint16_t value) {
- tBTA_AG_RES_DATA ag_res;
-
- memset(&ag_res, 0, sizeof(tBTA_AG_RES_DATA));
-
+ tBTA_AG_RES_DATA ag_res = {};
ag_res.ind.id = BTA_AG_IND_CALL;
ag_res.ind.value = value;
-
BTA_AgResult(BTA_AG_HANDLE_ALL, BTA_AG_IND_RES_ON_DEMAND, &ag_res);
}
*
******************************************************************************/
static bt_status_t btif_hf_check_if_slc_connected() {
- if (bt_hf_callbacks == NULL) {
+ if (bt_hf_callbacks == nullptr) {
BTIF_TRACE_WARNING("BTHF: %s: BTHF not initialized", __func__);
return BT_STATUS_NOT_READY;
} else {
BTIF_TRACE_DEBUG("Donot set hf_idx for BLDN/D since already in a call");
HAL_CBACK(bt_hf_callbacks, dial_call_cmd_cb,
- (event == BTA_AG_AT_D_EVT) ? p_data->val.str : NULL,
+ (event == BTA_AG_AT_D_EVT) ? p_data->val.str : nullptr,
&btif_hf_cb[idx].connected_bda);
break;
/* switch context to btif task context (copy full union size for convenience)
*/
status = btif_transfer_context(btif_hf_upstreams_evt, (uint16_t)event,
- (char*)p_data, param_len, NULL);
+ (char*)p_data, param_len, nullptr);
/* catch any failed context transfers */
ASSERTC(status == BT_STATUS_SUCCESS, "context transfer failed", status);
/* Inform the application that the audio connection has been initiated
* successfully */
btif_transfer_context(btif_in_hf_generic_evt, BTIF_HFP_CB_AUDIO_CONNECTING,
- (char*)bd_addr, sizeof(RawAddress), NULL);
+ (char*)bd_addr, sizeof(RawAddress), nullptr);
return BT_STATUS_SUCCESS;
}
if (is_connected(bd_addr) && (idx != BTIF_HF_INVALID_IDX)) {
if (btif_hf_cb[idx].peer_feat & BTA_AG_PEER_FEAT_VREC) {
- tBTA_AG_RES_DATA ag_res;
- memset(&ag_res, 0, sizeof(ag_res));
+ tBTA_AG_RES_DATA ag_res = {};
ag_res.state = 1;
BTA_AgResult(btif_hf_cb[idx].handle, BTA_AG_BVRA_RES, &ag_res);
if (is_connected(bd_addr) && (idx != BTIF_HF_INVALID_IDX)) {
if (btif_hf_cb[idx].peer_feat & BTA_AG_PEER_FEAT_VREC) {
- tBTA_AG_RES_DATA ag_res;
- memset(&ag_res, 0, sizeof(ag_res));
+ tBTA_AG_RES_DATA ag_res = {};
ag_res.state = 0;
BTA_AgResult(btif_hf_cb[idx].handle, BTA_AG_BVRA_RES, &ag_res);
return BT_STATUS_FAIL;
}
- tBTA_AG_RES_DATA ag_res;
- memset(&ag_res, 0, sizeof(tBTA_AG_RES_DATA));
+ tBTA_AG_RES_DATA ag_res = {};
if (is_connected(bd_addr) && (idx != BTIF_HF_INVALID_IDX)) {
ag_res.num = volume;
BTA_AgResult(
int signal, int batt_chg) {
CHECK_BTHF_INIT();
- if (is_connected(NULL)) {
+ if (is_connected(nullptr)) {
/* send all indicators to BTA.
** BTA will make sure no duplicates are sent out
*/
}
if (is_connected(bd_addr) && (idx != BTIF_HF_INVALID_IDX)) {
- tBTA_AG_RES_DATA ag_res;
+ tBTA_AG_RES_DATA ag_res = {};
/* Format the response */
snprintf(ag_res.str, sizeof(ag_res.str), "0,0,\"%.16s\"", cops);
}
if (is_connected(bd_addr) && (idx != BTIF_HF_INVALID_IDX)) {
- tBTA_AG_RES_DATA ag_res;
-
- memset(&ag_res, 0, sizeof(ag_res));
+ tBTA_AG_RES_DATA ag_res = {};
/* per the errata 2043, call=1 implies atleast one call is in progress
*(active/held)
** https://www.bluetooth.org/errata/errata_view.cfm?errata_id=2043
static bt_status_t set_sco_allowed(bool value) {
CHECK_BTHF_INIT();
-
BTA_AgSetScoAllowed(value);
return BT_STATUS_SUCCESS;
}
******************************************************************************/
static bt_status_t formatted_at_response(const char* rsp, RawAddress* bd_addr) {
CHECK_BTHF_INIT();
- tBTA_AG_RES_DATA ag_res;
+ tBTA_AG_RES_DATA ag_res = {};
int idx = btif_hf_idx_by_bdaddr(bd_addr);
if ((idx < 0) || (idx >= BTIF_HF_NUM_CB)) {
if (is_connected(bd_addr) && (idx != BTIF_HF_INVALID_IDX)) {
/* Format the response and send */
- memset(&ag_res, 0, sizeof(ag_res));
strncpy(ag_res.str, rsp, BTA_AG_AT_MAX_LEN);
BTA_AgResult(btif_hf_cb[idx].handle, BTA_AG_UNAT_RES, &ag_res);
}
if (is_connected(bd_addr) && (idx != BTIF_HF_INVALID_IDX)) {
- tBTA_AG_RES_DATA ag_res;
- memset(&ag_res, 0, sizeof(ag_res));
-
+ tBTA_AG_RES_DATA ag_res = {};
/* Format the response */
if (index == 0) {
ag_res.ok_flag = BTA_AG_OK_DONE;
const char* number,
bthf_call_addrtype_t type) {
tBTA_AG_RES res = 0xff;
- tBTA_AG_RES_DATA ag_res;
bt_status_t status = BT_STATUS_SUCCESS;
bool activeCallUpdated = false;
int idx, i;
BTIF_TRACE_DEBUG("%s: Record call termination timestamp", __func__);
clock_gettime(CLOCK_MONOTONIC, &btif_hf_cb[0].call_end_timestamp);
}
- BTA_AgResult(BTA_AG_HANDLE_ALL, BTA_AG_END_CALL_RES, NULL);
+ BTA_AgResult(BTA_AG_HANDLE_ALL, BTA_AG_END_CALL_RES, nullptr);
hf_idx = BTIF_HF_INVALID_IDX;
/* if held call was present, reset that as well */
if (((num_active + num_held) > 0) && (btif_hf_cb[idx].num_active == 0) &&
(btif_hf_cb[idx].num_held == 0) &&
(btif_hf_cb[idx].call_setup_state == BTHF_CALL_STATE_IDLE)) {
+ tBTA_AG_RES_DATA ag_res = {};
BTIF_TRACE_DEBUG(
"%s: Active/Held call notification received without call setup update",
__func__);
- memset(&ag_res, 0, sizeof(tBTA_AG_RES_DATA));
ag_res.audio_handle = BTA_AG_HANDLE_SCO_NO_CHANGE;
/* Addition call setup with the Active call
** CIND response should have been updated.
/* Ringing call changed? */
if (call_setup_state != btif_hf_cb[idx].call_setup_state) {
+ tBTA_AG_RES_DATA ag_res = {};
BTIF_TRACE_DEBUG("%s: Call setup states changed. old: %s new: %s", __func__,
dump_hf_call_state(btif_hf_cb[idx].call_setup_state),
dump_hf_call_state(call_setup_state));
- memset(&ag_res, 0, sizeof(tBTA_AG_RES_DATA));
-
switch (call_setup_state) {
case BTHF_CALL_STATE_IDLE: {
switch (btif_hf_cb[idx].call_setup_state) {
}
}
- memset(&ag_res, 0, sizeof(tBTA_AG_RES_DATA));
-
/* per the errata 2043, call=1 implies atleast one call is in progress
*(active/held)
** https://www.bluetooth.org/errata/errata_view.cfm?errata_id=2043
* Returns bt_status_t
*
******************************************************************************/
-bool btif_hf_is_call_idle(void) {
- if (bt_hf_callbacks == NULL) return true;
+bool btif_hf_is_call_idle() {
+ if (bt_hf_callbacks == nullptr) return true;
for (int i = 0; i < btif_max_hf_clients; ++i) {
if ((btif_hf_cb[i].call_setup_state != BTHF_CALL_STATE_IDLE) ||
/*******************************************************************************
*
- * Function btif_hf_call_terminated_recently
- *
- * Description Checks if a call has been terminated
- *
- * Returns bt_status_t
- *
- ******************************************************************************/
-bool btif_hf_call_terminated_recently() {
- struct timespec now;
-
- clock_gettime(CLOCK_MONOTONIC, &now);
- if (now.tv_sec <
- btif_hf_cb[0].call_end_timestamp.tv_sec + BTIF_HF_CALL_END_TIMEOUT) {
- return true;
- } else {
- btif_hf_cb[0].call_end_timestamp.tv_sec = 0;
- return false;
- }
-}
-
-/*******************************************************************************
- *
* Function cleanup
*
* Description Closes the HF interface
* Returns bt_status_t
*
******************************************************************************/
-static void cleanup(void) {
+static void cleanup() {
BTIF_TRACE_EVENT("%s", __func__);
btif_queue_cleanup(UUID_SERVCLASS_AG_HANDSFREE);
#else
btif_disable_service(BTA_HSP_SERVICE_ID);
#endif
- bt_hf_callbacks = NULL;
+ bt_hf_callbacks = nullptr;
}
}
/*****************************************************************************
* Externs
*****************************************************************************/
-extern bool btif_hf_call_terminated_recently();
extern bool check_cod(const RawAddress* remote_bdaddr, uint32_t cod);
/*****************************************************************************