summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--system/stack/rfcomm/rfc_l2cap_if.cc54
1 files changed, 26 insertions, 28 deletions
diff --git a/system/stack/rfcomm/rfc_l2cap_if.cc b/system/stack/rfcomm/rfc_l2cap_if.cc
index 5b7fc00185..10826d235a 100644
--- a/system/stack/rfcomm/rfc_l2cap_if.cc
+++ b/system/stack/rfcomm/rfc_l2cap_if.cc
@@ -91,28 +91,26 @@ void rfcomm_l2cap_if_init(void) {
void RFCOMM_ConnectInd(const RawAddress& bd_addr, uint16_t lcid, uint16_t /* psm */, uint8_t id) {
tRFC_MCB* p_mcb = rfc_alloc_multiplexer_channel(bd_addr, false);
- if ((p_mcb) && (p_mcb->state != RFC_MX_STATE_IDLE)) {
- /* if this is collision case */
- if ((p_mcb->is_initiator) && (p_mcb->state == RFC_MX_STATE_WAIT_CONN_CNF)) {
- p_mcb->pending_lcid = lcid;
-
- /* wait random timeout (2 - 12) to resolve collision */
- /* if peer gives up then local device rejects incoming connection and
- * continues as initiator */
- /* if timeout, local device disconnects outgoing connection and continues
- * as acceptor */
- log::verbose(
- "RFCOMM_ConnectInd start timer for collision, initiator's "
- "LCID(0x{:x}), acceptor's LCID(0x{:x})",
- p_mcb->lcid, p_mcb->pending_lcid);
-
- rfc_timer_start(p_mcb, (uint16_t)(bluetooth::common::time_get_os_boottime_ms() % 10 + 2));
- return;
- } else {
- /* we cannot accept connection request from peer at this state */
- /* don't update lcid */
- p_mcb = nullptr;
- }
+ if (p_mcb != nullptr && p_mcb->is_initiator && p_mcb->state == RFC_MX_STATE_WAIT_CONN_CNF) {
+ p_mcb->pending_lcid = lcid;
+
+ /* wait random timeout (2 - 12) to resolve collision */
+ /* if peer gives up then local device rejects incoming connection and
+ * continues as initiator */
+ /* if timeout, local device disconnects outgoing connection and continues
+ * as acceptor */
+ log::verbose(
+ "RFCOMM_ConnectInd start timer for collision, initiator's "
+ "LCID(0x{:x}), acceptor's LCID(0x{:x})",
+ p_mcb->lcid, p_mcb->pending_lcid);
+
+ rfc_timer_start(p_mcb, (uint16_t)(bluetooth::common::time_get_os_boottime_ms() % 10 + 2));
+ return;
+ }
+ if (p_mcb != nullptr && p_mcb->is_initiator && p_mcb->state != RFC_MX_STATE_IDLE) {
+ /* we cannot accept connection request from peer at this state */
+ /* don't update lcid */
+ p_mcb = nullptr;
} else {
/* store mcb even if null */
rfc_save_lcid_mcb(p_mcb, lcid);
@@ -141,7 +139,7 @@ void RFCOMM_ConnectInd(const RawAddress& bd_addr, uint16_t lcid, uint16_t /* psm
void RFCOMM_ConnectCnf(uint16_t lcid, tL2CAP_CONN result) {
tRFC_MCB* p_mcb = rfc_find_lcid_mcb(lcid);
- if (!p_mcb) {
+ if (p_mcb == nullptr) {
log::error("RFCOMM_ConnectCnf LCID:0x{:x}", lcid);
return;
}
@@ -188,7 +186,7 @@ void RFCOMM_ConfigInd(uint16_t lcid, tL2CAP_CFG_INFO* p_cfg) {
tRFC_MCB* p_mcb = rfc_find_lcid_mcb(lcid);
- if (!p_mcb) {
+ if (p_mcb == nullptr) {
log::error("RFCOMM_ConfigInd LCID:0x{:x}", lcid);
for (auto& [cid, mcb] : rfc_lcid_mcb) {
if (mcb != nullptr && mcb->pending_lcid == lcid) {
@@ -218,7 +216,7 @@ void RFCOMM_ConfigCnf(uint16_t lcid, uint16_t /* initiator */, tL2CAP_CFG_INFO*
tRFC_MCB* p_mcb = rfc_find_lcid_mcb(lcid);
- if (!p_mcb) {
+ if (p_mcb == nullptr) {
log::error("RFCOMM_ConfigCnf no MCB LCID:0x{:x}", lcid);
return;
}
@@ -237,7 +235,7 @@ void RFCOMM_ConfigCnf(uint16_t lcid, uint16_t /* initiator */, tL2CAP_CFG_INFO*
void RFCOMM_DisconnectInd(uint16_t lcid, bool is_conf_needed) {
log::verbose("lcid:0x{:x}, is_conf_needed:{}", lcid, is_conf_needed);
tRFC_MCB* p_mcb = rfc_find_lcid_mcb(lcid);
- if (!p_mcb) {
+ if (p_mcb == nullptr) {
log::warn("no mcb for lcid 0x{:x}", lcid);
return;
}
@@ -257,7 +255,7 @@ void RFCOMM_DisconnectInd(uint16_t lcid, bool is_conf_needed) {
void RFCOMM_BufDataInd(uint16_t lcid, BT_HDR* p_buf) {
tRFC_MCB* p_mcb = rfc_find_lcid_mcb(lcid);
- if (!p_mcb) {
+ if (p_mcb == nullptr) {
log::warn("Cannot find RFCOMM multiplexer for lcid 0x{:x}", lcid);
osi_free(p_buf);
return;
@@ -351,7 +349,7 @@ void RFCOMM_BufDataInd(uint16_t lcid, BT_HDR* p_buf) {
void RFCOMM_CongestionStatusInd(uint16_t lcid, bool is_congested) {
tRFC_MCB* p_mcb = rfc_find_lcid_mcb(lcid);
- if (!p_mcb) {
+ if (p_mcb == nullptr) {
log::error("RFCOMM_CongestionStatusInd dropped LCID:0x{:x}", lcid);
return;
} else {