* request a new channel will be made. set channel to <= 0 to
* automatically assign an channel ID.
*
- * Returns BTA_JV_SUCCESS, if the request is being processed.
- * BTA_JV_FAILURE, otherwise.
+ * Returns void
*
******************************************************************************/
-tBTA_JV_STATUS BTA_JvGetChannelId(int conn_type, uint32_t id, int32_t channel);
+void BTA_JvGetChannelId(int conn_type, uint32_t id, int32_t channel);
/*******************************************************************************
*
* established, tBTA_JV_L2CAP_CBACK is called with
* BTA_JV_L2CAP_OPEN_EVT.
*
- * Returns BTA_JV_SUCCESS, if the request is being processed.
- * BTA_JV_FAILURE, otherwise.
+ * Returns void
*
******************************************************************************/
-tBTA_JV_STATUS BTA_JvL2capStartServer(int conn_type, tBTA_SEC sec_mask,
- tBTA_JV_ROLE role,
- const tL2CAP_ERTM_INFO* ertm_info,
- uint16_t local_psm, uint16_t rx_mtu,
- tL2CAP_CFG_INFO* cfg,
- tBTA_JV_L2CAP_CBACK* p_cback,
- uint32_t l2cap_socket_id);
+void BTA_JvL2capStartServer(int conn_type, tBTA_SEC sec_mask, tBTA_JV_ROLE role,
+ std::unique_ptr<tL2CAP_ERTM_INFO> ertm_info,
+ uint16_t local_psm, uint16_t rx_mtu,
+ std::unique_ptr<tL2CAP_CFG_INFO> cfg,
+ tBTA_JV_L2CAP_CBACK* p_cback,
+ uint32_t l2cap_socket_id);
/*******************************************************************************
*
* BTA_JV_L2CAP_START_EVT. When the connection is established,
* tBTA_JV_L2CAP_CBACK is called with BTA_JV_L2CAP_OPEN_EVT.
*
- * Returns BTA_JV_SUCCESS, if the request is being processed.
- * BTA_JV_FAILURE, otherwise.
+ * Returns void
*
******************************************************************************/
-tBTA_JV_STATUS BTA_JvL2capStartServerLE(tBTA_SEC sec_mask, tBTA_JV_ROLE role,
- const tL2CAP_ERTM_INFO* ertm_info,
- uint16_t local_chan, uint16_t rx_mtu,
- tL2CAP_CFG_INFO* cfg,
- tBTA_JV_L2CAP_CBACK* p_cback,
- uint32_t l2cap_socket_id);
+void BTA_JvL2capStartServerLE(uint16_t local_chan, tBTA_JV_L2CAP_CBACK* p_cback,
+ uint32_t l2cap_socket_id);
/*******************************************************************************
*
* channel Only used for RFCOMM - to try to allocate a specific RFCOMM
* channel.
*
- * Returns BTA_JV_SUCCESS, if the request is being processed.
- * BTA_JV_FAILURE, otherwise.
+ * Returns void
*
******************************************************************************/
-tBTA_JV_STATUS BTA_JvGetChannelId(int conn_type, uint32_t id, int32_t channel) {
+void BTA_JvGetChannelId(int conn_type, uint32_t id, int32_t channel) {
VLOG(2) << __func__ << ": conn_type=" << conn_type;
if (conn_type != BTA_JV_CONN_TYPE_RFCOMM &&
conn_type != BTA_JV_CONN_TYPE_L2CAP &&
conn_type != BTA_JV_CONN_TYPE_L2CAP_LE) {
- LOG(ERROR) << __func__ << ": Invalid conn_type=" << conn_type;
- return BTA_JV_FAILURE;
+ CHECK(false) << "Invalid conn_type=" << conn_type;
}
do_in_bta_thread(FROM_HERE,
Bind(&bta_jv_get_channel_id, conn_type, channel, id, id));
- return BTA_JV_SUCCESS;
}
/*******************************************************************************
* established tBTA_JV_L2CAP_CBACK is called with
* BTA_JV_L2CAP_OPEN_EVT.
*
- * Returns BTA_JV_SUCCESS, if the request is being processed.
- * BTA_JV_FAILURE, otherwise.
+ * Returns void
*
******************************************************************************/
-tBTA_JV_STATUS BTA_JvL2capStartServer(int conn_type, tBTA_SEC sec_mask,
- tBTA_JV_ROLE role,
- const tL2CAP_ERTM_INFO* ertm_info,
- uint16_t local_psm, uint16_t rx_mtu,
- tL2CAP_CFG_INFO* cfg,
- tBTA_JV_L2CAP_CBACK* p_cback,
- uint32_t l2cap_socket_id) {
+void BTA_JvL2capStartServer(int conn_type, tBTA_SEC sec_mask, tBTA_JV_ROLE role,
+ std::unique_ptr<tL2CAP_ERTM_INFO> ertm_info,
+ uint16_t local_psm, uint16_t rx_mtu,
+ std::unique_ptr<tL2CAP_CFG_INFO> cfg,
+ tBTA_JV_L2CAP_CBACK* p_cback,
+ uint32_t l2cap_socket_id) {
VLOG(2) << __func__;
+ CHECK(p_cback);
- if (!p_cback) return BTA_JV_FAILURE; /* Nothing to do */
-
- std::unique_ptr<tL2CAP_CFG_INFO> cfg_copy;
- if (cfg) cfg_copy = std::make_unique<tL2CAP_CFG_INFO>(*cfg);
-
- std::unique_ptr<tL2CAP_ERTM_INFO> ertm_info_copy;
- if (ertm_info)
- ertm_info_copy = std::make_unique<tL2CAP_ERTM_INFO>(*ertm_info);
-
- do_in_bta_thread(
- FROM_HERE, Bind(&bta_jv_l2cap_start_server, conn_type, sec_mask, role,
- local_psm, rx_mtu, base::Passed(&cfg_copy),
- base::Passed(&ertm_info_copy), p_cback, l2cap_socket_id));
- return BTA_JV_SUCCESS;
+ do_in_bta_thread(FROM_HERE,
+ Bind(&bta_jv_l2cap_start_server, conn_type, sec_mask, role,
+ local_psm, rx_mtu, base::Passed(&cfg),
+ base::Passed(&ertm_info), p_cback, l2cap_socket_id));
}
/*******************************************************************************
* established, tBTA_JV_L2CAP_CBACK is called with
* BTA_JV_L2CAP_OPEN_EVT.
*
- * Returns BTA_JV_SUCCESS, if the request is being processed.
- * BTA_JV_FAILURE, otherwise.
+ * Returns void
*
******************************************************************************/
-tBTA_JV_STATUS BTA_JvL2capStartServerLE(tBTA_SEC sec_mask, tBTA_JV_ROLE role,
- const tL2CAP_ERTM_INFO* ertm_info,
- uint16_t local_chan, uint16_t rx_mtu,
- tL2CAP_CFG_INFO* cfg,
- tBTA_JV_L2CAP_CBACK* p_cback,
- uint32_t l2cap_socket_id) {
+void BTA_JvL2capStartServerLE(uint16_t local_chan, tBTA_JV_L2CAP_CBACK* p_cback,
+ uint32_t l2cap_socket_id) {
VLOG(2) << __func__;
-
- if (!p_cback) return BTA_JV_FAILURE; /* Nothing to do */
-
+ CHECK(p_cback);
do_in_bta_thread(FROM_HERE, Bind(&bta_jv_l2cap_start_server_le, local_chan,
p_cback, l2cap_socket_id));
-
- return BTA_JV_SUCCESS;
}
/*******************************************************************************
uint16_t mtu;
} l2cap_socket;
-static bt_status_t btSock_start_l2cap_server_l(l2cap_socket* sock);
+static void btsock_l2cap_server_listen(l2cap_socket* sock);
static std::mutex state_lock;
-1; // The fd is closed after sent to app in send_app_connect_signal()
// But for some reason we still leak a FD - either the server socket
// one or the accept socket one.
- if (btSock_start_l2cap_server_l(sock) != BT_STATUS_SUCCESS) {
- btsock_l2cap_free_l(sock);
- }
+ btsock_l2cap_server_listen(sock);
}
}
sock->channel = psm;
- if (btSock_start_l2cap_server_l(sock) != BT_STATUS_SUCCESS)
- btsock_l2cap_free_l(sock);
+ btsock_l2cap_server_listen(sock);
}
-static bt_status_t btSock_start_l2cap_server_l(l2cap_socket* sock) {
- tL2CAP_CFG_INFO cfg;
- bt_status_t stat = BT_STATUS_SUCCESS;
- /* Setup ETM settings:
- * mtu will be set below */
- memset(&cfg, 0, sizeof(tL2CAP_CFG_INFO));
-
- cfg.fcr_present = true;
- cfg.fcr = obex_l2c_fcr_opts_def;
-
+static void btsock_l2cap_server_listen(l2cap_socket* sock) {
APPL_TRACE_DEBUG("%s: fixed_chan=%d, channel=%d, is_le_coc=%d", __func__,
sock->fixed_chan, sock->channel, sock->is_le_coc);
if (sock->fixed_chan) {
- if (BTA_JvL2capStartServerLE(sock->security, 0, NULL, sock->channel,
- L2CAP_DEFAULT_MTU, NULL, btsock_l2cap_cbk,
- sock->id) != BTA_JV_SUCCESS)
- stat = BT_STATUS_FAIL;
+ BTA_JvL2capStartServerLE(sock->channel, btsock_l2cap_cbk, sock->id);
+ return;
+ }
- } else {
- /* If we have a channel specified in the request, just start the server,
- * else we request a PSM and start the server after we receive a PSM. */
- if (sock->channel <= 0) {
- if (sock->is_le_coc) {
- if (BTA_JvGetChannelId(BTA_JV_CONN_TYPE_L2CAP_LE, sock->id, 0) !=
- BTA_JV_SUCCESS)
- stat = BT_STATUS_FAIL;
- } else {
- if (BTA_JvGetChannelId(BTA_JV_CONN_TYPE_L2CAP, sock->id, 0) !=
- BTA_JV_SUCCESS)
- stat = BT_STATUS_FAIL;
- }
- } else {
- if (sock->is_le_coc) {
- if (BTA_JvL2capStartServer(BTA_JV_CONN_TYPE_L2CAP_LE, sock->security, 0,
- NULL, sock->channel, L2CAP_MAX_SDU_LENGTH,
- &cfg, btsock_l2cap_cbk,
- sock->id) != BTA_JV_SUCCESS)
- stat = BT_STATUS_FAIL;
- } else {
- if (BTA_JvL2capStartServer(BTA_JV_CONN_TYPE_L2CAP, sock->security, 0,
- &obex_l2c_etm_opt, sock->channel,
- L2CAP_MAX_SDU_LENGTH, &cfg, btsock_l2cap_cbk,
- sock->id) != BTA_JV_SUCCESS)
- stat = BT_STATUS_FAIL;
- }
- }
+ int connection_type =
+ sock->is_le_coc ? BTA_JV_CONN_TYPE_L2CAP_LE : BTA_JV_CONN_TYPE_L2CAP;
+
+ /* If we have a channel specified in the request, just start the server,
+ * else we request a PSM and start the server after we receive a PSM. */
+ if (sock->channel <= 0) {
+ BTA_JvGetChannelId(connection_type, sock->id, 0);
+ return;
+ }
+
+ /* Setup ETM settings: mtu will be set below */
+ std::unique_ptr<tL2CAP_CFG_INFO> cfg = std::make_unique<tL2CAP_CFG_INFO>(
+ tL2CAP_CFG_INFO{.fcr_present = true, .fcr = obex_l2c_fcr_opts_def});
+
+ std::unique_ptr<tL2CAP_ERTM_INFO> ertm_info;
+ if (!sock->is_le_coc) {
+ ertm_info.reset(new tL2CAP_ERTM_INFO(obex_l2c_etm_opt));
}
- return stat;
+
+ BTA_JvL2capStartServer(
+ connection_type, sock->security, 0, std::move(ertm_info), sock->channel,
+ L2CAP_MAX_SDU_LENGTH, std::move(cfg), btsock_l2cap_cbk, sock->id);
}
static bt_status_t btsock_l2cap_listen_or_connect(const char* name,
/* "role" is never initialized in rfcomm code */
if (listen) {
- bt_status_t stat = btSock_start_l2cap_server_l(sock);
- if (stat != BT_STATUS_SUCCESS) {
- btsock_l2cap_free_l(sock);
- }
+ btsock_l2cap_server_listen(sock);
} else {
if (fixed_chan) {
BTA_JvL2capConnectLE(sock->security, 0, NULL, channel, L2CAP_DEFAULT_MTU,